/* Saabsoft ERP — design system.
   One stylesheet, no preprocessor, no build step (ADR-009).
   Dense by intent: finance users compare rows, they do not scroll through cards. */

:root {
  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --surface-2: #fbfcfd;
  --border:    #e2e6ec;
  --border-2:  #cfd6e0;
  --text:      #12161d;
  --text-2:    #5b6472;
  --text-3:    #8b95a4;
  --accent:    #1d5fd0;
  --accent-2:  #e8f0fe;
  --accent-fg: #ffffff;
  --danger:    #b3261e;
  --danger-2:  #fdeceb;
  --ok:        #1a7f4b;
  --ok-2:      #e7f5ed;
  --warn:      #8a5a00;
  --warn-2:    #fdf3e0;
  --shadow:    0 1px 2px rgba(16,24,40,.06), 0 4px 12px rgba(16,24,40,.06);
  --radius:    7px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar-w: 236px;
  --header-h: 52px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --surface: #161b22; --surface-2: #1b2129;
    --border: #262d38; --border-2: #333c49;
    --text: #e6edf3; --text-2: #9aa5b1; --text-3: #6e7a89;
    --accent: #4d8bf0; --accent-2: #17233a; --accent-fg: #0b1220;
    --danger: #ff7b72; --danger-2: #2a1614;
    --ok: #48c98a; --ok-2: #10241a;
    --warn: #e3b341; --warn-2: #241d0f;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  --bg: #0e1116; --surface: #161b22; --surface-2: #1b2129;
  --border: #262d38; --border-2: #333c49;
  --text: #e6edf3; --text-2: #9aa5b1; --text-3: #6e7a89;
  --accent: #4d8bf0; --accent-2: #17233a; --accent-fg: #0b1220;
  --danger: #ff7b72; --danger-2: #2a1614;
  --ok: #48c98a; --ok-2: #10241a;
  --warn: #e3b341; --warn-2: #241d0f;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 13.5px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
/* An inline SVG with only a viewBox fills its container. Size every icon once,
   here, rather than discovering a 300px lock in the sidebar. */
.ico { width: 15px; height: 15px; flex: none; display: inline-block; vertical-align: -2px; }
a:hover { text-decoration: underline; }
h1,h2,h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 19px; } h2 { font-size: 15px; } h3 { font-size: 13px; }

/* ── numbers ──────────────────────────────────────────────────────────── */
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: .94em; }
.neg { color: var(--danger); }

/* ── layout ───────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand {
  height: var(--header-h); display: flex; align-items: center; gap: 9px;
  padding: 0 14px; border-bottom: 1px solid var(--border); flex: none;
}
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background: linear-gradient(135deg, var(--accent), #7aa5ee);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 11px;
}
.brand-name { font-weight: 650; letter-spacing: -.015em; }
.brand-name span { color: var(--text-3); font-weight: 500; }

.nav { flex: 1; overflow-y: auto; padding: 10px 8px 16px; }
.nav-section { margin-top: 12px; }
.nav-section:first-child { margin-top: 2px; }
.nav-title {
  font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3); padding: 6px 8px 4px;
}
.nav a, .nav .nav-item {
  display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 6px;
  color: var(--text-2); font-weight: 500; cursor: pointer; line-height: 1.35;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.nav .planned { color: var(--text-3); cursor: default; opacity: .75; }
.nav .planned:hover { background: none; color: var(--text-3); }
.nav .planned::after {
  content: "soon"; margin-left: auto; font-size: 9.5px; letter-spacing: .04em;
  color: var(--text-3); border: 1px solid var(--border); padding: 0 4px; border-radius: 4px;
}
.nav .ico { opacity: .8; }

.sidebar-foot { border-top: 1px solid var(--border); padding: 8px; flex: none; }

.main { display: flex; flex-direction: column; min-width: 0; }
.header {
  height: var(--header-h); display: flex; align-items: center; gap: 10px;
  padding: 0 18px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 20;
}
.header .spacer { flex: 1; }
.content { padding: 18px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.page-head .spacer { flex: 1; }
.subtle { color: var(--text-2); font-size: 12.5px; }

/* ── controls ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 11px;
  border: 1px solid var(--border-2); border-radius: 6px; background: var(--surface);
  color: var(--text); font: inherit; font-size: 12.5px; font-weight: 550; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:active { transform: translateY(.5px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); border-color: var(--accent); }
.btn-danger { color: var(--danger); border-color: var(--border-2); }
.btn-danger:hover { background: var(--danger-2); border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn-sm { height: 25px; padding: 0 8px; font-size: 12px; }

.input, .select, textarea.input {
  height: 30px; padding: 0 9px; border: 1px solid var(--border-2); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px; width: 100%;
}
textarea.input { height: auto; padding: 7px 9px; resize: vertical; }
.input:focus, .select:focus, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
.input::placeholder { color: var(--text-3); }
label.field { display: block; margin-bottom: 11px; }
label.field > span { display: block; font-size: 11.5px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.field-error { color: var(--danger); font-size: 11.5px; margin-top: 3px; }

/* ── card, table ──────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}
.card-head .spacer { flex: 1; }
.card-body { padding: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px,1fr)); gap: 14px; }

.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12.8px; }
table.tbl th, table.tbl td { padding: 7px 12px; text-align: left; border-bottom: 1px solid var(--border); }
table.tbl thead th {
  background: var(--surface-2); font-size: 11px; font-weight: 650; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .05em; white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
table.tbl thead th.sortable { cursor: pointer; user-select: none; }
table.tbl thead th.sortable:hover { color: var(--text); }
table.tbl thead th .arrow { opacity: .45; margin-left: 3px; font-size: 9px; }
table.tbl thead th.sorted .arrow { opacity: 1; color: var(--accent); }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr.clickable { cursor: pointer; }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tfoot td { font-weight: 650; background: var(--surface-2); border-top: 2px solid var(--border-2); }
.tbl-foot {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px;
  border-top: 1px solid var(--border); font-size: 12px; color: var(--text-2);
}
.tbl-foot .spacer { flex: 1; }
.tbl-toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.tbl-toolbar .search { flex: 1; max-width: 320px; }

.empty { padding: 40px 20px; text-align: center; color: var(--text-2); }
.empty h3 { margin-bottom: 5px; }
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%; animation: shimmer 1.3s ease infinite; border-radius: 4px; height: 11px;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ── badges ───────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 20px;
  font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border); white-space: nowrap;
}
.badge-ok     { background: var(--ok-2);     color: var(--ok);     border-color: transparent; }
.badge-warn   { background: var(--warn-2);   color: var(--warn);   border-color: transparent; }
.badge-danger { background: var(--danger-2); color: var(--danger); border-color: transparent; }
.badge-accent { background: var(--accent-2); color: var(--accent); border-color: transparent; }

/* ── combobox ─────────────────────────────────────────────────────────── */
.combo { position: relative; }
.combo-menu {
  position: absolute; z-index: 60; left: 0; right: 0; top: calc(100% + 3px);
  background: var(--surface); border: 1px solid var(--border-2); border-radius: 7px;
  box-shadow: var(--shadow); max-height: 260px; overflow-y: auto; padding: 4px;
}
.combo-opt { padding: 6px 9px; border-radius: 5px; cursor: pointer; }
.combo-opt small { display: block; color: var(--text-3); font-size: 11px; }
.combo-opt.on { background: var(--accent-2); }
.combo-empty { padding: 10px; color: var(--text-3); text-align: center; font-size: 12px; }

/* ── command palette ──────────────────────────────────────────────────── */
.scrim {
  position: fixed; inset: 0; background: rgba(11,16,24,.42); z-index: 100;
  display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh;
  backdrop-filter: blur(2px);
}
.palette {
  width: min(560px, 92vw); background: var(--surface); border: 1px solid var(--border-2);
  border-radius: 11px; box-shadow: 0 18px 50px rgba(0,0,0,.28); overflow: hidden;
}
.palette input {
  width: 100%; border: none; border-bottom: 1px solid var(--border); background: transparent;
  color: var(--text); font: inherit; font-size: 15px; padding: 13px 15px; outline: none;
}
.palette-list { max-height: 340px; overflow-y: auto; padding: 5px; }
.palette-item { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.palette-item.on { background: var(--accent-2); }
.palette-item .where { margin-left: auto; font-size: 11px; color: var(--text-3); }
.palette-hint { padding: 7px 13px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text-3); display: flex; gap: 12px; }
kbd {
  font: 11px var(--mono); background: var(--surface-2); border: 1px solid var(--border);
  border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; color: var(--text-2);
}

/* ── modal ────────────────────────────────────────────────────────────── */
.modal {
  width: min(560px, 94vw); background: var(--surface); border-radius: 11px;
  border: 1px solid var(--border-2); box-shadow: 0 18px 50px rgba(0,0,0,.28); overflow: hidden;
}
.modal-head { padding: 13px 16px; border-bottom: 1px solid var(--border); font-weight: 650; }
.modal-body { padding: 16px; max-height: 62vh; overflow-y: auto; }
.modal-foot { padding: 11px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* ── toasts ───────────────────────────────────────────────────────────── */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); border: 1px solid var(--border-2); border-left: 3px solid var(--accent);
  border-radius: 7px; box-shadow: var(--shadow); padding: 10px 13px; max-width: 380px;
  animation: rise .16s ease-out;
}
.toast.err { border-left-color: var(--danger); }
.toast.ok  { border-left-color: var(--ok); }
.toast b { display: block; margin-bottom: 2px; }
.toast span { color: var(--text-2); font-size: 12.3px; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ── login ────────────────────────────────────────────────────────────── */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: min(370px, 100%); }
.login-card .card-body { padding: 22px; }
.login-brand { display: flex; align-items: center; gap: 9px; justify-content: center; margin-bottom: 18px; }

/* ── misc ─────────────────────────────────────────────────────────────── */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 16px; align-items: baseline; }
.kv dt { color: var(--text-2); font-size: 12px; }
.kv dd { margin: 0; font-weight: 550; }
.stat { padding: 13px 15px; }
.stat .label { font-size: 11.5px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 23px; font-weight: 650; letter-spacing: -.02em; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat .note { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.banner {
  padding: 9px 13px; border-radius: 7px; font-size: 12.5px; display: flex; gap: 8px; align-items: center;
  background: var(--warn-2); color: var(--warn); border: 1px solid transparent; margin-bottom: 13px;
}
.banner.err { background: var(--danger-2); color: var(--danger); }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 14px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 90; transform: translateX(-100%); transition: transform .18s; width: var(--sidebar-w); }
  .sidebar.open { transform: none; }
  .content { padding: 13px; }
}

/* ── date picker ──────────────────────────────────────────────────────────
   A ledger date is not a birthday: what decides whether it is valid is the
   accounting period, so the grid shows period status directly. */
.dp { position: relative; display: flex; align-items: center; gap: 4px; }
.dp .input { padding-right: 4px; }
.dp-btn {
  height: 30px; width: 30px; flex: none; display: grid; place-items: center;
  border: 1px solid var(--border-2); border-radius: 6px; background: var(--surface);
  color: var(--text-2); cursor: pointer;
}
.dp-btn:hover { background: var(--surface-2); color: var(--text); }
.dp-status { margin-left: 2px; }

.dp-pop {
  position: absolute; z-index: 70; top: calc(100% + 5px); left: 0;
  background: var(--surface); border: 1px solid var(--border-2); border-radius: 9px;
  box-shadow: var(--shadow); overflow: hidden;
}
.dp-body { display: flex; }
.dp-presets {
  display: flex; flex-direction: column; gap: 2px; padding: 8px;
  border-right: 1px solid var(--border); background: var(--surface-2); min-width: 132px;
}
.dp-preset {
  text-align: left; padding: 5px 8px; border: none; background: none; border-radius: 5px;
  color: var(--text-2); font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.dp-preset:hover { background: var(--accent-2); color: var(--accent); }

.dp-cal { padding: 8px; }
.dp-head { display: flex; align-items: center; gap: 2px; margin-bottom: 6px; }
.dp-title { flex: 1; text-align: center; font-weight: 650; font-size: 12.5px; }
.dp-nav {
  border: none; background: none; color: var(--text-2); cursor: pointer;
  padding: 3px 6px; border-radius: 5px; font: inherit; line-height: 1;
}
.dp-nav:hover { background: var(--surface-2); color: var(--text); }

.dp-dow { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 2px; }
.dp-dow span {
  text-align: center; font-size: 10px; font-weight: 650; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .04em; padding: 3px 0;
}
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.dp-day {
  height: 28px; width: 30px; border: none; background: none; border-radius: 5px;
  color: var(--text); font: inherit; font-size: 12px; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.dp-day:hover:not(:disabled) { background: var(--surface-2); }
.dp-day.out { color: var(--text-3); }
.dp-day.weekend:not(.sel) { color: var(--text-3); }
.dp-day.today { box-shadow: inset 0 0 0 1px var(--accent); font-weight: 700; }
.dp-day.closed:not(.sel) { background: var(--danger-2); color: var(--danger); }
.dp-day.sel { background: var(--accent); color: #fff; font-weight: 650; }
.dp-day:disabled { opacity: .35; cursor: not-allowed; }

.dp-legend {
  display: flex; gap: 12px; margin-top: 7px; padding-top: 6px;
  border-top: 1px solid var(--border); font-size: 10.5px; color: var(--text-3);
}
.dp-legend span { display: flex; align-items: center; gap: 4px; }
.dp-swatch { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.dp-swatch.closed { background: var(--danger-2); border: 1px solid var(--danger); }
.dp-swatch.today  { box-shadow: inset 0 0 0 1px var(--accent); }

.dp-range { display: flex; flex-direction: column; gap: 7px; }
.dp-quick { display: flex; gap: 5px; flex-wrap: wrap; }

/* ── contracting: the certificate is arithmetic, so it is laid out as one ── */
table.tbl.tbl-calc td:first-child { color: var(--text-2); }
table.tbl.tbl-calc tr.row-total td { border-top: 2px solid var(--border-2); font-size: 14px; }
table.tbl tr.row-bad { background: color-mix(in srgb, var(--danger) 8%, transparent); }
.input.bad { border-color: var(--danger); }
.row-inline { display: flex; gap: 6px; align-items: center; }
.row-inline .input { flex: 1; }
label.field.check { display: flex; align-items: center; gap: 7px; margin-top: 22px; }
label.field.check > span { margin: 0; }
/* Certified against revised contract value - the number a QS looks for first. */
.meter { height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.meter-fill { height: 100%; background: var(--accent); transition: width .25s ease; }

/* ── the manual journal: analysis is asked for per line, per account ────── */
table.tbl.tbl-entry td { vertical-align: top; }
.dim-row { display: flex; flex-wrap: wrap; gap: 8px; }
.dim-row label.field.dim { margin-bottom: 0; min-width: 150px; flex: 1; }

/* ── attachments: the evidence behind a document ────────────────────────── */
.dropzone {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 12px; padding: 18px; border: 1px dashed var(--border-2);
  border-radius: 6px; color: var(--text-2); font-size: 12.5px; cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--surface-2); }
