:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1c2733;
  --muted: #6b7a8d;
  --line: #e2e8f0;
  --brand: #0f766e;
  --brand-dark: #0b5a53;
  --accent: #2563eb;
  --green: #059669;
  --red: #dc2626;
  --amber: #d97706;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Segoe UI", Arial, system-ui, sans-serif; font-size: 14px;
}
a { color: var(--accent); text-decoration: none; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 210px; background: #0e1c26; color: #cbd5e1; flex-shrink: 0;
  display: flex; flex-direction: column; padding: 0;
}
.brand { padding: 18px 20px; font-weight: 700; font-size: 18px; color: #fff;
  letter-spacing: .5px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand small { display:block; font-weight: 400; font-size: 11px; color: #7f93a3; letter-spacing: 0; }
.nav a {
  display: block; padding: 11px 20px; color: #cbd5e1; border-left: 3px solid transparent;
}
.nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav a.active { background: rgba(15,118,110,.22); border-left-color: var(--brand); color: #fff; }
.nav .group { padding: 16px 20px 6px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .08em; color: #5f7284; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 54px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 22px;
}
.topbar .title { font-weight: 600; font-size: 16px; }
.topbar .user { color: var(--muted); font-size: 13px; }
.content { padding: 22px; flex: 1; }

/* Buttons */
.btn {
  background: var(--brand); color: #fff; border: none; border-radius: 6px;
  padding: 8px 14px; font-size: 13px; cursor: pointer; font-weight: 600;
}
.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: #eef2f6; color: var(--ink); }
.btn.secondary:hover { background: #e2e8f0; }
.btn.danger { background: #fee2e2; color: var(--red); }
.btn-row { display: flex; gap: 10px; margin: 14px 0; flex-wrap: wrap; align-items: center; }
.saved { color: var(--green); font-weight: 600; font-size: 13px; opacity: 0; transition: opacity .3s; }
.saved.show { opacity: 1; }

/* Cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .hint { color: var(--muted); font-size: 12.5px; margin: 0 0 12px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.kpi .value.pos { color: var(--green); } .kpi .value.neg { color: var(--red); }

/* Tables (reports) */
table.pnl { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.pnl th, table.pnl td { border: 1px solid var(--line); padding: 5px 8px; text-align: right; white-space: nowrap; }
table.pnl th:first-child, table.pnl td:first-child { text-align: left; position: sticky; left: 0; background: var(--panel); }
table.pnl thead th { background: #eef2f6; position: sticky; top: 0; }
table.pnl tr.total td { font-weight: 700; background: #f0fdfa; }
table.pnl tr.section td { background: #f8fafc; font-weight: 600; }
.num-neg { color: var(--red); }
.scroll-x { overflow-x: auto; }

/* Charts grid — two per row, ~half page each */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(560px,1fr)); gap: 20px; }
.chart-box { height: 420px; }
.chart-full { grid-column: 1 / -1; }
.chart-full .chart-box { height: 460px; }

/* View selector on reports */
.viewbar { display:flex; align-items:center; gap:10px; margin-bottom:16px; }
.viewbar select { padding:8px 12px; border:1px solid var(--line); border-radius:6px; font-size:14px; font-weight:600; background:#fff; }

/* Alert banner (e.g. lines needing a project) */
.alert { background:#fef3c7; border:1px solid #fcd34d; color:#92400e; padding:10px 14px;
  border-radius:8px; font-size:13px; margin-bottom:14px; display:none; }
.alert.show { display:block; }

/* ---- Spreadsheet grid tweaks (Tabulator) ---- */
/* Remove number spinner arrows for pure-Excel feel */
.tabulator input[type=number]::-webkit-outer-spin-button,
.tabulator input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.tabulator input[type=number] { -moz-appearance: textfield; }

/* Make the cell being edited clearly visible (white field, dark text) */
.tabulator .tabulator-cell.tabulator-editing input,
.tabulator .tabulator-cell.tabulator-editing select {
  background: #ffffff !important; color: #111827 !important; border: 1px solid var(--accent) !important;
}

/* Cells that open a dropdown look different from typed cells */
.tabulator .tabulator-cell.sel-cell { background: rgba(37,99,235,.16); cursor: pointer; }
.tabulator .tabulator-cell.sel-cell:hover { background: rgba(37,99,235,.28); }
.tabulator .tabulator-cell.sel-cell::after { content: "\25BE"; float: right; color: #93c5fd; margin-left: 6px; }

/* Monthly totals row — clearly visible */
.tabulator .tabulator-calcs-bottom,
.tabulator .tabulator-calcs-bottom .tabulator-cell {
  background: #0f766e !important; color: #ffffff !important; font-weight: 700 !important;
  border-color: #0b5a53 !important;
}

/* Range selection highlight (Excel-like) */
.tabulator .tabulator-range-overlay .tabulator-range { border: 2px solid var(--accent); }

/* jspreadsheet: keep the grid inside its card and scroll horizontally WITHIN it,
   instead of spilling over the page. */
.card .jexcel_container { max-width: 100%; }
.card .jexcel_content {
  width: 100% !important; max-width: 100%;
  overflow: auto !important; box-sizing: border-box;
}

/* Excel-style fill handle (drag the corner to fill/extend) */
.tabulator { position: relative; }
.fill-handle {
  position: absolute; width: 10px; height: 10px; background: var(--brand);
  border: 1.5px solid #fff; box-shadow: 0 0 0 1px var(--brand);
  cursor: crosshair; z-index: 30; display: none; border-radius: 1px;
}
.tabulator .tabulator-cell.fill-target {
  box-shadow: inset 0 0 0 2px var(--accent) !important;
  background: rgba(37,99,235,.14) !important;
}

/* Login */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #0e1c26; }
.login-card { background: #fff; padding: 34px; border-radius: 12px; width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p.sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.login-card label { display: block; font-size: 13px; margin: 12px 0 5px; font-weight: 600; }
.login-card input { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 14px; }
.login-card .btn { width: 100%; margin-top: 20px; padding: 11px; }
.error { background: #fee2e2; color: var(--red); padding: 10px; border-radius: 6px; font-size: 13px; margin-top: 14px; }
.field-help { color: var(--muted); font-size: 12px; margin-top: 6px; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { background: #eef2f6; border: 1px solid var(--line); padding: 7px 14px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
