/* nasfm design system. Component reference: docs/UI.md.
   Window classes follow Material 3: compact < 600px (bottom bar), medium 600-839px (rail),
   expanded >= 840px (sidebar). Touch targets are 44px on coarse pointers (Apple HIG), never under
   24px (WCAG 2.5.8). Colors meet WCAG AA contrast in both themes. */

/* ---------------------------------------------------------------- tokens */
:root {
  color-scheme: light dark;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;

  --bg: light-dark(#f6f7f9, #111214);
  --surface: light-dark(#ffffff, #1a1b1e);
  --surface-2: light-dark(#f1f3f5, #222327);
  --surface-3: light-dark(#e7eaee, #2c2d32);
  --line: light-dark(#dde1e6, #33353b);
  --line-strong: light-dark(#c4cad1, #4a4d55);
  --fg: light-dark(#16181d, #ecedf0);
  --fg-2: light-dark(#4a515c, #b3b6bd);
  --muted: light-dark(#5c6470, #9a9ea7);
  --accent: light-dark(#1f5fd1, #7aa8ff);
  --accent-fg: light-dark(#ffffff, #0b1530);
  --accent-soft: light-dark(#e3ecfc, #1c2a47);
  --accent-line: light-dark(#9db9ef, #3d5a92);
  --danger: light-dark(#b42318, #ff8a80);
  --danger-fg: light-dark(#ffffff, #2b0b08);
  --danger-soft: light-dark(#fdecea, #3a1714);
  --warn: light-dark(#8a5300, #f2c060);
  --warn-soft: light-dark(#fff4e0, #3a2c10);
  --ok: light-dark(#1d7a3d, #6fd492);
  --ok-soft: light-dark(#e6f5eb, #12301e);
  --folder: light-dark(#d29b1d, #e8b64a);
  --selected: light-dark(#dce7fb, #23345a);
  --hover: light-dark(#eef1f5, #24262b);
  --scrim: rgb(0 0 0 / .45);
  --shadow-1: 0 1px 2px rgb(0 0 0 / .06), 0 1px 3px rgb(0 0 0 / .08);
  --shadow-2: 0 8px 28px rgb(0 0 0 / .18), 0 2px 6px rgb(0 0 0 / .1);
  --focus: light-dark(#1f5fd1, #9cc0ff);

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --r1: 6px; --r2: 10px; --r3: 14px;
  --bar-h: 56px;
  --nav-w: 248px;
  --rail-w: 84px;
  --bottom-h: 64px;
  --target: 36px;
  --content-max: 1280px;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
@media (pointer: coarse) { :root { --target: 44px; } }

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--bar-h) + var(--s4));
       scroll-padding-bottom: var(--s5); }
body { margin: 0; font: 400 15px/1.5 var(--font); background: var(--bg); color: var(--fg); -webkit-font-smoothing: antialiased; }
@media (pointer: coarse) { body { font-size: 16px; } }
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.08rem; }
h3 { font-size: .98rem; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: .15em; }
a:not([class]):hover { text-decoration-thickness: 2px; }
code, kbd, pre, samp { font-family: var(--mono); font-size: .9em; }
kbd { display: inline-block; min-width: 1.6em; padding: .05em .4em; border: 1px solid var(--line-strong); border-bottom-width: 2px;
      border-radius: 5px; background: var(--surface-2); text-align: center; font-size: .8em; line-height: 1.5; }
img, svg, video { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s4) 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r1); }
::selection { background: var(--accent-soft); }
.visually-hidden, .sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

.icon { width: 20px; height: 20px; max-width: none; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round;
        stroke-linejoin: round; vertical-align: middle; }
.icon.sm { width: 16px; height: 16px; }
.icon.lg { width: 28px; height: 28px; stroke-width: 1.6; }
.icon.xl { width: 44px; height: 44px; stroke-width: 1.4; }

.skip-link { position: absolute; left: var(--s2); top: -100px; z-index: 100; padding: var(--s2) var(--s3); background: var(--surface);
             border-radius: var(--r1); box-shadow: var(--shadow-2); }
.skip-link:focus { top: var(--s2); }

/* ---------------------------------------------------------------- app shell */
.app { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr);
       grid-template-rows: var(--bar-h) 1fr; grid-template-areas: "nav bar" "nav main"; }
.app-bar { grid-area: bar; position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: var(--s3);
           padding: 0 var(--s4); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
           border-bottom: 1px solid var(--line); }
.app-bar .spacer { flex: 1; }
.app-main { grid-area: main; min-width: 0; padding: var(--s5) var(--s5) var(--s7); }
.app-main > .content { max-width: var(--content-max); margin: 0 auto; }
.app-main > .content.narrow { max-width: 760px; }

.global-search { position: relative; flex: 1; max-width: 560px; }
.global-search > .icon { position: absolute; left: 12px; top: 50%; translate: 0 -50%; color: var(--muted); pointer-events: none; }
.global-search input { width: 100%; height: 40px; padding: 0 44px 0 40px; border-radius: 999px; background: var(--surface-2);
                       border: 1px solid transparent; }
.global-search input:focus { background: var(--surface); border-color: var(--accent-line); }
.global-search kbd { position: absolute; right: 12px; top: 50%; translate: 0 -50%; pointer-events: none; }
.global-search input:focus ~ kbd { display: none; }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 40; margin: 0; padding: var(--s1); list-style: none;
           max-height: min(60vh, 440px); overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r2); background: var(--surface);
           box-shadow: var(--shadow-2); }
.global-search.open .suggest { left: var(--s2); right: var(--s2); top: calc(100% - 2px); }
.has-suggest { position: relative; }
.has-suggest .suggest { top: calc(100% + 2px); }
.suggest [role="option"] { display: flex; align-items: center; gap: var(--s3); min-height: 44px; padding: var(--s1) var(--s3);
                           border-radius: var(--r1); cursor: pointer; }
.suggest [role="option"]:hover, .suggest [aria-selected="true"] { background: var(--hover); }
.suggest [aria-selected="true"] { box-shadow: inset 2px 0 0 var(--accent); }
.suggest .file-type { width: 28px; height: 28px; }
.suggest .file-type .icon { width: 18px; height: 18px; }
.suggest .s-name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest .s-where { display: block; font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest .s-all { color: var(--accent); font-weight: 600; border-top: 1px solid var(--line); border-radius: 0 0 var(--r1) var(--r1); }
.form-row.search-filters { grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr)); }
.list-item .li-sub.search-snippet { white-space: normal; overflow-wrap: anywhere; }

.side-nav { grid-area: nav; position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; display: flex;
            flex-direction: column; gap: var(--s1); padding: var(--s3) var(--s3) var(--s4); background: var(--surface);
            border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: var(--s2); height: calc(var(--bar-h) - var(--s3)); padding: 0 var(--s3);
         margin-bottom: var(--s2); color: var(--fg); text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand .logo { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-fg); }
.brand .logo .icon { width: 18px; height: 18px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group + .nav-group { margin-top: var(--s3); }
.nav-heading { padding: var(--s2) var(--s3) var(--s1); font-size: .75rem; font-weight: 650; text-transform: uppercase;
               letter-spacing: .06em; color: var(--muted); }
.nav-link { display: flex; align-items: center; gap: var(--s3); min-height: 40px; padding: 0 var(--s3); border-radius: 999px;
            color: var(--fg-2); text-decoration: none; font-weight: 550; }
.nav-link:hover { background: var(--hover); color: var(--fg); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-link .count { margin-left: auto; font-size: .8rem; color: var(--muted); }
.side-nav .nav-foot { margin-top: auto; padding-top: var(--s3); }
.admin-flag { display: inline-flex; align-items: center; padding: 0 var(--s2); border-radius: 999px; background: var(--warn-soft);
              color: var(--warn); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.btn.nav-toggle { display: none; }
.bottom-nav { display: none; }

/* Navigation rail (icons with short labels). Chosen by theme.js: by default below 840px, or whenever
   the person collapses the sidebar (remembered); never on phones, which use the bottom bar. */
@media (min-width: 600px) {
  html.nav-rail .app { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  html.nav-rail .side-nav { padding: var(--s2) var(--s1); align-items: stretch; }
  html.nav-rail .side-nav .brand { justify-content: center; padding: 0; }
  html.nav-rail .side-nav .brand .brand-text, html.nav-rail .nav-heading, html.nav-rail .nav-collapse .label { display: none; }
  html.nav-rail .nav-group + .nav-group { margin-top: var(--s2); padding-top: var(--s2); border-top: 1px solid var(--line); }
  html.nav-rail .nav-link { flex-direction: column; justify-content: center; gap: 2px; min-height: 56px; padding: var(--s1) 2px;
                            border-radius: var(--r2); font-size: .72rem; text-align: center; line-height: 1.2; }
  html.nav-rail .nav-link .count { display: none; }
  html.nav-rail .nav-collapse { justify-content: center; padding: 0; }
  html.nav-rail .nav-collapse .icon { rotate: 180deg; }
}
@media (max-width: 839.98px) { .app-main { padding: var(--s4) var(--s4) var(--s7); } }
.nav-collapse { display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 40px; margin-top: auto; padding: 0 var(--s3);
                border: 0; border-radius: 999px; background: none; color: var(--muted); font: inherit; font-size: .88rem; cursor: pointer; }
.nav-collapse:hover { background: var(--hover); color: var(--fg); }
@media (max-width: 599.98px) { .nav-collapse { display: none; } }

/* compact: top app bar + bottom navigation (people) or a drawer (admin, more than 5 destinations) */
@media (max-width: 599.98px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: var(--bar-h) 1fr; grid-template-areas: "bar" "main"; }
  .app-bar { padding: 0 var(--s2) 0 var(--s3); gap: var(--s1); }
  .app-bar .brand-compact { display: flex; flex: 1; height: auto; margin: 0; padding: 0 var(--s1); }
  .global-search { display: none; }
  .global-search.open { display: block; position: absolute; inset: 0; max-width: none; padding: var(--s2); background: var(--bg); z-index: 2; }
  .global-search.open > .icon { left: calc(var(--s2) + 12px); }
  .global-search.open kbd { display: none; }
  .app-main { padding: var(--s3) var(--s3) calc(var(--bottom-h) + var(--s7) + env(safe-area-inset-bottom)); }
  .side-nav { display: none; }
  .app.drawer-open .side-nav { display: flex; position: fixed; inset: 0 auto 0 0; z-index: 60; width: min(86vw, 320px); height: 100dvh;
                               box-shadow: var(--shadow-2); align-items: stretch; padding: var(--s3); }
  .app.drawer-open .side-nav .brand { justify-content: flex-start; padding: 0 var(--s3); }
  .app.drawer-open .side-nav .brand .brand-text, .app.drawer-open .nav-heading { display: block; }
  .app.drawer-open .nav-link { flex-direction: row; justify-content: flex-start; gap: var(--s3); min-height: 48px; padding: 0 var(--s3);
                               border-radius: 999px; font-size: .95rem; text-align: left; }
  .app.drawer-open .nav-group + .nav-group { border-top: 0; }
  .drawer-scrim { position: fixed; inset: 0; z-index: 55; background: var(--scrim); }
  .btn.nav-toggle { display: inline-flex; }
  html { scroll-padding-bottom: calc(var(--bottom-h) + var(--s4)); }
  .bottom-nav { display: flex; position: fixed; inset: auto 0 0 0; z-index: 30; height: calc(var(--bottom-h) + env(safe-area-inset-bottom));
                padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); }
  .bottom-nav > a, .bottom-nav-more { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
                                     color: var(--fg-2); text-decoration: none; font-size: .72rem; font-weight: 600; }
  .bottom-nav-more { min-width: 0; padding: 0; border: 0; background: none; font-family: inherit; cursor: pointer; }
  .bottom-nav > a .pill, .bottom-nav-more .pill { display: grid; place-items: center; width: 56px; height: 30px; border-radius: 999px; }
  .bottom-nav > a[aria-current="page"], .bottom-nav-more[aria-current="true"] { color: var(--fg); }
  .bottom-nav > a[aria-current="page"] .pill, .bottom-nav-more[aria-current="true"] .pill { background: var(--accent-soft); color: var(--accent); }
}
.brand-compact { display: none; }
.back-link { display: none; }

/* ---------------------------------------------------------------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: var(--target);
       padding: 0 var(--s4); border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); color: var(--fg);
       font: 600 .92rem/1 var(--font); text-decoration: none; white-space: nowrap; cursor: pointer; user-select: none;
       transition: background-color .12s, border-color .12s, box-shadow .12s; }
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn .icon { width: 18px; height: 18px; margin-left: -2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--fg)); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--danger-fg); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 88%, var(--fg)); }
.btn-danger-ghost { border-color: transparent; background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--fg-2); }
.btn-ghost:hover { background: var(--hover); color: var(--fg); }
.btn-tonal { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.btn-tonal:hover { background: color-mix(in srgb, var(--accent-soft) 80%, var(--accent)); }
.btn-icon { width: var(--target); min-width: var(--target); padding: 0; border-color: transparent; background: transparent; color: var(--fg-2); }
.btn-icon:hover { background: var(--hover); color: var(--fg); }
.btn-icon .icon { margin: 0; }
.btn-icon[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.btn-sm { min-height: 30px; padding: 0 var(--s3); font-size: .85rem; }
.btn-icon.btn-sm { width: 30px; min-width: 30px; padding: 0; }
@media (pointer: coarse) { .btn-sm { min-height: 40px; } .btn-icon.btn-sm { width: 40px; min-width: 40px; } }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn-link { display: inline; padding: 0; border: 0; background: none; color: var(--accent); font: inherit; text-decoration: underline;
            cursor: pointer; text-underline-offset: .15em; }
.btn-group { display: inline-flex; padding: 2px; gap: 2px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.btn-group .btn-icon { width: 34px; min-width: 34px; min-height: 30px; }
@media (pointer: coarse) { .btn-group .btn-icon { width: 40px; min-width: 40px; min-height: 38px; } }
.fab { position: fixed; right: var(--s4); bottom: calc(var(--bottom-h) + var(--s4) + env(safe-area-inset-bottom)); z-index: 25;
       width: 56px; height: 56px; border-radius: 16px; box-shadow: var(--shadow-2); display: none; }
@media (max-width: 599.98px) { .fab { display: inline-flex; } .hide-compact { display: none !important; } }
@media (min-width: 600px) { .show-compact { display: none !important; } }

/* ---------------------------------------------------------------- forms */
input, select, textarea, button { font: inherit; color: inherit; }
:where(.input, input:not([type=checkbox], [type=radio], [type=file], [type=hidden], [type=range]), select, textarea) {
  width: 100%; min-height: var(--target); padding: 0 var(--s3); border: 1px solid var(--line-strong); border-radius: var(--r1);
  background: var(--surface); color: var(--fg); font-size: 1rem; }
@media (min-width: 600px) and (pointer: fine) {
  :where(.input, input:not([type=checkbox], [type=radio], [type=file], [type=hidden], [type=range]), select, textarea) { font-size: .94rem; }
}
textarea { padding: var(--s2) var(--s3); min-height: 6rem; line-height: 1.5; resize: vertical; }
select { padding-right: var(--s6); appearance: none; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
  linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); flex: none; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
label { display: block; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .label { font-weight: 600; font-size: .9rem; }
.hint { color: var(--muted); font-size: .85rem; }
.field-error { color: var(--danger); font-size: .85rem; }
.form { display: flex; flex-direction: column; gap: var(--s4); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: var(--s3) var(--s4); align-items: end; }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.inline-form { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: end; }
.inline-form .field { flex: 1 1 12rem; }
.check { display: inline-flex; align-items: center; gap: var(--s2); min-height: var(--target); cursor: pointer; }
.choices { display: flex; flex-wrap: wrap; gap: 0 var(--s4); margin: 0; padding: 0; border: 0; }
fieldset { margin: 0; padding: var(--s3) var(--s4) var(--s2); border: 1px solid var(--line); border-radius: var(--r2); min-width: 0; }
legend { padding: 0 var(--s1); font-weight: 600; font-size: .9rem; }
.input-with-button { display: flex; gap: var(--s2); }
.input-with-button input { flex: 1; min-width: 0; }
.mono, input.mono { font-family: var(--mono); }
.toggle { appearance: none; position: relative; width: 40px !important; height: 24px !important; border-radius: 999px;
          background: var(--surface-3); border: 1px solid var(--line-strong); cursor: pointer; transition: background-color .15s; }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface);
                 box-shadow: var(--shadow-1); transition: translate .15s; }
.toggle:checked { background: var(--accent); border-color: var(--accent); }
.toggle:checked::after { translate: 16px 0; }

/* ---------------------------------------------------------------- layout helpers */
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--s2); }
.stack-lg { display: flex; flex-direction: column; gap: var(--s5); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.split { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3); }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.break { overflow-wrap: anywhere; }
/* Storage paths break at "/" (and inside a segment only when that segment cannot fit). */
.path { overflow-wrap: break-word; word-break: normal; }
.center { text-align: center; }
.columns-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--s5); align-items: start; }
@media (max-width: 959.98px) { .columns-2 { grid-template-columns: minmax(0, 1fr); } }

/* ---------------------------------------------------------------- page header, crumbs */
.page-header { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); margin-bottom: var(--s4); min-height: 44px; }
.page-header .titles { flex: 1 1 16rem; min-width: 0; }
.page-header h1 { overflow-wrap: anywhere; }
.page-header .sub { margin-top: 2px; color: var(--muted); font-size: .9rem; }
.page-header .actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin: 0 0 var(--s1); padding: 0; list-style: none;
          font-size: .9rem; color: var(--muted); }
.crumbs li { display: inline-flex; align-items: center; gap: 2px; min-width: 0; }
.crumbs a { display: inline-block; padding: 2px var(--s2); border-radius: var(--r1); color: var(--fg-2); text-decoration: none;
            max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs a:hover { background: var(--hover); color: var(--fg); }
.crumbs a.drop-target { background: var(--accent-soft); color: var(--accent); outline: 2px dashed var(--accent); }
.crumbs .icon { width: 14px; height: 14px; color: var(--line-strong); }
.crumbs [aria-current] { padding: 2px var(--s2); color: var(--fg); font-weight: 600; }
@media (max-width: 599.98px) {
  .crumbs { display: none; }
  .back-link { display: inline-flex; align-items: center; gap: 2px; min-height: 36px; margin: 0 0 var(--s1) calc(-1 * var(--s2));
               padding: 0 var(--s2); border-radius: var(--r1); color: var(--fg-2); text-decoration: none; font-weight: 550; max-width: 100%; }
  .back-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .back-link:hover { background: var(--hover); }
}

/* ---------------------------------------------------------------- surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r3); padding: var(--s4) var(--s5); }
.card + .card, .card + .section, .section + .section, .section + .card { margin-top: var(--s4); }
.columns-2 > .card + .card { margin-top: 0; } /* side by side: the grid gap spaces them, not the stacking rule */
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); justify-content: space-between; margin-bottom: var(--s3); }
.card-head p { color: var(--muted); font-size: .9rem; width: 100%; }
.card.danger-zone { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.danger-list { margin: var(--s3) 0 0; padding: 0; list-style: none; }
.danger-list > li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2) var(--s4);
                    padding: var(--s3) 0; border-top: 1px solid var(--line); }
.danger-list > li > div { flex: 1 1 18rem; min-width: 0; }
.danger-list > li .hint { margin-top: 2px; }
.danger-list form { margin: 0; }
.danger-list .btn-danger-ghost { border-color: color-mix(in srgb, var(--danger) 60%, transparent); }
.who-summary { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r2);
               background: var(--surface-2); }
.who-summary .icon { margin-top: 2px; color: var(--accent); }
.people-list { border: 1px solid var(--line); border-radius: var(--r2); }
.people-list .li-actions { display: flex; gap: var(--s2); align-items: center; }
.people-list .li-actions select { width: auto; min-width: 12rem; }
@media (max-width: 599.98px) {
  .people-list .list-item { flex-wrap: wrap; }
  .people-list .li-actions { order: 3; flex-basis: 100%; }
  .people-list .li-actions select { flex: 1; min-width: 0; }
}
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-head { padding: var(--s4) var(--s5) 0; }
@media (max-width: 599.98px) { .card { padding: var(--s4); border-radius: var(--r2); } .card.flush > .card-head { padding: var(--s4) var(--s4) 0; } }
.section > h2 { margin-bottom: var(--s3); }
.narrow-card { max-width: 420px; margin: 8vh auto 0; }
.auth-shell { min-height: 100vh; min-height: 100dvh; display: grid; place-items: start center; padding: var(--s5) var(--s3); }
.auth-shell .brand { justify-content: center; margin: 6vh 0 var(--s4); }
.auth-shell .card { width: min(100%, 420px); padding: var(--s5); }
.auth-shell h1 { font-size: 1.3rem; margin-bottom: var(--s1); }

.notice { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--r2);
          background: var(--accent-soft); color: var(--fg); border: 1px solid var(--accent-line); margin-bottom: var(--s4); }
.notice .icon { color: var(--accent); margin-top: 1px; }
.notice.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.notice.ok .icon { color: var(--ok); }
.notice.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.notice.warn .icon { color: var(--warn); }
.notice.error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.notice.error .icon { color: var(--danger); }
.notice > div { min-width: 0; flex: 1; }

.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 var(--s2); border-radius: 999px;
         background: var(--surface-3); color: var(--fg-2); font-size: .75rem; font-weight: 650; white-space: nowrap; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); margin: 0; padding: 0; list-style: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 4px 0 var(--s3); border: 1px solid var(--line-strong);
        border-radius: 999px; background: var(--surface); font-size: .86rem; }
.chip:not(:has(button)) { padding-right: var(--s3); }
.chip a { color: inherit; text-decoration: none; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.chip.group { border-color: var(--accent-line); }
.chip.host { border-style: dashed; }
.chip button { display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%;
               background: transparent; color: var(--muted); cursor: pointer; }
.chip button:hover { background: var(--hover); color: var(--fg); }

.empty { display: flex; flex-direction: column; align-items: center; gap: var(--s2); padding: var(--s7) var(--s4); text-align: center; color: var(--muted); }
.empty .icon { color: var(--line-strong); margin-bottom: var(--s2); }
.empty h2, .empty h3 { color: var(--fg); }
.empty .btn { margin-top: var(--s3); }

dl.props { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--s2) var(--s5); margin: 0; }
dl.props dt { color: var(--muted); font-size: .9rem; }
dl.props dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 599.98px) { dl.props { grid-template-columns: minmax(0, 1fr); gap: 0; } dl.props dd { margin-bottom: var(--s3); } }

/* ---------------------------------------------------------------- tables (data; files use .files) */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: var(--s2) var(--s3); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
.table th { font-size: .8rem; font-weight: 650; color: var(--muted); white-space: nowrap; }
@media (hover: hover) { .table tbody tr:hover { background: var(--hover); } }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.actions { text-align: right; white-space: nowrap; width: 1%; }
.table td.actions > * { vertical-align: middle; }
.table .row-denied td, .table tr.denied td { color: var(--danger); }
.table tr.disabled td, .table tr.no td { color: var(--muted); }
/* Admin access pages: keep role badges from stretching and give item paths room to read. */
.table.access-table .stack-sm { align-items: flex-start; }
.table.access-table td.primary { min-width: 12rem; }
.card.flush .table th:first-child, .card.flush .table td:first-child { padding-left: var(--s5); }
.card.flush .table th:last-child, .card.flush .table td:last-child { padding-right: var(--s5); }
/* Responsive tables: on compact screens each row becomes a card; cells with data-label show it. */
@media (max-width: 599.98px) {
  .table.responsive thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
  .table.responsive tbody tr:last-child { border-bottom: 0; }
  .table.responsive td { padding: 2px 0; border: 0; text-align: left; }
  .table.responsive td[data-label] { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); text-align: right;
                                     overflow-wrap: anywhere; }
  .table.responsive td[data-label]::before { content: attr(data-label); flex: none; max-width: 45%; text-align: left; font-size: .82rem;
                                             color: var(--muted); font-weight: 600; }
  .table.responsive td[data-label] > * { min-width: 0; }
  .table.responsive td.primary[data-label] { display: block; text-align: left; }
  .table.responsive td.primary[data-label]::before { display: none; }
  .table.responsive td.actions { width: auto; text-align: left; padding-top: var(--s2); white-space: normal; }
  .table.responsive td.primary { font-weight: 600; }
  .card.flush .table.responsive td:first-child, .card.flush .table.responsive td:last-child { padding-left: 0; padding-right: 0; }
}
td.clip { max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- lists */
.list { margin: 0; padding: 0; list-style: none; }
.list-item { display: flex; align-items: center; gap: var(--s3); min-height: 56px; padding: var(--s2) var(--s4); border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .li-icon { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: var(--r2);
                      background: var(--surface-2); color: var(--fg-2); }
.list-item .li-text { flex: 1; min-width: 0; }
.list-item .li-title { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg); text-decoration: none; }
a.li-title:hover { text-decoration: underline; }
.list-item .li-sub { display: block; color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-actions { display: flex; gap: var(--s1); align-items: center; flex: none; }

/* ---------------------------------------------------------------- tiles (home places) */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: var(--s3); margin: 0; padding: 0; list-style: none; }
.tile { position: relative; display: flex; align-items: center; gap: var(--s3); min-height: 64px; padding: var(--s3) var(--s3) var(--s3) var(--s4);
        background: var(--surface); border: 1px solid var(--line); border-radius: var(--r3); transition: border-color .12s, box-shadow .12s; }
@media (hover: hover) { .tile:hover { border-color: var(--line-strong); box-shadow: var(--shadow-1); } }
.tile .tile-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--s3); color: var(--fg); text-decoration: none; font-weight: 600; }
.tile .tile-link::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.tile .tile-link:focus-visible { outline: none; }
.tile:has(.tile-link:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.tile .tile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .tile-sub { display: block; font-weight: 400; color: var(--muted); font-size: .82rem; }
.tile > .btn-icon, .tile > button { position: relative; z-index: 1; }
.tile.unavailable { opacity: .65; }
.group-title { margin: var(--s5) 0 var(--s3); font-size: .82rem; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.group-title:first-child { margin-top: 0; }
.home-group + .home-group, .home-group + .card { margin-top: var(--s6); }

/* ---------------------------------------------------------------- file browser */
.file-type { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: var(--r1); color: var(--fg-2); }
.file-type .icon { width: 22px; height: 22px; }
.file-type.k-folder { color: var(--folder); }
.file-type.k-folder .icon { fill: color-mix(in srgb, var(--folder) 28%, transparent); }
.file-type.k-image { color: #2f9e6f; } .file-type.k-video { color: #c2410c; } .file-type.k-audio { color: #a855f7; }
.file-type.k-pdf { color: #dc2626; } .file-type.k-archive { color: #a16207; } .file-type.k-text, .file-type.k-markdown { color: #0e7490; }
.file-type.k-office { color: #2563eb; } .file-type.k-code { color: #7c3aed; }
.file-type img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }

.browser { position: relative; }
.browser-bars { display: grid; margin-bottom: var(--s3); }
.browser-bars > * { grid-area: 1 / 1; }
.browser-bars:has(> .selection-bar:not([hidden])) { position: sticky; top: calc(var(--bar-h) + var(--s1)); z-index: 15; }
.browser-bars:has(> .selection-bar:not([hidden])) > .browser-toolbar { visibility: hidden; }
.browser-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); min-height: 48px; }
.browser-toolbar .filter { position: relative; flex: 1 1 140px; max-width: 320px; }
@media (max-width: 599.98px) { #sort-button .label { display: none; } #sort-button { width: var(--target); padding: 0; } #sort-button .icon { margin: 0; } }
.browser-toolbar .filter .icon { position: absolute; left: 10px; top: 50%; translate: 0 -50%; color: var(--muted); width: 16px; height: 16px; }
.browser-toolbar .filter input { padding-left: 32px; min-height: 34px; border-radius: 999px; }
.selection-bar { display: flex; flex-wrap: nowrap; align-items: center; align-self: start;
                 gap: var(--s1) var(--s2); padding: var(--s1) var(--s2) var(--s1) var(--s1); min-height: 48px;
                 border-radius: 999px; background: var(--accent-soft); color: var(--fg); box-shadow: var(--shadow-1); }
.selection-bar .count { font-weight: 650; margin-right: auto; padding-right: var(--s2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.selection-bar .sel-more { display: none; }
.selection-bar .btn-ghost { color: var(--fg); }
html:has(.selection-bar:not([hidden])) { scroll-padding-top: calc(var(--bar-h) + 72px); }
@media (max-width: 599.98px) {
  /* Phones: count, the three common actions and More (one line, so the list never moves). */
  .selection-bar { border-radius: var(--r2); }
  .browser-toolbar { min-height: 52px; } /* the selection bar's height here: swapping them moves nothing */
  .selection-bar .sel-extra { display: none; }
  .selection-bar .sel-more { display: inline-flex; }
  .selection-bar .btn .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .selection-bar .btn { width: var(--target); padding: 0; flex: none; }
  .selection-bar .btn .icon { margin: 0; }
}

.files { margin: 0; padding: 0; list-style: none; }
.files-head { display: grid; grid-template-columns: 44px minmax(0, 1fr) 110px 170px 48px; align-items: center; min-height: 40px;
              padding: 0 var(--s2); border-bottom: 1px solid var(--line); font-size: .8rem; font-weight: 650; color: var(--muted); }
.files-head button { display: inline-flex; align-items: center; gap: 4px; padding: var(--s1) var(--s2); margin-left: calc(-1 * var(--s2));
                     border: 0; border-radius: var(--r1); background: none; color: inherit; font: inherit; cursor: pointer; }
.files-head button:hover { background: var(--hover); color: var(--fg); }
.files-head [aria-sort] button { color: var(--fg); }
.files-head .icon { width: 14px; height: 14px; }
.files-head .sel { display: grid; place-items: center; }
.file-row { position: relative; display: grid; grid-template-columns: 44px minmax(0, 1fr) 110px 170px 48px; align-items: center;
            min-height: 52px; padding: 0 var(--s2); border-bottom: 1px solid var(--line); border-radius: 0; user-select: none;
            -webkit-user-select: none; -webkit-touch-callout: none; }
@media (hover: hover) { .file-row:hover { background: var(--hover); } }
.file-row.selected { background: var(--selected); }
.file-row.menu-target { box-shadow: inset 0 0 0 2px var(--accent); }
.file-row.cut { opacity: .55; }
.file-row.focused { box-shadow: inset 3px 0 0 var(--accent); }
.file-row.drop-target { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); border-radius: var(--r1); }
.file-row .sel { display: grid; place-items: center; height: 100%; }
.file-row .sel input { width: 18px; height: 18px; cursor: pointer; }
.file-row .name { display: flex; align-items: center; gap: var(--s3); min-width: 0; }
.file-row .name a { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--s3); padding: var(--s2) 0; color: var(--fg);
                    text-decoration: none; font-weight: 550; }
.file-row .name a .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .name a:focus-visible { outline: none; }
.file-row:has(.name a:focus-visible) { box-shadow: inset 0 0 0 2px var(--focus); border-radius: var(--r1); }
.file-row .name a::after { content: ""; position: absolute; inset: 0 48px 0 44px; }
.file-row .meta-sub { display: none; }
.file-row .size, .file-row .mtime { color: var(--fg-2); font-size: .88rem; font-variant-numeric: tabular-nums; white-space: nowrap;
                                     overflow: hidden; text-overflow: ellipsis; }
.file-row .more { display: grid; place-items: center; position: relative; z-index: 1; }
.file-row .sel, .file-row .more { position: relative; z-index: 1; }
.file-row .badges { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; flex: none; }
.file-row .badges .badge { height: 18px; padding: 0 6px; font-size: .68rem; }
@media (max-width: 839.98px) {
  .files-head, .file-row { grid-template-columns: 44px minmax(0, 1fr) 90px 48px; }
  .files-head .mtime, .file-row .mtime { display: none; }
}
@media (max-width: 599.98px) {
  .files-head { display: none; }
  .file-row { grid-template-columns: minmax(0, 1fr) 44px; min-height: 64px; padding: 0 0 0 var(--s3); }
  .file-row .sel { position: absolute; inset: 0 auto 0 0; width: 56px; opacity: 0; }
  .browser.selecting .file-row .sel { position: relative; opacity: 1; width: 40px; }
  .browser.selecting .file-row { grid-template-columns: 40px minmax(0, 1fr) 44px; padding-left: 0; }
  .file-row .size { display: none; }
  .file-row .meta-sub { display: block; color: var(--muted); font-size: .82rem; font-weight: 400; overflow: hidden;
                        text-overflow: ellipsis; white-space: nowrap; }
  .file-row .name a { padding: var(--s2) 0; }
  .file-row .name a::after { inset: 0 44px 0 0; }
  .file-row .file-type { width: 40px; height: 40px; background: var(--surface-2); border-radius: var(--r2); }
  .file-row.selected .file-type { background: var(--accent); color: var(--accent-fg); }
}
.file-row .name .text { display: flex; flex-direction: column; min-width: 0; }

/* grid view */
.browser.view-grid .files-head { display: none; }
.browser.view-grid .files { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s3); }
@media (max-width: 599.98px) { .browser.view-grid .files { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--s2); } }
.browser.view-grid .file-row { display: flex; flex-direction: column; align-items: stretch; min-height: 0; padding: 0;
                               border: 1px solid var(--line); border-radius: var(--r2); background: var(--surface); overflow: hidden; }
.browser.view-grid .file-row.selected { background: var(--selected); border-color: var(--accent); }
.browser.view-grid .file-row .name a { flex-direction: column; align-items: stretch; gap: 0; padding: 0; }
.browser.view-grid .file-row .name a::after { inset: 0; }
.browser.view-grid .file-row .file-type { width: 100%; height: auto; aspect-ratio: 4 / 3; border-radius: 0; background: var(--surface-2); }
.browser.view-grid .file-row .file-type .icon { width: 48px; height: 48px; stroke-width: 1.4; }
.browser.view-grid .file-row .text { padding: var(--s2) 40px var(--s2) var(--s3); }
.browser.view-grid .file-row .meta-sub { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; overflow: hidden;
                                         text-overflow: ellipsis; white-space: nowrap; }
.browser.view-grid .file-row .size, .browser.view-grid .file-row .mtime { display: none; }
.browser.view-grid .file-row .sel { position: absolute; top: var(--s2); left: var(--s2); width: 28px; height: 28px; opacity: 0;
                                    border-radius: var(--r1); background: var(--surface); box-shadow: var(--shadow-1); z-index: 2; }
@media (hover: hover) { .browser.view-grid .file-row:hover .sel { opacity: 1; } }
.browser.view-grid .file-row.selected .sel, .browser.view-grid.selecting .file-row .sel,
.browser.view-grid .file-row .sel:focus-within { opacity: 1; }
.browser.view-grid .file-row .more { position: absolute; right: 2px; bottom: 2px; }
@media (pointer: coarse) { .browser.view-grid .file-row .sel { opacity: 1; } }

.drop-overlay { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: var(--s5);
                background: color-mix(in srgb, var(--accent) 14%, transparent); pointer-events: none; }
.drop-overlay > div { display: flex; flex-direction: column; align-items: center; gap: var(--s2); padding: var(--s6) var(--s7);
                      border: 2px dashed var(--accent); border-radius: var(--r3); background: var(--surface); box-shadow: var(--shadow-2);
                      text-align: center; font-weight: 650; }
.drop-overlay .icon { color: var(--accent); }
.drag-ghost { position: fixed; top: -100px; left: -100px; padding: var(--s2) var(--s3); border-radius: 999px; background: var(--accent);
              color: var(--accent-fg); font-weight: 650; font-size: .9rem; }

/* ---------------------------------------------------------------- menus (popover) */
.menu { position: fixed; inset: auto; margin: 0; min-width: 220px; max-width: min(320px, calc(100vw - 16px));
        max-height: min(70vh, 520px); overflow-y: auto; padding: var(--s1); border: 1px solid var(--line); border-radius: var(--r2);
        background: var(--surface); color: var(--fg); box-shadow: var(--shadow-2); }
.menu:popover-open { display: flex; flex-direction: column; }
.menu .menu-list { display: flex; flex-direction: column; }
.menu .menu-item, .menu > a, .menu > button, .menu form > button { display: flex; align-items: center; gap: var(--s3); width: 100%;
  min-height: 38px; padding: 0 var(--s3); border: 0; border-radius: var(--r1); background: none; color: var(--fg); text-align: left;
  text-decoration: none; font: inherit; font-size: .93rem; cursor: pointer; white-space: nowrap; }
@media (pointer: coarse) { .menu .menu-item, .menu > a, .menu > button, .menu form > button { min-height: 48px; } }
.menu .menu-item:hover, .menu .menu-item:focus-visible, .menu > a:hover, .menu > button:hover, .menu form > button:hover { background: var(--hover); outline: none; }
.menu .menu-item .icon { color: var(--fg-2); width: 18px; height: 18px; }
.menu .menu-item.danger, .menu .menu-item.danger .icon { color: var(--danger); }
.menu .menu-item kbd { margin-left: auto; }
.menu .menu-item[aria-checked="true"]::after { content: "✓"; margin-left: auto; color: var(--accent); font-weight: 700; }
.menu .menu-sep { height: 1px; margin: var(--s1) 0; background: var(--line); }
.menu .menu-label { padding: var(--s2) var(--s3) var(--s1); font-size: .75rem; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.menu .menu-head { display: flex; align-items: center; gap: var(--s2); padding: 0 var(--s1) var(--s2) var(--s3); margin-bottom: var(--s1);
                   border-bottom: 1px solid var(--line); }
.menu .menu-title { flex: 1; min-width: 0; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 600px) { .menu .menu-head { display: none; } }
.menu form { margin: 0; }
@media (max-width: 599.98px) {
  .menu.sheet-on-compact { inset: auto 0 0 0 !important; width: 100%; max-width: none; max-height: 75vh; border-radius: var(--r3) var(--r3) 0 0;
                           padding: var(--s2) var(--s2) calc(var(--s3) + env(safe-area-inset-bottom)); }
  .menu.sheet-on-compact::before { content: ""; display: block; align-self: center; width: 36px; height: 4px; margin: 2px 0 var(--s2);
                                   border-radius: 2px; background: var(--line-strong); flex: none; }
  .menu.sheet-on-compact::backdrop { background: var(--scrim); }
}

/* ---------------------------------------------------------------- dialogs */
dialog.dialog { width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); padding: 0; border: 1px solid var(--line);
                border-radius: var(--r3); background: var(--surface); color: var(--fg); box-shadow: var(--shadow-2); overflow: hidden; }
dialog.dialog.wide { width: min(760px, calc(100vw - 32px)); }
dialog.dialog[open] { display: flex; flex-direction: column; }
dialog.dialog::backdrop { background: var(--scrim); }
.dialog-head { display: flex; align-items: center; gap: var(--s2); padding: var(--s4) var(--s3) var(--s2) var(--s5); }
.dialog-head h2 { flex: 1; font-size: 1.12rem; overflow-wrap: anywhere; }
.dialog-body { padding: var(--s2) var(--s5) var(--s4); overflow-y: auto; display: flex; flex-direction: column; gap: var(--s4); }
.dialog-body > p { color: var(--fg-2); }
.dialog-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s2); padding: var(--s3) var(--s5) var(--s4);
               border-top: 1px solid var(--line); background: var(--surface); }
.dialog-foot .left { margin-right: auto; }
@media (max-width: 599.98px) {
  dialog.dialog, dialog.dialog.wide { width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; border-radius: var(--r3) var(--r3) 0 0; border-bottom: 0; }
  .dialog-foot { padding-bottom: calc(var(--s4) + env(safe-area-inset-bottom)); }
  .dialog-foot .btn { flex: 1; }
  .dialog-foot .left { flex-basis: 100%; }
}

/* Item details: a side panel on desktop, the dialog's usual bottom sheet on compact screens. */
dialog.details-dialog { width: min(420px, 100vw); height: 100vh; height: 100dvh; max-height: 100dvh; margin: auto 0 auto auto;
                        border-radius: 0; border-top: 0; border-right: 0; border-bottom: 0; }
.details-dialog .dialog-body { flex: 1; }
.details-status { color: var(--muted); }
.details-status.error { color: var(--danger); }
.details-badges { gap: var(--s1); }
.details-props dd { min-height: 1.5em; }
.details-list { margin: var(--s2) 0 0; padding-left: 1.2em; overflow-wrap: anywhere; }
.details-list li + li { margin-top: var(--s2); }
.details-badges .icon, .file-row .badges .icon { width: 14px; height: 14px; }
.details-props dd { overflow-wrap: anywhere; }
.details-dialog .dialog-body { min-height: 0; }
@media (max-width: 599.98px) {
  dialog.details-dialog { width: 100%; height: auto; max-height: 92dvh; margin: auto 0 0;
                          border-radius: var(--r3) var(--r3) 0 0; border: 1px solid var(--line); border-bottom: 0; }
  .details-dialog .dialog-body { flex: 0 1 auto; padding-bottom: calc(var(--s4) + env(safe-area-inset-bottom)); }
}

/* folder picker */
.picker { display: flex; flex-direction: column; min-height: 280px; max-height: 50vh; border: 1px solid var(--line); border-radius: var(--r2); overflow: hidden; }
.picker .crumbs { padding: var(--s2) var(--s2) var(--s1); margin: 0; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.picker .crumbs button { padding: 2px var(--s2); border: 0; border-radius: var(--r1); background: none; color: var(--fg-2); font: inherit; cursor: pointer; }
.picker .crumbs button:hover { background: var(--hover); }
.picker ul { flex: 1; overflow-y: auto; margin: 0; padding: var(--s1); list-style: none; }
.picker li button { display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 42px; padding: 0 var(--s3); border: 0;
                    border-radius: var(--r1); background: none; color: var(--fg); text-align: left; font: inherit; cursor: pointer; }
.picker li button:hover, .picker li button:focus-visible { background: var(--hover); outline: none; }
.picker li button[disabled] { color: var(--muted); cursor: not-allowed; }
.picker li button .icon { color: var(--folder); }
.picker .picker-empty { padding: var(--s5); text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------- toasts, upload panel */
.toasts { position: fixed; left: 50%; bottom: var(--s5); translate: -50% 0; z-index: 90; display: flex; flex-direction: column; gap: var(--s2);
          width: min(560px, calc(100vw - 24px)); pointer-events: none; }
@media (max-width: 599.98px) { .toasts { bottom: calc(var(--bottom-h) + var(--s3) + env(safe-area-inset-bottom)); } }
.toast { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s2) var(--s2) var(--s4); min-height: 48px;
         border-radius: var(--r2); background: light-dark(#23262d, #e9ebef); color: light-dark(#f2f3f5, #16181d); box-shadow: var(--shadow-2);
         pointer-events: auto; animation: toast-in .18s ease-out; }
.toast .msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast .btn { min-height: 34px; color: light-dark(#9cc0ff, #1f5fd1); background: transparent; border-color: transparent; }
.toast .btn:hover { background: rgb(127 127 127 / .2); }
.toast .btn-icon { color: inherit; }
.toast.error { background: var(--danger); color: var(--danger-fg); }
.toast.error .btn { color: inherit; }
@keyframes toast-in { from { opacity: 0; translate: 0 8px; } to { opacity: 1; translate: 0 0; } }

.upload-panel { position: fixed; right: var(--s4); bottom: var(--s4); z-index: 70; width: min(380px, calc(100vw - 24px));
                border: 1px solid var(--line); border-radius: var(--r3); background: var(--surface); box-shadow: var(--shadow-2); overflow: hidden; }
@media (max-width: 599.98px) { .upload-panel { right: 12px; bottom: calc(var(--bottom-h) + 12px + env(safe-area-inset-bottom)); } }
.upload-panel header { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s2) var(--s2) var(--s4); background: var(--surface-2); }
.upload-panel header h2 { flex: 1; font-size: .95rem; }
.upload-panel ul { max-height: 260px; overflow-y: auto; margin: 0; padding: var(--s1) 0; list-style: none; }
.upload-panel.collapsed ul { display: none; }
.upload-panel li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px var(--s2); padding: var(--s2) var(--s4); font-size: .88rem; }
.upload-panel li .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-panel li .state { color: var(--muted); font-size: .8rem; }
.upload-panel li.failed .state { color: var(--danger); }
.upload-panel li.done .state { color: var(--ok); }
.upload-panel progress { grid-column: 1 / -1; width: 100%; height: 4px; appearance: none; border: 0; border-radius: 2px; background: var(--surface-3); }
.upload-panel progress::-webkit-progress-bar { background: var(--surface-3); border-radius: 2px; }
.upload-panel progress::-webkit-progress-value { background: var(--accent); border-radius: 2px; }
.upload-panel progress::-moz-progress-bar { background: var(--accent); border-radius: 2px; }

/* ---------------------------------------------------------------- viewer */
.viewer-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--s5); align-items: start; }
@media (max-width: 1099.98px) { .viewer-layout { grid-template-columns: minmax(0, 1fr); } }
.viewer { display: grid; place-items: center; min-height: 320px; padding: var(--s3); border-radius: var(--r3);
          background: light-dark(#e9ecf0, #0c0d0f); border: 1px solid var(--line); overflow: hidden; }
.viewer img, .viewer video { display: block; max-width: 100%; max-height: 72vh; object-fit: contain; border-radius: var(--r1); background: var(--surface); }
.viewer audio { width: min(100%, 520px); }
.viewer iframe { width: 100%; height: 72vh; border: 0; border-radius: var(--r1); background: #fff; }
.viewer ol.lines { list-style: none; counter-reset: line; padding: var(--s3) 0; }
.viewer ol.lines li { counter-increment: line; display: grid; grid-template-columns: 4.5em minmax(0, 1fr); }
.viewer ol.lines li::before { content: counter(line); padding-right: var(--s3); text-align: right; color: var(--muted); user-select: none; }
.viewer ol.lines code { font: inherit; white-space: pre-wrap; overflow-wrap: anywhere; padding-right: var(--s4); }
.viewer .text-view { width: 100%; max-height: 72vh; overflow: auto; margin: 0; padding: var(--s4); border-radius: var(--r1); background: var(--surface);
                     font: .86rem/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; align-self: stretch; }
.viewer .unavailable { display: flex; flex-direction: column; align-items: center; gap: var(--s3); padding: var(--s6); text-align: center; color: var(--fg-2); }
.viewer-nav { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-top: var(--s3); }
.pager { display: flex; align-items: center; justify-content: center; gap: var(--s3); margin-top: var(--s3); }
.editor textarea { min-height: 60vh; font: .9rem/1.55 var(--mono); tab-size: 4; }
.side-panel { display: flex; flex-direction: column; gap: var(--s4); }

/* ---------------------------------------------------------------- misc */
.qr { display: inline-block; padding: var(--s3); border-radius: var(--r2); background: #fff; color: #000; line-height: 0; }
.qr svg { width: 200px; height: 200px; }
code.secret, .secret { word-break: break-all; font-family: var(--mono); }
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2) var(--s4); margin: 0; padding: 0; list-style: none;
         font: 1.05rem/1.4 var(--mono); }
.copy-field { display: flex; gap: var(--s2); }
.copy-field input { flex: 1; min-width: 0; font-family: var(--mono); }
.kbd-list { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2) var(--s4); margin: 0; }
.kbd-list dt { color: var(--fg-2); }
.kbd-list dd { margin: 0; text-align: right; white-space: nowrap; }
.kbd-section + .kbd-section { margin-top: var(--s4); }
.kbd-section h3 { margin-bottom: var(--s2); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.steps { margin: 0; padding-left: 1.2rem; display: flex; flex-direction: column; gap: var(--s2); }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: var(--accent-fg);
          font-weight: 700; font-size: .85rem; text-transform: uppercase; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-dot.ok { background: var(--ok); } .status-dot.warn { background: var(--warn); } .status-dot.danger { background: var(--danger); }
.meter { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.meter.warn > span { background: var(--warn); } .meter.danger > span { background: var(--danger); }
details.disclosure > summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: var(--s2); color: var(--accent); font-weight: 600; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::before { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
                                       rotate: -45deg; transition: rotate .12s; }
details.disclosure[open] > summary::before { rotate: 45deg; }
details.disclosure[open] > summary { margin-bottom: var(--s3); }
* + details.disclosure { margin-top: var(--s4); }
.pre-wrap { white-space: pre-wrap; }

/* storage meters (native progress; no inline widths under the CSP) */
progress.meter { display: block; width: 100%; border: 0; appearance: none; }
progress.meter::-webkit-progress-bar { background: var(--surface-3); border-radius: inherit; }
progress.meter::-webkit-progress-value { background: var(--accent); border-radius: inherit; }
progress.meter::-moz-progress-bar { background: var(--accent); border-radius: inherit; }
progress.meter.warn::-webkit-progress-value { background: var(--warn); }
progress.meter.warn::-moz-progress-bar { background: var(--warn); }
progress.meter.danger::-webkit-progress-value { background: var(--danger); }
progress.meter.danger::-moz-progress-bar { background: var(--danger); }

/* account credentials (one-time tokens shown in a copy field) */
.copy-field > .secret { flex: 1; min-width: 0; display: flex; align-items: center; padding: var(--s1) var(--s3);
  min-height: var(--target); border: 1px solid var(--line-strong); border-radius: var(--r1); background: var(--surface-2); }
.copy-field > .secret code { overflow-wrap: anywhere; }

/* search, trash, activity, edit and tags pages */
.list-item .li-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; color: var(--muted); font-size: .85rem; white-space: nowrap; }
.chip .dot.ns-host { background: var(--warn); }
.chip .dot.ns-group { background: var(--ok); }
.editor-page .editor textarea { min-height: max(60vh, calc(100dvh - 19rem)); }

/* sharing: links, collections, public share pages */
.auth-shell:has(.share-page) { grid-template-columns: minmax(0, 1fr); }
.auth-shell .share-page { width: min(960px, calc(100vw - 2 * var(--s3))); margin-inline: auto; }
.auth-shell .share-page-sm { width: min(600px, calc(100vw - 2 * var(--s3))); margin-inline: auto; }
.auth-shell .share-page .card, .auth-shell .share-page-sm .card { width: 100%; }
.share-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); }
.share-head .grow { flex: 1; min-width: 0; }
.share-head h1 { font-size: 1.25rem; margin: 0; overflow-wrap: anywhere; }
.share-head p { color: var(--muted); font-size: .88rem; }
.share-head .file-type { width: 44px; height: 44px; background: var(--accent-soft); color: var(--accent); }
.share-card.flush .share-head { padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); }
.card > .pad { padding: var(--s4) var(--s5); }
.card.flush > .pad { border-top: 1px solid var(--line); }
.card.flush > .pad:first-child { border-top: 0; }
.card > .pad > form { margin: 0; }
.share-card .crumbs-nav { padding: var(--s2) var(--s5); border-bottom: 1px solid var(--line); }
.crumbs.share { display: flex; }
.share-card.flush > .list > .list-item { padding-inline: var(--s5); }
.li-main { display: flex; align-items: center; gap: var(--s3); flex: 1; min-width: 0; color: var(--fg); text-decoration: none; font-weight: 600; }
.li-main .icon { color: var(--muted); }
.li-main .li-title, .li-main .li-sub { text-decoration: none; }
.li-main:focus-visible { outline: none; }
.list-item:has(.li-main:focus-visible) { outline: 2px solid var(--focus); outline-offset: -2px; border-radius: var(--r1); }
.option { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3); border: 1px solid var(--line);
          border-radius: var(--r2); background: var(--surface); cursor: pointer; }
@media (hover: hover) { .option:hover { border-color: var(--line-strong); } }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.option input { margin-top: 2px; }
.option .opt-title { display: block; font-weight: 600; }
.option .opt-sub { display: block; color: var(--muted); font-size: .86rem; }
.copy-field.big input { min-height: 48px; font-size: .95rem; }
.dropzone { display: flex; flex-direction: column; align-items: center; gap: var(--s2); padding: var(--s6) var(--s4);
            text-align: center; border: 2px dashed var(--line-strong); border-radius: var(--r3); background: var(--surface-2); }
.dropzone .icon { color: var(--accent); }
.dropzone .dz-title { font-weight: 650; }
.dropzone input[type=file] { max-width: 100%; font: inherit; color: var(--fg-2); }
.dropzone input[type=file]::file-selector-button { margin-right: var(--s2); min-height: var(--target); padding: 0 var(--s4);
  border: 1px solid var(--line-strong); border-radius: var(--r1); background: var(--surface); color: var(--fg);
  font: inherit; font-weight: 550; cursor: pointer; }
@media (max-width: 599.98px) {
  .share-card.flush .share-head { padding: var(--s4); }
  .share-card .crumbs-nav, .share-card.flush > .list > .list-item, .card > .pad { padding-inline: var(--s4); }
  .copy-field.big { flex-direction: column; }
  .copy-field.big .btn { width: 100%; }
}
.card.flush > .tag-note { padding: 0 var(--s5) var(--s4); }
@media (max-width: 599.98px) { .card.flush > .tag-note { padding: 0 var(--s4) var(--s4); } }

/* admin audit table */
.table td.audit-time { white-space: nowrap; }
@media (min-width: 600px) { .table td.actions .cluster { flex-wrap: nowrap; } }

/* account pages: one card width for every step of the sign-in flow */
.auth-shell { grid-template-columns: minmax(0, 420px); justify-items: stretch; justify-content: center; }
.empty h1 { color: var(--fg); }
.nowrap { white-space: nowrap; }
.page-header .sub, .empty p { overflow-wrap: anywhere; }
.chip { max-width: 100%; overflow-wrap: anywhere; }

/* unfinished uploads: a notice above the list that offers to continue or discard them */
.resume-notice .resume-title { font-weight: 650; }
.resume-notice .resume-list { margin: var(--s2) 0 0; padding-left: 1.1em; }
.resume-notice .resume-list li { overflow-wrap: anywhere; }
.resume-notice .resume-list li + li { margin-top: 2px; }
.resume-notice .resume-meta { margin-left: var(--s2); color: var(--muted); font-size: .88rem; white-space: nowrap; }
.resume-notice .resume-error { margin-top: var(--s2); color: var(--danger); font-size: .88rem; }
.resume-actions { margin-top: var(--s3); }
@media (max-width: 599.98px) { .resume-actions .btn { flex: 1 1 auto; } }

/* path suggestions: a Browse… button beside a source:/path field */
.path-input { display: flex; gap: var(--s2); align-items: flex-start; }
.path-input > input, .path-input > textarea { flex: 1 1 auto; min-width: 0; }
.path-input > .path-browse { flex: 0 0 auto; white-space: nowrap; }
@media (max-width: 599.98px) {
  .path-input { flex-wrap: wrap; }
  .path-input > .path-browse { width: 100%; justify-content: center; }
}

/* ---------------------------------------------------------------- photo viewer */
/* The full-screen photo viewer (static/js/viewer.js): a modal <dialog> over a dark stage, whichever
   theme the page uses, so photos keep their colour. The stage owns every touch gesture with
   touch-action: none (nothing behind it scrolls, so vertical drags never fight the page), the bars
   keep 44 px targets, and nothing animates, so prefers-reduced-motion needs no special case. */
html.pv-open, html.pv-open body { overflow: hidden; }
.pv-ready [data-photo] { cursor: zoom-in; }
dialog.photo-viewer { position: fixed; inset: 0; width: 100%; max-width: none; height: 100dvh; max-height: none;
                      margin: 0; padding: 0; border: 0; border-radius: 0; background: #0b0c0e; color: #f1f3f6;
                      overflow: hidden; }
dialog.photo-viewer[open] { display: flex; flex-direction: column; }
dialog.photo-viewer:focus { outline: none; }
dialog.photo-viewer::backdrop { background: #000; }
.pv-bar { display: flex; align-items: center; gap: var(--s2); flex: none; padding: max(var(--s2), env(safe-area-inset-top)) var(--s3) var(--s2); }
.pv-count { flex: 1; min-width: 0; margin: 0; color: #dfe3ea; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pv-tools { display: flex; align-items: center; gap: var(--s1); flex: none; }
.pv-bar .btn { color: #f1f3f6; border-color: rgb(255 255 255 / .22); background: rgb(255 255 255 / .08); }
.pv-bar .btn:focus-visible, .pv-step:focus-visible { outline: 2px solid #9cc0ff; outline-offset: 2px; }
@media (hover: hover) { .pv-bar .btn:hover { background: rgb(255 255 255 / .16); } }
.pv-play[aria-pressed="true"] { background: #e3ecfc; border-color: #e3ecfc; color: #0b1530; }
.pv-zoom { font: 600 1.2rem/1 var(--font); }
.pv-stage { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden;
            padding: var(--s1) var(--s2); touch-action: none; }
.pv-stage img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 2px;
                user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
                transform: translate(var(--pv-x, 0px), var(--pv-y, 0px)) scale(var(--pv-scale, 1)); transform-origin: center; }
.photo-viewer[data-zoomed="true"] .pv-stage { cursor: grab; }
.photo-viewer[data-zoomed="true"] .pv-stage:active { cursor: grabbing; }
.pv-step { position: absolute; top: 50%; translate: 0 -50%; color: #f1f3f6; border-color: rgb(255 255 255 / .22);
           background: rgb(12 13 15 / .55); }
.pv-prev { left: max(var(--s2), env(safe-area-inset-left)); }
.pv-next { right: max(var(--s2), env(safe-area-inset-right)); }
.pv-step[aria-disabled="true"] { opacity: .3; pointer-events: none; }
@media (hover: hover) { .pv-step:hover { background: rgb(12 13 15 / .85); } }
.pv-step .icon { width: 24px; height: 24px; }
.pv-hint { flex: none; margin: 0; padding: var(--s2) var(--s4) max(var(--s2), env(safe-area-inset-bottom));
           color: #a8aeb8; font-size: .78rem; text-align: center; }
@media (pointer: coarse) {
  .pv-tools .btn, .pv-step { min-width: 44px; min-height: 44px; }
  .pv-play { min-width: 0; padding-inline: var(--s3); }
}
@media (max-width: 599.98px) {
  .pv-hint { font-size: .72rem; }
  .pv-stage { padding: 0; }
}
