:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1c1b19;
  --ink-2: #57534e;
  --ink-3: #8a857e;
  --line: #e4e0d8;
  --line-2: #d4cfc5;
  --accent: #1f4fd1;
  --accent-ink: #ffffff;
  --ok: #15803d;
  --ok-bg: #e7f5ec;
  --warn: #b45309;
  --warn-bg: #fdf3e2;
  --bad: #c2261d;
  --bad-bg: #fdecea;
  --q: #6b7280;
  --q-bg: #f0efec;
  --shadow: 0 1px 2px rgba(28, 27, 25, .06), 0 2px 8px rgba(28, 27, 25, .05);
  --shadow-lg: 0 12px 40px rgba(28, 27, 25, .18);
  --radius: 10px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141412; --surface: #1d1c1a; --surface-2: #232220; --ink: #f1efea; --ink-2: #b8b3aa; --ink-3: #847f77;
    --line: #2f2d2a; --line-2: #3d3a36; --accent: #6f95ff; --accent-ink: #0b1430;
    --ok: #4ade80; --ok-bg: #12301d; --warn: #fbbf24; --warn-bg: #33270e; --bad: #f87171; --bad-bg: #3a1614;
    --q: #a1a1aa; --q-bg: #2a2927; --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 40px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141412; --surface: #1d1c1a; --surface-2: #232220; --ink: #f1efea; --ink-2: #b8b3aa; --ink-3: #847f77;
  --line: #2f2d2a; --line-2: #3d3a36; --accent: #6f95ff; --accent-ink: #0b1430;
  --ok: #4ade80; --ok-bg: #12301d; --warn: #fbbf24; --warn-bg: #33270e; --bad: #f87171; --bad-bg: #3a1614;
  --q: #a1a1aa; --q-bg: #2a2927; --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 40px rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--mono); }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 58px;
  background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--ink); display: grid; place-items: center; }
.brand-mark span { display: block; width: 12px; height: 3px; background: var(--bg); border-radius: 2px; box-shadow: 0 -5px 0 var(--bg), 0 5px 0 var(--bg); }
.nav { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--ink-2); font-weight: 500; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.on { background: var(--ink); color: var(--bg); }
.me { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.me-name { font-weight: 600; font-size: 14px; line-height: 1.1; }
.me-role { font-size: 12px; color: var(--ink-3); text-transform: capitalize; }

/* ---------- layout ---------- */
.page { max-width: 1480px; margin: 0 auto; padding: 28px 24px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; line-height: 1.15; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }
.section-title { display: flex; align-items: center; gap: 10px; margin: 30px 0 12px; font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
.section-title .count { font-family: var(--mono); background: var(--q-bg); color: var(--ink-2); border-radius: 99px; padding: 1px 8px; font-size: 12px; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line-2); background: var(--surface); font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.primary:hover { opacity: .9; }
.btn.go { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.input, select.input, textarea.input { width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface); }
textarea.input { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.input:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); margin-bottom: 5px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 14px; }

/* ---------- KPI strip ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi b { display: block; font-size: 28px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi span { font-size: 13px; color: var(--ink-2); }
.kpi.bad b { color: var(--bad); }

/* ---------- work cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.card { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 14px 18px;
  box-shadow: var(--shadow); cursor: pointer; transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--line-2); }
.card::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 0 4px 4px 0; background: var(--wf, var(--accent)); }
.card.overdue { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.card-code { font-family: var(--mono); font-weight: 600; font-size: 13px; }
.card-title { font-weight: 600; font-size: 16px; line-height: 1.3; margin: 2px 0 2px; overflow-wrap: anywhere; }
.card-ref { font-size: 13px; color: var(--ink-2); }
.card-meta { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 13px; color: var(--ink-2); flex-wrap: wrap; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.card.compact { padding: 10px 12px 10px 15px; }
.card.compact .card-title { font-size: 14px; }

.pill { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 99px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill.queued { background: var(--q-bg); color: var(--q); }
.pill.assigned { background: var(--warn-bg); color: var(--warn); }
.pill.in_progress { background: var(--ok-bg); color: var(--ok); }
.pill.done { background: var(--ok-bg); color: var(--ok); }
.pill.rejected, .pill.cancelled { background: var(--bad-bg); color: var(--bad); }
.pill.overdue { background: var(--bad-bg); color: var(--bad); }
.pill.urgent { background: var(--bad); color: #fff; }
.pill.high { background: var(--warn-bg); color: var(--warn); }
.pill.low { background: var(--q-bg); color: var(--q); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.in_progress .dot { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.timer { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.timer.bad { color: var(--bad); font-weight: 600; }

.avatar { width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 600;
  color: #fff; flex: none; letter-spacing: .02em; }
.who { display: inline-flex; align-items: center; gap: 7px; color: var(--ink); font-weight: 500; }

.empty { padding: 28px; text-align: center; color: var(--ink-3); border: 1.5px dashed var(--line-2); border-radius: var(--radius); background: var(--surface-2); }

/* ---------- bulk selection ---------- */
.pick { width: 18px; height: 18px; margin: 0 2px 0 0; accent-color: var(--ink); cursor: pointer; flex: none; }
.card.selected { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink), var(--shadow); }
.bulkbar { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 30; width: min(860px, calc(100% - 32px));
  display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 18px; background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 14px; box-shadow: var(--shadow-lg); animation: fade .15s; }
.bulkbar b { white-space: nowrap; }
.bulkbar .input { flex: 1; min-width: 120px; }
.page { padding-bottom: 110px; }

/* ---------- board ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; font-weight: 500; font-size: 14px; display: inline-flex; align-items: center; gap: 8px; }
.tab.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tab i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 1fr); gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-height: 240px; }
.col-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 2px 4px 10px; }
.col-head h3 { margin: 0; font-size: 15px; }
.col-head .n { font-family: var(--mono); font-size: 13px; color: var(--ink-2); }
.col-sub { font-size: 12px; color: var(--ink-3); padding: 0 4px 10px; margin-top: -6px; }
.col .card { margin-bottom: 10px; }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.person { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.person .avatar { width: 34px; height: 34px; font-size: 13px; }
.person-name { font-weight: 600; font-size: 14px; }
.person-sub { font-size: 12px; color: var(--ink-2); }
.person .load { margin-left: auto; font-family: var(--mono); font-size: 18px; font-weight: 600; }

/* ---------- table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }

/* ---------- tracker rail (pizza tracker style) ---------- */
.rail { display: flex; gap: 4px; margin: 4px 0 18px; }
.rail-step { flex: 1; min-width: 0; text-align: center; }
.rail-bar { height: 8px; border-radius: 99px; background: var(--line); margin-bottom: 7px; }
.rail-step.done .rail-bar { background: var(--ok); }
.rail-step.current .rail-bar { background: linear-gradient(90deg, var(--ok) 0 50%, var(--line) 50%); background-size: 200% 100%; animation: railgo 1.8s linear infinite; background-image: repeating-linear-gradient(-45deg, var(--warn) 0 8px, color-mix(in srgb, var(--warn) 60%, transparent) 8px 16px); }
@keyframes railgo { to { background-position: 32px 0; } }
.rail-label { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-step.current .rail-label { color: var(--ink); font-weight: 600; }
.rail-step.done .rail-label { color: var(--ink-2); }

/* ---------- drawer / modal ---------- */
.scrim { position: fixed; inset: 0; background: rgba(20, 19, 17, .45); z-index: 40; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100%); background: var(--bg); z-index: 41; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; animation: slide .2s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.drawer-head { padding: 18px 22px; border-bottom: 1px solid var(--line); background: var(--surface); }
.drawer-body { padding: 18px 22px 40px; overflow-y: auto; flex: 1; }
.modal { position: fixed; z-index: 41; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100% - 32px)); max-height: calc(100% - 40px);
  overflow-y: auto; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 22px; animation: fade .15s; }
.modal.wide { width: min(980px, calc(100% - 32px)); }
.modal h2, .drawer h2 { margin: 0 0 16px; font-size: 20px; letter-spacing: -.01em; }
.close { position: absolute; top: 14px; right: 14px; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); }
.timeline li::after { content: ""; position: absolute; left: 8.5px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline li.sent_back::before, .timeline li.rejected::before, .timeline li.cancelled::before { background: var(--bad); }
.timeline li.completed::before, .timeline li.approved::before, .timeline li.done::before { background: var(--ok); }
.timeline .when { font-size: 12px; color: var(--ink-3); }
.timeline .note { margin-top: 4px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; white-space: pre-wrap; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: var(--ink); color: var(--bg); padding: 48px; display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; }
.login-art h1 { font-size: 42px; line-height: 1.08; letter-spacing: -.03em; margin: 0 0 14px; max-width: 520px; }
.login-art p { color: color-mix(in srgb, var(--bg) 70%, transparent); max-width: 460px; margin: 0; }
.flow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 36px; }
.flow span { border: 1px solid color-mix(in srgb, var(--bg) 30%, transparent); border-radius: 8px; padding: 8px 12px; font-family: var(--mono); font-size: 13px; }
.flow span.now { background: var(--bg); color: var(--ink); }
.flow em { font-style: normal; opacity: .5; }
.login-form { display: grid; place-items: center; padding: 32px 16px; }
.login-form form { width: min(360px, 100%); }
.login-form h2 { margin: 0 0 6px; font-size: 24px; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }

/* ---------- toast ---------- */
.toasts { position: fixed; bottom: 18px; right: 18px; z-index: 60; display: grid; gap: 8px; }
.toast { background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 14px; max-width: 360px; animation: slide .2s; }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------- admin ---------- */
.stage-row { display: grid; grid-template-columns: 34px minmax(140px, 1.4fr) 92px 112px 92px minmax(180px, 2fr) 74px; gap: 8px; align-items: start;
  padding: 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: var(--surface-2); }
.stage-row .num { font-family: var(--mono); font-weight: 600; color: var(--ink-3); padding-top: 9px; text-align: center; }
.stage-row .members { display: flex; flex-wrap: wrap; gap: 4px 10px; max-height: 96px; overflow-y: auto; padding: 6px 2px; font-size: 13px; }
.stage-row .tools { display: flex; gap: 2px; }
.stage-hdr { display: grid; grid-template-columns: 34px minmax(140px, 1.4fr) 92px 112px 92px minmax(180px, 2fr) 74px; gap: 8px; padding: 0 10px 4px; font-size: 12px; color: var(--ink-3); font-weight: 600; }
.codebox { display: flex; gap: 8px; }
.codebox input { font-family: var(--mono); font-size: 13px; }

@media (max-width: 860px) {
  .topbar { padding: 8px 16px 0; gap: 8px 12px; height: auto; flex-wrap: wrap; }
  .brand { flex: 1; }
  .nav { order: 3; flex-basis: 100%; padding-bottom: 8px; }
  .me-text { display: none; }
  .page { padding: 20px 16px 48px; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-art { padding: 32px 20px; }
  .login-art h1 { font-size: 30px; }
  .grid2 { grid-template-columns: 1fr; }
  .stage-hdr { display: none; }
  .stage-row { grid-template-columns: 1fr 1fr; }
  .stage-row .num { display: none; }
  .stage-row .members, .stage-row .nm { grid-column: 1 / -1; }
  .kv { grid-template-columns: 100px 1fr; }
  .cards { grid-template-columns: 1fr; }
  .bulkbar { flex-wrap: wrap; bottom: 12px; padding: 12px; }
  .bulkbar .input { flex-basis: 100%; order: 2; }
  .bulkbar .btn { order: 3; flex: 1; }
}
@media (max-width: 520px) {
  .brand-text { display: none; }
}
