:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: rgba(11, 11, 11, 0.10);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #1baf7a;
  --accent-ink: #0b7a52;
  --accent-soft: rgba(27, 175, 122, 0.12);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: rgba(255, 255, 255, 0.10);
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --accent: #199e70;
    --accent-ink: #4fd3a3;
    --accent-soft: rgba(25, 158, 112, 0.18);
    --series-1: #3987e5;
    --series-2: #d95926;
  --series-3: #199e70;
    --good-text: #0ca30c;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: rgba(255, 255, 255, 0.10);
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --accent: #199e70;
  --accent-ink: #4fd3a3;
  --accent-soft: rgba(25, 158, 112, 0.18);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --good-text: #0ca30c;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }

/* Sidebar */
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 24px;
  padding: 20px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13px;
}
.brand-name { font-weight: 650; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border: 0; border-radius: 9px;
  background: transparent; color: var(--text-2); text-align: left;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.nav .ico { width: 18px; text-align: center; opacity: .85; }
.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 8px; }

/* Main */
.main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-label { font-size: 18px; font-weight: 650; min-width: 170px; text-align: center; }
.month-label::first-letter { text-transform: uppercase; }
.view { padding: 24px 28px 48px; max-width: 1280px; }

.icon-btn {
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 18px; line-height: 1; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); }
.btn {
  padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface);
  font-weight: 550; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--critical); }
.btn:disabled { opacity: .55; cursor: default; }

h2.section-title { font-size: 15px; font-weight: 650; margin: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; }
.page-head p { margin: 2px 0 0; color: var(--text-2); }

/* Cards & grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-sub { color: var(--muted); font-size: 12px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.cols-2 { grid-template-columns: 1.4fr 1fr; }
.cols-2-even { grid-template-columns: 1fr 1fr; }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.kpi .label { color: var(--text-2); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 650; letter-spacing: -0.01em; margin: 4px 0 2px; }
.kpi .hint { color: var(--muted); font-size: 12px; }
.kpi.hero { background: var(--accent); border-color: transparent; color: #fff; }
.kpi.hero .label, .kpi.hero .hint { color: rgba(255,255,255,.85); }
.neg { color: var(--critical); }
.kpi.hero .neg { color: #fff; }

/* Alerts */
.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border-radius: 10px;
  background: var(--surface-2); font-size: 13px;
}
.alert .badge { flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; }
.alert.critical .badge { background: var(--critical); }
.alert.warning .badge { background: var(--warning); color: #0b0b0b; }
.alert.good .badge { background: var(--good); }
.alert.info .badge { background: var(--series-1); }
.alert b { font-weight: 600; }
.empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

/* Charts */
.chart { width: 100%; display: block; overflow: visible; }
.chart text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .lbl { fill: var(--text-2); font-size: 12px; }
.chart .val { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .hit { fill: transparent; }
.chart .mark { transition: opacity .12s; }
.chart g.hov .mark { opacity: .8; }
.chart .crosshair { stroke: var(--text-2); stroke-width: 1; opacity: 0; }
.chart g.hov .crosshair { opacity: .5; }
.proj-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 14px; }
.proj-summary > div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--text-2); }
.proj-summary b.big { display: block; font-size: 18px; color: var(--text); margin-top: 2px; }
.proj-summary i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.14);
  padding: 7px 10px; font-size: 12px; max-width: 240px;
}
.tooltip b { display: block; font-weight: 600; margin-bottom: 2px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.list th { font-size: 12px; font-weight: 600; color: var(--muted); }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list td.desc { white-space: normal; min-width: 120px; }
table.list tr:last-child td { border-bottom: 0; }
table.list tfoot td { font-weight: 650; border-top: 1px solid var(--axis); border-bottom: 0; }
table.list .row-actions { text-align: right; width: 1%; }
table.list .row-actions button { opacity: .45; }
table.list tr:hover .row-actions button { opacity: 1; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--text-2); }
.pill.ok { background: rgba(12,163,12,.14); color: var(--good-text); }
.pill.late { background: rgba(208,59,59,.14); color: var(--critical); }
.pill.soon { background: rgba(250,178,25,.18); color: #8a5a00; }
:root[data-theme="dark"] .pill.soon { color: var(--warning); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pill.soon { color: var(--warning); } }
.check { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }

.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 10px; width: fit-content; margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 6px 14px; border-radius: 7px; color: var(--text-2); font-weight: 550; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Progress */
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; border-radius: 999px; background: var(--series-1); }
.progress.over > div { background: var(--critical); }
.progress.done > div { background: var(--good); }

/* Forms */
form .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
form .field label { font-size: 12px; font-weight: 600; color: var(--text-2); }
form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input[type=text], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.inline-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); margin-bottom: 12px; }
.form-preview { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.form-preview:empty { display: none; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.help { font-size: 12px; color: var(--muted); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.4); display: grid; place-items: center; padding: 16px; }
.modal-backdrop[hidden] { display: none; }
.modal { width: min(460px, 100%); max-height: 90vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px 20px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 17px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 13px; }

/* AI */
.ai-text { font-size: 14px; line-height: 1.6; }
.ai-text h3, .ai-text h4 { margin: 14px 0 6px; font-size: 14px; }
.ai-text p { margin: 0 0 8px; }
.ai-text ul, .ai-text ol { margin: 0 0 8px; padding-left: 20px; }
.ai-text li { margin-bottom: 3px; }
.ai-text code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.ai-text table { border-collapse: collapse; margin: 6px 0 10px; font-size: 13px; }
.ai-text th, .ai-text td { border: 1px solid var(--border); padding: 4px 8px; }
.ai-meta { color: var(--muted); font-size: 12px; margin-top: 8px; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

.chat { display: grid; grid-template-rows: 1fr auto; height: calc(100vh - 170px); min-height: 420px; padding: 0; overflow: hidden; }
.chat-log { overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 14px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.model { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg.error { align-self: flex-start; background: rgba(208,59,59,.12); color: var(--critical); }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: var(--surface); }
.chat-input textarea { resize: none; height: 44px; max-height: 160px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.suggestions button { border: 1px solid var(--border); background: var(--surface); padding: 7px 12px; border-radius: 999px; font-size: 13px; color: var(--text-2); }
.suggestions button:hover { border-color: var(--accent); color: var(--accent-ink); }
.chat-empty { margin: auto; text-align: center; max-width: 520px; color: var(--text-2); }
.chat-empty .big { font-size: 34px; color: var(--accent); }

.new-month { text-align: center; padding: 48px 20px; }
.new-month p { color: var(--text-2); }

@media (max-width: 960px) {
  .cols-2, .cols-2-even { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand-sub, .sidebar-foot { display: none; }
  .nav { flex-direction: row; overflow-x: auto; width: 100%; }
  .nav button { white-space: nowrap; }
  .topbar { padding: 10px 16px; }
  .view { padding: 16px 16px 40px; }
  .month-label { min-width: 120px; font-size: 16px; }
  .msg { max-width: 92%; }
  form .row { grid-template-columns: 1fr; }
}
