:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #94a3b8;
  --line: #e6eaf2;
  --line-2: #eef1f7;
  --brand: #0e7c86;       /* teal */
  --brand-d: #0a5d65;
  --navy: #112a46;
  --accent: #f59e0b;
  --pos: #16a34a;
  --neg: #dc2626;
  --pos-soft: #e7f6ec;
  --neg-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fff3df;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
  --shadow-lg: 0 12px 40px rgba(16,24,40,.18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, button, textarea { font-family: inherit; font-size: 14px; }
h1, h2, h3 { margin: 0; }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); border-radius: var(--radius-sm); cursor: pointer; font-weight: 600;
  transition: background .12s, border-color .12s, box-shadow .12s; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--neg); border-color: var(--neg-soft); }
.btn.danger:hover { background: var(--neg-soft); }
.btn.block { width: 100%; justify-content: center; padding: 11px; }
.btn.sm { padding: 5px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--ink-2); }

/* ---------- banners ---------- */
.banner { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13.5px; margin: 10px 0; }
.banner.err { background: var(--neg-soft); color: var(--neg); }
.banner.ok { background: var(--pos-soft); color: var(--pos); }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.topbanner { margin: 0; border-radius: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #e7f1f2, var(--bg)); padding: 24px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; }
.brand-lg { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 800; color: var(--navy); justify-content: center; }
.brand-lg .logo { font-size: 26px; }
.auth-tag { text-align: center; color: var(--ink-2); margin: 8px 0 18px; font-size: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.auth-form input { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 14px; }
.auth-form input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,124,134,.12); }
.auth-links { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.auth-footer { margin-top: 20px; color: var(--muted); font-size: 12px; }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: #cdd7e4; display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 9px; padding: 6px 8px 16px; font-weight: 800; color: #fff; }
.brand .logo { font-size: 22px; }
.brand-name { font-size: 15px; letter-spacing: .2px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-foot { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid rgba(255,255,255,.08); padding-top: 8px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: var(--radius-sm); color: #cdd7e4;
  cursor: pointer; font-size: 14px; font-weight: 600; }
.nav-item:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-item .ni { width: 18px; text-align: center; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 12px 22px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.co { flex: 1; min-width: 0; }
.co-name { font-size: 17px; font-weight: 700; border: 1px solid transparent; background: transparent; padding: 5px 8px;
  border-radius: var(--radius-sm); color: var(--ink); width: 100%; max-width: 360px; }
.co-name:hover { background: var(--surface-2); }
.co-name:focus { outline: none; border-color: var(--line); background: var(--surface); }
.top-right { display: flex; align-items: center; gap: 14px; }
.save-state { font-size: 12.5px; color: var(--muted); }
.save-state.saving { color: var(--accent); }
.save-state.error { color: var(--neg); }
.user-chip { font-size: 12.5px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 20px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.view { padding: 22px; max-width: 1280px; width: 100%; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.view-head h1 { font-size: 22px; font-weight: 800; color: var(--navy); }
.view-head .sub { color: var(--ink-2); font-size: 13.5px; margin-top: 3px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { padding: 14px 18px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h3 { font-size: 15px; font-weight: 700; color: var(--navy); }
.grid { display: grid; gap: 16px; }

/* KPI cards */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi .label { font-size: 12.5px; color: var(--ink-2); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 25px; font-weight: 800; color: var(--navy); margin-top: 8px; letter-spacing: -.5px; }
.kpi .value.pos { color: var(--pos); } .kpi .value.neg { color: var(--neg); }
.kpi .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi .ico { font-size: 15px; }

.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.dash-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; }
thead th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 700;
  background: var(--surface-2); position: sticky; top: 0; }
thead th:first-child { background: var(--surface-2); z-index: 2; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:hover td:first-child { background: var(--surface-2); }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); } .neg { color: var(--neg); }

/* forecast grid */
.fc-table .grp td { background: var(--surface-2); font-weight: 700; color: var(--navy); font-size: 12px;
  text-transform: uppercase; letter-spacing: .3px; }
.fc-table .grp td:first-child { background: var(--surface-2); }
.fc-table input.cell { width: 92px; text-align: right; border: 1px solid transparent; background: transparent;
  padding: 5px 6px; border-radius: 6px; font-variant-numeric: tabular-nums; color: var(--ink); }
.fc-table input.cell:hover { border-color: var(--line); }
.fc-table input.cell:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 2px rgba(14,124,134,.12); }
.fc-table .cat-name { display: flex; align-items: center; gap: 6px; }
.fc-table .cat-name .del { color: var(--muted); cursor: pointer; opacity: 0; font-size: 12px; }
.fc-table tr:hover .cat-name .del { opacity: 1; }
.fc-table .total-row td { font-weight: 700; border-top: 2px solid var(--line); }
.fc-table .open-row td, .fc-table .close-row td { font-weight: 700; background: #f1f5f9; }
.fc-table .open-row td:first-child, .fc-table .close-row td:first-child { background: #f1f5f9; }
.fc-table .close-row td.neg { color: var(--neg); }
.fc-table .net-row td { font-weight: 700; }

.row-flex { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.pill.in { background: var(--pos-soft); color: var(--pos); }
.pill.out { background: var(--neg-soft); color: var(--neg); }
.pill.gray { background: var(--surface-2); color: var(--ink-2); }

select.input, input.input, textarea.input { padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); width: 100%; }
select.input:focus, input.input:focus, textarea.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,124,134,.1); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }

/* scenarios */
.scn-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.scn { border: 2px solid var(--line); border-radius: var(--radius); padding: 16px; cursor: pointer; background: var(--surface); }
.scn.active { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,124,134,.1); }
.scn h4 { font-size: 15px; color: var(--navy); margin-bottom: 4px; }
.scn .adj { font-size: 12.5px; color: var(--ink-2); margin-top: 8px; }
.range-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12.5px; }
.range-row input[type=range] { flex: 1; }

/* ---------- charts ---------- */
.chart { width: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- overlays / modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 16px; z-index: 100; overflow-y: auto; }
.overlay-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 760px; }
.modal-card { max-width: 560px; }
.overlay-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.overlay-head h2 { font-size: 17px; color: var(--navy); }
.overlay-head .x { cursor: pointer; color: var(--muted); font-size: 18px; }
.modal-body { padding: 20px; }
.ad-add { display: flex; gap: 8px; padding: 16px 20px 0; }
.ad-add input { flex: 1; padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.admin-card .table-wrap { padding: 12px 20px 20px; }
.ad-table th, .ad-table td { text-align: left; }
.ad-table td small { color: var(--muted); }
.b { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 700; background: var(--surface-2); color: var(--ink-2); }
.b.ok { background: var(--pos-soft); color: var(--pos); }
.b.off { background: var(--neg-soft); color: var(--neg); }
.b.warn { background: var(--warn-soft); color: var(--warn); }
.b.admin { background: #e7eefb; color: #1d4ed8; }
.comp button { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 2px 7px; cursor: pointer; margin-right: 3px; font-size: 12px; }
.comp button:hover { background: var(--surface-2); }
.ad-star { cursor: pointer; color: var(--muted); font-size: 16px; }
.ad-star.on { color: var(--accent); }
.ad-susp, .ad-reset, .ad-del { cursor: pointer; margin-left: 6px; font-size: 14px; }

/* steps (import wizard) */
.steps { display: flex; gap: 6px; margin-bottom: 16px; }
.step { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.step.on { background: var(--brand); }
.map-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.preview-table td, .preview-table th { font-size: 12px; padding: 6px 8px; }

/* toast */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff;
  padding: 11px 18px; border-radius: 24px; font-size: 13.5px; box-shadow: var(--shadow-lg); z-index: 200; }

/* gate */
.gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 24px; }
.gate-card { width: 100%; max-width: 480px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px; }
.gate-card h2 { color: var(--navy); margin-bottom: 8px; }
.plan { display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px 16px; margin: 12px 0; }
.plan .price { font-size: 20px; font-weight: 800; color: var(--navy); margin-right: 10px; }

.only-mobile { display: none; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .big { font-size: 34px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; width: 230px; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .only-mobile { display: inline-block; }
  .two-col, .dash-row { grid-template-columns: 1fr; }
  .map-grid { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, .head-actions, #trialBanner { display: none !important; }
  .app { grid-template-columns: 1fr; }
  .view { padding: 0; }
  .card { box-shadow: none; border-color: #ccc; }
  body { background: #fff; }
}
