/* FileLink admin panel — GitHub's design language (Primer): its colour tokens, type scale and
   components (header, nav list, boxes with rows, buttons, labels, toggle switches, flashes, segmented
   controls, underline tabs), built mobile-first: a bottom tab bar on phones, a side nav on desktops.
   No external fonts or assets (strict CSP): the font, the flags and the icons are in /static
   (Vazirmatn: OFL 1.1, flag-icons: MIT, Octicons: MIT). */
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/vazirmatn-variable.woff2") format("woff2");
  font-weight: 100 900; font-style: normal; font-display: swap;
}

/* ---- colour tokens (Primer light / dark) ---- */
:root, html[data-theme="light"] {
  --bg: #ffffff; --bg-subtle: #f6f8fa; --bg-inset: #f6f8fa; --bg-hover: #eff2f5; --bg-selected: #e7ebef;
  --border: #d1d9e0; --border-muted: #dfe4e9;
  --fg: #1f2328; --fg-muted: #59636e; --fg-onemph: #ffffff;
  --accent: #0969da; --accent-emph: #0969da; --accent-subtle: #ddf4ff; --accent-border: #54aeff66;
  --success: #1a7f37; --success-emph: #1f883d; --success-hover: #1c8139; --success-subtle: #dafbe1; --success-border: #4ac26b66;
  --danger: #d1242f; --danger-emph: #cf222e; --danger-subtle: #ffebe9; --danger-border: #ff818266;
  --attention: #9a6700; --attention-emph: #bf8700; --attention-subtle: #fff8c5; --attention-border: #d4a72c66;
  --done: #8250df; --done-subtle: #fbefff; --done-border: #c297ff66;
  --header-bg: #f6f8fa; --header-fg: #1f2328; --header-border: #d1d9e0;
  --btn-bg: #f6f8fa; --btn-hover: #eff2f5; --btn-border: #d1d9e0; --btn-shadow: 0 1px 0 #1f23280a;
  --toggle-off: #e6eaef; --knob: #ffffff;
  --overlay-shadow: 0 1px 3px #1f23281f, 0 8px 24px #4247503d;
  --scrim: rgb(31 35 40 / .5);
  --log-bg: #f6f8fa;
  color-scheme: light;
}
/* Panel theme setting (Settings → Panel): dark (default), light, auto = like the device. */
html[data-theme="dark"] {
  --bg: #0d1117; --bg-subtle: #151b23; --bg-inset: #010409; --bg-hover: #262c36; --bg-selected: #2a313c;
  --border: #3d444d; --border-muted: #2a313c;
  --fg: #f0f6fc; --fg-muted: #9198a1; --fg-onemph: #ffffff;
  --accent: #4493f8; --accent-emph: #1f6feb; --accent-subtle: #388bfd1a; --accent-border: #388bfd66;
  --success: #3fb950; --success-emph: #238636; --success-hover: #29903b; --success-subtle: #2ea04326; --success-border: #2ea04366;
  --danger: #f85149; --danger-emph: #da3633; --danger-subtle: #f851491a; --danger-border: #f8514966;
  --attention: #d29922; --attention-emph: #9e6a03; --attention-subtle: #bb800926; --attention-border: #bb800966;
  --done: #ab7df8; --done-subtle: #ab7df826; --done-border: #ab7df866;
  --header-bg: #010409; --header-fg: #f0f6fc; --header-border: #3d444d;
  --btn-bg: #212830; --btn-hover: #262c36; --btn-border: #3d444d; --btn-shadow: none;
  --toggle-off: #2a313c; --knob: #f0f6fc;
  --overlay-shadow: 0 0 0 1px #3d444d, 0 8px 24px #010409;
  --scrim: rgb(1 4 9 / .7);
  --log-bg: #010409;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #0d1117; --bg-subtle: #151b23; --bg-inset: #010409; --bg-hover: #262c36; --bg-selected: #2a313c;
    --border: #3d444d; --border-muted: #2a313c;
    --fg: #f0f6fc; --fg-muted: #9198a1; --fg-onemph: #ffffff;
    --accent: #4493f8; --accent-emph: #1f6feb; --accent-subtle: #388bfd1a; --accent-border: #388bfd66;
    --success: #3fb950; --success-emph: #238636; --success-hover: #29903b; --success-subtle: #2ea04326; --success-border: #2ea04366;
    --danger: #f85149; --danger-emph: #da3633; --danger-subtle: #f851491a; --danger-border: #f8514966;
    --attention: #d29922; --attention-emph: #9e6a03; --attention-subtle: #bb800926; --attention-border: #bb800966;
    --done: #ab7df8; --done-subtle: #ab7df826; --done-border: #ab7df866;
    --header-bg: #010409; --header-fg: #f0f6fc; --header-border: #3d444d;
    --btn-bg: #212830; --btn-hover: #262c36; --btn-border: #3d444d; --btn-shadow: none;
    --toggle-off: #2a313c; --knob: #f0f6fc;
    --overlay-shadow: 0 0 0 1px #3d444d, 0 8px 24px #010409;
    --scrim: rgb(1 4 9 / .7);
    --log-bg: #010409;
    color-scheme: dark;
  }
}

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, Tahoma, "Noto Sans Arabic", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 6px; --radius-lg: 12px;
  --side: 248px;           /* desktop side nav */
  --tabbar: 58px;          /* phone bottom tab bar */
  --tap: 40px;             /* smallest button on a phone */
}
/* Panel font setting. Vazirmatn has no Cyrillic: Russian falls back to the system font. */
html[data-font="vazirmatn"] { --font: "Vazirmatn", -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, Tahoma, sans-serif; }

/* ---- base ---- */
* { box-sizing: border-box; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font); line-height: 1.5;
  overflow-wrap: break-word; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-weight: 600; margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
code, .mono, pre, kbd { font-family: var(--mono); font-size: .88em; }
code { background: var(--bg-hover); padding: .1em .4em; border-radius: var(--radius); }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
hr { border: 0; border-top: 1px solid var(--border-muted); margin: 1rem 0; }
:focus-visible { outline: 2px solid var(--accent-emph); outline-offset: -2px; box-shadow: none; }
.icon { width: 16px; height: 16px; flex: none; fill: currentColor; vertical-align: text-bottom; }
.icon.lg { width: 20px; height: 20px; }
.icon.xl { width: 24px; height: 24px; }
[dir="rtl"] .icon.flip { transform: scaleX(-1); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---- utilities ---- */
.muted { color: var(--fg-muted); }
.small { font-size: .86rem; }
.nowrap { white-space: nowrap; }
.truncate { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.err, .error { color: var(--danger); }
.ok { color: var(--success); }
.warn-text { color: var(--attention); }
.strong { font-weight: 600; }
.row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.stack { display: grid; gap: .75rem; }
.grow { flex: 1; min-width: 0; }
.mt { margin-top: 1rem; }
.mb0 { margin-bottom: 0; }

/* ---- header (Primer Header) ---- */
.header { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: .5rem;
  height: 56px; padding: 0 1rem; background: var(--header-bg); color: var(--header-fg);
  border-bottom: 1px solid var(--header-border); }
.brand { display: inline-flex; align-items: center; gap: .5rem; color: var(--header-fg); font-weight: 600; font-size: 1rem; }
.brand:hover { text-decoration: none; }
.brand .logo { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-emph); color: #fff; }
.brand .sub { color: var(--fg-muted); font-weight: 400; }
.header .spacer { flex: 1; }
.header-btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-width: 36px; height: 36px;
  padding: 0 .55rem; border: 1px solid var(--border); border-radius: var(--radius); background: transparent;
  color: var(--header-fg); font: inherit; cursor: pointer; }
.header-btn:hover { background: var(--bg-hover); text-decoration: none; }

/* language menu (a <details> dropdown) */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-pop { position: absolute; inset-inline-end: 0; top: calc(100% + 4px); z-index: 40; min-width: 180px;
  margin: 0; padding: .25rem; list-style: none; background: var(--bg); border-radius: var(--radius-lg);
  box-shadow: var(--overlay-shadow); }
.menu-pop a, .menu-pop button { display: flex; align-items: center; gap: .6rem; width: 100%; min-height: 36px;
  padding: .4rem .6rem; border: 0; border-radius: var(--radius); background: none; color: var(--fg);
  font: inherit; text-align: start; cursor: pointer; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--bg-hover); text-decoration: none; }
.menu-pop [aria-current="true"] { font-weight: 600; }
.menu-pop .danger { color: var(--danger); }
.menu-pop .danger:hover { background: var(--danger-subtle); }
.flag { width: 20px; height: 15px; border-radius: 2px; flex: none; object-fit: cover; }

/* ---- layout ---- */
.layout { display: block; }
.main { min-width: 0; padding: 1rem 1rem calc(var(--tabbar) + 2rem + env(safe-area-inset-bottom)); max-width: 1180px; }
.main.no-nav { padding-bottom: 2rem; margin: 0 auto; }

/* side nav (Primer NavList): desktop column; on a phone the "More" sheet */
.sidenav { padding: .5rem; }
.nav-group { margin: 0; padding: 0; list-style: none; }
.nav-group + .nav-group { margin-top: .5rem; padding-top: .5rem; border-top: 1px solid var(--border-muted); }
.nav-heading { padding: .4rem .5rem .2rem; font-size: .8rem; font-weight: 600; color: var(--fg-muted); }
.nav-item { position: relative; display: flex; align-items: center; gap: .6rem; min-height: 36px; padding: .35rem .6rem;
  border-radius: var(--radius); color: var(--fg); }
.nav-item .icon { color: var(--fg-muted); }
.nav-item:hover { background: var(--bg-hover); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--bg-selected); font-weight: 600; }
.nav-item[aria-current="page"]::before { content: ""; position: absolute; inset-inline-start: -.5rem; top: .35rem; bottom: .35rem;
  width: 4px; border-radius: 6px; background: var(--accent-emph); }
.nav-item[aria-current="page"] .icon { color: var(--fg); }
.nav-item .counter { margin-inline-start: auto; }

/* phone / tablet: bottom tab bar + the "More" sheet */
.tabbar { position: fixed; inset-inline: 0; bottom: 0; z-index: 36; display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--header-bg); border-top: 1px solid var(--header-border); }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0;
  padding: 0 2px; border: 0; background: none; color: var(--fg-muted); font: inherit; font-size: .75rem; cursor: pointer; }
.tab .icon { width: 20px; height: 20px; }
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab:hover { text-decoration: none; color: var(--fg); }
.tab[aria-current="page"], .tab[aria-expanded="true"] { color: var(--fg); font-weight: 600; }
.tab[aria-current="page"] .icon { color: var(--accent); }
.tab .dot { position: absolute; margin-inline-start: 18px; margin-top: -14px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger-emph); }
.tab { position: relative; }

.scrim { display: none; }
@media (max-width: 1011px) {
  .sidenav { position: fixed; inset-inline: 0; bottom: 0; z-index: 35; max-height: 82vh; overflow-y: auto;
    padding: .5rem .75rem calc(var(--tabbar) + .75rem + env(safe-area-inset-bottom));
    background: var(--bg); border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: var(--overlay-shadow);
    transform: translateY(105%); transition: transform .2s cubic-bezier(.33, 1, .68, 1); visibility: hidden; }
  .nav-open .sidenav { transform: none; visibility: visible; }
  .nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 34; background: var(--scrim); }
  .sheet-handle { display: block; width: 36px; height: 4px; margin: .25rem auto .5rem; border-radius: 4px; background: var(--border); }
  /* the sheet lists every page as a big tap target, two per row */
  .sidenav .nav-group { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem; }
  .sidenav .nav-heading { grid-column: 1 / -1; }
  .sidenav .nav-item { min-height: 44px; }
  .sidenav .nav-item[aria-current="page"]::before { display: none; }
}
@media (min-width: 1012px) {
  .tabbar, .sheet-handle { display: none; }
  .layout.with-nav { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); }
  .sidenav { position: sticky; top: 56px; align-self: start; height: calc(100vh - 56px); overflow-y: auto;
    padding: 1rem .75rem; border-inline-end: 1px solid var(--border-muted); }
  .main { padding: 1.5rem 2rem 3rem; }
}
@media (prefers-reduced-motion: reduce) { .sidenav { transition: none; } }

/* ---- page head ---- */
.page-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; padding-bottom: .75rem;
  border-bottom: 1px solid var(--border-muted); }
.page-head h1 { flex: 1; min-width: 10rem; font-size: 1.35rem; }
.page-head .counter { font-size: .85rem; }
.page-desc { margin: -.25rem 0 1rem; color: var(--fg-muted); max-width: 75ch; }
.back { display: inline-flex; align-items: center; gap: .3rem; margin-bottom: .5rem; color: var(--fg-muted); font-size: .9rem; }
.section-title { display: flex; align-items: center; gap: .5rem; margin: 1.5rem 0 .5rem; font-size: 1rem; }
.section-title .counter { font-weight: 400; }

/* ---- Box: bordered container with a header and rows ---- */
.box { margin-bottom: 1rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); }
.box-header { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .75rem 1rem;
  background: var(--bg-subtle); border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.box-header:last-child { border-bottom: 0; border-radius: var(--radius); }
.box-title { flex: 1; min-width: 0; font-size: 1rem; font-weight: 600; display: flex; align-items: center; gap: .5rem; }
.box-body { padding: 1rem; }
.box-row { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-top: 1px solid var(--border-muted); }
.box-header + .box-row, .box > .box-row:first-child, .box > form > .box-row:first-child { border-top: 0; }
.box-row.top { align-items: flex-start; }
.box-row:hover.hoverable { background: var(--bg-subtle); }
.box-row .lead { flex: none; color: var(--fg-muted); }
.box-row .body { flex: 1; min-width: 0; }
.box-row .title { font-weight: 600; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; min-width: 0; }
.box-row .meta { color: var(--fg-muted); font-size: .86rem; display: flex; gap: .2rem .6rem; flex-wrap: wrap; }
.box-row .actions { flex: none; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.box-footer { padding: .75rem 1rem; border-top: 1px solid var(--border-muted); background: var(--bg-subtle);
  border-radius: 0 0 var(--radius) var(--radius); }
.box-empty { padding: 2rem 1rem; text-align: center; color: var(--fg-muted); }
.box.danger-zone { border-color: var(--danger-border); }
.box.danger-zone .box-header { background: var(--danger-subtle); border-color: var(--danger-border); }
a.box-row { color: inherit; }
a.box-row:hover { background: var(--bg-subtle); text-decoration: none; }
a.box-row .chev { color: var(--fg-muted); }
[dir="rtl"] a.box-row .chev { transform: scaleX(-1); }
/* a row that is a disclosure (status details) */
details.box-row, details.fold { display: block; padding: 0; }
details.fold > summary { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; cursor: pointer; list-style: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary:hover { background: var(--bg-subtle); }
details.fold > summary .chev { color: var(--fg-muted); transition: transform .15s; }
details.fold[open] > summary .chev { transform: rotate(180deg); }
.fold-body { padding: 0 1rem 1rem; }
@media (max-width: 767px) {
  .box-row.wrap-sm { flex-wrap: wrap; }
  .box-row.wrap-sm .actions { width: 100%; justify-content: flex-start; }
}

/* key / value rows */
.kv { display: grid; grid-template-columns: minmax(8rem, max-content) 1fr; gap: .4rem 1rem; margin: 0; }
.kv dt { color: var(--fg-muted); }
.kv dd { margin: 0; min-width: 0; }
@media (max-width: 599px) {
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dt { font-size: .86rem; }
  .kv dd { margin-bottom: .55rem; }
}

/* number tiles */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1rem; }
@media (min-width: 768px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { display: block; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: inherit; min-width: 0; }
a.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile .tile-label { color: var(--fg-muted); font-size: .86rem; display: flex; align-items: center; gap: .35rem; }
.tile .value { font-size: 1.6rem; font-weight: 600; line-height: 1.3; margin: .15rem 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .note { color: var(--fg-muted); font-size: .8rem; }

/* ---- buttons (Primer Button) ---- */
.btn { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 32px; padding: 0 .85rem; border: 1px solid var(--btn-border); border-radius: var(--radius);
  background: var(--btn-bg); box-shadow: var(--btn-shadow); color: var(--fg); font: inherit; font-weight: 500;
  line-height: 20px; white-space: nowrap; cursor: pointer; user-select: none; text-decoration: none; }
.btn:hover { background: var(--btn-hover); text-decoration: none; }
.btn .icon { color: var(--fg-muted); }
.btn-primary { background: var(--success-emph); border-color: #1f23281a; color: #fff; }
.btn-primary:hover { background: var(--success-hover); }
.btn-primary .icon { color: #fff; }
.btn-danger { color: var(--danger); }
.btn-danger .icon { color: var(--danger); }
.btn-danger:hover { background: var(--danger-emph); border-color: var(--danger-emph); color: #fff; }
.btn-danger:hover .icon { color: #fff; }
.btn-invisible { border-color: transparent; background: transparent; box-shadow: none; color: var(--accent); }
.btn-invisible:hover { background: var(--bg-hover); }
.btn-sm { min-height: 28px; padding: 0 .6rem; font-size: .86rem; }
.btn-block { display: flex; width: 100%; }
.btn-icon { padding: 0; width: 32px; }
.btn-icon.btn-sm { width: 28px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.htmx-request { opacity: .6; pointer-events: none; }
@media (pointer: coarse), (max-width: 767px) {
  .btn { min-height: var(--tap); }
  .btn-sm { min-height: 36px; }
  .btn-icon { width: var(--tap); }
  .btn-icon.btn-sm { width: 36px; }
}

/* ---- labels and counters ---- */
.label { display: inline-flex; align-items: center; gap: .25rem; padding: 0 .5rem; min-height: 20px; line-height: 18px;
  border: 1px solid var(--border); border-radius: 2em; font-size: .78rem; font-weight: 500; color: var(--fg-muted);
  white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
a.label:hover { text-decoration: none; border-color: var(--fg-muted); }
.label-success, .label.done, .label.on { color: var(--success); border-color: var(--success-border); }
.label-danger, .label.failed { color: var(--danger); border-color: var(--danger-border); }
.label-attention { color: var(--attention); border-color: var(--attention-border); }
.label-accent { color: var(--accent); border-color: var(--accent-border); }
.label-done { color: var(--done); border-color: var(--done-border); }
.label.off { color: var(--fg-muted); }
.counter { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 2em; background: var(--bg-hover);
  color: var(--fg); font-size: .78rem; font-weight: 500; line-height: 18px; text-align: center; }
.counter.danger { background: var(--danger-emph); color: #fff; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--fg-muted); flex: none; }
.dot.ok { background: var(--success); } .dot.warn { background: var(--attention); } .dot.fail { background: var(--danger); }

/* ---- flash (alerts) ---- */
.flash { display: flex; align-items: flex-start; gap: .6rem; margin-bottom: 1rem; padding: .75rem 1rem;
  border: 1px solid var(--accent-border); border-radius: var(--radius); background: var(--accent-subtle); color: var(--fg); }
.flash > .icon { margin-top: 2px; color: var(--accent); }
.flash .grow > :last-child { margin-bottom: 0; }
.flash-success { background: var(--success-subtle); border-color: var(--success-border); }
.flash-success > .icon { color: var(--success); }
.flash-warn { background: var(--attention-subtle); border-color: var(--attention-border); }
.flash-warn > .icon { color: var(--attention); }
.flash-error { background: var(--danger-subtle); border-color: var(--danger-border); }
.flash-error > .icon { color: var(--danger); }
.flash .btn { margin-inline-start: auto; }
.flash-list { margin-bottom: 1rem; }
.flash-list .flash { margin-bottom: .5rem; align-items: center; }

/* ---- toggle switch (Primer ToggleSwitch: a button) ---- */
.toggle { display: inline-flex; align-items: center; gap: .5rem; padding: 4px 0; border: 0; background: none;
  color: var(--fg-muted); font: inherit; font-size: .86rem; cursor: pointer; flex: none; }
.toggle .state { min-width: 2.2em; text-align: end; }
.toggle .track { position: relative; width: 44px; height: 26px; border: 1px solid var(--border); border-radius: 13px;
  background: var(--toggle-off); transition: background .15s, border-color .15s; flex: none; }
.toggle .knob { position: absolute; top: 2px; inset-inline-start: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--knob); box-shadow: 0 1px 2px rgb(0 0 0 / .3); transition: inset-inline-start .15s; }
.toggle[aria-checked="true"] .track { background: var(--accent-emph); border-color: var(--accent-emph); }
.toggle[aria-checked="true"] .knob { inset-inline-start: 20px; background: #fff; }
.toggle[aria-checked="true"] .state { color: var(--fg); }
.group-counts { display: block; margin-top: .25rem; font-weight: 600; color: var(--fg-muted); }
.toggle[aria-checked="mixed"] .track { background: var(--accent-subtle); border-color: var(--accent-emph); }
.toggle[aria-checked="mixed"] .knob { inset-inline-start: 11px; background: var(--accent-emph); }
.toggle[aria-checked="mixed"] .state { color: var(--fg); }
.toggle.warn[aria-checked="mixed"] .track { border-color: var(--attention-emph); }
.toggle.warn[aria-checked="mixed"] .knob { background: var(--attention-emph); }
.toggle.danger[aria-checked="true"] .track { background: var(--danger-emph); border-color: var(--danger-emph); }
.toggle.warn[aria-checked="true"] .track { background: var(--attention-emph); border-color: var(--attention-emph); }
.toggle.htmx-request { opacity: .6; pointer-events: none; }
.toggle[disabled] { opacity: .5; cursor: not-allowed; }
@media (prefers-reduced-motion: reduce) { .toggle .knob, .toggle .track { transition: none; } }

/* ---- forms ---- */
label { font-weight: 500; }
.form-group { display: grid; gap: .3rem; margin-bottom: 1rem; }
.form-group .note { font-weight: 400; }
.note { color: var(--fg-muted); font-size: .86rem; }
.form-control, .form-select, input[type="text"], input[type="number"], input[type="search"], input[type="password"],
input[type="file"], select, textarea {
  max-width: 100%; min-height: 32px; padding: 5px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--fg); font: inherit; font-size: 14px; line-height: 20px; }
input[type="file"] { padding: 4px; }
textarea { width: 100%; min-height: 4.5rem; resize: vertical; }
select { padding-inline-end: 28px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-emph); box-shadow: inset 0 0 0 1px var(--accent-emph); }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent-emph); flex: none; }
.check { display: inline-flex; align-items: center; gap: .5rem; font-weight: 400; cursor: pointer; }
.input-block { width: 100%; }
.invalid input, .invalid select, input:user-invalid { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .86rem; }
.search-field { position: relative; display: flex; align-items: center; flex: 1; min-width: 12rem; }
.search-field .icon { position: absolute; inset-inline-start: 10px; color: var(--fg-muted); pointer-events: none; }
.search-field input { width: 100%; padding-inline-start: 32px; }
/* phones: 16 px inputs (iOS would zoom in otherwise) and full-width fields */
@media (pointer: coarse), (max-width: 767px) {
  input[type="text"], input[type="number"], input[type="search"], input[type="password"], select, textarea { font-size: 16px; min-height: var(--tap); }
}
.inline-form { display: flex; align-items: flex-end; gap: .75rem; flex-wrap: wrap; }
.inline-form .form-group { margin-bottom: 0; }
@media (max-width: 599px) {
  .inline-form { display: grid; }
  .inline-form .form-group input, .inline-form .form-group select { width: 100%; }
}

/* settings rows: name + help on one side, the control on the other */
.setting { display: flex; align-items: center; gap: .75rem 1rem; padding: .85rem 1rem; border-top: 1px solid var(--border-muted); flex-wrap: wrap; }
.setting:first-child, .box-header + .setting { border-top: 0; }
.setting .body { flex: 1 1 16rem; min-width: 0; }
.setting .name { font-weight: 600; display: block; }
.setting .help { color: var(--fg-muted); font-size: .86rem; margin-top: .15rem; }
.setting .control { flex: none; display: flex; align-items: center; gap: .5rem; }
.setting .control input[type="number"] { width: 7.5rem; }
.setting .control input[type="text"] { width: 9rem; }
.setting .control input.wide { width: min(30rem, 100%); }
.setting .defaults { flex-basis: 100%; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; color: var(--fg-muted); font-size: .8rem; }
.setting.invalid { background: var(--danger-subtle); }
@media (max-width: 599px) {
  .setting .control:has(input:not([type="hidden"]), select) { flex-basis: 100%; }
  .setting .control input[type="number"], .setting .control input[type="text"], .setting .control select { width: 100%; }
}
.savebar { position: sticky; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); z-index: 10; display: flex; align-items: center;
  justify-content: flex-end; gap: .75rem; flex-wrap: wrap; margin-top: -1px; padding: .75rem 1rem; background: var(--bg-subtle);
  border: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); }
@media (min-width: 1012px) { .savebar { bottom: 0; } }

/* ---- segmented control ---- */
.segmented { display: inline-flex; padding: 2px; gap: 2px; border-radius: var(--radius); background: var(--bg-hover);
  border: 1px solid var(--border-muted); max-width: 100%; flex-wrap: wrap; }
.segmented > a, .segmented > button { display: inline-flex; align-items: center; gap: .35rem; min-height: 30px; padding: 0 .75rem;
  border: 1px solid transparent; border-radius: 5px; background: none; color: var(--fg); font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap; }
.segmented > a:hover, .segmented > button:hover { background: var(--bg-selected); text-decoration: none; }
.segmented > [aria-current="page"], .segmented > [aria-pressed="true"] { background: var(--bg); border-color: var(--border); font-weight: 600; }
@media (pointer: coarse), (max-width: 767px) { .segmented > a, .segmented > button { min-height: 36px; } }
.segmented.full { display: flex; }
.segmented.full > * { flex: 1; justify-content: center; }

/* ---- underline tabs ---- */
.underline-nav { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border-muted); overflow-x: auto; scrollbar-width: none; }
.underline-nav a { display: inline-flex; align-items: center; gap: .4rem; padding: .6rem .75rem; color: var(--fg);
  border-bottom: 2px solid transparent; white-space: nowrap; }
.underline-nav a:hover { text-decoration: none; border-bottom-color: var(--border); }
.underline-nav a[aria-current="page"] { font-weight: 600; border-bottom-color: #fd8c73; }

/* filter chips (links) */
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .75rem; }
.chip { display: inline-flex; align-items: center; gap: .35rem; min-height: 30px; padding: 0 .75rem; border: 1px solid var(--border);
  border-radius: 2em; color: var(--fg); background: var(--bg); font-size: .86rem; font-weight: 500; }
.chip:hover { background: var(--bg-hover); text-decoration: none; }
.chip[aria-current="page"], .chip[aria-pressed="true"] { background: var(--accent-subtle); border-color: var(--accent-border); color: var(--accent); }
button.chip { font: inherit; font-size: .86rem; cursor: pointer; }
@media (pointer: coarse), (max-width: 767px) { .chip { min-height: 36px; } }

/* filter panel (<details>) */
.filters { margin-bottom: 1rem; }
.filters > summary { display: inline-flex; }
.filters[open] > summary { margin-bottom: .75rem; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .75rem; align-items: end; padding: 1rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-subtle); }
.filter-grid .form-group { margin: 0; }
.filter-grid select, .filter-grid input[type="text"], .filter-grid input[type="search"] { width: 100%; }

/* ---- pagination ---- */
.pager { display: flex; align-items: center; justify-content: center; gap: .75rem; margin: 1rem 0; }

/* ---- blank slate ---- */
.blankslate { padding: 2rem 1rem; text-align: center; color: var(--fg-muted); }
.blankslate .icon { width: 24px; height: 24px; margin-bottom: .5rem; }

/* ---- dashboard bits ---- */
.recent .title .truncate { max-width: 100%; }
.kind-icon { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg-hover); color: var(--fg-muted); flex: none; }
.kind-icon.failed { background: var(--danger-subtle); color: var(--danger); }
.kind-icon.processing { background: var(--accent-subtle); color: var(--accent); }
.limits { display: grid; gap: 1rem; }
@media (min-width: 768px) { .limits { grid-template-columns: 1fr 1fr; } }
.limits h3 { margin-bottom: .5rem; font-size: .9rem; display: flex; align-items: center; gap: .4rem; }

/* job rows */
.job .title { font-weight: 500; }
.job .file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: var(--bg-hover); color: var(--fg); font-weight: 600; }

/* ---- Texts ---- */
.text-row { padding: 1rem; border-top: 1px solid var(--border-muted); }
.text-row:first-child { border-top: 0; }
.text-row .head { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-bottom: .5rem; }
.text-row .head code { font-size: .8rem; }
.text-row .grid2 { display: grid; gap: .75rem; }
@media (min-width: 900px) { .text-row .grid2 { grid-template-columns: 1fr 1fr; } }
.text-row .ref { padding: .5rem .75rem; border-radius: var(--radius); background: var(--bg-subtle); border: 1px solid var(--border-muted);
  color: var(--fg-muted); font-family: var(--font); font-size: .9rem; max-height: 14rem; overflow-y: auto; }
.text-row .ref-label { font-size: .78rem; color: var(--fg-muted); margin-bottom: .2rem; }
.text-row textarea { font-family: var(--font); }
.text-row .row-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
.text-row.invalid { background: var(--danger-subtle); }
.text-row .unsaved { display: none; }
.text-row.dirty .unsaved { display: inline-flex; }
.text-row.dirty { box-shadow: inset 3px 0 0 var(--attention-emph); }
[dir="rtl"] .text-row.dirty { box-shadow: inset -3px 0 0 var(--attention-emph); }
.text-tools { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.lang-panel .box-header h2 { font-size: 1rem; }

/* searchable language picker */
.picker { position: relative; }
.picker-btn { display: inline-flex; align-items: center; gap: .5rem; min-height: 32px; padding: 0 .75rem; border: 1px solid var(--btn-border);
  border-radius: var(--radius); background: var(--btn-bg); color: var(--fg); font: inherit; font-weight: 500; cursor: pointer; }
.picker-btn:hover { background: var(--btn-hover); }
@media (pointer: coarse), (max-width: 767px) { .picker-btn { min-height: var(--tap); } }
.picker-pop { position: absolute; inset-inline-start: 0; top: calc(100% + 4px); z-index: 40; width: min(320px, calc(100vw - 2rem));
  background: var(--bg); border-radius: var(--radius-lg); box-shadow: var(--overlay-shadow); overflow: hidden; }
.picker-search { display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem; border-bottom: 1px solid var(--border-muted); }
.picker-search input { flex: 1; min-width: 0; border: 0; box-shadow: none; padding-inline: 0; background: transparent; }
.picker-search input:focus { box-shadow: none; }
.picker-list { list-style: none; margin: 0; padding: .25rem; max-height: 50vh; overflow-y: auto; }
.picker-list [role="option"] { display: flex; align-items: center; gap: .5rem; min-height: 36px; padding: .35rem .6rem; border-radius: var(--radius); cursor: pointer; }
.picker-list [role="option"]:hover, .picker-list [role="option"].active { background: var(--bg-hover); }
.picker-list [role="option"][aria-selected="true"] { font-weight: 600; }
.picker-list .code { margin-inline-start: auto; color: var(--fg-muted); font-family: var(--mono); font-size: .8rem; }
.picker-list .dirty-count { color: var(--attention); font-size: .78rem; }
.picker-empty { padding: .75rem; color: var(--fg-muted); }

/* ---- Logs ---- */
.log { margin: 0; padding: .75rem 1rem; background: var(--log-bg); border: 1px solid var(--border); border-radius: var(--radius);
  font-family: var(--mono); font-size: .8rem; line-height: 1.55; max-height: 70vh; overflow-y: auto; }
.log .entry { padding: 1px 0; white-space: pre-wrap; word-break: break-word; }
.log .ts { color: var(--fg-muted); }
.log .lvl { font-weight: 600; }
.log .lvl-error .lvl, .log .lvl-critical .lvl { color: var(--danger); }
.log .lvl-warning .lvl { color: var(--attention); }
.log .lvl-info .lvl { color: var(--accent); }
.log .lvl-error, .log .lvl-critical { background: var(--danger-subtle); }
.log pre { margin: .2rem 0 .3rem; color: var(--fg-muted); }

/* ---- login / error pages ---- */
.auth { max-width: 360px; margin: 8vh auto 2rem; padding: 0 1rem; }
.auth-logo { display: grid; place-items: center; margin-bottom: 1rem; }
.auth-logo .logo { width: 48px; height: 48px; }
.auth-logo .logo .icon { width: 24px; height: 24px; }
.auth h1 { text-align: center; font-size: 1.5rem; font-weight: 300; margin-bottom: 1rem; }
.auth .box-body { padding: 1.25rem; }
.auth .widget { display: grid; place-items: center; margin: 1rem 0; min-height: 44px; }
.auth input[type="password"] { width: 100%; }

/* ---- misc ---- */
.steps { margin: 0; padding-inline-start: 1.25rem; }
.steps li { margin-bottom: .4rem; }
.help-list { margin: 0; padding-inline-start: 1.25rem; color: var(--fg-muted); }
.box.attached { margin-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; }
@media (max-width: 767px) { .section-nav { display: none; } }
.tab[data-current] { color: var(--fg); font-weight: 600; }
.tab[data-current] .icon { color: var(--accent); }
.box > details.fold { border-top: 1px solid var(--border-muted); min-width: 0; }
.box > .box-header + details.fold, .box > details.fold:first-child { border-top: 0; }
details.fold > summary > .grow { min-width: 0; }
.fold-body { min-width: 0; overflow-wrap: anywhere; }
@media (min-width: 768px) {
  .box.quick { display: grid; grid-template-columns: 1fr 1fr; }
  .box.quick .box-header { grid-column: 1 / -1; }
  .box.quick .setting:nth-child(3) { border-top: 0; }
  .box.quick .setting:nth-child(odd) { border-inline-start: 1px solid var(--border-muted); }
}
/* an action that failed (panel.js initErrors) */
.toast { position: fixed; inset-inline: 16px; bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom)); z-index: 50;
  max-width: 480px; margin: 0 auto; padding: .75rem 1rem; border-radius: var(--radius); background: var(--danger-emph);
  color: #fff; font-weight: 500; box-shadow: var(--overlay-shadow); }
@media (min-width: 1012px) { .toast { bottom: 24px; } }

.form-actions { margin: 1rem 0; }
.mb { margin-bottom: .75rem; }

/* v2.39.3: the running version at the bottom of the menu */
.nav-version { margin: 16px 12px 8px; font-size: 12px; color: var(--fg-muted); text-align: start; }

/* v2.39.4 Monitor page: SVG meters and line charts (attributes only; colours here, both themes) */
.meter { display: block; width: 100%; height: 8px; margin: .35rem 0 .25rem; }
[dir="rtl"] .meter { transform: scaleX(-1); }
.meter-track { fill: var(--bg-hover); }
.meter.tone-ok .meter-fill { fill: var(--success-emph); }
.meter.tone-warn .meter-fill { fill: var(--attention-emph); }
.meter.tone-fail .meter-fill { fill: var(--danger-emph); }
.meter.tone-accent .meter-fill, .meter.tone-off .meter-fill { fill: var(--accent-emph); }
.mon-state { margin-bottom: 1rem; }
.box-header .segmented { margin-inline-start: auto; }
.mon-chart { margin: 0 0 1rem; }
.mon-chart:last-child { margin-bottom: 0; }
.mon-chart figcaption { display: flex; flex-wrap: wrap; gap: .25rem .9rem; margin-bottom: .35rem; }
.mon-chart svg { display: block; width: 100%; height: 120px; background: var(--bg-subtle); border-radius: var(--radius); }
.mon-chart .grid { stroke: var(--border-muted); stroke-width: 1; vector-effect: non-scaling-stroke; }
.mon-chart polyline { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.mon-chart .axis { display: flex; justify-content: space-between; margin-top: .2rem; }
.s-cpu { stroke: var(--accent-emph); }
.s-mem { stroke: var(--attention-emph); }
.s-run { stroke: var(--success-emph); }
.s-wait { stroke: var(--danger-emph); }
.legend { display: inline-flex; align-items: center; gap: .3rem; color: var(--fg-muted); }
.legend::before { content: ""; width: .9rem; height: 3px; border-radius: 2px; background: currentColor; }
.legend.s-cpu::before { background: var(--accent-emph); }
.legend.s-mem::before { background: var(--attention-emph); }
.legend.s-run::before { background: var(--success-emph); }
.legend.s-wait::before { background: var(--danger-emph); }
