:root {
  --brand: #1d4ed8;
  --accent: #f59e0b;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --soft: #f9fafb;
  --good: #15803d;
  --good-bg: #dcfce7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117; --panel: #161b22; --ink: #e6edf3; --muted: #8b949e; --line: #30363d; --soft: #1c2128;
    --good: #4ade80; --good-bg: #14532d55; --bad: #f87171; --bad-bg: #7f1d1d55; --warn: #fbbf24; --warn-bg: #78350f55;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 1rem; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* Layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  background: var(--panel); border-right: 1px solid var(--line); padding: 1rem .75rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: .25rem;
}
.brand { display: flex; align-items: center; gap: .6rem; padding: .25rem .5rem 1rem; font-weight: 700; }
.brand img { width: 34px; height: 34px; border-radius: 8px; object-fit: contain; }
.brand .logo { width: 34px; height: 34px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: .8rem; font-weight: 800; }
.brand .sub { display: block; font-weight: 500; font-size: .75rem; color: var(--muted); }
.nav-group { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: .9rem .6rem .3rem; }
.nav a {
  display: flex; align-items: center; gap: .6rem; padding: .5rem .6rem; border-radius: 8px; color: var(--ink);
  text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--soft); }
.nav a.active { background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand); }
.nav a .badge { margin-left: auto; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.side .me { margin-top: auto; padding: .75rem .5rem 0; border-top: 1px solid var(--line); font-size: .85rem; }
main { padding: 1.75rem 2rem 4rem; max-width: 1200px; width: 100%; }
.topbar { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 50; transform: translateX(-105%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .side.open { transform: none; }
  .topbar {
    display: flex; align-items: center; gap: .75rem; padding: .6rem 1rem; background: var(--panel);
    border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 40;
  }
  main { padding: 1rem 1rem 4rem; }
}

/* Cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); }
.card > h2:first-child, .card > .row:first-child h2 { margin-bottom: .75rem; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .g2, .g3 { grid-template-columns: 1fr; } }
.stat .label { font-size: .8rem; color: var(--muted); font-weight: 500; }
.stat .value { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .value small { font-size: .9rem; color: var(--muted); font-weight: 500; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { margin: .2rem 0 0; color: var(--muted); }

/* Clock hero */
.hero { display: flex; gap: 1.5rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.hero .status { display: flex; align-items: center; gap: .8rem; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: #22c55e; box-shadow: 0 0 0 4px #22c55e33; animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px #22c55e11; } }
.timer { font-size: 2.4rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

/* Buttons & forms */
button, .btn {
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: .5rem .9rem; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: .4rem;
  text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--soft); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
button.big { font-size: 1.1rem; padding: .85rem 1.6rem; border-radius: 12px; }
button.go { background: #16a34a; border-color: #16a34a; color: #fff; }
button.stop { background: #dc2626; border-color: #dc2626; color: #fff; }
button.link { border: 0; background: none; color: var(--brand); padding: 0; font-weight: 500; }
button.icon { padding: .4rem; }
button.sm, .btn.sm { padding: .3rem .6rem; font-size: .82rem; }

label.field { display: block; }
label.field > span { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .3rem; }
label.field .help { display: block; font-size: .75rem; color: var(--muted); margin-top: .25rem; font-weight: 400; }
input, select, textarea {
  font: inherit; width: 100%; padding: .55rem .7rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 38px; width: 64px; }
textarea { min-height: 80px; resize: vertical; }
.form { display: grid; gap: .9rem; }
.form.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) { .form.two { grid-template-columns: 1fr; } }
.check { display: flex; gap: .55rem; align-items: flex-start; cursor: pointer; }
.check input { margin-top: .2rem; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .sl { position: absolute; inset: 0; background: var(--line); border-radius: 22px; transition: .15s; cursor: pointer; }
.switch .sl::before { content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + .sl { background: var(--brand); }
.switch input:checked + .sl::before { transform: translateX(18px); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -1.2rem; padding: 0 1.2rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: .5rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--soft); }
th.r, td.r { text-align: right; }
th.sortable { cursor: pointer; user-select: none; }

/* Chips, badges, bars */
.chip { display: inline-flex; align-items: center; gap: .35rem; font-size: .75rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--soft); border: 1px solid var(--line); white-space: nowrap; }
.chip .sw { width: 8px; height: 8px; border-radius: 50%; }
.chip.good { background: var(--good-bg); color: var(--good); border-color: transparent; }
.chip.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge { background: var(--bad); color: #fff; font-size: .7rem; font-weight: 700; padding: .05rem .45rem; border-radius: 999px; }
.bar { height: 8px; border-radius: 99px; background: var(--soft); border: 1px solid var(--line); overflow: hidden; }
.bar > div { height: 100%; background: var(--brand); border-radius: 99px; transition: width .4s; }
.bar.accent > div { background: var(--accent); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: .75rem; font-weight: 700; color: #fff; background: var(--brand); flex: none; }
.person { display: flex; align-items: center; gap: .6rem; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.callout { padding: .75rem 1rem; border-radius: 10px; background: var(--warn-bg); color: var(--ink); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }
.callout.info { background: color-mix(in srgb, var(--brand) 8%, transparent); border-color: color-mix(in srgb, var(--brand) 25%, transparent); }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: .6rem .8rem; color: var(--muted); }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.list-item { display: flex; align-items: center; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.cat-bars .r { display: grid; grid-template-columns: 110px 1fr 60px; gap: .6rem; align-items: center; font-size: .85rem; margin: .35rem 0; }
.pin { font: 700 1.6rem ui-monospace, monospace; letter-spacing: .25em; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }

/* Modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 100; padding: 1rem; animation: fade .12s; }
.modal { background: var(--panel); border-radius: 14px; width: min(560px, 100%); max-height: 90vh; overflow-y: auto; padding: 1.3rem 1.4rem; border: 1px solid var(--line); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(820px, 100%); }
.modal .actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.2rem; }
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: .5rem; align-items: center; }
.toast { background: #111827; color: #fff; padding: .65rem 1rem; border-radius: 10px; font-weight: 500; box-shadow: 0 8px 30px rgba(0,0,0,.25); animation: fade .15s; max-width: 90vw; }
.toast.err { background: #b91c1c; }

/* Auth screens */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(1200px 500px at 50% -10%, color-mix(in srgb, var(--brand) 22%, transparent), transparent), var(--bg); }
.auth .card { width: min(420px, 100%); padding: 1.8rem; }
.auth .brand { justify-content: center; padding-bottom: 1.2rem; font-size: 1.1rem; }
.settings-group { scroll-margin-top: 1rem; }
.setting { display: grid; grid-template-columns: 1fr 260px; gap: 1rem; align-items: center; padding: .8rem 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting .help { font-size: .78rem; color: var(--muted); }
@media (max-width: 700px) { .setting { grid-template-columns: 1fr; gap: .4rem; } }
.perm-grid th:not(:first-child), .perm-grid td:not(:first-child) { text-align: center; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.result-W { color: var(--good); font-weight: 700; }
.result-L { color: var(--bad); font-weight: 700; }
.alliance-red { color: #dc2626; }
.alliance-blue { color: #2563eb; }
.us { font-weight: 800; text-decoration: underline; }
button svg { width: 20px; height: 20px; }
.app > div { min-width: 0; }
.tabs { scrollbar-width: thin; }

/* Tasks */
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 1rem; overflow-x: auto; padding-bottom: .5rem; align-items: start; }
.board .col { background: color-mix(in srgb, var(--panel) 55%, var(--bg)); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem; min-height: 160px; display: flex; flex-direction: column; gap: .55rem; transition: background .1s, border-color .1s; }
.board .col.over { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--panel)); }
.col-head { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: .85rem; padding: .2rem .3rem .3rem; }
.col-head .muted { margin-left: auto; font-weight: 500; }
.dot.status-todo { background: #94a3b8; } .dot.status-in_progress { background: #3b82f6; } .dot.status-blocked { background: #ef4444; } .dot.status-done { background: #22c55e; }
.col-head .dot { width: 9px; height: 9px; }
.task-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .7rem .75rem; cursor: pointer; box-shadow: var(--shadow); }
.task-card:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); }
.task-card.dragging { opacity: .45; }
.task-card .title { font-weight: 600; line-height: 1.3; }
.stack-av { display: inline-flex; }
.stack-av .avatar { margin-left: -6px; border: 2px solid var(--panel); }
.stack-av .avatar:first-child { margin-left: 0; }
.avatar.sm { width: 24px; height: 24px; font-size: .62rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; border-radius: 0; padding: .42rem .8rem; font-weight: 600; color: var(--muted); background: none; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand); }
.people-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .35rem .8rem; max-height: 180px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: .6rem; }
.comments { display: flex; flex-direction: column; gap: .7rem; }
.comment { display: flex; gap: .6rem; align-items: flex-start; }
.modal .actions { flex-wrap: wrap; }
.bar.over > div { background: var(--bad); }
@media (max-width: 860px) { .board { grid-template-columns: repeat(4, 80vw); scroll-snap-type: x mandatory; } .board .col { scroll-snap-align: start; } }

/* Audit log */
.audit { padding-top: .4rem; }
.audit-day { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 1rem 0 .35rem; border-bottom: 1px solid var(--line); }
.audit-day:first-child { padding-top: .5rem; }
.audit-row { display: flex; gap: .8rem; align-items: flex-start; padding: .75rem 0; border-bottom: 1px solid var(--line); line-height: 1.45; }
.audit-row:last-child { border-bottom: 0; }
.audit-ic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.audit-ic svg { width: 17px; height: 17px; }
.audit-time { font-size: .8rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; padding-top: .1rem; }
.audit-details { margin-top: .4rem; display: flex; flex-direction: column; gap: .35rem; }
.audit-changes { display: grid; gap: .25rem; max-width: 760px; font-size: .84rem; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .7rem; }
.audit-changes .chg { display: grid; grid-template-columns: minmax(110px, max-content) fit-content(40%) auto minmax(0, 1fr); gap: .5rem; align-items: baseline; }
.audit-changes .k { font-weight: 600; color: var(--muted); }
.audit-changes .from { text-decoration: line-through; color: var(--muted); overflow-wrap: anywhere; }
.audit-changes .to { font-weight: 600; overflow-wrap: anywhere; }
.audit-changes .arrow { color: var(--muted); }
@media (max-width: 640px) { .audit-changes .chg { grid-template-columns: 1fr; gap: 0; } .audit-changes .arrow { display: none; } .audit-changes .chg + .chg { margin-top: .35rem; } }

/* View as role */
.preview-bar { position: sticky; top: 0; z-index: 45; display: flex; align-items: center; gap: .7rem; padding: .6rem 1.2rem; background: #7c3aed; color: #fff; font-size: .9rem; }
.preview-bar svg { width: 18px; height: 18px; flex: none; }
.preview-bar button { border-color: rgba(255,255,255,.4); background: rgba(255,255,255,.12); color: #fff; }
.preview-bar button.primary { background: #fff; color: #5b21b6; border-color: #fff; }
.app.previewing .side { border-right: 3px solid #7c3aed; }
@media (max-width: 860px) { .preview-bar .hide-sm { display: none; } .preview-bar { padding: .5rem .8rem; } .preview-bar + .topbar { top: 44px; } }
.view-as-list { display: flex; flex-direction: column; gap: .5rem; }
.view-as-list button { display: flex; align-items: center; gap: .7rem; padding: .7rem .9rem; font-weight: 500; white-space: normal; }
.view-as-list button.on { border-color: #7c3aed; background: color-mix(in srgb, #7c3aed 10%, transparent); }
.view-as-list .sw { width: 12px; height: 12px; border-radius: 50%; flex: none; }
button svg + * { margin-left: 0; }

/* Profile pictures */
.avatar { position: relative; overflow: hidden; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar.xl { width: 84px; height: 84px; font-size: 1.6rem; }
.card.locked { opacity: .78; }
.lock { display: inline-block; margin-top: .5rem; font-size: .75rem; color: var(--muted); }
.rank { font-size: .72rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.clock-list { max-height: 55vh; overflow-y: auto; }
