:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #1b1f27;
  --muted: #646c7a;
  --accent: #f5821f;
  --accent-ink: #2b1906;
  --accent-strong: #b45309;
  --accent-soft: #fdecd9;
  --danger: #c4314b;
  --ok: #1f8a4c;
  --folder: #f0a24e;
  --shadow: 0 8px 30px rgba(20, 28, 45, 0.12);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111318; --surface: #191c23; --surface-2: #20242d; --border: #2c313c; --text: #e8eaef;
    --muted: #9aa2b1; --accent: #f5a04f; --accent-ink: #241403; --accent-strong: #ffb673; --accent-soft: #3a2a14; --danger: #f06a80;
    --ok: #4cc37f; --folder: #f5a04f; --shadow: 0 8px 30px rgba(0, 0, 0, 0.5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111318; --surface: #191c23; --surface-2: #20242d; --border: #2c313c; --text: #e8eaef;
  --muted: #9aa2b1; --accent: #f5a04f; --accent-ink: #241403; --accent-strong: #ffb673; --accent-soft: #3a2a14; --danger: #f06a80;
  --ok: #4cc37f; --folder: #f5a04f; --shadow: 0 8px 30px rgba(0, 0, 0, 0.5); color-scheme: dark;
}

/* Brand: BAJ Design ("Base"). The Worker sets data-brand on <html> (src/brand.ts). Palette from baj.design: ink #242220, bone #EDEAE3,
   purple #7B4FFF, lighter purple #B79CFF for dark mode, pink #EE3C8F (not used for fills). System fonts only: the CSP allows no web fonts.
   Contrast (WCAG AA, checked): white on #7B4FFF 4.77, ink on #B79CFF 6.95, links #5B2FE0 on the page 6.35, #B79CFF on the dark page 7.63. */
:root[data-brand="baj"] {
  --bg: #f3f1ec; --surface: #ffffff; --surface-2: #ebe8e1; --border: #dcd8cf; --text: #242220; --muted: #6a655e;
  --accent: #7B4FFF; --accent-ink: #ffffff; --accent-strong: #5B2FE0; --accent-soft: #e9e3ff; --folder: #7B4FFF;
  --mark-ink: #242220; --shadow: 0 8px 30px rgba(36, 34, 32, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root[data-brand="baj"]:not([data-theme="light"]) {
    --bg: #1b1a18; --surface: #242220; --surface-2: #2e2b28; --border: #3d3934; --text: #EDEAE3; --muted: #a29c92;
    --accent: #B79CFF; --accent-ink: #242220; --accent-strong: #B79CFF; --accent-soft: #34294f; --folder: #B79CFF; --mark-ink: #EDEAE3;
  }
}
:root[data-brand="baj"][data-theme="dark"] {
  --bg: #1b1a18; --surface: #242220; --surface-2: #2e2b28; --border: #3d3934; --text: #EDEAE3; --muted: #a29c92;
  --accent: #B79CFF; --accent-ink: #242220; --accent-strong: #B79CFF; --accent-soft: #34294f; --folder: #B79CFF; --mark-ink: #EDEAE3;
}
.brand .mark-baj { width: 26px; height: 26px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-by { font-size: 11.5px; font-weight: 500; color: var(--muted); }
.mark-baj .m1 { stroke: var(--mark-ink); }
.mark-baj .m2 { stroke: var(--accent); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
h1 { font-size: 20px; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.hidden { display: none !important; }

/* Buttons and inputs */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: default; }
.icon-btn { border: 0; background: transparent; padding: 6px; border-radius: 6px; cursor: pointer; color: var(--muted); line-height: 0; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=url], select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
input:focus-visible, select:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, .row:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }

/* Auth screens */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand svg { width: auto; height: 26px; }
.auth-card .brand { margin-bottom: 22px; }
.auth-card .btn.primary { width: 100%; justify-content: center; padding: 10px; }

/* App layout */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100%; }
.sidebar { border-right: 1px solid var(--border); background: var(--surface); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 4px 8px 16px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.quota { margin-top: auto; padding: 10px; font-size: 12.5px; color: var(--muted); }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin: 6px 0; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; gap: 12px; align-items: center; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar .search { flex: 1; max-width: 520px; }
.topbar .menu-btn { display: none; }
.content { padding: 20px 24px 60px; }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head .spacer { flex: 1; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-size: 18px; font-weight: 600; }
.crumbs a { color: var(--muted); padding: 2px 4px; border-radius: 6px; }
.crumbs a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.crumbs .sep { color: var(--muted); }
.crumbs .cur { padding: 2px 4px; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-weight: 500; }
.pill.accent { background: var(--accent-soft); color: var(--accent-strong); }

/* File list */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list-head, .row { display: grid; grid-template-columns: 1fr 120px 110px 44px; align-items: center; gap: 12px; padding: 0 12px; }
.list-head { height: 36px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.row { min-height: 48px; border-bottom: 1px solid var(--border); cursor: pointer; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row .name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row .name span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.ficon { width: 26px; height: 26px; flex: none; }
.empty { padding: 56px 16px; text-align: center; color: var(--muted); }
.empty svg { width: 46px; height: 46px; opacity: 0.6; margin-bottom: 8px; }
.drop-hint.denied { background: color-mix(in srgb, var(--danger) 12%, transparent); border-color: var(--danger); color: var(--danger); }
.drop-hint { position: fixed; inset: 0; background: color-mix(in srgb, var(--accent) 14%, transparent); border: 3px dashed var(--accent); z-index: 50; display: grid; place-items: center; font-size: 18px; font-weight: 600; color: var(--accent-strong); pointer-events: none; }

/* Menus, dialogs, toasts */
.menu { position: fixed; z-index: 60; min-width: 180px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; }
.menu button { display: flex; width: 100%; gap: 10px; align-items: center; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); outline: none; }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog.wide { width: min(980px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 14, 22, 0.45); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-body { padding: 18px 20px; overflow: auto; max-height: calc(100vh - 170px); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }
.section + .section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.inline { display: flex; gap: 8px; align-items: center; }
.inline > input, .inline > select { flex: 1; }
.inline > select.role { flex: 0 0 120px; }
.people { margin-top: 10px; }
.person { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.person:last-child { border-bottom: 0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.person .who { flex: 1; min-width: 0; }
.person .who div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkbox { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.linkbox .url { display: flex; gap: 8px; align-items: center; }
.linkbox .url input { font-family: ui-monospace, monospace; font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preview { display: grid; place-items: center; min-height: 300px; background: var(--surface-2); border-radius: 10px; overflow: hidden; }
.preview img, .preview video { max-width: 100%; max-height: 70vh; display: block; }
.preview iframe { width: 100%; height: 72vh; border: 0; background: #fff; }
.preview iframe.viewer { background: transparent; color-scheme: normal; }
.preview.viewer-box { display: block; position: relative; }
.preview .pv-note { padding: 6px 12px; font-size: 12.5px; color: var(--muted); background: var(--accent-soft); }
.preview .pv-status { position: absolute; inset: 0; z-index: 1; display: grid; place-content: center; justify-items: center; text-align: center; padding: 24px; color: var(--muted); background: var(--surface-2); }
.preview .pv-status.error { color: var(--text); }
.preview audio, .preview-audio { margin: 40px; max-width: calc(100% - 32px); }
.preview pre { margin: 0; padding: 16px; width: 100%; max-height: 70vh; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 12.5px/1.5 ui-monospace, monospace; align-self: start; }
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13.5px; }
.toast.error { background: var(--danger); color: #fff; }
.uploads { position: fixed; right: 16px; bottom: 16px; width: 320px; max-width: calc(100vw - 32px); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); z-index: 40; overflow: hidden; }
.uploads .uh { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; font-weight: 600; border-bottom: 1px solid var(--border); }
.uploads .ui { padding: 8px 12px; font-size: 13px; }
.uploads .ui .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; max-width: 760px; }
table.simple { width: 100%; border-collapse: collapse; font-size: 13px; }
table.simple td, table.simple th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.simple th { color: var(--muted); font-weight: 500; font-size: 12px; }
.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font: 12px/1.5 ui-monospace, monospace; white-space: pre-wrap; word-break: break-all; }
.feed .item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.feed .item:last-child { border-bottom: 0; }
.feed .when { color: var(--muted); font-size: 12.5px; width: 130px; flex: none; }
.public-wrap { max-width: 960px; margin: 0 auto; padding: 20px 16px 60px; }
.public-top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.dropzone { border: 2px dashed var(--border); border-radius: 14px; padding: 40px 16px; text-align: center; background: var(--surface); }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 30; width: 260px; transform: translateX(-100%); transition: transform 0.18s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .topbar { padding: 10px 16px; }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 16px 16px 60px; }
  .list-head, .row { grid-template-columns: 1fr 44px; }
  .list-head .c-size, .list-head .c-mod, .row .c-size, .row .c-mod { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .feed .when { width: 90px; }
  .hide-sm { display: none; }
}

.pill.danger { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
table.simple.mod td:first-child { min-width: 180px; }
table.simple td.actions > * { margin: 0 0 6px 6px; }
table.simple td.actions { text-align: right; min-width: 220px; }
.ficon-sm svg { width: 20px; height: 20px; color: var(--muted); }
textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font: inherit; color: inherit; resize: vertical; }
textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.prose h2 { margin-top: 18px; }
.prose ol { padding-left: 20px; margin: 0; }
.prose li { margin: 4px 0; }
table.simple.mod td { overflow-wrap: anywhere; }
table.simple.mod td.actions { min-width: 140px; }
table.simple.mod td.actions > .btn { display: flex; width: max-content; margin: 0 0 6px auto; }
.nav .badge { margin-left: auto; background: var(--accent); color: var(--accent-ink); border-radius: 99px; font-size: 11px; font-weight: 700; padding: 1px 7px; }
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-bottom: 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-strong); font-weight: 500; }
.banner:hover { text-decoration: none; filter: brightness(1.03); }
.pill.warn { background: color-mix(in srgb, #e8a33a 18%, transparent); color: #b7791f; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg .icon-btn { border-radius: 0; padding: 7px 9px; }
.seg .icon-btn.on { background: var(--accent-soft); color: var(--accent-strong); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.card-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; cursor: pointer; min-width: 0; }
.card-item:hover { background: var(--surface-2); }
.card-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.gpreview { aspect-ratio: 4 / 3; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; margin-bottom: 8px; }
.gthumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.gicon .ficon { width: 52px; height: 52px; }
.gname { display: flex; align-items: center; gap: 4px; font-weight: 500; }
.gname .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb-sm { width: 26px; height: 26px; object-fit: cover; border-radius: 4px; flex: none; }
.snippet { flex-basis: 100%; font-size: 12.5px; color: var(--muted); margin-top: 2px; white-space: normal; }
.snippet mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--text); border-radius: 3px; padding: 0 2px; }
.row .name:has(.snippet) { flex-wrap: wrap; row-gap: 0; padding: 6px 0; }
@media (max-width: 760px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.topbar .search { position: relative; }
.kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font: 11px/1 ui-monospace, monospace; color: var(--muted); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 3px 6px; background: var(--surface-2); pointer-events: none; }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 50; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; max-height: min(70vh, 480px); overflow: auto; }
.sopt { display: flex; gap: 10px; align-items: flex-start; padding: 7px 9px; border-radius: 7px; cursor: pointer; }
.sopt[aria-selected="true"] { background: var(--accent-soft); }
.sopt .ficon { width: 22px; height: 22px; }
.stext { min-width: 0; flex: 1; }
.sname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.sopt .snippet { margin: 2px 0 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sall { color: var(--accent-strong); font-size: 13px; border-top: 1px solid var(--border); border-radius: 0 0 7px 7px; margin-top: 3px; }

/* setup + posture */
.health { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.health li { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; display: grid; gap: 4px; }
.health .pill { margin-right: 8px; }
.pill.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, #d98a00 18%, transparent); color: #b36b00; }
@media (prefers-color-scheme: dark) { .pill.warn { color: #f0b34a; } }
.profiles { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin: 0 0 12px; display: grid; gap: 8px; }
.profile, .check { display: flex; gap: 10px; align-items: flex-start; }
.check { align-items: center; margin-bottom: 12px; }
.profile input, .check input { width: auto; margin-top: 3px; }
.check input { margin-top: 0; }
.pill.error { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }

/* Drag and drop, selection */
.row[draggable="true"], .card-item[draggable="true"] { user-select: none; -webkit-user-select: none; }
.drop-over, .row.drop-over, .card-item.drop-over { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--accent-soft); }
.crumbs a.drop-over, .nav a.drop-over { background: var(--accent-soft); outline: 2px solid var(--accent); outline-offset: 0; color: var(--accent-strong); }
.dragging { opacity: 0.45; }
.nav a:focus-visible, .crumbs a:focus-visible, .card-item:focus-visible, .row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
[aria-dropeffect="move"], [aria-dropeffect="copy"] { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent); }
.row.sel, .card-item.sel { background: var(--accent-soft); }
.sel-box { width: 16px; height: 16px; flex: none; margin: 0; accent-color: var(--accent); cursor: pointer; }
.card-item { position: relative; }
.card-item .sel-box { position: absolute; top: 14px; left: 14px; z-index: 1; opacity: 0; }
.card-item:hover .sel-box, .card-item.sel .sel-box, .card-item .sel-box:focus-visible { opacity: 1; }
.selbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; margin-bottom: 12px; background: var(--accent-soft); border: 1px solid var(--border); border-radius: var(--radius); }
.selbar .n { font-weight: 600; margin-right: auto; }
.drag-ghost { position: fixed; top: 0; left: -1000px; padding: 8px 14px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 14px; }
.toast .toast-act { margin-left: 10px; background: none; border: 0; color: inherit; font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 0; }
.uploads .ubody { max-height: 40vh; overflow-y: auto; }
.uploads .usum { padding: 8px 12px; font-size: 13px; font-weight: 600; border-bottom: 1px solid var(--border); }

/* Image viewer: a dark lightbox in either theme. Chrome colours are fixed (dark on dark), the accent, focus ring and error colours follow the theme tokens. */
dialog.iv {
  --iv-bg: #0a0c10; --iv-fg: #eef0f4; --iv-muted: #a3abb9; --iv-chip: rgba(255, 255, 255, 0.1); --iv-chip-hover: rgba(255, 255, 255, 0.2); --iv-line: rgba(255, 255, 255, 0.1);
  width: 100vw; height: 100vh; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; border-radius: 0; box-shadow: none;
  background: var(--iv-bg); color: var(--iv-fg); color-scheme: dark; overflow: hidden;
}
dialog.iv[open] { display: flex; flex-direction: column; }
dialog.iv::backdrop { background: #000; }
.iv-top { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--iv-line); background: rgba(255, 255, 255, 0.04); }
.iv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.iv-count { color: var(--iv-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.iv-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 8px; padding: 7px 11px; background: var(--iv-chip); color: var(--iv-fg); cursor: pointer; white-space: nowrap; text-decoration: none; line-height: 1.2; }
.iv-btn:hover { background: var(--iv-chip-hover); text-decoration: none; }
.iv-btn:disabled { opacity: 0.4; cursor: default; }
.iv-time { display: inline-flex; align-items: center; gap: 6px; color: var(--iv-muted); }
.iv-select { width: auto; padding: 6px 8px; border: 0; border-radius: 8px; background: var(--iv-chip); color: var(--iv-fg); cursor: pointer; }
.iv-select option { background: #1b1f27; color: #eef0f4; }
.iv-btn:focus-visible, .iv-select:focus-visible, .iv-nav:focus-visible, .iv-thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.iv-progress { height: 3px; flex: none; visibility: hidden; background: var(--iv-line); }
.iv-progress.on { visibility: visible; }
.iv-progress > i { display: block; height: 100%; width: 100%; background: var(--accent); transform-origin: left center; transform: scaleX(0); }
.iv-stage { position: relative; flex: 1; min-height: 0; outline: none; touch-action: pan-y pinch-zoom; overflow: hidden; }
.iv-img { position: absolute; inset: 0; margin: auto; max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; user-select: none; -webkit-user-drag: none; transition: opacity 0.15s; }
.iv-img.up { width: 100%; height: 100%; }
.iv-stage:not([data-state="ready"]) .iv-img:not([src]), .iv-stage[data-state="error"] .iv-img { visibility: hidden; }
.iv-stage[data-state="loading"] .iv-img { opacity: 0.35; }
.iv-load { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; gap: 10px; color: var(--iv-muted); pointer-events: none; }
.iv-stage[data-state="loading"] .iv-load { display: flex; }
.iv-spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--iv-chip-hover); border-top-color: var(--accent); animation: iv-spin 0.8s linear infinite; }
@keyframes iv-spin { to { transform: rotate(360deg); } }
.iv-msg { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; color: var(--iv-fg); font-size: 15px; pointer-events: none; }
.iv-msg.hidden { display: none; }
.iv-note { position: absolute; left: 12px; bottom: 12px; padding: 4px 10px; border-radius: 99px; background: rgba(0, 0, 0, 0.65); color: var(--iv-fg); font-size: 12px; }
.iv-more { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 2; }
.iv-more.hidden, .iv-note.hidden { display: none; }
.iv-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; width: 44px; height: 44px; border: 0; border-radius: 50%; display: grid; place-items: center; background: rgba(0, 0, 0, 0.55); color: #fff; cursor: pointer; }
.iv-nav:hover { background: rgba(0, 0, 0, 0.8); }
.iv-nav:disabled { opacity: 0.3; cursor: default; }
.iv-prev { left: 12px; }
.iv-next { right: 12px; }
.iv-strip { display: flex; gap: 8px; flex: none; overflow-x: auto; overflow-y: hidden; padding: 10px 14px; border-top: 1px solid var(--iv-line); background: rgba(255, 255, 255, 0.04); scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.iv-thumb { flex: none; width: 84px; height: 62px; padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; display: grid; place-items: center; background: var(--iv-chip); cursor: pointer; opacity: 0.7; }
.iv-thumb:hover { opacity: 1; }
.iv-thumb.cur { border-color: var(--accent); opacity: 1; }
.iv-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.iv-thumb .ficon { width: 28px; height: 28px; }
.iv-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
@media (max-width: 640px) {
  .iv-top { flex-wrap: wrap; padding: 8px 10px; gap: 8px; }
  .iv-title { flex: 1 1 100%; order: -1; }
  .iv-count { margin-right: auto; }
  .iv-lbl { display: none; }
  .iv-nav { width: 38px; height: 38px; }
  .iv-prev { left: 6px; }
  .iv-next { right: 6px; }
  .iv-thumb { width: 64px; height: 48px; }
  .iv-strip { padding: 8px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  dialog.iv *, dialog.iv { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
