:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --border: #dfe2ec;
  --text: #14161f;
  --text-muted: #656d82;
  --accent-blue: #2f8fe6;
  --accent-purple: #8b5cf6;
  --accent-magenta: #d63fb0;
  --accent-orange: #e8863d;
  --success: #1a9c6e;
  --success-bg: #e3f7ef;
  --warning: #b3760a;
  --warning-bg: #fbf0dc;
  --danger: #d13f4a;
  --danger-bg: #fbe6e7;
  --sidebar-bg: #0a0d14;
  --sidebar-text: #c7cce0;
  --shadow: 0 1px 2px rgba(20, 22, 31, 0.04), 0 8px 24px -12px rgba(20, 22, 31, 0.12);
  --font-display: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display", system-ui, sans-serif;
  --font-body: -apple-system, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0d14;
    --surface: #141926;
    --surface-2: #1b2233;
    --border: #262e42;
    --text: #f3f5fa;
    --text-muted: #8d96ac;
    --success: #34d399;
    --success-bg: #12291f;
    --warning: #fbbf24;
    --warning-bg: #2c2210;
    --danger: #fb6467;
    --danger-bg: #2c1518;
    --sidebar-bg: #060810;
    --sidebar-text: #c7cce0;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px -16px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  --bg: #0a0d14;
  --surface: #141926;
  --surface-2: #1b2233;
  --border: #262e42;
  --text: #f3f5fa;
  --text-muted: #8d96ac;
  --success: #34d399;
  --success-bg: #12291f;
  --warning: #fbbf24;
  --warning-bg: #2c2210;
  --danger: #fb6467;
  --danger-bg: #2c1518;
  --sidebar-bg: #060810;
  --sidebar-text: #c7cce0;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px -16px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }

.menu-toggle { display: none; }
.sidebar-backdrop { display: none; }

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 32px;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar::before {
  content: ""; position: absolute; inset: -40% -20% auto auto; width: 340px; height: 340px;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.35), transparent 70%); pointer-events: none;
}
.sidebar::after {
  content: ""; position: absolute; inset: auto auto -30% -20%; width: 280px; height: 280px;
  background: radial-gradient(circle, rgba(47, 143, 230, 0.3), transparent 70%); pointer-events: none;
}

.brand { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.brand-mark { width: 38px; height: 38px; flex-shrink: 0; }
.brand-word { font-family: var(--font-display); font-weight: 700; font-size: 18px; color: #fff; }
.brand-word span {
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple) 45%, var(--accent-magenta) 75%, var(--accent-orange));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.nav { display: flex; flex-direction: column; gap: 2px; position: relative; z-index: 1; }
.nav-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: #565f79; margin: 14px 12px 6px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px; color: var(--sidebar-text); text-decoration: none; font-size: 14px; font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, 0.06); }
.nav a.active { background: linear-gradient(90deg, rgba(47, 143, 230, 0.22), rgba(139, 92, 246, 0.18)); color: #fff; box-shadow: inset 1px 0 0 var(--accent-purple); }

.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255, 255, 255, 0.08); display: flex; align-items: center; gap: 10px; position: relative; z-index: 1; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--accent-blue), var(--accent-magenta)); display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 700; font-size: 13px; color: #fff; flex-shrink: 0; }
.sidebar-footer .who { font-size: 13px; font-weight: 600; color: #fff; }
.sidebar-footer .plan { font-size: 12px; color: #8892ab; }

/* Media query fica depois das regras base de .sidebar de propósito: com a mesma
   especificidade (0,1,0), quem vem depois no arquivo ganha a cascata — colocar
   antes fazia a regra base (position:relative) cancelar o position:fixed daqui. */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 264px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 18px;
    margin-bottom: 14px;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 50;
  }
  .sidebar-backdrop.open { display: block; }
}

.main { padding: 28px 36px 60px; max-width: 1180px; }

.topbar { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; margin-bottom: 26px; flex-wrap: wrap; }
.topbar h1 { font-family: var(--font-display); font-size: 26px; font-weight: 700; margin: 0; text-wrap: balance; }
.topbar .sub { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

/* Fica depois das regras base de .main/.topbar de propósito — mesma
   especificidade, então precisa vir depois no arquivo pra vencer a cascata
   (mesma lição do .sidebar mais acima, agora pra essas duas). */
@media (max-width: 860px) {
  .main { padding: 20px 16px 40px; }
  .topbar h1 { font-size: 22px; }
}

/* ---------- Buttons ---------- */
.btn { font-family: var(--font-body); font-weight: 600; font-size: 13.5px; border-radius: 10px; padding: 10px 18px; border: 1px solid transparent; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; }
.btn-primary { background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple)); color: #fff; box-shadow: 0 6px 16px -6px rgba(139, 92, 246, 0.55); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.btn:focus-visible { outline: 2px solid var(--accent-purple); outline-offset: 2px; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-sm.active { background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple)); color: #fff; border-color: transparent; }

/* ---------- Status strip ---------- */
.status-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 28px; }
@media (max-width: 700px) { .status-strip { grid-template-columns: 1fr; } }
.status-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.status-card .count { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 28px; font-weight: 600; }
.status-card .label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-ok { background: var(--success); }
.dot-warn { background: var(--warning); }
.dot-danger { background: var(--danger); }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 34px 0 14px; flex-wrap: wrap; gap: 10px; }
.section-head h2 { font-family: var(--font-display); font-size: 17px; font-weight: 700; margin: 0; }

/* ---------- Lists / cards ---------- */
.customers { display: flex; flex-direction: column; gap: 10px; }
.customer { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 18px; }
@media (max-width: 760px) {
  /* minmax(0, ...) é necessário aqui: sem isso, .due/.actions ocupando as duas
     colunas fazem o grid calcular a largura como se os botões nunca quebrassem
     linha (o max-content de um flex-wrap ignora o wrap), estourando a tela. */
  .customer { grid-template-columns: minmax(0, auto) minmax(0, 1fr); }
  .customer .due, .customer .actions { grid-column: 1 / -1; min-width: 0; }
}
.customer .avatar { width: 42px; height: 42px; font-size: 14px; }
.who .name { font-weight: 600; font-size: 14.5px; }
.who .meta { color: var(--text-muted); font-size: 12.5px; font-family: var(--font-mono); display: flex; align-items: center; gap: 6px; margin-top: 2px; flex-wrap: wrap; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 5px 11px; border-radius: 999px; font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill-ok { background: var(--success-bg); color: var(--success); }
.pill-warn { background: var(--warning-bg); color: var(--warning); }
.pill-danger { background: var(--danger-bg); color: var(--danger); }
.pill-muted { background: var(--surface-2); color: var(--text-muted); font-size: 10.5px; padding: 2px 7px; }

.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); display: flex; align-items: center; justify-content: center; cursor: pointer; text-decoration: none; flex-shrink: 0; }
.wa-btn { display: inline-flex; align-items: center; gap: 4px; height: 34px; padding: 0 12px; border-radius: 9px; border: none; font-size: 12.5px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.wa-btn.sent { background: var(--border) !important; color: var(--text-muted) !important; }
.wa-btn.sent::after { content: ' ✓'; }

.empty { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.hint { font-size: 11.5px; color: var(--text-muted); }

.bulk-send-bar { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 16px; box-shadow: 0 12px 30px -10px rgba(0,0,0,0.35); align-items: center; gap: 12px; font-size: 13px; font-weight: 600; }

/* ---------- Templates ---------- */
.templates { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 760px) { .templates { grid-template-columns: 1fr; } }
.tpl-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.tpl-head { display: flex; align-items: center; gap: 8px; }
.tpl-head .swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.tpl-head .title { font-weight: 700; font-size: 13.5px; }
.tpl-card textarea { width: 100%; min-height: 110px; resize: vertical; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 10px; padding: 10px 12px; font-family: var(--font-body); font-size: 13px; line-height: 1.5; }
.tpl-card .hint { font-size: 11.5px; color: var(--text-muted); }
.tpl-card .row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.tpl-card.hoje .swatch { background: var(--success); }
.tpl-card.vence_em_breve .swatch { background: var(--warning); }
.tpl-card.venceu .swatch { background: var(--danger); }

/* ---------- Forms ---------- */
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; box-shadow: var(--shadow); max-width: 560px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.field .hint { font-size: 11.5px; color: var(--text-muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], textarea, select {
  font-family: var(--font-body); font-size: 14px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-purple); outline-offset: 1px; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }

/* ---------- Alerts ---------- */
.alert { border-radius: 10px; padding: 12px 16px; font-size: 13.5px; margin-bottom: 20px; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--danger-bg); color: var(--danger); }

/* ---------- Guest (login/register) ---------- */
.guest-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--sidebar-bg); position: relative; overflow: hidden; }
.guest-shell::before { content: ""; position: absolute; inset: -20% auto auto -10%; width: 480px; height: 480px; background: radial-gradient(circle, rgba(47, 143, 230, 0.35), transparent 70%); }
.guest-shell::after { content: ""; position: absolute; inset: auto -10% -20% auto; width: 480px; height: 480px; background: radial-gradient(circle, rgba(214, 63, 176, 0.3), transparent 70%); }
.guest-card { position: relative; z-index: 1; background: #141926; border: 1px solid #262e42; border-radius: 18px; padding: 36px; width: 100%; max-width: 380px; color: #f3f5fa; box-shadow: 0 20px 60px -20px rgba(0,0,0,0.6); }
.guest-card .brand { justify-content: center; margin-bottom: 24px; }
.guest-card h1 { font-family: var(--font-display); font-size: 20px; text-align: center; margin: 0 0 24px; }
.guest-card .field label { color: #8d96ac; }
.guest-card input { background: #1b2233; border-color: #262e42; color: #f3f5fa; }
.guest-card .btn-primary { width: 100%; justify-content: center; padding: 12px; }
.guest-card .switch { text-align: center; margin-top: 18px; font-size: 13px; color: #8d96ac; }
.guest-card .switch a { color: var(--accent-blue); font-weight: 600; text-decoration: none; }

/* ---------- Admin table ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
