:root, :root[data-theme="light"] {
  --ink: #101828;
  --muted: #5b6676;
  --line: #e2e7ee;
  --paper: #ffffff;
  --bg: #eef2f7;
  --chip: #eef1f6;
  --field: #ffffff;
  --field-line: #d3dae4;
  --navy: #0f1d3a;
  --accent: #2455e6;
  --accent-dark: #1a3fb8;
  --good: #11794a;  --good-bg: #e2f5ec;
  --warn: #9a5b00;  --warn-bg: #fdf0d8;
  --bad: #b0372a;   --bad-bg: #fde8e4;
  --info: #1d5fa8;  --info-bg: #e4f0fb;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 12px 32px rgba(16, 24, 40, 0.07);
  --brand: #0f1d3a;
  --on-brand: #ffffff;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --ink: #e8edf5;
  --muted: #9aa7ba;
  --line: #263247;
  --paper: #131c2e;
  --bg: #0b1220;
  --chip: #1e2b43;
  --field: #0e1626;
  --field-line: #2c3a53;
  --navy: #2a3a5c;
  --accent: #6b8dff;
  --accent-dark: #5578ee;
  --good: #4ade9a;  --good-bg: #12372a;
  --warn: #f5b857;  --warn-bg: #3a2c10;
  --bad: #ff8d7e;   --bad-bg: #3d1a16;
  --info: #7db8f0;  --info-bg: #14304b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html {
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }

/* ---------- navigation ---------- */
.nav {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  width: min(1100px, calc(100% - 32px)); margin: 0 auto; padding: 16px 0;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; }
.mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--navy); color: #fff; font-weight: 700;
}
.nav-links { display: flex; gap: 8px; align-items: center; }
.shell { width: min(1100px, calc(100% - 32px)); margin: 0 auto 48px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; padding: 0;
  background: transparent; border: 1px solid var(--field-line); cursor: pointer; color: var(--ink);
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: var(--chip); }

/* ---------- type ---------- */
h1, h2, h3, .name { font-weight: 700; letter-spacing: -0.02em; }
h1 { font-size: clamp(36px, 5vw, 56px); line-height: 1.02; margin: 0 0 12px; }
h2 { font-size: 24px; margin: 0 0 8px; }
h3 { font-size: 18px; margin: 0; }
.lede { font-size: 17px; line-height: 1.55; color: var(--muted); max-width: 52ch; }
.kicker { font-size: 14px; font-weight: 600; color: var(--accent); margin-bottom: 8px; }
.muted { color: var(--muted); }
.fine { font-size: 13px; color: var(--muted); text-align: left; margin: 8px 0 0; line-height: 1.45; }

/* ---------- surfaces ---------- */
.step, .panel, .stat, .plate, .person, .login {
  background: var(--paper); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.hero { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 28px; align-items: center; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 28px; }
.step { padding: 16px; }
.step b { display: block; margin-bottom: 6px; }
.step span { color: var(--muted); }

/* ---------- buttons ---------- */
.btn, .ghost {
  display: inline-flex; justify-content: center; align-items: center; border-radius: 12px;
  padding: 11px 16px; text-decoration: none; border: 1px solid transparent;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
  transition: background 0.15s;
}
:root[data-theme="dark"] .btn { color: #0b1220; }
.btn:hover { background: var(--accent-dark); }
.ghost { background: transparent; color: var(--ink); border-color: var(--field-line); }
.ghost:hover { background: var(--chip); }
.btn.bad { background: var(--bad); }
.btn.warn { background: var(--warn); }
.btn.good { background: var(--good); }
.btn.full, .ghost.full { width: 100%; }
.row-actions, .toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
.actions { display: grid; gap: 8px; }

/* ---------- plate (home, admin, print) ---------- */
.plate { width: min(420px, 100%); margin-left: auto; padding: 26px 22px 20px; text-align: center; }
.org { font-size: 13px; font-weight: 600; color: var(--muted); }
.room {
  display: inline-block; margin-top: 14px; background: var(--navy); color: #fff;
  border-radius: 8px; padding: 4px 12px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.avatar, .avatar.photo {
  width: 96px; height: 96px; border-radius: 50%; margin: 16px auto 0; display: grid; place-items: center;
  color: #fff; font-size: 30px; font-weight: 700; background: hsl(var(--h) 45% 38%); object-fit: cover; object-position: center 20%;
}
.name { font-size: 30px; margin: 12px 0 0; line-height: 1.1; }
.role { margin: 6px 0 0; color: var(--muted); }
.summary { text-align: left; line-height: 1.55; margin: 16px 0 0; }
.meta { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.chip, .badge { border-radius: 999px; padding: 4px 10px; background: var(--chip); font-size: 13px; font-weight: 500; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad  { background: var(--bad-bg);  color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }

/* ---------- forms ---------- */
label { display: grid; gap: 6px; font-size: 14px; font-weight: 500; text-align: left; }
input, textarea, select {
  width: 100%; border: 1px solid var(--field-line); background: var(--field); border-radius: 12px; padding: 11px 12px;
}
input[type="color"] { height: 44px; padding: 4px; cursor: pointer; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: 3px solid rgba(36, 85, 230, 0.2); }
textarea { min-height: 110px; resize: vertical; }
form { display: grid; gap: 10px; }
.form-card { text-align: left; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.error { color: var(--bad); font-size: 14px; margin: 0; }
.ok { background: var(--good-bg); color: var(--good); border-radius: 12px; padding: 14px; text-align: left; font-weight: 600; }

/* ---------- admin ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 16px 0; }
.stat { padding: 14px; }
.stat b { display: block; font-size: 30px; letter-spacing: -0.02em; }
.stat span { color: var(--muted); font-size: 14px; }
.layout { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 16px; }
.panel { padding: 16px; }
.list { display: grid; gap: 10px; }
.item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--paper); }
.item header, .person { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.person { padding: 12px 14px; text-decoration: none; align-items: center; }
.person:hover, .item:hover { border-color: var(--muted); }
.who { display: flex; gap: 10px; align-items: center; }
.avatar.sm { width: 42px; height: 42px; font-size: 15px; margin: 0; }
.split { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
.timeline { display: grid; gap: 8px; margin-top: 8px; }
.login { width: min(420px, 100%); margin: 8vh auto; padding: 24px; }
.banner { background: var(--warn-bg); border-radius: 12px; padding: 10px 12px; color: var(--warn); margin-bottom: 12px; }

/* ---------- printable door cards ---------- */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.door { padding: 22px 16px; text-align: center; break-inside: avoid; }
.door .name { font-size: 26px; }
.qr { width: 180px; height: 180px; margin: 8px auto 0; display: block; background: #fff; padding: 6px; border-radius: 8px; }

/* ---------- phone card (public page after QR scan) ---------- */
.phone { width: min(440px, 100%); margin: 0 auto; }
.idcard { background: var(--paper); overflow: hidden; min-height: 100vh; }
.idcard-top {
  position: relative;
  background-color: var(--brand);
  background-image:
    repeating-radial-gradient(circle at 100% 0, color-mix(in srgb, var(--on-brand) 11%, transparent) 0 1px, transparent 1px 26px),
    radial-gradient(120% 150% at 0% 0%, color-mix(in srgb, var(--brand) 80%, #fff) 0%, var(--brand) 55%, color-mix(in srgb, var(--brand) 78%, #000) 100%);
  color: var(--on-brand);
  padding: 22px 22px 76px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.brand-line { display: flex; align-items: center; gap: 10px; max-width: 62%; }
.brand-logo { width: 44px; height: 44px; object-fit: contain; background: #fff; border-radius: 10px; padding: 4px; flex: none; }
.idcard-top .org { color: var(--on-brand); opacity: 0.85; line-height: 1.35; font-size: 14px; }
.doorplate { text-align: right; }
.doorplate b {
  display: block; font-size: 46px; line-height: 1; font-weight: 800;
  letter-spacing: -0.03em; font-variant-numeric: tabular-nums;
}
.doorplate span { font-size: 13px; opacity: 0.8; }
.idcard-top .icon-btn {
  position: absolute; z-index: 2; right: 16px; bottom: 14px; color: var(--on-brand);
  border-color: color-mix(in srgb, var(--on-brand) 40%, transparent);
}
.idcard-top .icon-btn:hover { background: color-mix(in srgb, var(--on-brand) 15%, transparent); }
.idcard-body { position: relative; z-index: 1; padding: 0 22px 32px; margin-top: -60px; }
.profile { display: grid; grid-template-columns: 140px 1fr; gap: 16px; align-items: start; }
.portrait {
  display: block; width: 140px; aspect-ratio: 3 / 4; border-radius: 16px;
  object-fit: cover; object-position: center top;
  border: 4px solid var(--paper); background: var(--chip);
  box-shadow: 0 8px 22px rgba(15, 29, 58, 0.25);
}
.portrait.ph {
  display: grid; place-items: center; color: #fff; font-size: 40px; font-weight: 700;
  background: hsl(var(--h) 45% 38%);
}
.who-info { padding-top: 68px; min-width: 0; }
.who-info .name { margin: 0; font-size: 22px; line-height: 1.2; overflow-wrap: anywhere; }
.who-info .role { margin: 6px 0 0; font-size: 15px; font-weight: 600; color: var(--ink); }
.facts { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
.facts li { display: flex; gap: 8px; align-items: flex-start; line-height: 1.3; }
.facts svg { width: 16px; height: 16px; flex: none; margin-top: 1px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.idcard-body .summary { margin: 18px 0 0; opacity: 0.92; }
.ask { margin: 26px 0 10px; font-size: 17px; font-weight: 700; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  display: grid; gap: 4px; text-align: left; padding: 14px; border-radius: 14px;
  border: 1px solid transparent; cursor: pointer; transition: transform 0.12s;
}
.tile:active { transform: scale(0.98); }
.tile svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tile b { font-size: 16px; color: var(--ink); }
.tile small { color: var(--muted); font-size: 13px; line-height: 1.3; }
.tile.good { color: var(--good); background: var(--good-bg); }
.tile.info { color: var(--info); background: var(--info-bg); }
.tile.warn { color: var(--warn); background: var(--warn-bg); }
.tile.bad  { color: var(--bad);  background: var(--bad-bg); }
.privacy { margin: 14px 0 0; font-size: 13px; color: var(--muted); line-height: 1.45; }

.sheet-wrap { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.backdrop { position: absolute; inset: 0; background: rgba(5, 10, 22, 0.55); }
.sheet {
  position: relative; width: min(440px, 100%); background: var(--paper); border-radius: 22px 22px 0 0;
  padding: 10px 20px 22px; max-height: 92vh; overflow: auto; text-align: left;
  animation: rise 0.22s ease-out;
}
.sheet::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--field-line); margin: 0 auto 12px; }
.sheet-title { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; }
.sheet-title svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .tile { transition: none; } }

@media (max-width: 900px) {
  .hero, .layout, .split, .steps, .cards { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .plate { margin: 8px auto 0; }
}

@media print {
  :root, :root[data-theme="dark"] {
    --ink: #101828; --muted: #5b6676; --line: #e2e7ee; --paper: #ffffff; --bg: #ffffff;
    --chip: #eef1f6; --navy: #0f1d3a;
  }
  body { background: #fff; }
  .noprint { display: none !important; }
  .cards { gap: 8mm; }
  .door, .plate { box-shadow: none; }
}

/* ---------- results report ---------- */
.report-head { margin-bottom: 4px; }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin: 14px 0; }
.filters label { min-width: 120px; width: auto; }
.distbar { display: flex; height: 38px; border-radius: 10px; overflow: hidden; margin-top: 10px; }
.seg { display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; min-width: 0; }
.seg.good { background: var(--good); }
.seg.info { background: var(--info); }
.seg.warn { background: var(--warn); }
.seg.bad { background: var(--bad); }
:root[data-theme="dark"] .seg { color: #0b1220; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; font-size: 14px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.dot.good { background: var(--good); }
.dot.info { background: var(--info); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.tablewrap { overflow-x: auto; }
.rtable { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 920px; }
.rtable th, .rtable td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.rtable th { font-size: 13px; color: var(--muted); font-weight: 600; }
.rtable td b { font-size: 16px; }
.rtable td a { text-decoration: none; }
.scorebar { height: 6px; border-radius: 6px; background: var(--chip); margin-top: 6px; overflow: hidden; min-width: 70px; }
.scorebar span { display: block; height: 100%; background: var(--accent); }
.method ul { margin: 8px 0 0; padding-left: 18px; line-height: 1.55; font-size: 14px; }
.method li { margin-bottom: 6px; }
.printonly { display: none; }
.item .ghost { margin-top: 8px; padding: 6px 12px; font-size: 13px; }

@page report { size: A4 landscape; margin: 12mm; }
.report { page: report; }

@media print {
  .rtable { min-width: 0; font-size: 11px; }
  .rtable td b { font-size: 13px; }
  .tablewrap { overflow: visible; }
  .rtable tr { break-inside: avoid; }
  .panel, .stat { box-shadow: none; }
  .printonly { display: flex; justify-content: space-between; margin-top: 28px; font-size: 13px; }
  .report-head h1 { font-size: 26px !important; }
  .seg, .scorebar span, .dot, .badge { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- toasts ---------- */
#toasts {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); pointer-events: none;
}
.toast {
  background: var(--ink); color: var(--paper); padding: 12px 16px; border-radius: 12px;
  font-weight: 600; box-shadow: var(--shadow); border-left: 5px solid var(--good);
  animation: rise 0.2s ease-out; transition: opacity 0.3s;
}
.toast.bad { border-left-color: var(--bad); }
.toast.info { border-left-color: var(--info); }
.toast.out { opacity: 0; }
button:disabled { opacity: 0.6; cursor: progress; }

/* ---------- department comparison ---------- */
.cmp { display: grid; gap: 10px; margin-top: 12px; }
.cmp-row { display: grid; grid-template-columns: minmax(150px, 280px) 1fr 52px 56px; gap: 12px; align-items: center; }
.cmp-name { display: grid; line-height: 1.25; }
.cmp-name small { color: var(--muted); }
.cmp-track { position: relative; height: 16px; background: var(--chip); border-radius: 8px; }
.cmp-fill { position: absolute; inset: 0 auto 0 0; border-radius: 8px; background: var(--accent); }
.cmp-mark { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); opacity: 0.7; }
.cmp-val { text-align: right; font-size: 16px; }
.delta { font-size: 13px; font-weight: 600; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.distbar.sm { height: 22px; margin-top: 0; min-width: 150px; font-size: 12px; }
.dept-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.dept-head h2 { margin: 0; }
@media (max-width: 700px) {
  .cmp-row { grid-template-columns: 1fr 52px 56px; }
  .cmp-name { grid-column: 1 / -1; }
}
@media print {
  .dept { break-before: page; }
  .dept.solo { break-before: auto; }
  .cmp-row { break-inside: avoid; }
  .cmp-fill, .cmp-mark { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
