:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f8f9f6;
  --border: #e2e5de;
  --text: #1b1f1c;
  --muted: #68716a;
  --accent: #0f6e4f;
  --accent-hover: #0b5a40;
  --accent-soft: #e3f1ea;
  --danger: #b4322a;
  --danger-soft: #fbe9e7;
  --warn: #9a6400;
  --warn-soft: #fdf1dc;
  --info-soft: #e7eef8;
  --sidebar: #12261e;
  --sidebar-text: #c9d6cf;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .05), 0 1px 1px rgba(16, 24, 20, .03);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1311;
    --surface: #171c19;
    --surface-2: #1c221f;
    --border: #2a322d;
    --text: #e6ebe7;
    --muted: #8d998f;
    --accent: #3fb68a;
    --accent-hover: #5cc79e;
    --accent-soft: #15302a;
    --danger: #f07a6f;
    --danger-soft: #3a1c19;
    --warn: #e6b04f;
    --warn-soft: #33280f;
    --info-soft: #18243a;
    --sidebar: #0b0f0d;
    --sidebar-text: #aebbb3;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.01em; line-height: 1.25; }
h1 a { color: inherit; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.25rem 0 .5rem; }
code { font-family: var(--mono); font-size: .85em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.danger { color: var(--danger); }
.good { color: var(--accent); }
.nowrap { white-space: nowrap; }
.strong { font-weight: 700; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 1.05rem; padding: 4px 10px 20px; }
.brand:hover { text-decoration: none; }
.brand svg { width: 26px; height: 26px; color: #5fd3a6; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .who {
  color: var(--sidebar-text); padding: 9px 12px; border-radius: 8px; font-weight: 500;
}
.nav a:hover, .who:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active, .who.active { background: rgba(95, 211, 166, .14); color: #fff; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; }
.who { display: flex; align-items: center; gap: 10px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: #2c5545; color: #fff; display: grid; place-items: center; font-size: .8rem; font-weight: 700; }
.sidebar .link-btn { color: var(--sidebar-text); padding: 6px 12px; }

.main { padding: 28px 36px 60px; max-width: 1240px; width: 100%; min-width: 0; }
.main-solo { margin: 0 auto; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.back { display: inline-block; font-size: .85rem; margin-bottom: 6px; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; margin-bottom: 18px; }
.grid-form { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, 1fr); gap: 18px; align-items: start; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; min-width: 0;
}
.grid-2 > .card, .grid-form > .card { margin-bottom: 0; }
.card-flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.card-head.pad { padding: 16px 20px 6px; }
.empty { padding: 18px 20px; margin: 0; }
.notes { white-space: pre-wrap; margin: .75rem 0 0; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow);
  border-top: 3px solid var(--border);
}
.stat-label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat-value { font-size: 1.5rem; letter-spacing: -.02em; }
.stat-sub { font-size: .82rem; color: var(--muted); }
.stat-danger { border-top-color: var(--danger); }
.stat-danger .stat-value { color: var(--danger); }
.stat-good { border-top-color: var(--accent); }
.stat-good .stat-value { color: var(--accent); }

/* ---------- lists & tables ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--border); }
.list a { display: flex; justify-content: space-between; gap: 12px; padding: 10px 2px; color: inherit; }
.list a:hover { text-decoration: none; background: var(--surface-2); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--border); border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table-click tbody tr { cursor: pointer; }
.table-click tbody tr:hover { background: var(--surface-2); }
.table td a { color: inherit; }
.table.compact th, .table.compact td { padding: 6px 4px; }
.card > .table th { background: transparent; }

.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 9px; border-radius: 99px; white-space: nowrap; vertical-align: middle; }
.badge-em_dia { background: var(--info-soft); color: var(--text); }
.badge-vence_hoje { background: var(--warn-soft); color: var(--warn); }
.badge-atrasado { background: var(--danger-soft); color: var(--danger); }
.badge-quitado { background: var(--accent-soft); color: var(--accent); }
.tag { font-size: .8rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; white-space: nowrap; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; }
.kv .strong { color: var(--text); font-size: 1.1rem; border-top: 1px solid var(--border); padding-top: 8px; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form.narrow, .narrow { max-width: 560px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: .85rem; font-weight: 600; color: var(--muted); min-width: 0; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
textarea { resize: vertical; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
legend { font-weight: 700; font-size: .9rem; padding: 0 6px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > label { flex: 1 1 140px; }
.row > .grow { flex: 2 1 220px; }
.self-end { align-self: flex-end; }
.hint { margin: 0; font-size: .82rem; color: var(--muted); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 4px; }
.quick-terms { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: -4px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 300px; }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 3px; flex-wrap: wrap; }
.tab { padding: 6px 12px; border-radius: 7px; color: var(--muted); font-weight: 600; font-size: .88rem; }
.tab:hover { text-decoration: none; color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .92rem;
  padding: 9px 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; background: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-align: left; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
.chip {
  font: inherit; font-size: .82rem; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 4px 10px; border-radius: 99px; align-self: flex-start;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- flash ---------- */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; }
.flash-ok { background: var(--accent-soft); color: var(--accent); }
.flash-erro { background: var(--danger-soft); color: var(--danger); }
.flash-info { background: var(--info-soft); color: var(--text); font-size: .88rem; }

/* ---------- login ---------- */
.login-wrap { min-height: calc(100vh - 88px); display: grid; place-items: center; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login-head { text-align: center; margin-bottom: 4px; }
.login-head svg { width: 40px; height: 40px; color: var(--accent); }
.login-head h1 { font-size: 1.3rem; margin-top: 6px; }
.login-head p { margin: 2px 0 0; }
.empty-state { text-align: center; padding: 80px 20px; }
.empty-state h1 { margin-bottom: 8px; }

.preview { position: sticky; top: 20px; }

/* ---------- responsivo ---------- */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-form { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .who-name { display: none; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; gap: 6px; }
  .brand { padding: 4px 6px; }
  .nav { flex-direction: row; overflow-x: auto; order: 3; width: 100%; }
  .nav a { white-space: nowrap; padding: 7px 10px; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; border: 0; padding: 0; align-items: center; }
  .who { padding: 4px 8px; }
  .main { padding: 18px 16px 40px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .hide-sm { display: none; }
  .stat-value { font-size: 1.25rem; }
  h1 { font-size: 1.35rem; }
  .toolbar input[type=search] { max-width: none; }
}
@media (max-width: 340px) {
  .stats { grid-template-columns: 1fr; }
}
