:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #6b7684;
  --line: #e2e6ea;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --ok-bg: #e7f6ec; --ok-ink: #1f7a3d;
  --err-bg: #fdeaea; --err-ink: #b42318;
  --row-alt: #fafbfc;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:#11161c; --panel:#1a2129; --ink:#e7ecf1; --muted:#95a1ad;
    --line:#2a333d; --accent:#4a86ff; --row-alt:#1e262f;
    --ok-bg:#163224; --ok-ink:#7ee0a5; --err-bg:#3a1d1d; --err-ink:#f3a6a0;
    --shadow:none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; gap: 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 0 20px; height: 56px; position: sticky; top: 0; z-index: 10;
}
.topbar .brand a { font-weight: 700; color: var(--ink); font-size: 16px; }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { color: var(--muted); font-weight: 500; }
.topbar nav a:hover { color: var(--ink); text-decoration: none; }
.topbar .user { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 14px; }
.topbar .user .logout { color: var(--err-ink); }

.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px 64px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head h1 { margin: 2px 0; font-size: 22px; }
.back { font-size: 13px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.total-badge {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; font-size: 14px; color: var(--muted); white-space: nowrap;
}
.total-badge strong { color: var(--ink); font-size: 18px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 14px; font-size: 14px; cursor: pointer;
  font-weight: 500; text-decoration: none; line-height: 1;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-small { padding: 5px 10px; font-size: 13px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; }
.flash-success { background: var(--ok-bg); color: var(--ok-ink); }
.flash-error { background: var(--err-bg); color: var(--err-ink); }

/* cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.acc-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; color: var(--ink); box-shadow: var(--shadow); display: block;
}
.acc-card:hover { border-color: var(--accent); text-decoration: none; }
.acc-num { font-size: 12px; color: var(--muted); }
.acc-label { font-size: 18px; font-weight: 700; margin: 2px 0 8px; }
.acc-owner { font-size: 13px; color: var(--muted); }
.acc-foot { display: flex; justify-content: space-between; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

/* grid / tables */
.grid-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
table.grid { border-collapse: collapse; width: 100%; font-size: 14px; }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: 7px 10px; text-align: left; }
table.grid th { background: var(--row-alt); font-weight: 600; color: var(--muted); position: sticky; top: 0; white-space: nowrap; }
table.grid tbody tr:nth-child(even) { background: var(--row-alt); }
table.grid .rownum { color: var(--muted); width: 42px; text-align: right; font-variant-numeric: tabular-nums; }
table.grid .total-col { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
table.grid input {
  width: 100%; min-width: 64px; border: 1px solid transparent; background: transparent;
  color: var(--ink); padding: 3px 5px; border-radius: 4px; font: inherit; font-size: 13px;
}
table.grid input:focus { border-color: var(--accent); outline: none; background: var(--bg); }
table.grid input.err { border-color: var(--err-ink); background: var(--err-bg); }
table.grid.readonly td { white-space: nowrap; }
.actions { width: 40px; text-align: center; }
.del { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; line-height: 1; }
.del:hover { color: var(--err-ink); }

/* forms */
.form-narrow { max-width: 520px; }
label { display: block; margin-bottom: 12px; font-size: 14px; color: var(--muted); }
label input, label select { display: block; width: 100%; margin-top: 4px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); font: inherit; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin-right: 18px; }
label.inline input { width: auto; margin: 0; }
textarea { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); font: 13px ui-monospace, Menlo, Consolas, monospace; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filters select, .filters input { padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); font: inherit; }

.panel { margin-bottom: 18px; }
.panel > summary { display: inline-flex; list-style: none; margin-bottom: 12px; }
.panel > summary::-webkit-details-marker { display: none; }
.row-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.row-form input, .row-form select { padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); font: inherit; }
.inline-form { display: flex; gap: 6px; align-items: center; }
.inline-form input { padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--ink); font: inherit; }

.import-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.import-panel textarea { margin-bottom: 10px; }

/* login */
.login-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 32px; width: 100%; max-width: 360px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card .muted { margin: 0 0 20px; }
.login-card button { width: 100%; justify-content: center; margin-top: 6px; }

/* ---- Sheets-style grid: column colour groups ---- */
:root {
  --grp-lock:#eceff3; --grp-avl:#e6f4ea; --grp-mix:#e8f0fe;
  --grp-k50:#fef3e0; --grp-crystal:#f3e8fd;
  --grp-lock-h:#dde3ea; --grp-avl-h:#cfe9d6; --grp-mix-h:#d2e3fc;
  --grp-k50-h:#fde6c4; --grp-crystal-h:#e7d3fb;
  --suspended:#fdecec;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --grp-lock:#242c35; --grp-avl:#15301f; --grp-mix:#152338;
    --grp-k50:#33260f; --grp-crystal:#271733;
    --grp-lock-h:#2e3742; --grp-avl-h:#1d4029; --grp-mix-h:#1d3251;
    --grp-k50-h:#473413; --grp-crystal-h:#38204a;
    --suspended:#3a1d1d;
  }
}

.sheet table.grid { font-size: 13px; }
.sheet table.grid th, .sheet table.grid td {
  padding: 2px 4px; border: 1px solid var(--line); white-space: nowrap;
}
.sheet table.grid thead th { font-size: 12px; padding: 5px 6px; }

td.grp-lock, th.grp-lock { background: var(--grp-lock); }
td.grp-avl, th.grp-avl { background: var(--grp-avl); }
td.grp-mix, th.grp-mix { background: var(--grp-mix); }
td.grp-k50, th.grp-k50 { background: var(--grp-k50); }
td.grp-crystal, th.grp-crystal { background: var(--grp-crystal); }
th.grp-lock { background: var(--grp-lock-h); }
th.grp-avl { background: var(--grp-avl-h); }
th.grp-mix { background: var(--grp-mix-h); }
th.grp-k50 { background: var(--grp-k50-h); }
th.grp-crystal { background: var(--grp-crystal-h); }

/* auto-calculated columns: bold, slightly stronger tint, not editable look */
td.is-computed input, td.locked input { font-weight: 600; cursor: not-allowed; }
td.is-computed { font-weight: 600; }
td.locked input { color: var(--muted); cursor: not-allowed; }

/* suspended rows */
tr.suspended > td { background: var(--suspended) !important; }
tr.suspended td.grp-lock input { color: var(--err-ink); }

/* row-number + totals */
.sheet table.grid .rownum { position: sticky; left: 0; z-index: 2; background: var(--row-alt); }
.sheet table.grid thead .rownum { z-index: 4; }
tfoot .totals-row td { font-weight: 700; border-top: 2px solid var(--ink); background: var(--row-alt); }
tfoot .totals-row td.total-cell { text-align: right; font-variant-numeric: tabular-nums; }
.sheet .grid-wrap, .grid-wrap.sheet { max-height: 75vh; overflow: auto; }
.sheet table.grid thead th { position: sticky; top: 0; z-index: 3; }
