/* ---------- Tokens ---------- */
:root {
  --bg: #f6f6f4; --surface: #ffffff; --surface-2: #fafaf9; --text: #18181b; --muted: #71717a;
  --line: #e7e5e4; --line-strong: #d6d3d1; --primary: #18181b; --on-primary: #ffffff;
  --ring: #6366f1; --today: #6366f1; --off: #f4f4f3; --off-text: #a8a29e; --danger: #dc2626;
  --shadow: 0 1px 2px rgba(24,24,27,.04), 0 1px 3px rgba(24,24,27,.06);
  --shadow-lg: 0 12px 40px rgba(24,24,27,.16), 0 2px 6px rgba(24,24,27,.06);
  --P-bg: #dcfce7;  --P-fg: #166534;
  --SW-bg: #dbeafe; --SW-fg: #1e40af;
  --F-bg: #fef3c7;  --F-fg: #92400e;
  --M-bg: #ffe4e6;  --M-fg: #9f1239;
  --T-bg: #ede9fe;  --T-fg: #5b21b6;
  --MG-bg: #ffedd5; --MG-fg: #9a3412;
  --PR-bg: #f1f5f9; --PR-fg: #334155;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f11; --surface: #18181b; --surface-2: #1d1d21; --text: #f4f4f5; --muted: #a1a1aa;
    --line: #27272a; --line-strong: #3f3f46; --primary: #f4f4f5; --on-primary: #18181b;
    --ring: #818cf8; --today: #818cf8; --off: #141416; --off-text: #52525b;
    --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
    --P-bg: #14532d66;  --P-fg: #86efac;
    --SW-bg: #1e3a8a66; --SW-fg: #93c5fd;
    --F-bg: #78350f66;  --F-fg: #fcd34d;
    --M-bg: #88133766;  --M-fg: #fda4af;
    --T-bg: #4c1d9566;  --T-fg: #c4b5fd;
    --MG-bg: #7c2d1266; --MG-fg: #fdba74;
    --PR-bg: #33415588; --PR-fg: #cbd5e1;
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
main { padding: 24px 16px 96px; max-width: 1480px; margin: 0 auto; }
a { color: inherit; }
h1 { font-size: 24px; font-weight: 650; letter-spacing: -.02em; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 4px; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; }
kbd { font: 11px ui-monospace, Menlo, monospace; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--surface); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 12px; }
.lead { max-width: 720px; margin: 8px 0 20px; }
.error { color: var(--danger); margin: 0 0 12px; font-size: 13px; }
.error.banner { background: color-mix(in srgb, var(--danger) 10%, transparent); padding: 10px 14px; border-radius: 10px; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer; font: inherit; font-weight: 550; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { opacity: .9; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.ms { height: 44px; background: var(--surface); }
.iconbtn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; border: 1px solid transparent; background: transparent; color: var(--text); cursor: pointer; text-decoration: none; }
.iconbtn:hover { background: var(--surface); border-color: var(--line); }

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 20px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; text-decoration: none; letter-spacing: -.01em; }
.brand-sub { color: var(--muted); font-weight: 500; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: var(--on-primary); }
.logo svg { width: 18px; height: 18px; stroke-width: 2.6; }
.logo.lg { width: 48px; height: 48px; border-radius: 14px; margin-bottom: 16px; }
.logo.lg svg { width: 28px; height: 28px; }
.logo.warn { background: var(--danger); color: #fff; }
.nav { display: flex; align-items: center; gap: 6px; }
.navlink { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 550; }
.navlink:hover { color: var(--text); background: var(--surface); }
.navlink.active { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
.me { display: flex; align-items: center; gap: 10px; margin-left: 10px; padding-left: 14px; border-left: 1px solid var(--line); }
.me-text { display: flex; flex-direction: column; line-height: 1.2; }
.me-name { font-weight: 600; font-size: 13px; }
.me-role { color: var(--muted); font-size: 12px; }
.avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: var(--on-primary); font-size: 12px; font-weight: 650; letter-spacing: .02em; flex: none; }
.avatar.sm { width: 26px; height: 26px; font-size: 10.5px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

/* ---------- Page head + legend ---------- */
.pagehead { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.monthnav { display: flex; align-items: center; gap: 6px; }
.monthnav h1 { min-width: 200px; text-align: center; }
.monthnav .year { color: var(--muted); font-weight: 500; }
.monthnav .btn { margin-left: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; list-style: none; padding: 0; margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 7px; }

/* ---------- Code tags + colours ---------- */
.tag, .pr-tag { display: inline-flex; align-items: center; justify-content: center; height: 22px; min-width: 28px; padding: 0 7px; border-radius: 6px; font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.pr-tag { background: var(--PR-bg); color: var(--PR-fg); font-weight: 600; font-size: 11px; height: 18px; padding: 0 6px; border: 1px solid color-mix(in srgb, var(--PR-fg) 18%, transparent); }
.c-P  { --bg-c: var(--P-bg);  --fg-c: var(--P-fg); }
.c-SW { --bg-c: var(--SW-bg); --fg-c: var(--SW-fg); }
.c-F  { --bg-c: var(--F-bg);  --fg-c: var(--F-fg); }
.c-M  { --bg-c: var(--M-bg);  --fg-c: var(--M-fg); }
.c-T  { --bg-c: var(--T-bg);  --fg-c: var(--T-fg); }
.c-MG { --bg-c: var(--MG-bg); --fg-c: var(--MG-fg); }
.c-PR { --bg-c: var(--PR-bg); --fg-c: var(--PR-fg); }
.legend .tag, .cell .tag { background: var(--bg-c); color: var(--fg-c); }
.cell .tag { background: transparent; padding: 0; min-width: 0; }

/* ---------- Panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 13px; }

/* ---------- Team grid ---------- */
.gridwrap { overflow-x: auto; }
.grid { border-collapse: separate; border-spacing: 0; font-size: 12px; width: 100%; }
.grid th, .grid td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 0; text-align: center; white-space: nowrap; }
.grid tbody tr:last-child > * { border-bottom: 0; }
.grid thead th { position: sticky; top: 0; background: var(--surface); padding: 8px 2px; min-width: 52px; font-weight: 500; }
.grid thead .wd { display: block; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.grid thead .dn { display: block; font-size: 14px; font-weight: 650; }
.grid thead th.off { color: var(--off-text); }
.grid thead th.off .wd, .grid thead th.off .dn { color: var(--off-text); }
.grid thead th.is-today .dn { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--today); color: #fff; }
.grid .name-col { position: sticky; left: 0; z-index: 2; background: var(--surface); text-align: left; padding: 0 16px; min-width: 200px; font-weight: 600; font-size: 13px; }
.grid tbody .name-col { display: flex; align-items: center; gap: 10px; height: 48px; }
.grid thead .name-col { z-index: 3; color: var(--muted); font-weight: 500; font-size: 12px; }
.grid td.off { background: var(--off) repeating-linear-gradient(135deg, transparent 0 6px, color-mix(in srgb, var(--line) 60%, transparent) 6px 7px); }
.grid td.cell { height: 48px; background: var(--bg-c, transparent); color: var(--fg-c, var(--text)); transition: background .12s; }
.grid td.cell.is-today { box-shadow: inset 2px 0 0 var(--today), inset -2px 0 0 var(--today); }
.grid tr.editable td.cell { cursor: pointer; }
.grid tr.editable td.cell:hover { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--ring) 45%, transparent); }
.grid .cell-body { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.grid .sum-col { position: sticky; right: 0; background: var(--surface); min-width: 96px; padding: 0 10px; border-right: 0; border-left: 1px solid var(--line); }
.grid thead .sum-col { color: var(--muted); font-size: 11px; }
.missing { display: inline-grid; place-items: center; min-width: 26px; height: 22px; padding: 0 7px; border-radius: 11px; background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); font-weight: 650; }
.missing.done { background: var(--P-bg); color: var(--P-fg); }
.cell.selected { box-shadow: inset 0 0 0 2px var(--ring) !important; }

/* ---------- Personal calendar ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--fg-c, var(--danger)); opacity: .8; }
.stat-n { font-size: 22px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-l { color: var(--muted); font-size: 12px; }
.stat.todo .stat-n { color: var(--danger); }
.calendar .cal-head, .calendar .cal-body { display: grid; grid-template-columns: repeat(5, 1fr) repeat(2, .55fr); }
.cal-head div { padding: 10px 12px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-bottom: 1px solid var(--line); }
.cal-head .we { color: var(--off-text); }
.day { min-height: 104px; padding: 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; position: relative; }
.cal-body > :nth-child(7n) { border-right: 0; }
.day.empty { background: var(--surface-2); }
.day.off { background: var(--off); color: var(--off-text); }
.day .dnum { font-size: 13px; font-weight: 650; width: 26px; height: 26px; display: inline-grid; place-items: center; border-radius: 50%; margin: -3px 0 0 -3px; }
.day.is-today .dnum { background: var(--today); color: #fff; }
.day .holiday { font-size: 11px; line-height: 1.25; }
.day.cell { cursor: pointer; background: var(--bg-c, var(--surface)); color: var(--fg-c, var(--text)); transition: background .12s; }
.day.cell:hover { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--ring) 45%, transparent); }
.day .cell-body { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.day .tag { font-size: 20px; height: auto; font-weight: 750; letter-spacing: -.01em; }
.day .pr-tag { font-size: 12px; height: 22px; }
.calendar .panel-head { display: block; }

/* ---------- Editor ---------- */
.editor { position: fixed; right: 20px; bottom: 20px; z-index: 30; width: 380px; max-width: calc(100vw - 32px); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 16px; animation: pop .14s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.editor-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.editor-kicker { color: var(--muted); font-size: 12px; }
.editor-head strong { font-size: 16px; letter-spacing: -.01em; }
.codes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.code { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); cursor: pointer; font: inherit; text-align: left; transition: background .12s, border-color .12s; }
.code:hover { border-color: var(--fg-c); }
.code-k { font-weight: 750; font-size: 15px; color: var(--fg-c); }
.code-v { font-size: 11.5px; color: var(--muted); line-height: 1.2; }
.code.active { background: var(--bg-c); border-color: var(--fg-c); box-shadow: 0 0 0 1px var(--fg-c); }
.pr-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); margin-bottom: 14px; }
.pr-row label { font-weight: 600; }
select, input[type=email], input[name=name] { height: 36px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); color: var(--text); font: inherit; }
select:disabled { opacity: .45; }
.actions { display: flex; justify-content: space-between; gap: 8px; }
.actions .primary { flex: 1; max-width: 180px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40; max-width: calc(100vw - 32px); background: var(--primary); color: var(--on-primary); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 550; animation: pop .14s ease-out; }

/* ---------- Login / denied ---------- */
.auth { min-height: calc(100vh - 160px); display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 32px; text-align: center; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card > .muted { margin-bottom: 24px; }
.auth-card .btn { margin-top: 8px; }
.dev-form { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.dev-form label { font-weight: 600; font-size: 13px; }
.dev-form input { height: 42px; }
.note { margin: 16px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- People ---------- */
.people { width: 100%; border-collapse: collapse; }
.people th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--line); }
.people td { padding: 8px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.people tr:last-child td { border-bottom: 0; }
.people tr.inactive { opacity: .55; }
.people .new-row { background: var(--surface-2); }
.people input[name=name] { width: 100%; min-width: 180px; }
.people input[type=email] { width: 280px; }
.person { display: flex; align-items: center; gap: 10px; }
.badge { display: inline-block; margin-left: 8px; font-size: 11px; padding: 2px 8px; border-radius: 10px; }
.badge.warn { background: var(--F-bg); color: var(--F-fg); }
.switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 10px; background: var(--line-strong); cursor: pointer; transition: background .15s; }
.switch span::after { content: ""; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--P-fg); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--ring); outline-offset: 2px; }
.roles { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin: 20px 0 8px; }
.role-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.role-card p:last-child { margin: 10px 0 0; font-weight: 550; word-break: break-all; }

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  .topbar { padding: 10px 16px; }
  .me-text, .brand-sub { display: none; }
  .me { margin-left: 4px; padding-left: 10px; }
  .monthnav h1 { min-width: 0; font-size: 20px; }
  .calendar .cal-head, .calendar .cal-body { grid-template-columns: repeat(5, 1fr) repeat(2, .5fr); }
  .day { min-height: 72px; padding: 6px; }
  .day .tag { font-size: 15px; }
  .day .pr-tag { font-size: 10px; padding: 0 4px; }
  .day .holiday { display: none; }
  .cal-head div { padding: 8px 6px; }
  .editor { left: 0; right: 0; bottom: 0; width: 100%; max-width: none; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
  .people input[type=email] { width: 100%; min-width: 200px; }
  .gridwrap { -webkit-overflow-scrolling: touch; }
  .grid .name-col { min-width: 150px; padding: 0 10px; }
  .stats { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .stat { padding: 8px 8px 8px 11px; border-radius: 10px; }
  .stat-n { font-size: 17px; }
  .stat-l { font-size: 10.5px; line-height: 1.2; }
  .legend { gap: 6px 12px; font-size: 12px; }
  .calendar .panel-head { display: none; }
}
.stat.todo .stat-n.done { color: var(--P-fg); }
.stat.todo:has(.done)::before { background: var(--P-fg); }
.backup-card { margin-bottom: 8px; }
.backup-card p { margin: 6px 0 0; }
