/* SLS Payment Planning portal */

:root {
  color-scheme: light;
  --surface-0: #f1f3f5;
  --surface-1: #fcfcfb;
  --surface-2: #f6f7f8;
  --border: #dcdfe3;
  --border-strong: #b9bec5;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #83837c;

  --series-1: #2a78d6;   /* receipts  */
  --series-2: #eb6834;   /* payments  */

  --good: #0f7b4f;
  --warning: #a86b00;
  --critical: #c0362c;
  --critical-bg: #fdeceb;
  --good-bg: #e9f5ef;

  --grade-a: #dc2626;
  --grade-b: #ea580c;
  --grade-c: #2563eb;
  --grade-d: #64748b;

  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .05);
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--surface-0);
  color: var(--text-primary);
}

/* ---------------- shell ---------------- */

header.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px; height: 56px;
  background: #14243b; color: #fff;
  position: sticky; top: 0; z-index: 50;
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: .3px; white-space: nowrap; }
.brand small { display: block; font-weight: 400; font-size: 11px; opacity: .7; letter-spacing: 0; }

nav.tabs { display: flex; gap: 2px; flex: 1; }
nav.tabs a {
  color: #c9d4e3; text-decoration: none; padding: 8px 14px; border-radius: 6px;
  font-weight: 500; font-size: 13px; white-space: nowrap;
}
nav.tabs a:hover { background: rgba(255,255,255,.08); color: #fff; }
nav.tabs a.active { background: #2a78d6; color: #fff; }

.syncbox { display: flex; align-items: center; gap: 10px; font-size: 12px; color: #c9d4e3; }
.syncbox b { color: #fff; font-weight: 600; }
.whoami { display: flex; align-items: center; gap: 8px; padding-left: 10px;
          border-left: 1px solid rgba(255,255,255,.18); }
.whoami a { color: #fff; text-decoration: none; font-weight: 600; white-space: nowrap; }
.whoami a:hover { text-decoration: underline; }
.whoami .role { display: block; font-weight: 400; font-size: 10.5px; opacity: .65; }

button {
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: var(--surface-1);
  color: var(--text-primary); cursor: pointer;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: #2a78d6; border-color: #2a78d6; color: #fff; }
button.primary:hover:not(:disabled) { background: #2166bb; }
button.danger { color: var(--critical); border-color: #e8b4b0; }
button.sm { padding: 3px 8px; font-size: 12px; }

main { padding: 18px 20px 60px; max-width: 1680px; margin: 0 auto; }

/* ---------------- cards ---------------- */

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px;
}
.card > h2 {
  margin: 0; padding: 12px 16px; font-size: 14px; font-weight: 600;
  border-bottom: 1px solid var(--border); display: flex; align-items: center;
  justify-content: space-between; gap: 12px;
}
.card > h2 .hint { font-weight: 400; font-size: 12px; color: var(--text-muted); }
.card .body { padding: 14px 16px; }
.card .body.flush { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.c4 { grid-template-columns: repeat(4, 1fr); }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.grid.c2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1200px) { .grid.c4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 900px) { .grid.c4, .grid.c3, .grid.c2 { grid-template-columns: 1fr; } }

/* ---------------- stat tiles ---------------- */

.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.tile .label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.tile .value { font-size: 26px; font-weight: 650; margin-top: 4px; letter-spacing: -.5px;
               font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.tile.neg .value { color: var(--critical); }
.tile.pos .value { color: var(--good); }

/* ---------------- tables ---------------- */

.tablewrap { overflow: auto; max-height: 72vh; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left;
         white-space: nowrap; }
thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2);
  font-weight: 600; font-size: 12px; color: var(--text-secondary);
  border-bottom: 1px solid var(--border-strong); cursor: pointer; user-select: none;
}
thead th.nosort { cursor: default; }
thead th .arrow { color: var(--text-muted); font-size: 10px; }
tbody tr:hover { background: #f7fafd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono);
                 font-size: 12.5px; }
td.wide { white-space: normal; min-width: 200px; }
tr.critical td { background: var(--critical-bg); }
tr.critical:hover td { background: #fbe2e0; }
tr.nonworking td { color: var(--text-muted); background: #fafafa; }
tfoot td { font-weight: 650; background: var(--surface-2); position: sticky; bottom: 0; }

.neg { color: var(--critical); }
.pos { color: var(--good); }

/* ---------------- chips & badges ---------------- */

.grade {
  display: inline-block; width: 20px; height: 20px; line-height: 20px; text-align: center;
  border-radius: 5px; color: #fff; font-weight: 700; font-size: 11px;
}
.grade.A { background: var(--grade-a); }
.grade.B { background: var(--grade-b); }
.grade.C { background: var(--grade-c); }
.grade.D { background: var(--grade-d); }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px;
  font-weight: 600; border: 1px solid;
}
.badge.pay { color: var(--good); border-color: #a9d5c1; background: var(--good-bg); }
.badge.part { color: var(--warning); border-color: #e6cc94; background: #fdf6e7; }
.badge.rolled { color: var(--text-secondary); border-color: var(--border-strong);
                background: var(--surface-2); }
.badge.unfunded { color: var(--critical); border-color: #e8b4b0; background: var(--critical-bg); }
.badge.held { color: #5b21b6; border-color: #cbb6f0; background: #f4efff; }
.badge.receipt { color: var(--series-1); border-color: #a8c9ec; background: #eaf2fc; }
.badge.master { color: var(--good); border-color: #a9d5c1; background: var(--good-bg); }
.badge.bc { color: var(--warning); border-color: #e6cc94; background: #fdf6e7; }
.badge.pinned { color: #5b21b6; border-color: #cbb6f0; background: #f4efff; }
.badge.msme { color: var(--critical); border-color: #e8b4b0; background: var(--critical-bg); }

.alert {
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 13px;
  border: 1px solid; display: flex; gap: 10px; align-items: flex-start;
}
.alert.crit { background: var(--critical-bg); border-color: #e8b4b0; color: #7f2018; }
.alert.warn { background: #fdf6e7; border-color: #e6cc94; color: #6b4400; }
.alert.info { background: #eaf2fc; border-color: #a8c9ec; color: #17457c; }
.alert.ok { background: var(--good-bg); border-color: #a9d5c1; color: #0b5537; }
.alert b { font-weight: 650; }

/* ---------------- toolbar ---------------- */

.toolbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.toolbar .spacer { flex: 1; }
input[type=text], input[type=number], input[type=date], select, textarea {
  font: inherit; font-size: 13px; padding: 5px 8px; border: 1px solid var(--border-strong);
  border-radius: 6px; background: var(--surface-1); color: var(--text-primary);
}
input:focus, select:focus { outline: 2px solid #2a78d6; outline-offset: -1px; }
input.cell { width: 74px; padding: 2px 6px; font-size: 12.5px; text-align: right;
             font-family: var(--mono); }
select.cell { padding: 2px 4px; font-size: 12.5px; }
input.notes { width: 100%; min-width: 160px; padding: 2px 6px; font-size: 12.5px; }
label.check { display: inline-flex; align-items: center; gap: 5px; font-size: 13px;
              cursor: pointer; user-select: none; }

/* ---------------- day expander ---------------- */

tr.dayrow { cursor: pointer; }
tr.dayrow td:first-child::before {
  content: "\25B8"; display: inline-block; width: 14px; color: var(--text-muted);
  transition: transform .12s;
}
tr.dayrow.open td:first-child::before { transform: rotate(90deg); }
tr.detail > td { padding: 0; background: var(--surface-2); }
tr.detail .inner { padding: 10px 14px 14px 34px; }
tr.detail h4 { margin: 10px 0 6px; font-size: 12px; color: var(--text-secondary);
               text-transform: uppercase; letter-spacing: .5px; }
tr.detail table { background: var(--surface-1); border: 1px solid var(--border);
                  border-radius: 6px; overflow: hidden; }

/* ---------------- chart ---------------- */

.chart { width: 100%; display: block; }
.chart .gridline { stroke: var(--border); stroke-width: 1; }
.chart .axis { stroke: var(--border-strong); stroke-width: 1; }
.chart .zero { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart text { fill: var(--text-secondary); font-size: 10px; font-family: inherit; }
.chart .balance { fill: none; stroke: var(--text-primary); stroke-width: 2;
                  stroke-linejoin: round; stroke-linecap: round; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hover-band { fill: rgba(42, 120, 214, .09); pointer-events: none; }

.legend { display: flex; gap: 16px; align-items: center; font-size: 12px;
          color: var(--text-secondary); padding: 0 4px 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px;
            margin-right: 6px; vertical-align: -1px; }

.tooltip {
  position: fixed; z-index: 100; pointer-events: none; background: #14243b; color: #fff;
  padding: 8px 10px; border-radius: 6px; font-size: 12px; box-shadow: 0 4px 12px rgba(0,0,0,.25);
  min-width: 150px;
}
.tooltip .tt-title { font-weight: 650; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .tt-row span:last-child { font-family: var(--mono); }
.tooltip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px;
             margin-right: 5px; }

/* ---------------- modal ---------------- */

.modal-bg {
  position: fixed; inset: 0; background: rgba(11, 20, 34, .45); z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--surface-1); border-radius: 10px; width: min(520px, 92vw);
  box-shadow: 0 12px 40px rgba(0,0,0,.28); max-height: 88vh; overflow: auto;
}
.modal h3 { margin: 0; padding: 14px 18px; border-bottom: 1px solid var(--border);
            font-size: 15px; }
.modal .body { padding: 16px 18px; }
.modal .foot { padding: 12px 18px; border-top: 1px solid var(--border);
               display: flex; gap: 8px; justify-content: flex-end; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 600;
               color: var(--text-secondary); margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; }
.field .help { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }

/* ---------------- misc ---------------- */

.subtabs { display: flex; gap: 4px; padding: 10px 16px 0; }
.subtabs button.active { background: #2a78d6; border-color: #2a78d6; color: #fff; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid #ffffff55;
           border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { padding: 40px; text-align: center; color: var(--text-muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 13px; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; }
