/* =====================================================================
   AT'S CONNECTION — Folha de estilo
   Identidade: "Sinal / Conexão". Indigo (#4F46E5) + Cyan (#06B6D4).
   Tipografia: Space Grotesk (títulos/números) + Inter (texto).
   Temas claro e escuro via [data-theme].
   ===================================================================== */

/* ---------- Tokens: TEMA ESCURO (padrão) ---------- */
:root,
[data-theme="dark"] {
  --bg:          #0f1117;
  --bg-grid:     rgba(255,255,255,.02);
  --surface:     #171a23;
  --surface-2:   #1e222e;
  --surface-3:   #262b39;
  --border:      #2a2f3d;
  --border-soft: #232733;
  --text:        #e6e8ef;
  --text-2:      #b6bccb;
  --muted:       #8a92a6;

  --brand:       #6366f1;
  --brand-2:     #22d3ee;
  --brand-ink:   #ffffff;
  --brand-soft:  rgba(99,102,241,.16);

  --success:     #34d399;
  --success-soft:rgba(52,211,153,.14);
  --warning:     #fbbf24;
  --warning-soft:rgba(251,191,36,.14);
  --danger:      #f87171;
  --danger-soft: rgba(248,113,113,.14);
  --info:        #38bdf8;

  --shadow:      0 10px 30px -12px rgba(0,0,0,.6);
  --shadow-sm:   0 4px 14px -8px rgba(0,0,0,.5);
  --ring:        0 0 0 3px rgba(99,102,241,.35);
}

/* ---------- Tokens: TEMA CLARO ---------- */
[data-theme="light"] {
  --bg:          #eef1f7;
  --bg-grid:     rgba(20,30,60,.03);
  --surface:     #ffffff;
  --surface-2:   #f4f6fb;
  --surface-3:   #eaeef6;
  --border:      #e2e6ef;
  --border-soft: #edf0f6;
  --text:        #161a25;
  --text-2:      #3c4356;
  --muted:       #6b7385;

  --brand:       #4f46e5;
  --brand-2:     #0891b2;
  --brand-ink:   #ffffff;
  --brand-soft:  rgba(79,70,229,.10);

  --success:     #059669;
  --success-soft:rgba(5,150,105,.10);
  --warning:     #d97706;
  --warning-soft:rgba(217,119,6,.12);
  --danger:      #dc2626;
  --danger-soft: rgba(220,38,38,.10);
  --info:        #0284c7;

  --shadow:      0 12px 30px -18px rgba(30,41,89,.35);
  --shadow-sm:   0 6px 16px -12px rgba(30,41,89,.30);
  --ring:        0 0 0 3px rgba(79,70,229,.25);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 34px 34px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1,h2,h3,h4,.font-display {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  letter-spacing: -.02em;
  margin: 0;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
::selection { background: var(--brand-soft); }

/* ================= LAYOUT ================= */
.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 258px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--border-soft);
}
.brand .logo {
  position: relative;
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center;
  box-shadow: 0 8px 20px -8px var(--brand);
}
.brand .logo svg { width: 22px; height: 22px; color: #fff; }
/* pulso de "sinal" — elemento assinatura */
.brand .logo::after {
  content: '';
  position: absolute; inset: -6px;
  border-radius: 16px;
  border: 2px solid var(--brand);
  opacity: 0;
  animation: signal 2.8s ease-out infinite;
}
@keyframes signal {
  0%   { transform: scale(.85); opacity: .55; }
  70%  { transform: scale(1.35); opacity: 0; }
  100% { opacity: 0; }
}
.brand .name { font-size: 16px; font-weight: 700; line-height: 1.1; }
.brand .name small { display: block; font-family: 'Inter'; font-weight: 500; font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }

.nav { padding: 14px 12px; overflow-y: auto; flex: 1; }
.nav-group { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 16px 12px 8px; font-weight: 600; }
.nav-group:first-child { margin-top: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--text-2); font-weight: 500; font-size: 14.5px;
  margin-bottom: 2px;
  transition: background .15s, color .15s;
}
.nav a svg { width: 19px; height: 19px; flex-shrink: 0; opacity: .85; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
[data-theme="light"] .nav a.active { color: var(--brand); }
.nav a.active svg { opacity: 1; }

.sidebar-foot { padding: 14px; border-top: 1px solid var(--border-soft); }
.userchip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.userchip .avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px;
  flex-shrink: 0;
}
.userchip .meta { min-width: 0; }
.userchip .meta b { font-size: 13.5px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.userchip .meta span { font-size: 11.5px; color: var(--muted); }

/* ---------- Área principal ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 66px; flex-shrink: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.topbar .page-title { font-size: 18px; font-weight: 600; }
.topbar .page-title small { display:block; font-family:'Inter'; font-weight:500; font-size:12px; color: var(--muted); letter-spacing: 0; }
.topbar .spacer { flex: 1; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  display: grid; place-items: center; cursor: pointer;
  transition: .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--brand); }
.icon-btn svg { width: 19px; height: 19px; }

.menu-toggle { display: none; }

.content { padding: 26px 24px 60px; max-width: 1320px; width: 100%; margin: 0 auto; min-width: 0; }

/* ================= COMPONENTES ================= */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}
.card-head { padding: 18px 20px; border-bottom: 1px solid var(--border-soft); display: flex; align-items: center; gap: 12px; }
.card-head h3 { font-size: 15.5px; font-weight: 600; }
.card-head .spacer { flex: 1; }
.card-body { padding: 20px; }

/* stat cards */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px,1fr)); gap: 16px; margin-bottom: 22px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 18px 16px;
  position: relative; overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.stat::before {
  content:''; position:absolute; right:-30px; top:-30px;
  width: 110px; height: 110px; border-radius: 50%;
  background: var(--accent, var(--brand-soft)); opacity:.5; filter: blur(6px);
}
.stat .ico {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; margin-bottom: 14px;
  background: var(--accent, var(--brand-soft)); color: var(--accent-ink, var(--brand));
  position: relative; z-index: 1;
}
.stat .ico svg { width: 21px; height: 21px; }
.stat .val { font-family: 'Space Grotesk'; font-size: 30px; font-weight: 700; line-height: 1; position: relative; z-index: 1; }
.stat .lbl { color: var(--muted); font-size: 13px; margin-top: 6px; position: relative; z-index: 1; }
.stat.a-brand   { --accent: var(--brand-soft);   --accent-ink: var(--brand); }
.stat.a-success { --accent: var(--success-soft); --accent-ink: var(--success); }
.stat.a-warning { --accent: var(--warning-soft); --accent-ink: var(--warning); }
.stat.a-danger  { --accent: var(--danger-soft);  --accent-ink: var(--danger); }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
/* Sem isto, um filho com tabela larga (min-width) impede a coluna de encolher
   e estoura a largura da tela no mobile. min-width:0 libera o encolhimento e
   deixa a rolagem acontecer dentro do .table-wrap. */
.grid-2 > * { min-width: 0; }
.stats > * { min-width: 0; }

/* Tabela */
.table-wrap { overflow-x: auto; border-radius: 12px; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 720px; }
table.data th, table.data td { padding: 12px 14px; text-align: left; white-space: nowrap; }
table.data thead th {
  font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  font-weight: 600; border-bottom: 1px solid var(--border);
  background: var(--surface-2); position: sticky; top: 0;
}
table.data tbody td { border-bottom: 1px solid var(--border-soft); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
.cell-name { font-weight: 600; color: var(--text); }
.cell-sub { color: var(--muted); font-size: 12.5px; }

/* Badges / pills */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.4;
  border: 1px solid transparent;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.b-success { color: var(--success); background: var(--success-soft); }
.badge.b-warning { color: var(--warning); background: var(--warning-soft); }
.badge.b-danger  { color: var(--danger);  background: var(--danger-soft); }
.badge.b-muted   { color: var(--muted);   background: var(--surface-3); }
.badge.b-brand   { color: var(--brand);   background: var(--brand-soft); }
.badge.live .dot { animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* Botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn svg { width: 17px; height: 17px; }
.btn:hover { border-color: var(--brand); }
.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: var(--brand-ink); border: none;
  box-shadow: 0 8px 20px -10px var(--brand);
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: var(--danger); color:#fff; border-color: transparent; }
.btn-sm { padding: 7px 11px; font-size: 13px; border-radius: 9px; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }

/* Formulários */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.col-2 { grid-column: span 2; }
.field.col-full { grid-column: 1 / -1; }
label.lbl { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.input, .select, textarea.input {
  width: 100%; padding: 11px 13px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 14.5px; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, textarea.input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
textarea.input { resize: vertical; min-height: 88px; }
.select { appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a92a6' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
.hint { font-size: 11.5px; color: var(--muted); }

/* Toolbar (busca + filtros) */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 18px; }
.search { position: relative; flex: 1; min-width: 200px; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.search input { padding-left: 40px; }

/* Alertas / flash */
.alert {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-radius: 12px; margin-bottom: 18px;
  font-size: 14px; font-weight: 500; border: 1px solid transparent;
}
.alert svg { width: 19px; height: 19px; flex-shrink: 0; }
.alert.success { background: var(--success-soft); color: var(--success); }
.alert.danger  { background: var(--danger-soft);  color: var(--danger); }
.alert.warning { background: var(--warning-soft); color: var(--warning); }

/* Empty state */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: .5; }
.empty h4 { color: var(--text); font-size: 16px; margin-bottom: 6px; }

/* Paginação */
.pagination { display: flex; gap: 6px; justify-content: flex-end; margin-top: 18px; }
.pagination a, .pagination span {
  min-width: 38px; height: 38px; padding: 0 10px; border-radius: 10px;
  display: grid; place-items: center; font-size: 14px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
}
.pagination a:hover { border-color: var(--brand); color: var(--text); }
.pagination .cur { background: var(--brand); color: #fff; border-color: transparent; }

/* Divisor de seção em formulário */
.form-section { grid-column: 1 / -1; margin-top: 6px; padding-top: 14px; border-top: 1px dashed var(--border); }
.form-section:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.form-section h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-family: 'Inter'; font-weight: 700; }

.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border-soft); }

/* Footer */
.foot { padding: 18px 24px; color: var(--muted); font-size: 12.5px; text-align: center; border-top: 1px solid var(--border); }
.foot b { color: var(--text-2); font-weight: 600; }

/* Backdrop mobile */
.backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 39; }

/* ================= LOGIN ================= */
.auth {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr;
}
.auth-hero {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, #4f46e5, #06b6d4 120%);
  color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-hero::before {
  content:''; position:absolute; inset:0;
  background-image: radial-gradient(circle at 25% 30%, rgba(255,255,255,.18), transparent 40%),
                    radial-gradient(circle at 80% 75%, rgba(255,255,255,.12), transparent 45%);
}
.auth-hero .badge-top { position: relative; display:inline-flex; align-items:center; gap:8px; font-weight:600; font-size:13px; }
.auth-hero h1 { position: relative; font-size: 40px; line-height: 1.08; margin: 18px 0 14px; max-width: 460px; }
.auth-hero p { position: relative; max-width: 420px; opacity: .92; font-size: 15px; }
.auth-hero .rings { position:absolute; right:-90px; bottom:-90px; width: 320px; height:320px; }
.auth-hero .rings span { position:absolute; inset:0; border:1px solid rgba(255,255,255,.25); border-radius:50%; }
.auth-hero .rings span:nth-child(2){ inset:40px; }
.auth-hero .rings span:nth-child(3){ inset:80px; }
.auth-hero .rings span:nth-child(4){ inset:120px; border-color: rgba(255,255,255,.5); }

.auth-form { display: grid; place-items: center; padding: 40px 24px; background: var(--bg); }
.auth-box { width: 100%; max-width: 380px; }
.auth-box .logo-row { display:flex; align-items:center; gap:12px; margin-bottom: 28px; }
.auth-box .logo-row .logo { width:44px;height:44px;border-radius:12px;background:linear-gradient(135deg,var(--brand),var(--brand-2));display:grid;place-items:center; box-shadow:0 8px 20px -8px var(--brand); }
.auth-box .logo-row .logo svg{ width:24px;height:24px;color:#fff; }
.auth-box h2 { font-size: 24px; margin-bottom: 6px; }
.auth-box .sub { color: var(--muted); margin-bottom: 24px; font-size: 14px; }
.auth-box .field { margin-bottom: 16px; }
.auth-box .btn-primary { width: 100%; padding: 12px; font-size: 15px; }
.auth-hint { margin-top: 20px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border:1px solid var(--border); font-size: 12.5px; color: var(--muted); }
.auth-hint b { color: var(--text-2); }
.auth .theme-fab { position: fixed; top: 20px; right: 20px; }

/* ================= RESPONSIVO ================= */
@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
}
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100vh;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .backdrop { display: block; }
  .menu-toggle { display: grid; }
  .content { padding: 18px 16px 50px; }
  .topbar { padding: 0 16px; }
  .stat .val { font-size: 26px; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }
  .field.col-2 { grid-column: 1 / -1; }
}
@media (max-width: 460px) {
  .topbar .page-title small { display: none; }
  .stats { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat .val { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
