:root {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --border: #e6e9f1;
  --border-strong: #d5dae6;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --primary: #6366f1;
  --primary-2: #4f46e5;
  --primary-soft: #eef0ff;
  --green: #10b981;  --green-soft: #e7f8f1;  --green-text: #047857;
  --amber: #f59e0b;  --amber-soft: #fff5e3;  --amber-text: #b45309;
  --red: #ef4444;    --red-soft: #fdecec;    --red-text: #b91c1c;
  --blue: #3b82f6;   --blue-soft: #eaf2ff;   --blue-text: #1d4ed8;
  --violet-soft: #f3edff; --violet-text: #7c3aed;
  --wa: #25d366; --wa-2: #1da851;
  --sidebar: #0b1020; --sidebar-2: #151c36; --sidebar-text: #a3aec6;
  --radius: 18px; --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .05);
  --shadow-lg: 0 24px 48px rgba(16, 24, 40, .16);
  --av-bg: 92%; --av-fg: 34%;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0e19;
    --surface: #121829;
    --surface-2: #0f1424;
    --border: #222a3f;
    --border-strong: #2f3953;
    --text: #e8ecf5;
    --text-2: #c4cbdb;
    --muted: #8b95ad;
    --primary-soft: #1e2050;
    --green-soft: #0e2a21;  --green-text: #4ade80;
    --amber-soft: #2c2110;  --amber-text: #fbbf24;
    --red-soft: #2f1417;    --red-text: #f87171;
    --blue-soft: #132140;   --blue-text: #93c5fd;
    --violet-soft: #231a40; --violet-text: #c4b5fd;
    --sidebar: #070a13; --sidebar-2: #0e1428;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --av-bg: 24%; --av-fg: 82%;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; letter-spacing: -.02em; }
h1 { font-size: 26px; font-weight: 800; }
h2 { font-size: 16px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; }
p { margin: 0; }
.muted { color: var(--muted); }
.block { display: block; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }
.text-amber { color: var(--amber-text); font-weight: 600; }
.icon { width: 18px; height: 18px; flex: none; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: var(--sidebar-text);
  padding: 22px 14px;
  display: flex; flex-direction: column; gap: 6px;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px 26px; color: #fff; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, #6366f1, #22c55e);
  box-shadow: 0 10px 24px rgba(99, 102, 241, .35);
}
.brand-logo svg { width: 22px; height: 22px; }
.brand-logo.lg { width: 56px; height: 56px; border-radius: 18px; margin: 0 auto 18px; }
.brand-logo.lg svg { width: 28px; height: 28px; }
.brand-text strong { display: block; font-size: 16px; letter-spacing: -.01em; }
.brand-text small { display: block; font-size: 12px; color: var(--sidebar-text); }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a, .nav-btn {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 12px;
  font-weight: 500; font-size: 14px;
  color: var(--sidebar-text);
  transition: background .15s, color .15s;
}
.nav a:hover, .nav-btn:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active {
  background: linear-gradient(90deg, rgba(99, 102, 241, .28), rgba(99, 102, 241, .08));
  color: #fff;
  box-shadow: inset 3px 0 0 #818cf8;
}
.sidebar-foot { margin-top: auto; }
.nav-btn { width: 100%; background: none; border: 0; cursor: pointer; font-family: inherit; }

.main { padding: 32px 36px 56px; max-width: 1320px; width: 100%; }

/* ---------- Page head ---------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 24px;
}
.page-head p { margin-top: 4px; }
.head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 500; margin-bottom: 6px; }
.back:hover { color: var(--primary); }

.month-nav {
  display: flex; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 4px; box-shadow: var(--shadow);
}
.month-nav span { min-width: 136px; text-align: center; font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 11px;
  border: 1px solid transparent; cursor: pointer;
  font: 600 14px/1 Inter, system-ui, sans-serif;
  transition: transform .08s, background .15s, box-shadow .15s, border-color .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 9px; gap: 6px; }
.btn-sm .icon { width: 15px; height: 15px; }
.btn-block { width: 100%; }
.btn-primary {
  color: #fff;
  background: linear-gradient(180deg, var(--primary), var(--primary-2));
  box-shadow: 0 6px 16px rgba(79, 70, 229, .28);
}
.btn-primary:hover { box-shadow: 0 8px 22px rgba(79, 70, 229, .38); }
.btn-ghost { background: var(--surface); color: var(--text-2); border-color: var(--border); box-shadow: var(--shadow); }
.btn-ghost:hover { border-color: var(--border-strong); color: var(--text); }
.btn-wa { color: #fff; background: linear-gradient(180deg, var(--wa), var(--wa-2)); box-shadow: 0 4px 12px rgba(37, 211, 102, .28); }
.btn-wa:hover { box-shadow: 0 6px 18px rgba(37, 211, 102, .4); }
.btn-soft-green { background: var(--green-soft); color: var(--green-text); }
.btn-soft-green:hover { border-color: var(--green); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  color: var(--muted); cursor: pointer; list-style: none;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn::-webkit-details-marker { display: none; }

form.htmx-request button { opacity: .6; pointer-events: none; }
form.htmx-request .btn-wa span::after { content: "…"; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; display: flex; gap: 16px; align-items: flex-start; box-shadow: var(--shadow);
}
.stat-icon {
  width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; flex: none;
}
.stat-icon .icon { width: 21px; height: 21px; }
.ic-blue { background: var(--blue-soft); color: var(--blue-text); }
.ic-green { background: var(--green-soft); color: var(--green-text); }
.ic-amber { background: var(--amber-soft); color: var(--amber-text); }
.ic-red { background: var(--red-soft); color: var(--red-text); }
.ic-violet { background: var(--violet-soft); color: var(--violet-text); }
.ic-wa { background: var(--green-soft); color: var(--wa-2); }
.stat-body { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 800; letter-spacing: -.02em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 12px; }
.progress { height: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; margin: 6px 0 6px; }
.progress span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #34d399, #10b981); }

/* ---------- Banner ---------- */
.banner {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; margin-bottom: 18px;
  border-radius: 13px; border: 1px dashed var(--border-strong);
  color: var(--text-2); background: var(--surface);
}
.banner a { color: var(--primary); font-weight: 600; }
.banner .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.banner-on { border-style: solid; border-color: transparent; background: var(--green-soft); color: var(--green-text); }
.banner-on .dot { background: var(--green); box-shadow: 0 0 0 4px rgba(16, 185, 129, .2); animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); } }

/* ---------- Card / Table ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 10px; font-weight: 600; color: var(--muted);
}
.tabs a span {
  font-size: 11px; padding: 1px 7px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.tabs a:hover { color: var(--text); }
.tabs a.active { background: var(--primary-soft); color: var(--primary); }
.tabs a.active span { background: var(--primary); border-color: var(--primary); color: #fff; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .right { text-align: right; }
.table small { font-size: 12px; }
.row-off { opacity: .55; }

.who { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.who strong { display: block; font-weight: 600; }
.who small { display: block; color: var(--muted); font-size: 12px; }
.avatar {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
  background: hsl(var(--h) 70% var(--av-bg));
  color: hsl(var(--h) 55% var(--av-fg));
}

.actions { display: inline-flex; gap: 6px; align-items: center; justify-content: flex-end; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 99px;
  font-size: 12px; font-weight: 600; font-style: normal; white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-pago { background: var(--green-soft); color: var(--green-text); }
.pill-atrasado { background: var(--red-soft); color: var(--red-text); }
.pill-hoje { background: var(--amber-soft); color: var(--amber-text); }
.pill-pendente { background: var(--blue-soft); color: var(--blue-text); }
.pill-off { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pill-btn { border: 0; cursor: pointer; font-family: inherit; }
.pill-btn:hover { filter: brightness(.96); }
.tag { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--border); }
.error-detail { color: var(--red-text); max-width: 380px; margin-top: 4px; word-break: break-word; }

/* menu (details) */
.menu { position: relative; }
.menu[open] > summary { background: var(--surface-2); color: var(--text); }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-lg);
  text-align: left;
}
.menu-item {
  display: block; width: 100%; padding: 9px 12px; border-radius: 8px;
  background: none; border: 0; text-align: left; cursor: pointer;
  font: 500 14px Inter, system-ui, sans-serif; color: var(--text-2);
}
.menu-item:hover { background: var(--surface-2); color: var(--text); }
.menu-item.danger { color: var(--red-text); }
.menu-item.danger:hover { background: var(--red-soft); }

/* empty */
.empty { padding: 56px 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty-icon {
  width: 60px; height: 60px; border-radius: 18px; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); margin-bottom: 8px;
}
.empty-icon .icon { width: 28px; height: 28px; }
.empty .btn { margin-top: 12px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-weight: 600; font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.field small { color: var(--muted); font-size: 12px; }
input, select, textarea {
  width: 100%; font: 400 14px Inter, system-ui, sans-serif; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 11px; padding: 10px 12px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input, select { height: 42px; }
textarea { resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99, 102, 241, .15); }
.input-prefix, .input-suffix { display: flex; align-items: stretch; }
.input-prefix b, .input-suffix b {
  display: grid; place-items: center; padding: 0 12px; font-weight: 600; font-size: 13px; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border-strong); white-space: nowrap;
}
.input-prefix b { border-radius: 11px 0 0 11px; border-right: 0; }
.input-prefix input { border-radius: 0 11px 11px 0; }
.input-suffix b { border-radius: 0 11px 11px 0; border-left: 0; }
.input-suffix input { border-radius: 11px 0 0 11px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.span-2 { grid-column: span 2; }
.form-card { padding: 28px; max-width: 820px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
.danger-zone {
  max-width: 820px; margin-top: 18px; padding: 20px 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  border-color: var(--red-soft);
}
.danger-zone p { margin-top: 2px; }

.alert { padding: 12px 14px; border-radius: 11px; margin-bottom: 18px; font-weight: 500; }
.alert-erro { background: var(--red-soft); color: var(--red-text); }

.stack { display: flex; flex-direction: column; gap: 18px; }
.section { padding: 24px; }
.section-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.section-head > div:nth-child(2) { flex: 1; }
.section-head p { font-size: 13px; }
.hint { margin-top: 16px; font-size: 13px; color: var(--muted); padding: 10px 14px; border-radius: 10px; background: var(--surface-2); }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 16px; color: var(--muted); font-size: 13px; }
.chips code { padding: 3px 8px; border-radius: 7px; background: var(--violet-soft); color: var(--violet-text); }
.msgs textarea { font-size: 13px; }
.save-bar {
  position: sticky; bottom: 16px; z-index: 5;
  display: flex; justify-content: flex-end;
  padding: 12px; border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  backdrop-filter: blur(10px); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.test-card { margin-top: 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 10px; }
.inline-form input { width: 220px; }

.evo-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.qr-box {
  display: flex; align-items: center; gap: 22px; margin-bottom: 20px; padding: 18px;
  border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border);
}
.qr-box:empty { display: none; }
.qr-box img { width: 230px; height: 230px; border-radius: 12px; background: #fff; padding: 8px; flex: none; }
.qr-box p { margin-top: 6px; font-size: 13px; }
@media (max-width: 860px) { .qr-box { flex-direction: column; text-align: center; } }

/* switch */
.switch { position: relative; width: 50px; height: 28px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; border-radius: 99px; background: var(--border-strong); transition: .2s; }
.slider::before {
  content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px;
  border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); transition: .2s;
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(22px); }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 4px rgba(16, 185, 129, .25); }

/* search */
.search { position: relative; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.search input { padding-left: 36px; width: 240px; height: 40px; box-shadow: var(--shadow); border-color: var(--border); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: 20px; right: 20px; z-index: 100;
  display: flex; align-items: center; gap: 10px;
  max-width: min(440px, calc(100vw - 32px));
  padding: 13px 16px; border-radius: 13px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  font-weight: 500; cursor: pointer;
  animation: toast-in .3s ease-out, toast-out .4s ease-in 5s forwards;
}
.toast-ok .icon { color: var(--green); }
.toast-erro { border-color: var(--red); }
.toast-erro .icon { color: var(--red); }
.toast-info .icon { color: var(--blue); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); visibility: hidden; } }

/* ---------- Login ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; overflow: hidden; }
.login-bg {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(600px 400px at 15% 20%, rgba(99, 102, 241, .28), transparent 60%),
    radial-gradient(500px 400px at 85% 80%, rgba(34, 197, 94, .22), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 400px; padding: 36px 32px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 16px; text-align: center;
}
.login-card h1 { font-size: 22px; }
.login-card .field { text-align: left; }
.login-card .alert { margin: 0; }
.login-card .btn { margin-top: 6px; height: 44px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    height: auto; flex-direction: row; align-items: center; gap: 4px;
    padding: 10px 16px;
  }
  .brand { padding: 0; margin-right: 8px; }
  .brand-text { display: none; }
  .brand-logo { width: 36px; height: 36px; }
  .nav { flex-direction: row; gap: 2px; }
  .nav a, .nav-btn { padding: 9px 11px; }
  .nav a span, .nav-btn span { display: none; }
  .nav a.active { box-shadow: inset 0 -2px 0 #818cf8; }
  .sidebar-foot { margin: 0 0 0 auto; }
  .main { padding: 22px 16px 40px; }
  h1 { font-size: 22px; }
  .head-actions { width: 100%; }
  .search, .search input { width: 100%; flex: 1; }
  .grid-2 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .form-card { padding: 20px; }
  .danger-zone { flex-direction: column; align-items: flex-start; padding: 20px; }
  .actions .btn span { display: none; }
  .inline-form { width: 100%; }
  .inline-form input { width: auto; flex: 1; }
}
@media (max-width: 540px) {
  .stats { grid-template-columns: 1fr; }
  .month-nav span { min-width: 110px; }
}
