:root {
  --navy: #0f2c4c;
  --navy-2: #1b4470;
  --accent: #1d6fb8;
  --primary: #1d6fb8;
  --primary-hover: #185f9e;
  --accent-soft: #e6f0fa;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --input-bg: #ffffff;
  --hover: #f1f5f9;
  --chip: #eef2f6;
  --line: #dde3ea;
  --line-strong: #c3ccd7;
  --focus-line: #9cc3ea;
  --text: #17212d;
  --heading: #0f2c4c;
  --muted: #5d6a79;
  --topbar: #0f2c4c;
  --toast-bg: #0f2c4c;
  --strong: #0f2c4c;
  --info-fg: #1b4470;
  --danger: #b3261e;
  --danger-soft: #fbeceb;
  --danger-line: #e6b8b5;
  --ok: #1f7a3d;
  --ok-soft: #e8f4ec;
  --warn: #8a5a00;
  --warn-soft: #fdf4e0;
  --del-bg: #fdf1f0;
  --del-fg: #8c2c25;
  --ins-bg: #eef7f1;
  --ins-fg: #1d5e33;
  --overlay: rgba(15, 30, 50, .45);
  --auth-bg: linear-gradient(160deg, #0f2c4c 0%, #183f68 55%, #22547f 100%);
  --shadow: 0 1px 2px rgba(15, 44, 76, .06), 0 2px 8px rgba(15, 44, 76, .05);
  color-scheme: light;
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
}

/* Dark theme: follows the system unless the user picked Light; or forced with the Dark switch. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #5aa7ea;
    --primary: #2a74b8;
  --primary-hover: #3583cc;
    --accent-soft: #1a3350;
    --bg: #0d141d;
    --panel: #151f2b;
    --panel-2: #1a2633;
    --input-bg: #101923;
    --hover: #1e2b3a;
    --chip: #223142;
    --line: #273647;
    --line-strong: #36495e;
    --focus-line: #3f78ad;
    --text: #e2e8ef;
    --heading: #e9eff6;
    --muted: #93a2b3;
    --topbar: #0a1520;
    --toast-bg: #24405f;
  --toast-bg: #24405f;
    --strong: #2f7cc4;
    --info-fg: #a8cdf1;
    --danger: #f08a82;
    --danger-soft: #3a1d1c;
    --danger-line: #6b3330;
    --ok: #6fcf8f;
    --ok-soft: #173221;
    --warn: #e6bb63;
    --warn-soft: #382c12;
    --del-bg: #351e1e;
    --del-fg: #f2aaa4;
    --ins-bg: #16301f;
    --ins-fg: #94dcae;
    --overlay: rgba(0, 0, 0, .6);
    --auth-bg: linear-gradient(160deg, #08121c 0%, #0f2033 55%, #163049 100%);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --accent: #5aa7ea;
  --primary: #2a74b8;
  --primary-hover: #3583cc;
  --accent-soft: #1a3350;
  --bg: #0d141d;
  --panel: #151f2b;
  --panel-2: #1a2633;
  --input-bg: #101923;
  --hover: #1e2b3a;
  --chip: #223142;
  --line: #273647;
  --line-strong: #36495e;
  --focus-line: #3f78ad;
  --text: #e2e8ef;
  --heading: #e9eff6;
  --muted: #93a2b3;
  --topbar: #0a1520;
  --toast-bg: #24405f;
  --strong: #2f7cc4;
  --info-fg: #a8cdf1;
  --danger: #f08a82;
  --danger-soft: #3a1d1c;
  --danger-line: #6b3330;
  --ok: #6fcf8f;
  --ok-soft: #173221;
  --warn: #e6bb63;
  --warn-soft: #382c12;
  --del-bg: #351e1e;
  --del-fg: #f2aaa4;
  --ins-bg: #16301f;
  --ins-fg: #94dcae;
  --overlay: rgba(0, 0, 0, .6);
  --auth-bg: linear-gradient(160deg, #08121c 0%, #0f2033 55%, #163049 100%);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .25);
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--heading); margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
code, .mono { font-family: var(--mono); font-size: .88em; }
.boot { padding: 40px; color: var(--muted); }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  height: 56px; padding: 0 20px;
  background: var(--topbar); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; color: #fff; }
.brand:hover { text-decoration: none; }
.brand img { width: 28px; height: 28px; }
.nav { display: flex; gap: 2px; }
.nav a { color: #c9d6e6; padding: 7px 11px; border-radius: 6px; font-size: .94rem; }
.nav a:hover { color: #fff; background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { color: #fff; background: rgba(255,255,255,.14); }
.topsearch { flex: 1; max-width: 420px; margin-left: auto; }
.topsearch input {
  width: 100%; height: 34px; border: 0; border-radius: 6px; padding: 0 12px;
  background: rgba(255,255,255,.12); color: #fff; font-size: .94rem;
}
.topsearch input::placeholder { color: #a9bbd0; }
.topsearch input:focus { outline: 2px solid #6fa8dc; background: rgba(255,255,255,.18); }
.usermenu { display: flex; align-items: center; gap: 10px; font-size: .9rem; color: #c9d6e6; white-space: nowrap; }
.usermenu a { color: #c9d6e6; }
.usermenu button { background: none; border: 0; color: #c9d6e6; cursor: pointer; font: inherit; padding: 4px; }
.usermenu button:hover, .usermenu a:hover { color: #fff; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }
main.wide { max-width: none; }
.page-head { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .grow { flex: 1; min-width: 200px; }
.crumbs { font-size: .86rem; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }
.crumbs span + span::before { content: "›"; margin: 0 6px; color: var(--line-strong); }
.sub { color: var(--muted); font-size: .92rem; margin-top: 4px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { flex: 1; }
.card-body { padding: 18px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Forms ---------- */
label.f { display: block; }
label.f > span, .flabel { display: block; font-size: .84rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: .95rem; color: var(--text);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 10px; background: var(--input-bg);
}
textarea { resize: vertical; min-height: 70px; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus-line); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); vertical-align: middle; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: .94rem; }
.hint { font-size: .82rem; color: var(--muted); margin-top: 4px; }
.err { color: var(--danger); font-size: .9rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--line-strong);
  background: var(--input-bg); color: var(--text); font: inherit; font-size: .92rem; font-weight: 500;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger-line); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.sm { height: 28px; padding: 0 10px; font-size: .85rem; }
.btn.icon { width: 30px; padding: 0; }
.btn.icon.sm { width: 26px; height: 26px; }

/* ---------- Tables ---------- */
table.list { width: 100%; border-collapse: collapse; font-size: .94rem; }
table.list th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 9px 14px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
table.list td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--hover); }
table.list td.actions { text-align: right; white-space: nowrap; }

.badge { display: inline-block; font-size: .76rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--chip); color: var(--muted); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.badge.green { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.red { background: var(--danger-soft); color: var(--danger); }

.notice { border-radius: 6px; padding: 10px 14px; font-size: .92rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--accent-soft); color: var(--info-fg); }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Toasts & modal ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--toast-bg); border: 1px solid var(--line-strong); color: #fff; padding: 10px 16px; border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.18); font-size: .92rem; max-width: 420px; }
.toast.error { background: var(--danger); }
.modal-bg { position: fixed; inset: 0; background: var(--overlay); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px; overflow: auto; }
.modal { background: var(--panel); border-radius: 10px; width: 100%; max-width: 480px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 760px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-head h2 { flex: 1; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: var(--auth-bg); }
.auth { width: 100%; max-width: 380px; background: var(--panel); border-radius: 12px; padding: 30px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.auth .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth .logo img { width: 36px; height: 36px; }
.auth .logo b { font-size: 1.2rem; color: var(--heading); }
.auth h1 { font-size: 1.2rem; margin-bottom: 6px; }
.auth form > * + * { margin-top: 14px; }
.auth .btn { width: 100%; height: 40px; }
.qr { display: block; margin: 8px auto; width: 200px; height: 200px; image-rendering: pixelated; }
.secret { font-family: var(--mono); font-size: .85rem; background: var(--chip); padding: 8px; border-radius: 6px; word-break: break-all; text-align: center; }
.code-input { font-size: 1.4rem !important; letter-spacing: .3em; text-align: center; font-family: var(--mono) !important; }

/* ---------- Training editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.editor.nopreview { grid-template-columns: minmax(0, 1fr); }
.sticky { position: sticky; top: 72px; }
.preview-frame { width: 100%; height: calc(100vh - 150px); border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.field-card { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.field-card + .field-card { margin-top: 10px; }
.field-card.open { border-color: var(--focus-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; }
.field-row .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field-row .target { font-family: var(--mono); font-size: .82rem; color: var(--muted); }
.field-body { border-top: 1px solid var(--line); padding: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-body .full { grid-column: 1 / -1; }
.subsection { grid-column: 1 / -1; border-top: 1px dashed var(--line); padding-top: 12px; }
.subsection > .flabel { margin-bottom: 8px; }
.opt-row { display: grid; grid-template-columns: 26px minmax(120px, 1fr) minmax(160px, 2fr) auto; gap: 8px; align-items: start; }
.opt-row + .opt-row { margin-top: 8px; }
.opt-row .num { color: var(--muted); font-size: .82rem; padding-top: 9px; text-align: right; }
.opt-row textarea, .pc-row textarea { min-height: 38px; }
.pc-row { display: grid; grid-template-columns: 50px 1fr; gap: 8px; align-items: start; }
.pc-row + .pc-row { margin-top: 6px; }
.pc-row b { padding-top: 8px; text-align: center; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { background: none; border: 0; padding: 8px 14px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--heading); border-bottom-color: var(--accent); font-weight: 600; }
.idlist { display: flex; flex-wrap: wrap; gap: 6px; }
.idlist code { background: var(--chip); padding: 2px 7px; border-radius: 4px; }
.idlist code.used { background: var(--ok-soft); color: var(--ok); }

/* ---------- Report form ---------- */
.report-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 18px; align-items: start; }
.report-layout.nopreview { grid-template-columns: minmax(0, 760px); justify-content: center; }
.fi + .fi { margin-top: 18px; }
.fi > .flabel { display: flex; align-items: baseline; gap: 8px; font-size: .9rem; color: var(--text); }
.fi > .flabel .tgt { font-weight: 400; font-family: var(--mono); font-size: .76rem; color: var(--muted); }
.var-list .var-item { display: flex; gap: 8px; align-items: flex-start; }
.var-list .var-item + .var-item { margin-top: 8px; }
.var-item .idx { flex: 0 0 40px; color: var(--muted); font-size: .82rem; padding-top: 6px; display: flex; align-items: center; justify-content: flex-end; gap: 2px; }
.var-item .idx span { padding-top: 0; }
.var-item .body { flex: 1; min-width: 0; }
.var-item .ctl { display: flex; gap: 2px; padding-top: 3px; }
.score-item > * + * { margin-top: 6px; }
.total-box { display: inline-block; font-size: 1.25rem; font-weight: 700; color: var(--heading); background: var(--accent-soft); padding: 6px 14px; border-radius: 6px; }
.fulltext { font-size: .84rem; color: var(--muted); margin-top: 4px; white-space: pre-wrap; border-left: 3px solid var(--line); padding-left: 8px; }
.mk-bar { display: flex; gap: 2px; margin-bottom: 4px; }
.mk-bar button { width: 28px; height: 24px; border: 1px solid var(--line); background: var(--input-bg); border-radius: 4px; cursor: pointer; font-size: .82rem; color: var(--muted); }
.mk-bar button:hover { color: var(--text); background: var(--hover); }
.img-field { display: flex; gap: 10px; align-items: center; }
.img-field img { max-width: 140px; max-height: 90px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel-2); }
.savebar { position: sticky; bottom: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(4px); border-top: 1px solid var(--line); padding: 10px 0; margin-top: 18px; }
.dirty-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); display: inline-block; }

/* change log (git-log style) */
.log { position: relative; }
.log-entry { display: grid; grid-template-columns: 16px 1fr; gap: 12px; padding-bottom: 16px; position: relative; }
.log-entry::before { content: ""; position: absolute; left: 7px; top: 16px; bottom: 0; width: 2px; background: var(--line); }
.log-entry:last-child::before { display: none; }
.log-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--panel); border: 3px solid var(--accent); margin-top: 2px; }
.log-entry.created .log-dot { border-color: var(--ok); }
.log-entry.upgraded .log-dot { border-color: var(--warn); }
.log-meta { font-size: .86rem; color: var(--muted); }
.log-meta b { color: var(--text); }
.diff { margin-top: 6px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; font-size: .88rem; }
.diff-row { display: grid; grid-template-columns: 170px 1fr 1fr; border-top: 1px solid var(--line); }
.diff-row:first-child { border-top: 0; }
.diff-row > div { padding: 6px 10px; white-space: pre-wrap; word-break: break-word; }
.diff-row .k { font-weight: 600; background: var(--panel-2); }
.diff-row .from { background: var(--del-bg); color: var(--del-fg); }
.diff-row .to { background: var(--ins-bg); color: var(--ins-fg); }
.diff img { max-height: 40px; border-radius: 3px; }

@media (max-width: 1000px) {
  .editor, .report-layout { grid-template-columns: minmax(0, 1fr); }
  .sticky { position: static; }
  .preview-frame { height: 70vh; }
  .nav a { padding: 7px 8px; }
}
@media (max-width: 720px) {
  .field-body { grid-template-columns: 1fr; }
  .diff-row { grid-template-columns: 1fr; }
  main { padding: 16px 14px 60px; }
}

/* Theme switch */
.usermenu button.theme, .auth-theme { white-space: nowrap; }
.auth-wrap { flex-direction: column; gap: 14px; }
.auth-theme { background: none; border: 0; color: #c9d6e6; font: inherit; font-size: .85rem; cursor: pointer; }
.auth-theme:hover { color: #fff; }
/* The preview is paper: keep it white in dark mode. */
.preview-frame { color-scheme: light; }

/* Score slider */
.score-slider { display: flex; align-items: center; gap: 10px; max-width: 520px; }
.score-slider input[type=range] { flex: 1; accent-color: var(--strong); height: 28px; cursor: pointer; }
.score-slider.unset input[type=range] { opacity: .45; filter: grayscale(1); }
.score-end { font-size: .8rem; color: var(--muted); min-width: 14px; text-align: center; }
.score-value { min-width: 84px; font-weight: 700; font-size: 1.05rem; color: var(--heading); background: var(--accent-soft); border-radius: 6px; padding: 3px 10px; text-align: center; }
.score-slider.unset .score-value { font-weight: 500; font-size: .85rem; color: var(--muted); background: var(--chip); }

/* Required fields & sections */
.req { color: var(--danger); font-weight: 700; margin-left: 2px; }
.fi.missing > .flabel { color: var(--danger); }
.fi.missing { box-shadow: inset 3px 0 0 var(--danger); padding-left: 10px; margin-left: -13px; }
.missing-list { margin-top: 8px; }
.form-section + .form-section, .fi + .form-section, .form-section + .fi { margin-top: 22px; }
.form-section-head { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; border-bottom: 2px solid var(--line); padding: 4px 0 8px; font: inherit; cursor: pointer; text-align: left; color: var(--heading); }
.form-section-head h3 { flex: 1; font-size: 1.02rem; }
.form-section-head .chev { width: 16px; color: var(--muted); transition: transform .15s; }
.form-section.closed .chev { transform: rotate(-90deg); }
.form-section-body { padding-top: 14px; }
.form-section.closed .form-section-body { display: none; }
.field-card.section-card { background: var(--panel-2); border-style: dashed; }
.field-card.section-card .name { color: var(--heading); text-transform: uppercase; letter-spacing: .04em; font-size: .88rem; }
.fields-list > * + * { margin-top: 10px; }
.in-section { margin-left: 22px; }

/* Filters & sortable tables */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.filters .f { width: 160px; }
.filters .f.narrow { width: 96px; }
.filters .f > span { font-size: .76rem; }
.filters input, .filters select { padding: 5px 8px; font-size: .88rem; }
th.sortable { padding: 0 !important; }
th.sortable button { all: unset; display: block; width: 100%; box-sizing: border-box; padding: 9px 14px; cursor: pointer; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; }
th.sortable button:hover { color: var(--text); }
th.sortable button:focus-visible { outline: 2px solid var(--focus-line); }
.sort-ind { font-size: .7rem; opacity: .7; margin-left: 2px; }

/* Dashboard */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 16px; }
.tile { display: flex; flex-direction: column; gap: 2px; padding: 18px 20px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text); }
a.tile:hover { text-decoration: none; border-color: var(--line-strong); }
.tile-n { font-size: 2.1rem; font-weight: 700; color: var(--heading); line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile-l { color: var(--muted); font-size: .92rem; }
.tile-s { font-size: .82rem; color: var(--accent); margin-top: 2px; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); gap: 28px 32px; }
.chart { margin: 0; min-width: 0; }
.chart figcaption { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; color: var(--heading); }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .val { fill: var(--text); font-size: 11px; font-weight: 600; font-family: inherit; }
.chart .bar { fill: var(--accent); }
.chart .hit { fill: transparent; }
.chart .col:hover .bar { fill: var(--primary-hover); }
.chart .col:hover .hit { fill: var(--hover); opacity: .5; }
.rank { display: flex; flex-direction: column; gap: 6px; }
.rank-row { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 2fr) 40px; gap: 10px; align-items: center; color: var(--text); padding: 3px 4px; border-radius: 4px; }
.rank-row:hover { background: var(--hover); text-decoration: none; }
.rank-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.rank-track { height: 12px; display: block; }
.rank-bar { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.rank-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; font-size: .9rem; }
.week-list { list-style: none; margin: 0; padding: 0; }
.week-list li a { display: block; padding: 10px 18px; border-bottom: 1px solid var(--line); color: var(--text); }
.week-list li:last-child a { border-bottom: 0; }
.week-list li a:hover { background: var(--hover); text-decoration: none; }
.wl-main { display: flex; gap: 8px; align-items: center; }

/* Calendar */
.legend { display: flex; gap: 14px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dot.planned, .cal-item.planned { --c: var(--accent); --cb: var(--accent-soft); }
.dot.current, .cal-item.current { --c: var(--ok); --cb: var(--ok-soft); }
.dot.past, .cal-item.past { --c: var(--muted); --cb: var(--chip); }
.dot { background: var(--c); }
.cal-head h2 { flex: none; min-width: 170px; text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-dow { padding: 8px 10px; font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--panel-2); }
.cal-day { min-height: 112px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-day:nth-child(7n + 7) { border-right: 0; }
.cal-day.out { background: var(--panel-2); }
.cal-day.out .cal-num { opacity: .45; }
.cal-num { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; border-radius: 50%; }
.cal-day.today .cal-num { background: var(--primary); color: #fff; font-weight: 700; }
.cal-item { all: unset; box-sizing: border-box; display: block; width: 100%; cursor: pointer; font-size: .78rem; line-height: 1.25; padding: 3px 6px; border-radius: 4px;
  background: var(--cb); color: var(--text); border-left: 3px solid var(--c); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-item:hover { filter: brightness(.96); }
.cal-item:focus-visible { outline: 2px solid var(--focus-line); }
.cal-item.cont { opacity: .8; }
.cal-co { color: var(--muted); margin-left: 4px; }
.cont-mark { color: var(--muted); }
@media (max-width: 720px) {
  .cal-day { min-height: 70px; padding: 3px; }
  .cal-co { display: none; }
  .charts { grid-template-columns: 1fr; }
}

/* Tabs on pages */
.page-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 12px; }
.page-tabs button { background: none; border: 0; padding: 12px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.page-tabs button.on { color: var(--heading); border-bottom-color: var(--accent); }
.page-tabs .count { font-weight: 500; font-size: .8rem; margin-left: 4px; color: var(--muted); }

/* Files */
.file-list { list-style: none; margin: 0; padding: 0; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 9px 18px; border-bottom: 1px solid var(--line); }
.file-list li:last-child { border-bottom: 0; }
.file-icon { width: 34px; height: 34px; border-radius: 6px; background: var(--chip); color: var(--muted); display: flex; align-items: center; justify-content: center; font-size: .66rem; font-weight: 700; text-transform: uppercase; flex: none; }
.file-name { flex: 1; min-width: 0; }
.file-name b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.dropzone { border: 2px dashed var(--line-strong); border-radius: 8px; padding: 18px; text-align: center; color: var(--muted); transition: background .15s, border-color .15s; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.assessment-file { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.form-disabled { opacity: .55; }
.grid2 > .card + .card, .grid2 > .card { margin-top: 0; }

/* ---------- Top bar: desktop order, mobile menu ---------- */
.menu { display: contents; }
.brand { order: 0; }
.menu .nav { order: 1; }
.topsearch { order: 2; }
.menu .usermenu { order: 3; }
.menu-btn { display: none; }

/* ---------- Responsive (phones & small tablets) ---------- */
html, body { overflow-x: hidden; }
img, svg, iframe { max-width: 100%; }
.tabs { overflow-x: auto; scrollbar-width: none; flex-wrap: nowrap; }
.tabs button { white-space: nowrap; flex: none; }

@media (max-width: 960px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 14px 10px; gap: 8px 10px; }
  .brand { flex: 1; }
  .menu-btn { display: inline-flex; flex-direction: column; justify-content: center; gap: 4px; order: 1;
    width: 40px; height: 36px; padding: 0 9px; background: rgba(255,255,255,.1); border: 0; border-radius: 6px; cursor: pointer; }
  .menu-btn span { display: block; height: 2px; background: #fff; border-radius: 2px; transition: transform .15s, opacity .15s; }
  .topbar.open .menu-btn span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .topbar.open .menu-btn span:nth-child(2) { opacity: 0; }
  .topbar.open .menu-btn span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
  .topsearch { order: 2; flex-basis: 100%; max-width: none; margin: 0; }
  .menu { display: none; order: 3; flex-basis: 100%; flex-direction: column; gap: 4px; padding: 6px 0 4px; border-top: 1px solid rgba(255,255,255,.12); }
  .topbar.open .menu { display: flex; }
  .menu .nav { flex-direction: column; gap: 2px; }
  .menu .nav a { padding: 10px 12px; font-size: 1rem; }
  .menu .usermenu { flex-wrap: wrap; gap: 4px 16px; padding: 8px 12px 2px; border-top: 1px solid rgba(255,255,255,.12); }
  .menu .usermenu a, .menu .usermenu button { padding: 6px 0; font-size: .95rem; }

}

@media (max-width: 720px) {
  :root { font-size: 15px; }
  main { padding: 14px 12px 70px; }
  h1 { font-size: 1.3rem; }
  .page-head { gap: 8px; margin-bottom: 14px; }
  .page-head .grow { flex-basis: 100%; }
  .page-head input[type=text] { max-width: none !important; }
  .card-head { padding: 12px 14px; flex-wrap: wrap; }
  .card-body { padding: 14px; }

  /* tables scroll inside their card instead of widening the page */
  table.list { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.list th, table.list td { padding: 9px 12px; white-space: nowrap; }

  .filters { padding: 10px 12px; }
  .filters .f { width: calc(50% - 5px); }
  .filters .f.narrow { width: calc(25% - 8px); }

  /* training editor */
  .field-row { flex-wrap: wrap; row-gap: 4px; padding: 8px 10px; }
  .field-row .name { order: -1; flex-basis: 100%; white-space: normal; }
  .field-row .target { flex: 1; }
  .section-card .field-row .name { flex-basis: auto; flex: 1; order: 0; }
  .in-section { margin-left: 10px; }
  .field-body { padding: 12px; }
  .opt-row { grid-template-columns: 22px minmax(0, 1fr); }
  .opt-row > :nth-child(3) { grid-column: 2; }
  .opt-row > :nth-child(4) { grid-column: 2; justify-content: flex-end; }
  .opt-row.small { display: none; }
  .pc-row { grid-template-columns: 34px minmax(0, 1fr); }

  /* report form */
  .score-slider { flex-wrap: wrap; }
  .score-slider input[type=range] { flex-basis: calc(100% - 60px); order: 1; }
  .score-slider .score-end:first-child { order: 0; }
  .savebar .row { gap: 8px; }
  .savebar .spacer { display: none; }
  .fi.missing { margin-left: -10px; padding-left: 7px; }
  .var-item .ctl { flex-direction: column; }

  /* dashboard */
  .tile { padding: 14px 16px; }
  .tile-n { font-size: 1.7rem; }
  .rank-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 32px; }

  /* modals and toasts */
  .modal-bg { padding: 4vh 10px; }
  .toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; }
  .file-list li { flex-wrap: wrap; padding: 10px 14px; }
  .file-list li .file-name { flex-basis: calc(100% - 50px); }
}

/* Calendar agenda (phones) */
.agenda { list-style: none; margin: 0; padding: 0; }
.agenda-day { display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.agenda-day:last-child { border-bottom: 0; }
.agenda-date { display: flex; flex-direction: column; align-items: center; line-height: 1.1; padding-top: 4px; }
.agenda-date b { font-size: 1.3rem; color: var(--heading); }
.agenda-date span { font-size: .75rem; color: var(--muted); text-transform: uppercase; }
.agenda-day.today .agenda-date b { color: var(--primary); }
.agenda-items { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.agenda-item { white-space: normal; padding: 8px 10px; font-size: .9rem; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.agenda-item b { display: inline; }

/* Drag and drop */
.drag-handle { display: inline-flex; align-items: center; justify-content: center; width: 22px; min-height: 26px; flex: none;
  color: var(--muted); cursor: grab; touch-action: none; border-radius: 4px; user-select: none; }
.drag-handle svg { fill: currentColor; }
.drag-handle:hover { color: var(--text); background: var(--hover); }
.sort-active, .sort-active * { cursor: grabbing !important; user-select: none; }
[data-sort] { position: relative; }
.sort-dragging { opacity: .45; }
.sort-drop-before::before { content: ""; position: absolute; left: 0; right: 0; top: -6px; height: 3px; border-radius: 2px; background: var(--accent); z-index: 2; }
.sort-end { position: relative; height: 0; margin: 0 !important; }
.sort-end.on::before { content: ""; position: absolute; left: 0; right: 0; top: 2px; height: 3px; border-radius: 2px; background: var(--accent); z-index: 2; }
.sort-list > * + * { margin-top: 10px; }

/* Admin panel */
.pad-b0 { padding-bottom: 0; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); gap: 14px; align-items: start; }
.loc-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; }
.loc-list li { display: flex; align-items: center; gap: 10px; padding: 6px 10px; }
.loc-list li + li { border-top: 1px solid var(--line); }
.loc-list .mono { overflow-wrap: anywhere; }
.grow { flex: 1; min-width: 0; }

/* Dropdown options drag and drop */
.opt-row .num { display: flex; align-items: center; justify-content: flex-end; gap: 2px; padding-top: 6px; }
@media (min-width: 721px) { .opt-row { grid-template-columns: 44px minmax(120px, 1fr) minmax(160px, 2fr) auto; } }
@media (max-width: 720px) { .opt-row { grid-template-columns: 44px minmax(0, 1fr); } }
.opt-list .sort-drop-before::before { top: -5px; }

/* Conditional fields picker */
.shows-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.shows-list .check.in { padding-left: 22px; }
.shows-list .check { align-items: baseline; }

/* Report page: trainee name and surname */
.name-edit { display: flex; gap: 10px; flex-wrap: wrap; max-width: 620px; }
.name-edit label { flex: 1 1 200px; min-width: 0; }
.name-edit label > span { display: block; font-size: .78rem; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.name-edit input { font-size: 1.15rem; font-weight: 700; color: var(--heading); width: 100%; }
.linklike { all: unset; color: var(--accent); cursor: pointer; text-decoration: underline; }
.linklike:focus-visible { outline: 2px solid var(--focus-line); }
.add-trainee { padding: 14px 18px; border-top: 1px solid var(--line); }
.add-trainee input { flex: 1 1 180px; max-width: 260px; min-width: 0; }
@media (max-width: 720px) { .add-trainee input { max-width: none; } }

/* Calendar month / year picker */
.cal-title { flex: none !important; }
.mypick { position: relative; display: inline-flex; gap: 2px; }
.mypick-btn { all: unset; cursor: pointer; padding: 2px 6px; border-radius: 6px; font: inherit; color: var(--heading); }
.mypick-btn:hover, .mypick-btn[aria-expanded=true] { background: var(--hover); }
.mypick-btn:focus-visible { outline: 2px solid var(--focus-line); }
.mypick-pop { position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow-lg, 0 8px 24px rgba(0,0,0,.18)); padding: 10px; width: 250px; font-size: .92rem; font-weight: 400; }
.mypick-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.mypick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.mypick-grid button { all: unset; text-align: center; padding: 7px 0; border-radius: 6px; cursor: pointer; color: var(--text); }
.mypick-grid button:hover { background: var(--hover); }
.mypick-grid button.now { box-shadow: inset 0 0 0 1px var(--accent); }
.mypick-grid button.on { background: var(--accent); color: #fff; font-weight: 600; }
.mypick-grid button:focus-visible { outline: 2px solid var(--focus-line); }

/* Branding */
.brand img, .auth .logo img { width: auto; max-width: 120px; object-fit: contain; flex: none; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.brand { min-width: 0; }
.logo-preview { display: inline-flex; align-items: center; justify-content: center; width: 56px; height: 44px; border-radius: 8px; border: 1px solid var(--line); }
.logo-preview img { height: 32px; width: auto; max-width: 44px; object-fit: contain; }
.logo-preview.light { background: #fff; }
.logo-preview.dark { background: var(--topbar); }

/* Checkbox links */
.link-list > * + * { margin-top: 10px; }
.link-card { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.link-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 12px; border-bottom: 1px solid var(--line); }
.link-body { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; padding: 12px; }
.link-body .full { grid-column: 1 / -1; }
@media (max-width: 720px) { .link-body { grid-template-columns: 1fr; } }
