/* Villa Santirome Insight — same palette as the original income dashboard;
   dark (navy) by default, light on request. */
:root {
  color-scheme: dark;
  --page-bg: #0b2436;
  --surface: #12303f;
  --surface-2: #102530;
  --text-primary: #f7f0e4;
  --text-secondary: #c9d8de;
  --text-muted: #8ea4ae;
  --border: rgba(247,240,228,0.12);
  --gridline: rgba(247,240,228,0.10);
  --accent-teal: #2fbfb0;
  --accent-coral: #ff6f4c;
  --meter-track: rgba(247,240,228,0.10);
  --shadow: 0 1px 2px rgba(0,0,0,0.2), 0 8px 24px rgba(0,0,0,0.3);
  --cat-1: #3987e5; --cat-2: #d95926; --cat-3: #199e70; --cat-4: #c98500; --cat-5: #9b6ad6;
  --future: rgba(57,135,229,0.45);
  --good: #4ade80; --good-bg: rgba(74,222,128,0.14);
  --bad: #f87171;  --bad-bg: rgba(248,113,113,0.14);
  --warn: #fbbf24; --warn-bg: rgba(251,191,36,0.14);
}
:root[data-theme="light"] {
  color-scheme: light;
  --page-bg: #f7f0e4;
  --surface: #ffffff;
  --surface-2: #fcfcfb;
  --text-primary: #0b2436;
  --text-secondary: #3e5568;
  --text-muted: #6b7a86;
  --border: rgba(11,36,54,0.10);
  --gridline: #e5e1d6;
  --accent-teal: #0f7a8c;
  --accent-coral: #e85a37;
  --meter-track: #ece3d2;
  --shadow: 0 1px 2px rgba(11,36,54,0.04), 0 8px 24px rgba(11,36,54,0.06);
  --cat-1: #2a78d6; --cat-2: #eb6834; --cat-3: #1baf7a; --cat-4: #eda100; --cat-5: #8b5cf6;
  --future: rgba(42,120,214,0.35);
  --good: #15803d; --good-bg: rgba(21,128,61,0.12);
  --bad: #b91c1c;  --bad-bg: rgba(185,28,28,0.12);
  --warn: #a16207; --warn-bg: rgba(161,98,7,0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page-bg); color: var(--text-primary);
  font-family: 'Manrope', system-ui, -apple-system, sans-serif; font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .display { font-family: 'Sora', system-ui, sans-serif; }
.num { font-variant-numeric: tabular-nums; }
a { color: var(--accent-teal); }
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 16px 16px 64px; }

/* ---------- header ---------- */
header.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0 14px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; }
.brand > div { min-width: 0; }
.brand img { width: 38px; height: 38px; border-radius: 22%; flex: none; }
.brand h1 { font-size: 18px; font-weight: 800; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .sub { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 700; color: var(--text-muted); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.live.on .dot { background: var(--good); box-shadow: 0 0 0 3px var(--good-bg); }
.icon-btn { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px; cursor: pointer; font-weight: 700; font-size: 12.5px; }
.menu { position: relative; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 8px; min-width: 220px; z-index: 20; }
.menu-panel .who { padding: 6px 8px 10px; font-size: 12.5px; color: var(--text-secondary); border-bottom: 1px solid var(--border); margin-bottom: 6px; word-break: break-all; }
.menu-panel button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.menu-panel button:hover { background: var(--gridline); }

/* ---------- filters + tabs ---------- */
.controls { position: sticky; top: 0; z-index: 10; background: var(--page-bg); padding: 8px 0 10px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); min-width: 0; }
.filters select, .filters input { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 7px 8px; font-size: 13px; font-weight: 600; width: 100%; min-width: 0; }
.filters .custom { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters .export { align-self: end; }
.filters .export a { display: block; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 7px 8px; font-size: 13px; font-weight: 700; text-decoration: none; }
.tabs { display: flex; gap: 6px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; background: none; border: 1px solid transparent; border-radius: 999px; padding: 7px 14px; font-weight: 700; font-size: 13px; color: var(--text-secondary); cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--surface); border-color: var(--border); color: var(--text-primary); }
.period-label { margin-top: 8px; font-size: 12px; color: var(--text-muted); font-weight: 600; }

/* ---------- sections + cards ---------- */
section { margin-bottom: 26px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.section-head h2 { font-size: 15px; font-weight: 800; margin: 0; }
.note { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 14px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 13px 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi .label { font-size: 11px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; }
.kpi .value { font-family: 'Sora', system-ui, sans-serif; font-size: 22px; font-weight: 800; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .sub { font-size: 11.5px; color: var(--text-secondary); margin-top: 3px; font-weight: 600; }
.delta { font-weight: 800; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

/* ---------- goal ---------- */
.goal-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.goal-figure { font-family: 'Sora', system-ui, sans-serif; font-size: 30px; font-weight: 800; line-height: 1.05; }
.goal-figure .of { font-size: 15px; font-weight: 700; color: var(--text-secondary); }
.goal-pct { font-size: 13px; font-weight: 800; color: var(--accent-coral); }
.meter { height: 14px; border-radius: 999px; background: var(--meter-track); overflow: hidden; position: relative; }
.meter .confirmed { position: absolute; inset: 0 auto 0 0; background: var(--future); border-radius: 999px; }
.meter .realized { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, var(--accent-teal), var(--accent-coral)); border-radius: 999px; min-width: 6px; }
.goal-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.goal-stats div { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.goal-stats strong { display: block; font-size: 15px; color: var(--text-primary); font-weight: 800; }

/* ---------- vertical bars (monthly) ---------- */
.vbars { display: flex; align-items: flex-end; gap: 6px; height: 200px; overflow-x: auto; padding-top: 18px; }
.vbar { flex: 1 0 38px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.vbar .val { font-size: 10.5px; font-weight: 700; margin-bottom: 4px; white-space: nowrap; }
.vbar .bar { width: 70%; max-width: 30px; border-radius: 5px 5px 0 0; background: var(--cat-1); min-height: 2px; }
.vbar .bar.future { background: var(--future); }
.vbar .x { margin-top: 6px; font-size: 10.5px; color: var(--text-muted); font-weight: 700; white-space: nowrap; }
.vbar .occ { font-size: 10px; color: var(--text-secondary); font-weight: 700; }
.chart-base { border-top: 1px solid var(--gridline); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 11.5px; color: var(--text-muted); font-weight: 600; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- horizontal bars ---------- */
.hbars { display: flex; flex-direction: column; gap: 12px; }
.hbar { display: grid; grid-template-columns: minmax(70px, 110px) 1fr auto; align-items: center; gap: 8px; }
.hbar .name { font-size: 12.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 18px; background: var(--gridline); border-radius: 5px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 5px; min-width: 3px; }
.hbar .amount { font-size: 12.5px; font-weight: 800; text-align: right; white-space: nowrap; }

/* ---------- unit cards ---------- */
.units { display: grid; grid-template-columns: 1fr; gap: 12px; }
.unit h3 { font-size: 15px; margin: 0 0 2px; }
.unit .type { font-size: 11.5px; color: var(--text-muted); font-weight: 600; margin-bottom: 10px; }
.mini { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
.mini div { font-size: 11.5px; color: var(--text-muted); font-weight: 600; }
.mini strong { display: block; font-size: 15px; color: var(--text-primary); font-weight: 800; }
.forward { display: flex; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); font-size: 11.5px; color: var(--text-muted); font-weight: 600; flex-wrap: wrap; }
.forward span strong { color: var(--text-primary); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { border-collapse: collapse; width: 100%; }
table.data th { text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.3px; color: var(--text-muted); font-weight: 700; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: 8px; font-size: 12.5px; border-bottom: 1px solid var(--gridline); white-space: nowrap; }
table.data td.num, table.data th.num { text-align: right; }
table.data tr.total td { font-weight: 800; border-top: 1px solid var(--border); }
.heat td.cell { text-align: center; font-weight: 800; border-radius: 6px; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.3px; }
.pill.ok { background: var(--good-bg); color: var(--good); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.status-list { display: grid; grid-template-columns: 1fr; gap: 10px; }
.empty { font-size: 12.5px; color: var(--text-muted); padding: 6px 0; }
.error-banner { background: var(--bad-bg); color: var(--bad); border-radius: 10px; padding: 10px 12px; font-weight: 700; margin-bottom: 14px; }
.loading { opacity: 0.55; transition: opacity 0.2s; }

footer { margin-top: 32px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 11.5px; color: var(--text-muted); line-height: 1.7; }

/* ---------- login + dialogs ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login .brand { margin-bottom: 18px; }
form.stack { display: flex; flex-direction: column; gap: 12px; }
form.stack label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 700; color: var(--text-secondary); }
form.stack input { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 15px; }
.btn { background: var(--accent-teal); color: #0b2436; border: 0; border-radius: 10px; padding: 11px 14px; font-weight: 800; cursor: pointer; }
:root[data-theme="light"] .btn { color: #fff; }
.form-msg { font-size: 12.5px; font-weight: 700; min-height: 1.2em; }
.form-msg.bad { color: var(--bad); }
.form-msg.ok { color: var(--good); }
dialog { background: var(--surface); color: var(--text-primary); border: 1px solid var(--border); border-radius: 14px; padding: 18px; width: min(92vw, 380px); }
dialog::backdrop { background: rgba(0,0,0,0.5); }

@media (max-width: 639px) { .live .label { display: none; } }

/* ---------- wider screens ---------- */
@media (min-width: 640px) {
  .wrap { padding: 22px 24px 72px; }
  .filters { grid-template-columns: repeat(4, minmax(0, 1fr)) auto; }
  .filters .custom { grid-column: 1 / 3; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .goal-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .units { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 980px) {
  .kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .units { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .brand h1 { font-size: 20px; }
}
