/* Belt Collins Ops – house style.
   Reference: the BCI CRM / Data portal (brain.bcihk.net, data.bcihk.net). See DESIGN.md for the rules.
   Use the tokens below; do not hard-code colours, radii or shadows in templates. */

/* ---------- 1. Tokens ---------- */
:root {
  /* colour */
  --bg: #f5f5f7;            /* page */
  --surface: #fff;          /* cards, tables, inputs on focus */
  --surface-2: #fbfbfd;     /* sidebar, header */
  --fill: #0000000a;        /* quiet fills: inputs, hover */
  --fill-strong: #e8e8ed;   /* selected nav item */
  --line: #00000014;        /* hairlines */
  --line-strong: #d2d2d7;   /* input borders */
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #0071e3;        /* primary action, links */
  --accent-hover: #0077ed;
  --accent-soft: #0071e31f;
  --focus: #0071e32e;
  --ok: #0a7c66;      --ok-soft: #0a7c6614;
  --warn: #bf4800;    --warn-soft: #fff4e8;
  --danger: #d70015;  --danger-soft: #ff3b3014;
  --legacy: #6941c6;  --legacy-soft: #6941c614;
  /* type */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Helvetica Neue", "PingFang SC", "Microsoft YaHei", "Noto Sans", sans-serif;
  --fs-xs: 11px; --fs-sm: 12px; --fs-md: 14px; --fs-lg: 16px; --fs-h2: 17px; --fs-h1: 28px;
  /* shape */
  --r-sm: 10px; --r-md: 12px; --r-lg: 18px; --r-xl: 22px; --r-pill: 980px;
  --shadow-1: 0 1px 2px #0000000a;
  --shadow-2: 0 1px 2px #0000000a, 0 8px 24px #0000000a;
  --shadow-3: 0 1px 2px #0000000a, 0 18px 50px #00000014;
  /* space (4px grid) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px;
}

/* ---------- 2. Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: var(--fs-md)/1.55 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
h1 { font-size: var(--fs-h1); font-weight: 600; letter-spacing: -.02em; line-height: 1.2; margin: 0 0 var(--s4); }
h2 { font-size: var(--fs-h2); font-weight: 600; letter-spacing: -.01em; margin: 0 0 var(--s3); }
.muted { color: var(--muted); }
.err { color: var(--danger); }
code { font-size: .92em; background: var(--fill); padding: 1px 5px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- 3. App shell: sidebar + header ---------- */
body.shell { display: grid; grid-template-columns: 246px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface-2); border-right: 1px solid var(--line); padding: var(--s5) 10px;
  position: sticky; top: 0; height: 100vh; overflow: auto; }
.side-brand { display: flex; align-items: center; gap: 13px; padding: var(--s1) 6px 22px; color: var(--text); }
.side-brand:hover { text-decoration: none; }
.side-brand img { width: 68px; height: auto; display: block; }
.side-brand strong { display: block; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.side-brand small { display: block; font-size: var(--fs-xs); color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-top: 2px; }
.side-nav a { display: flex; align-items: center; gap: var(--s3); padding: 11px 14px; border-radius: var(--r-md);
  color: var(--text); font-size: var(--fs-md); margin-bottom: 2px; }
.side-nav a i { font-style: normal; width: 14px; text-align: center; color: var(--muted); font-size: var(--fs-sm); }
.side-nav a:hover { background: var(--fill); text-decoration: none; }
.side-nav a.on { background: var(--fill-strong); font-weight: 500; }
.side-group { font-size: var(--fs-xs); color: var(--muted); letter-spacing: .02em; padding: 14px 14px 6px; }
.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: var(--s4); padding: var(--s3) 22px; background: var(--surface-2);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.search { position: relative; flex: 1; max-width: 520px; margin: 0; }
.search input { width: 100%; border: 0; background: var(--fill); border-radius: var(--r-md); padding: 10px 64px 10px 34px; font-size: 15px; }
.search input:focus { background: var(--surface); box-shadow: 0 0 0 4px var(--focus); outline: none; }
.search-icon { position: absolute; left: var(--s3); top: 50%; transform: translateY(-50%); color: var(--muted); }
.search kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 10px; border: 1px solid var(--line-strong);
  border-radius: 4px; padding: 1px 5px; color: var(--muted); background: var(--surface); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.top-right form { margin: 0; }
.who { color: var(--muted); font-size: var(--fs-sm); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { padding: 22px 26px 40px; max-width: 1400px; }
@media (max-width: 860px) {
  body.shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content { padding: 14px; }
  .who { display: none; }
}

/* ---------- 4. Components ---------- */
/* buttons: primary (filled), light (outline-ish), ghost (text), bad (destructive), pill-btn (quiet) */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 16px; border-radius: var(--r-pill);
  border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; font: inherit; font-weight: 500;
  line-height: 1.2; transition: background .15s; }
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn.light { background: var(--surface); color: var(--accent); border-color: var(--line-strong); }
.btn.light:hover { background: var(--accent-soft); }
.btn.ghost { background: transparent; color: var(--accent); border-color: transparent; }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.bad { background: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .45; cursor: default; }
.pill-btn { border: 0; background: #0000000d; border-radius: var(--r-pill); padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; color: var(--text); }
.pill-btn:hover { background: #00000014; }
.actions { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin: var(--s3) 0; }

/* form fields */
label { display: block; font-size: var(--fs-sm); color: var(--muted); margin-bottom: 3px; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  font: inherit; background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--focus); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
textarea { min-height: 76px; }
label:has(> input[type=checkbox]) { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: var(--fs-md); margin-right: var(--s3); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--s3) var(--s4); }
.filters { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-bottom: var(--s4); }
.filters > input, .filters > select { width: auto; min-width: 140px; }
.filters > input[name=q] { min-width: 280px; }

/* cards */
.panel { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-2); padding: 18px 20px; margin-bottom: var(--s4); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: var(--s3); margin-bottom: var(--s4); }
.stat { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-2); padding: 14px 16px; }
.stat .label { font-size: var(--fs-sm); color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 500; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .value.accent { color: var(--accent); } .stat .value.warn { color: var(--warn); }

/* tables */
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border-radius: 14px;
  overflow: hidden; box-shadow: var(--shadow-1); }
table.grid th, table.grid td { border-bottom: 1px solid var(--line); padding: 9px 12px; text-align: left; vertical-align: top; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid th { background: #fafafc; font-weight: 500; color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; }
table.grid tbody tr:hover td, table.grid tr:hover > td { background: #00000005; }
.panel table.grid { box-shadow: none; border-radius: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.nowrap, table.grid td:has(> a:only-child) { white-space: nowrap; }
table.grid input, table.grid select { padding: 6px 8px; }

/* status tags */
.tag { display: inline-block; padding: 1px 9px; border-radius: var(--r-pill); font-size: var(--fs-sm); font-weight: 500;
  background: var(--fill); color: var(--muted); white-space: nowrap; }
.tag.running { background: var(--accent-soft); color: var(--accent); }
.tag.approved { background: var(--ok-soft); color: var(--ok); }
.tag.rejected, .tag.withdrawn { background: var(--danger-soft); color: var(--danger); }
.tag.legacy { background: var(--legacy-soft); color: var(--legacy); }

/* approval timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { border-left: 2px solid var(--line); padding: 0 0 var(--s3) 14px; position: relative; }
.timeline li:before { content: ""; position: absolute; left: -5px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.timeline li:last-child { padding-bottom: 0; }

/* empty state */
.empty { padding: var(--s6); text-align: center; color: var(--muted); background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }

/* language picker */
.lang-select { width: auto; padding: 4px 10px; border-radius: var(--r-pill); font-size: var(--fs-sm); cursor: pointer;
  background: var(--surface); border: 1px solid var(--line-strong); color: var(--text); }

/* ---------- 5. Sign-in (exact metrics of the CRM card: 400px wide, fields 40px, buttons 32px) ---------- */
body.on-login { font-size: 16px; line-height: 1.47; }
.login-lang { position: fixed; top: var(--s4); right: var(--s5); z-index: 2; }
.login-lang .lang-select { border: 0; box-shadow: 0 1px 2px #0000000a, 0 4px 14px #00000014; padding: 6px 12px; font-size: .82rem; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(1200px 600px at 10% -10%, #0071e314, transparent 55%),
              radial-gradient(900px 500px at 100% 0%, #34c7590f, transparent 50%), var(--bg); }
.login-card { background: var(--surface); border-radius: var(--r-xl); display: grid; gap: .35rem; width: min(400px, 92vw);
  padding: 2.1rem 1.7rem 1.6rem; box-shadow: var(--shadow-3); }
.login-brand { display: flex; align-items: center; gap: .85rem; margin-bottom: .85rem; }
.login-mark { width: 72px; height: auto; display: block; object-fit: contain; }
.login-brand strong { display: block; font-size: 1.02rem; font-weight: 700; line-height: 1.2; letter-spacing: -.02em; }
.login-brand span { display: block; font-size: .75rem; color: var(--muted); margin-top: .12rem; }
.login-card h1 { font-size: 1.85rem; letter-spacing: -.03em; margin: 0 0 .2rem; }
.login-card .lbl { font-size: .86rem; line-height: 1.3; color: var(--muted); margin: .15rem 0 0; }
.login-card .field { color: var(--text); background: var(--fill); border: 0; border-radius: var(--r-md); padding: .65rem .8rem;
  width: 100%; font: inherit; font-size: 1rem; line-height: 1.2; transition: background .2s, box-shadow .2s; }
.login-card .field:focus { background: var(--surface); box-shadow: 0 0 0 4px var(--focus); outline: none; }
.login-card .btn { width: 100%; margin-top: .45rem; border: 0; padding: .47rem .95rem; font-size: .86rem; line-height: 1.2; letter-spacing: -.01em; }
.login-card .btn.primary { background: var(--accent); color: #fff; }
.login-card .btn.primary:hover { background: var(--accent-hover); }
.login-card .btn.ghost:disabled { color: #9ca3af; background: #0000000d; opacity: 1; }
.login-msg { margin-top: .65rem; font-size: .86rem; color: var(--text); }
.login-msg.err { color: var(--danger); }
.login-msg:empty { display: none; }

/* segmented tabs (admin sub-navigation) */
.tabs { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--fill); border-radius: var(--r-md); margin-bottom: var(--s4); }
.tabs a { padding: 6px 14px; border-radius: 9px; color: var(--text); font-size: 13px; }
.tabs a:hover { text-decoration: none; background: #0000000a; }
.tabs a.on { background: var(--surface); box-shadow: var(--shadow-1); font-weight: 500; }

/* required fields and long forms */
div:has(> [required]) > label::after { content: " *"; color: var(--danger); }
form .actions.sticky { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: var(--s4) 0 var(--s2); margin: 0; }

/* key figure on a detail page */
.amount-lg { font-size: 20px; font-weight: 600; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
