@import url('https://fonts.googleapis.com/css2?family=Big+Shoulders+Display:wght@600;700&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --ink: #14171a;
  --paper: #eef1ee;
  --surface: #ffffff;
  --surface-2: #e3e8e2;
  --border: #ccd3ca;
  --text: #1b1f1d;
  --text-muted: #5b6259;
  --accent: #c0272d;
  --accent-ink: #ffffff;
  --accent-soft: #f5dcdc;
  --teal: #2c4a63;
  --teal-soft: #dde6ec;
  --ok: #2f7d4f;
  --ok-soft: #dcefe1;
  --warn: #b5651d;
  --warn-soft: #f2ddc7;
  --shadow: 0 1px 2px rgba(20,23,26,0.06), 0 6px 20px rgba(20,23,26,0.06);
  --radius: 6px;
  --font-display: 'Big Shoulders Display', 'Arial Narrow', sans-serif;
  --font-body: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #14171a; --paper: #15181a; --surface: #1c2023; --surface-2: #23282b;
    --border: #343b3d; --text: #e9ece7; --text-muted: #9aa39a;
    --accent: #e2555a; --accent-ink: #241012; --accent-soft: #3a1c1e;
    --teal: #7fa8c9; --teal-soft: #1c2733;
    --ok: #5cb37f; --ok-soft: #1a2c22; --warn: #dd9450; --warn-soft: #3a2c1a;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 6px 20px rgba(0,0,0,0.35);
  }
}
:root[data-theme="dark"] {
  --ink: #14171a; --paper: #15181a; --surface: #1c2023; --surface-2: #23282b;
  --border: #343b3d; --text: #e9ece7; --text-muted: #9aa39a;
  --accent: #e2555a; --accent-ink: #241012; --accent-soft: #3a1c1e;
  --teal: #7fa8c9; --teal-soft: #1c2733;
  --ok: #5cb37f; --ok-soft: #1a2c22; --warn: #dd9450; --warn-soft: #3a2c1a;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 6px 20px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--paper); color: var(--text); font-family: var(--font-body);
  font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; text-wrap: balance; letter-spacing: 0.2px; margin: 0; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.cap { text-transform: uppercase; letter-spacing: 0.08em; font-size: 11.5px; font-weight: 600; color: var(--text-muted); }
a { color: var(--teal); }

/* ---------- Shell: sidebar + conteúdo ---------- */
.shell { position: relative; display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  width: 248px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 0 16px; overflow: hidden;
  transition: width 0.2s ease, padding 0.2s ease;
}
.shell.sidebar-collapsed .sidebar { width: 0; padding-left: 0; padding-right: 0; border-right: none; }
.sidebar-logo { padding: 0 20px 20px; white-space: nowrap; }
.sidebar-logo .logo-chip { background: #182430; border-radius: 8px; padding: 9px 14px; display: inline-flex; align-items: center; }
.sidebar-logo .logo-chip img { height: 24px; width: auto; display: block; }

.sidebar-collapse-btn {
  position: absolute; top: 24px; left: 248px;
  width: 22px; height: 34px; border-radius: 0 6px 6px 0; background: var(--surface); border: 1px solid var(--border); border-left: none;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-muted); z-index: 5;
  transition: left 0.2s ease; font-size: 12px; padding: 0;
}
.sidebar-collapse-btn:hover { color: var(--text); background: var(--surface-2); }
.shell.sidebar-collapsed .sidebar-collapse-btn { left: 0; }

.side-nav { display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden; flex: 1; white-space: nowrap; padding-top: 4px; }
.side-nav .home-link { margin-bottom: 4px; }
.sidebar-section { border-top: 1px solid var(--border); padding-top: 6px; margin-top: 6px; }
.section-toggle {
  appearance: none; border: none; background: transparent; cursor: pointer; width: 100%;
  display: flex; align-items: center; justify-content: space-between; padding: 10px 20px;
}
.section-toggle:hover .cap { color: var(--text); }
.section-toggle .chevron { font-size: 11px; color: var(--text-muted); transition: transform 0.15s ease; }
.section-toggle[aria-expanded="true"] .chevron { transform: rotate(90deg); }
.section-body { display: none; flex-direction: column; padding-bottom: 4px; }
.section-body.open { display: flex; }

.side-link {
  appearance: none; border: none; background: transparent; cursor: pointer; text-align: left; text-decoration: none;
  display: block; width: 100%; font-family: var(--font-body); font-weight: 500; font-size: 13.3px;
  color: var(--text-muted); padding: 8px 20px 8px 32px; border-left: 3px solid transparent;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.side-link:hover { color: var(--text); background: var(--surface-2); }
.side-link[aria-selected="true"] { color: var(--accent); border-left-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.side-link:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.side-link.home-link { font-weight: 600; font-size: 14px; color: var(--text); padding: 9px 20px 9px 17px; }
.side-link.home-link[aria-selected="true"] { color: var(--accent); }

.sidebar-footer { padding: 14px 20px 0; margin-top: 10px; border-top: 1px solid var(--border); white-space: nowrap; }
.sidebar-footer .who-email { font-size: 11.5px; color: var(--text-muted); margin: 6px 0 10px; word-break: break-all; white-space: normal; }

.role-pill { display: inline-flex; align-items: center; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; padding: 3px 8px; border-radius: 999px; }
.role-pill.admin { background: var(--accent-soft); color: var(--accent); }
.role-pill.user { background: var(--teal-soft); color: var(--teal); }

.main { flex: 1; min-width: 0; padding: 28px 36px 64px; max-width: 1180px; margin: 0 auto; }
.main.home-view { max-width: none; margin: 0; padding: 0; }
@media (max-width: 880px) {
  .shell { flex-direction: column; }
  .sidebar-collapse-btn { display: none; }
  .sidebar, .shell.sidebar-collapsed .sidebar { width: 100%; padding: 12px 14px; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar-logo { padding: 0 0 10px; }
  .main { padding: 20px 18px 48px; }
}

/* ---------- Página inicial (dentro do shell) ---------- */
/* Mesmo azul-marinho da tela de login — visual único, não segue o tema claro/escuro do app.
   Precisa do `.main.home-view` (sem max-width/padding) pra preencher a largura toda ao lado do menu. */
#tab-inicio.active {
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 140% at 50% 0%, #1c2e48 0%, #101c30 55%, #0b1526 100%);
  width: 100%; min-height: 100vh;
}
.home-clean-logo { height: 87px; width: auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade 0.28s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.op-head { margin-bottom: 18px; }
.op-head h2 { font-size: 24px; }
.op-head p { margin: 4px 0 0; color: var(--text-muted); font-size: 13.5px; max-width: 62ch; }

.grid-2 { display: grid; grid-template-columns: minmax(0,1.15fr) minmax(0,0.85fr); gap: 18px; align-items: start; }
@media (max-width: 880px) { .grid-2 { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.card h3 { font-size: 12px; }
.card .card-sub { font-size: 12px; color: var(--text-muted); margin: 3px 0 14px; }

.field-row { display: grid; grid-template-columns: 1fr; gap: 12px; }
.field-cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-cols-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 520px) { .field-cols-2, .field-cols-3 { grid-template-columns: 1fr; } }

label.field { display: flex; flex-direction: column; justify-content: flex-end; gap: 5px; font-size: 12.8px; color: var(--text); }
label.field .hint { font-size: 11px; color: var(--text-muted); font-weight: 400; }

input[type="number"], input[type="text"], input[type="email"], input[type="password"], select {
  width: 100%; font-family: var(--font-mono); font-size: 13.5px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px;
  padding: 8px 10px; transition: border-color 0.15s ease, background 0.15s ease;
}
.input-wrap {
  display: flex; align-items: stretch;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.input-wrap:hover { border-color: var(--text-muted); }
.input-wrap:focus-within { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-wrap .prefix, .input-wrap .suffix {
  display: flex; align-items: center; flex-shrink: 0;
  font-family: var(--font-mono); font-size: 13px; color: var(--text-muted); white-space: nowrap;
}
.input-wrap .prefix { padding: 0 2px 0 10px; }
.input-wrap .suffix { padding: 0 10px 0 2px; }
.input-wrap input { flex: 1; min-width: 0; background: transparent; border: none; box-shadow: none; }
.input-wrap input:hover { border-color: transparent; }
.input-wrap input:focus { outline: none; }

input:hover, select:hover { border-color: var(--text-muted); }
input:focus, select:focus { outline: none; border-color: var(--accent); background: var(--surface); }
input:focus-visible, select:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) center, calc(100% - 11px) center;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 28px;
}

.checkline { display: flex; align-items: center; gap: 8px; font-size: 12.8px; }
.divider { height: 1px; background: var(--border); margin: 14px 0; border: none; }

button.btn {
  font-family: var(--font-body); font-weight: 600; font-size: 13px; border-radius: 5px; padding: 9px 16px;
  cursor: pointer; border: 1px solid transparent; transition: filter 0.15s ease, background 0.15s ease;
}
button.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.btn:active { transform: translateY(1px); }
button.btn.primary { background: var(--accent); color: var(--accent-ink); }
button.btn.primary:hover { filter: brightness(1.06); }
button.btn.primary:disabled { background: var(--ok); cursor: default; }
button.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
button.btn.ghost:hover { background: var(--surface-2); }
button.btn.danger { background: transparent; border-color: var(--warn); color: var(--warn); }
button.btn.danger:hover { background: var(--warn-soft); }

.result-card { position: sticky; top: 16px; }
.result-price { display: flex; flex-direction: column; gap: 2px; padding: 4px 0 16px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.result-price .amount { font-family: var(--font-mono); font-size: 34px; font-weight: 500; letter-spacing: -0.5px; }
.result-price .amount .cents { font-size: 20px; color: var(--text-muted); }

.burden-bar { display: flex; width: 100%; height: 14px; border-radius: 999px; overflow: hidden; background: var(--surface-2); margin: 10px 0 14px; }
.burden-bar span { height: 100%; transition: width 0.3s ease; }

table.breakdown { width: 100%; border-collapse: collapse; font-size: 12.8px; }
table.breakdown th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600; padding: 0 0 6px; border-bottom: 1px solid var(--border); }
table.breakdown td { padding: 6px 0; border-bottom: 1px dashed var(--border); }
table.breakdown td.num { text-align: right; font-family: var(--font-mono); }
table.breakdown tr.total td { border-bottom: none; border-top: 2px solid var(--border); padding-top: 9px; font-weight: 600; }
table.breakdown tr.subtle td { color: var(--text-muted); }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 7px; }

.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.stat { background: var(--surface-2); border-radius: 5px; padding: 10px 12px; }
.stat .cap { display: block; margin-bottom: 3px; }
.stat .val { font-family: var(--font-mono); font-size: 17px; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.teal { background: var(--teal-soft); color: var(--teal); }

.note { font-size: 12px; color: var(--text-muted); background: var(--surface-2); border-left: 3px solid var(--teal); border-radius: 0 5px 5px 0; padding: 8px 11px; margin-top: 12px; }
.note.warn { border-left-color: var(--warn); }
.note strong { color: var(--text); }

.cmp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .cmp-grid { grid-template-columns: 1fr; } }
.cmp-card { border-radius: var(--radius); border: 1px solid var(--border); padding: 16px; background: var(--surface); }
.cmp-card .cmp-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.cmp-card.win { border-color: var(--ok); box-shadow: 0 0 0 1px var(--ok) inset; }
.cmp-total { font-family: var(--font-mono); font-size: 26px; margin: 8px 0 2px; }
.verdict { grid-column: 1 / -1; text-align: center; padding: 16px; border-radius: var(--radius); background: var(--surface-2); font-size: 14px; margin-top: 4px; }
.verdict strong { color: var(--accent); }

.month-table-wrap { overflow-x: auto; }
table.log { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
table.log th { text-align: left; padding: 8px 10px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); border-bottom: 1px solid var(--border); }
table.log td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.log td.num { text-align: right; font-family: var(--font-mono); }
table.log tbody tr:hover { background: var(--surface-2); }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.bar-row .label { width: 190px; font-size: 12.5px; flex-shrink: 0; }
.bar-row .track { flex: 1; background: var(--surface-2); border-radius: 4px; height: 18px; position: relative; overflow: hidden; }
.bar-row .fill { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 4px; }
.bar-row .val { width: 110px; text-align: right; font-family: var(--font-mono); font-size: 12.5px; flex-shrink: 0; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); font-size: 13.5px; }

/* ---------- Login ---------- */
.login-body { background: radial-gradient(120% 140% at 50% 0%, #1c2e48 0%, #101c30 55%, #0b1526 100%); min-height: 100vh; }
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 24px; }
.login-wrap .login-logo { height: 87px; width: auto; }
.login-form { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 320px; }
.login-form label.field { color: #cdd8e8; font-size: 12.5px; }
.login-form input { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.18); color: #fff; }
.login-form input:focus { background: rgba(255,255,255,0.1); border-color: var(--accent); }
.login-error { background: rgba(224,74,79,0.15); border: 1px solid var(--accent); color: #ffd7d7; font-size: 12.8px; padding: 10px 12px; border-radius: 6px; }
.login-cta {
  margin-top: 4px; background: var(--accent); color: #fff; font-family: var(--font-body); font-weight: 600;
  font-size: 14px; padding: 12px 20px; border-radius: 6px; border: none; cursor: pointer; transition: filter 0.15s ease;
}
.login-cta:hover { filter: brightness(1.08); }

/* ---------- Admin ---------- */
table.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.admin-table th { text-align: left; padding: 8px 10px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); border-bottom: 1px solid var(--border); }
table.admin-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.admin-table input[type="text"], table.admin-table input[type="email"], table.admin-table input[type="password"] { max-width: 220px; }
.save-bar { position: sticky; bottom: 0; background: var(--paper); padding: 14px 0; margin-top: 10px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--ok); color: #fff; padding: 10px 16px; border-radius: 6px; font-size: 13px; box-shadow: var(--shadow); z-index: 50; }
.toast.error { background: var(--accent); }
