:root {
  --bg: #0b1320;
  --bg-2: #111c2e;
  --panel: #16233a;
  --panel-2: #1d2e49;
  --line: #26385a;
  --text: #e8eef7;
  --muted: #8ea4c4;
  --gold: #c9a84c;
  --blue: #4a8fd4;
  --green: #4cc38a;
  --red: #e2566b;
  --amber: #e0a93b;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 70% -10%, #16243c 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

/* ---------- header ---------- */
#top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 19, 32, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 14px 22px 0;
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.brand-mark {
  font-weight: 800;
  letter-spacing: 0.5px;
  font-size: 18px;
  color: var(--bg);
  background: linear-gradient(135deg, var(--gold), #e6cd83);
  padding: 8px 12px;
  border-radius: 10px;
}
.brand-text h1 { margin: 0; font-size: 19px; font-weight: 700; }
.brand-text p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

#tab-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 14px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--gold); border-bottom-color: var(--gold); }

/* ---------- layout ---------- */
#app { max-width: 1180px; margin: 0 auto; padding: 22px; }
.tab-content { display: none; animation: fade 0.25s ease; }
.tab-content.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.panel h2 { margin: 0 0 6px; font-size: 17px; }
.panel h3 { margin: 0 0 12px; font-size: 15px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.link { color: var(--blue); cursor: pointer; text-decoration: underline; }

.grid { display: grid; gap: 16px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 26px 4px 12px; }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.kpi {
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.kpi .value { font-size: 27px; font-weight: 800; margin-top: 6px; }
.kpi .sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.kpi.headline { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(201, 168, 76, 0.25); }
.kpi.headline .value { color: var(--gold); }
.val-good { color: var(--green); }
.val-bad { color: var(--red); }
.val-warn { color: var(--amber); }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; position: sticky; top: 0; }
tbody tr:hover { background: rgba(74, 143, 212, 0.07); }
.table-wrap { overflow-x: auto; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--red); }       /* positive variance = money lost */
.neg { color: var(--blue); }      /* negative variance = under-usage / recount */

/* mini bar inside a table cell */
.bar-cell { position: relative; }
.bar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(226, 86, 107, 0.16); border-right: 2px solid var(--red); z-index: 0; }
.bar-cell span { position: relative; z-index: 1; }

/* ---------- chips / pills ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.pill-red { background: rgba(226, 86, 107, 0.15); color: var(--red); }
.pill-amber { background: rgba(224, 169, 59, 0.15); color: var(--amber); }
.pill-blue { background: rgba(74, 143, 212, 0.15); color: var(--blue); }
.pill-green { background: rgba(76, 195, 138, 0.15); color: var(--green); }

/* ---------- charts ---------- */
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 340px; }

/* ---------- weekly archive tiles ---------- */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.tile {
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
}
.tile:hover { transform: translateY(-2px); border-color: var(--blue); }
.tile .t-week { font-size: 16px; font-weight: 700; }
.tile .t-var { font-size: 24px; font-weight: 800; color: var(--gold); margin-top: 8px; }
.tile .t-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- insights ---------- */
.insight {
  border-left: 3px solid var(--blue);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.insight.sev-high { border-left-color: var(--red); }
.insight.sev-med { border-left-color: var(--amber); }
.insight.sev-low { border-left-color: var(--blue); }
.insight h4 { margin: 0 0 6px; font-size: 14.5px; }
.insight p { margin: 0; font-size: 13.5px; color: var(--text); line-height: 1.55; }
.insight .imp { color: var(--gold); font-weight: 700; }

.action-list { counter-reset: act; }
.action {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.action:last-child { border-bottom: none; }
.action .n {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--gold); color: var(--bg); font-weight: 800;
  display: grid; place-items: center; font-size: 13px;
}
.action .body { font-size: 13.5px; line-height: 1.5; }

/* ---------- dropzone ---------- */
#dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 42px 20px;
  text-align: center;
  color: var(--muted);
  margin: 16px 0;
  transition: all 0.15s;
}
#dropzone.hover { border-color: var(--blue); background: rgba(74, 143, 212, 0.08); color: var(--text); }
#upload-log { font-size: 13px; color: var(--muted); }
#upload-log .ok { color: var(--green); }
#upload-log .err { color: var(--red); }

/* ---------- misc ---------- */
.back-link { color: var(--blue); cursor: pointer; font-size: 13px; font-weight: 600; }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
select, input[type="search"] {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: 9px 12px; font-size: 13.5px; font-family: inherit;
}
input[type="search"] { min-width: 240px; }
#foot { text-align: center; color: var(--muted); font-size: 12px; padding: 18px; }
.empty { text-align: center; color: var(--muted); padding: 40px; }
.spark { height: 46px; }

@media (max-width: 640px) {
  .brand-text h1 { font-size: 16px; }
  .kpi .value { font-size: 22px; }
}
