/* =====================================================================
   Grandeur Vault — UI system. Dark, warm, quiet. Mobile → wide desktop.
   ===================================================================== */
:root {
  --bg: #0b0b0c; --bg-elev: #101012; --surface: #141416; --surface-2: #1a1a1d; --surface-3: #222226; --surface-4: #2a2a2f;
  --border: #232327; --border-strong: #303036; --border-focus: #c9ab6c;
  --text: #ece9e2; --text-2: #b8b4ab; --muted: #8a867d; --faint: #5b5852;
  --accent: #d4b57a; --accent-2: #e6cc95; --accent-ink: #1a1408; --accent-soft: rgba(212, 181, 122, .12); --accent-line: rgba(212, 181, 122, .35);
  --danger: #e5695e; --danger-soft: rgba(229, 105, 94, .12); --ok: #74c592; --ok-soft: rgba(116, 197, 146, .12); --warn: #e4b95f; --warn-soft: rgba(228, 185, 95, .12);
  --r-xs: 6px; --r-sm: 9px; --r: 14px; --r-lg: 18px;
  --shadow-1: 0 1px 0 rgba(255,255,255,.03) inset, 0 6px 24px rgba(0,0,0,.35); --shadow-2: 0 20px 60px rgba(0,0,0,.55);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --pad: 24px; --gap: 14px; --content: 1180px; --control-h: 42px;
}
@media (min-width: 1440px) { :root { --content: 1320px; --pad: 32px; } }
@media (max-width: 768px) { :root { --pad: 16px; --gap: 12px; --control-h: 44px; } }

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }
button { font: inherit; color: inherit; }
img { max-width: 100%; }
input, select, textarea { font: inherit; color: var(--text); }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.015em; margin: 0; line-height: 1.25; }
h1 { font-size: clamp(22px, 2.2vw, 28px); } h2 { font-size: 17px; } h3 { font-size: 15px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 12px; } .mono { font-family: var(--mono); font-size: 12.5px; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.stack { display: flex; flex-direction: column; gap: 10px; }
:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

/* ---------- controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .auth-card label { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.input { width: 100%; min-height: var(--control-h); background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 9px 13px; color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s, background .15s; }
.input:hover { border-color: #3a3a41; }
.input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(212, 181, 122, .14); }
.input::placeholder { color: var(--faint); }
select.input { appearance: none; -webkit-appearance: none; padding-right: 34px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; cursor: pointer; }
input[type="date"].input { min-width: 0; }
input[type="date"].input::-webkit-calendar-picker-indicator { filter: invert(.8); cursor: pointer; }
.input.code { font-family: var(--mono); font-size: 26px; letter-spacing: .32em; text-align: center; min-height: 56px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--control-h); background: linear-gradient(180deg, var(--accent-2), var(--accent)); color: var(--accent-ink); border: 0; border-radius: var(--r-sm); padding: 0 18px; font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none !important; white-space: nowrap; transition: filter .15s, transform .05s, background .15s, border-color .15s; user-select: none; }
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; transform: none; filter: none; }
.btn.secondary { background: var(--surface-3); color: var(--text); border: 1px solid var(--border-strong); }
.btn.secondary:hover { background: var(--surface-4); }
.btn.ghost { background: transparent; color: var(--text-2); border: 1px solid transparent; }
.btn.ghost:hover { color: var(--text); background: var(--surface-3); }
.btn.danger { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(229, 105, 94, .3); }
.btn.sm { min-height: 32px; padding: 0 11px; font-size: 13px; border-radius: 7px; }
.btn.icon { padding: 0 9px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }
.notice { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 12px 14px; font-size: 14px; line-height: 1.5; }
.notice.warn { border-color: rgba(228, 185, 95, .35); background: var(--warn-soft); }
.notice.ok { border-color: rgba(116, 197, 146, .35); background: var(--ok-soft); }
.notice.danger { border-color: rgba(229, 105, 94, .35); background: var(--danger-soft); }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; letter-spacing: .02em; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border-strong); vertical-align: middle; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: rgba(116, 197, 146, .3); }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: rgba(228, 185, 95, .3); }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(229, 105, 94, .3); }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.pill { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 13px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border-strong); font-size: 13px; color: var(--text-2); cursor: pointer; white-space: nowrap; transition: all .15s; user-select: none; }
.pill:hover { color: var(--text); border-color: #3a3a41; }
.pill.active { color: var(--accent-2); border-color: var(--accent-line); background: var(--accent-soft); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- auth pages ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; min-height: 100dvh; padding: 24px; background: radial-gradient(900px 500px at 50% -10%, rgba(212, 181, 122, .09), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 36px 34px; box-shadow: var(--shadow-2); }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 26px; }
.brand-mark { width: 13px; height: 13px; flex: none; background: linear-gradient(135deg, var(--accent-2), var(--accent)); transform: rotate(45deg); border-radius: 2px; box-shadow: 0 0 16px rgba(212, 181, 122, .45); }
.brand-name { font-size: 12px; letter-spacing: .24em; text-transform: uppercase; color: var(--text-2); white-space: nowrap; }
.lead { font-size: 17px; line-height: 1.45; margin: 0 0 18px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
@media (max-width: 480px) { .auth-body { padding: 16px; align-items: flex-start; padding-top: 12vh; } .auth-card { padding: 28px 22px; } }

/* ---------- app shell ---------- */
/* Installed on a phone or iPad the page runs under the status bar (black-translucent + viewport-fit=cover): the insets are 0 everywhere else. */
.topbar { position: sticky; top: 0; z-index: 30; background: rgba(11, 11, 12, .82); backdrop-filter: saturate(140%) blur(16px); -webkit-backdrop-filter: saturate(140%) blur(16px); border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top, 0px); }
.topbar-inner { max-width: var(--content); margin: 0 auto; padding: 0 max(var(--pad), env(safe-area-inset-right, 0px)) 0 max(var(--pad), env(safe-area-inset-left, 0px)); height: 62px; display: flex; align-items: center; gap: 22px; }
.topbar .brand { margin: 0; flex: none; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent); padding-right: 24px; }
.nav::-webkit-scrollbar { display: none; }
.nav a { position: relative; color: var(--muted); padding: 9px 13px; border-radius: 8px; font-size: 14px; font-weight: 500; white-space: nowrap; transition: color .15s, background .15s; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--text); background: var(--surface-3); }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: 10px; flex: none; }
.user-menu .name { font-size: 13.5px; color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Below ~1000px the owner's six nav items and the user area compete for the bar: drop the name first, then tighten the links. */
@media (max-width: 1140px) { .user-menu .name { display: none; } .topbar-inner { gap: 14px; } .nav a { padding: 9px 10px; } }
/* Phone: the sideways nav becomes a bottom tab bar (five tabs max, the rest behind "More"), with room for the home indicator. */
.tabbar { display: none; }
@media (max-width: 768px) {
  .topbar .nav, .user-menu { display: none; }
  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; align-items: stretch; background: rgba(16, 16, 18, .94); backdrop-filter: saturate(140%) blur(16px); -webkit-backdrop-filter: saturate(140%) blur(16px); border-top: 1px solid var(--border); padding: 6px calc(4px + env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) calc(4px + env(safe-area-inset-left, 0px)); }
  .tabbar:empty { display: none; }   /* nothing to show until the session is known */
  .tabbar .tab { position: relative; flex: 1 1 0; min-width: 0; min-height: 50px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font: inherit; font-size: 10.5px; font-weight: 500; letter-spacing: .01em; border: 0; background: none; border-radius: 10px; padding: 4px 2px; text-decoration: none !important; cursor: pointer; transition: color .15s; }
  .tabbar .tab .ic { width: 22px; height: 22px; }
  .tabbar .tab.active { color: var(--accent); }
  .tabbar .tab:active { background: var(--surface-2); }
  .tab-badge { position: absolute; top: 1px; left: calc(50% + 5px); min-width: 17px; height: 17px; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 2px solid var(--bg); }
  .tab-badge.accent { background: var(--accent); color: var(--accent-ink); }
}
main.content { max-width: var(--content); margin: 0 auto; padding: 28px max(var(--pad), env(safe-area-inset-right, 0px)) 96px max(var(--pad), env(safe-area-inset-left, 0px)); }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.view-head p { margin: 4px 0 0; max-width: 60ch; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 20px 22px; box-shadow: var(--shadow-1); }
.card + .card { margin-top: var(--gap); }
.card h2 { margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: var(--gap); }
.grid-2 .card + .card { margin-top: 0; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar .input { width: auto; min-width: 150px; min-height: 36px; padding: 6px 12px; font-size: 13.5px; }
.toolbar select.input { padding-right: 32px; }
.toolbar input[data-f="q"] { min-width: 200px; flex: 1 1 200px; }
.toolbar .pills { display: flex; gap: 6px; }
@media (max-width: 768px) { .toolbar .pills { flex-basis: 100%; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; margin-right: calc(-1 * var(--pad)); padding-right: var(--pad); } .toolbar .pills::-webkit-scrollbar { display: none; } }
.empty { text-align: center; padding: 56px 20px; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: var(--r); line-height: 1.6; }
.empty strong { color: var(--text); }

@media (max-width: 768px) {
  .topbar-inner { height: 56px; gap: 12px; }
  .topbar .brand-name { font-size: 11px; }   /* the nav lives in the bottom bar on phones, so the name has the room */
  .nav a { padding: 8px 11px; font-size: 13.5px; }
  .user-menu .name { display: none; }
  .user-menu .btn { min-height: 34px; padding: 0 10px; }
  main.content { padding-top: 18px; }
  .card { padding: 16px; border-radius: 12px; }
  .toolbar { gap: 8px; }
  .toolbar .pill { min-height: 34px; padding: 0 12px; }
  .toolbar .input { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .toolbar input[data-f="q"] { flex-basis: 100%; }
}

/* ---------- upload view ---------- */
.upload-options { display: grid; grid-template-columns: minmax(150px, 190px) minmax(260px, 1.1fr) minmax(220px, 1fr); gap: var(--gap); margin-bottom: var(--gap); }
.watch-btn { width: 100%; justify-content: flex-start; background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text); font-weight: 500; padding: 0 11px; text-align: left; overflow: hidden; }
.watch-btn:hover { border-color: #3a3a41; background: var(--surface-3); filter: none; }
.watch-btn img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; background: #fff; flex: none; }
.watch-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.dropzone { position: relative; border: 1.5px dashed var(--border-strong); border-radius: var(--r); padding: 38px 24px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; background: linear-gradient(180deg, rgba(255,255,255,.015), transparent), var(--surface); }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: rgba(212, 181, 122, .05); }
.dropzone .big { font-size: 16px; font-weight: 600; }
.dropzone .icon { width: 46px; height: 46px; margin: 0 auto 12px; border-radius: 13px; background: var(--accent-soft); border: 1px solid var(--accent-line); display: flex; align-items: center; justify-content: center; color: var(--accent); }
.queue { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.qitem { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.qitem .thumb { width: 56px; height: 56px; border-radius: 8px; background: var(--surface-3); display: flex; align-items: center; justify-content: center; color: var(--faint); font-size: 10.5px; font-weight: 700; letter-spacing: .06em; overflow: hidden; }
.qitem .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.qitem .meta { min-width: 0; }
.qitem .fname { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qitem .sub { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.qitem .actions { display: flex; gap: 4px; }
.progress { height: 5px; background: var(--surface-3); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .25s; border-radius: 3px; }
.progress.done > i { background: var(--ok); }
.progress.err > i { background: var(--danger); }
.day-chip { background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: 6px; padding: 1px 8px; font-size: 12px; color: var(--text); cursor: pointer; }
.upload-banner { position: sticky; top: 62px; z-index: 25; background: rgba(26, 26, 29, .92); backdrop-filter: blur(12px); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 10px 14px; margin-bottom: 16px; display: flex; gap: 12px; align-items: center; font-size: 13.5px; }
.upload-banner .progress { flex: 1; margin: 0; min-width: 80px; }
@media (max-width: 900px) { .upload-options { grid-template-columns: minmax(140px, 190px) minmax(0, 1fr); } .upload-options .field:last-child { grid-column: 1 / -1; } }
@media (max-width: 560px) { .upload-options { grid-template-columns: 1fr; } .dropzone { padding: 30px 16px; } .qitem { grid-template-columns: 46px minmax(0, 1fr); } .qitem .thumb { width: 46px; height: 46px; } .qitem .actions { grid-column: 1 / -1; justify-content: flex-end; } .upload-banner { top: 56px; } }

/* ---------- file grids ---------- */
.day-group { margin-bottom: 30px; }
.day-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.day-head h2 { font-size: 17px; }
.member-head { font-size: 13px; color: var(--muted); margin: 12px 0 8px; display: flex; gap: 10px; align-items: center; }
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: var(--gap); }
.fcard { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; position: relative; transition: border-color .15s, transform .15s, box-shadow .15s; }
.fcard:hover { border-color: var(--border-strong); box-shadow: var(--shadow-1); }
.fcard.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
/* Deleted: dim the media, not the words — the status and the Restore button are the point of that view. */
.fcard.deleted .fthumb { opacity: .55; filter: grayscale(1); }
.fcard.deleted .fname { color: var(--text-2); }
.fthumb { aspect-ratio: 4 / 3; background: var(--surface-3); display: flex; align-items: center; justify-content: center; color: var(--faint); font-weight: 700; letter-spacing: .08em; font-size: 12px; position: relative; overflow: hidden; }
.fthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fthumb .dur { position: absolute; right: 8px; bottom: 8px; background: rgba(0, 0, 0, .72); color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 4px; font-family: var(--mono); }
.fthumb .kindtag { position: absolute; left: 8px; top: 8px; background: rgba(0, 0, 0, .6); color: #ddd; font-size: 10px; padding: 2px 7px; border-radius: 4px; letter-spacing: .08em; }
/* The checkbox sits on the thumbnail (itself a tap target), so it gets a generous hit area of its own. */
.fcard .check-hit { position: absolute; left: 0; top: 0; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; z-index: 2; cursor: pointer; }
.fcard .check { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.fcard.has-check .kindtag { left: 44px; }
/* Card body: name → facts → status → (note) → (request) → actions; one 6px rhythm between rows. */
.fbody { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.fbody .fname { font-size: 13.5px; font-weight: 600; letter-spacing: -.005em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fmeta { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; line-height: 1.4; }
.fmeta .when { margin-left: auto; white-space: nowrap; min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.fstatus { display: flex; flex-wrap: wrap; gap: 6px; }
.fstatus .badge { height: 24px; padding: 0 9px; gap: 4px; }
.fstatus .badge .ic { width: 13px; height: 13px; }
.fnote { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-style: italic; }
.freq { border: 1px solid rgba(229, 105, 94, .32); background: var(--danger-soft); border-radius: 9px; padding: 8px 10px; display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; line-height: 1.4; }
.freq-text { display: flex; gap: 7px; align-items: flex-start; color: var(--text-2); }
.freq-text > span { min-width: 0; overflow-wrap: anywhere; }
.freq-text .ic { color: var(--danger); flex: none; margin-top: 2px; }
.freq-text b { color: var(--danger); font-weight: 600; }
.freq-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.freq-actions .btn { min-height: 36px; min-width: 0; padding: 0 12px; font-size: 12.5px; }
.factions { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.factions .btn { min-height: 36px; padding: 0 12px; font-size: 12.5px; gap: 6px; }
.factions .iconbtn { width: 36px; padding: 0; flex: none; color: var(--text-2); }
.factions .iconbtn:hover, .factions .iconbtn[aria-expanded="true"] { color: var(--text); background: var(--surface-3); }
.ic { width: 16px; height: 16px; flex: none; }
.new-dot { position: absolute; right: 8px; top: 8px; z-index: 2; background: rgba(0, 0, 0, .72); color: var(--accent-2); border-color: transparent; }
/* Overflow menu for the rarer card actions (fixed: the card clips its own overflow). */
.menu { position: fixed; z-index: 55; min-width: 190px; max-height: calc(100dvh - 16px); overflow: auto; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 10px; padding: 6px; box-shadow: var(--shadow-2); animation: menu-in .12s ease-out; }
.menu.above { animation-name: menu-in-above; }
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes menu-in-above { from { opacity: 0; transform: translateY(4px) scale(.98); } to { opacity: 1; transform: none; } }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 0 10px; border: 0; background: none; color: var(--text); font: inherit; font-size: 13.5px; border-radius: 7px; cursor: pointer; text-align: left; text-decoration: none !important; }
.menu-item .ic { color: var(--text-2); }
.menu-item:hover { background: var(--surface-3); color: var(--text); }
.menu-item:focus-visible { background: var(--surface-3); color: var(--text); outline: none; box-shadow: inset 0 0 0 2px var(--border-focus); }
.menu-item.danger, .menu-item.danger .ic { color: var(--danger); }
.menu-item.danger:hover, .menu-item.danger:focus-visible { background: var(--danger-soft); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }
.select-bar { position: sticky; bottom: 14px; z-index: 22; margin-top: 20px; background: rgba(26, 26, 29, .95); backdrop-filter: blur(12px); border: 1px solid var(--accent-line); border-radius: 12px; padding: 10px 14px; display: flex; gap: 10px; align-items: center; box-shadow: var(--shadow-2); flex-wrap: wrap; }
/* Watch chip: same 24px pill as the status badges so a card's status reads as one row. */
.wchip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; height: 24px; background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: 999px; padding: 0 9px 0 3px; font-size: 12px; font-weight: 500; color: var(--text); cursor: pointer; }
.wchip img { width: 18px; height: 18px; border-radius: 50%; object-fit: cover; background: #fff; flex: none; }
.wchip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wchip.none { color: var(--warn); background: var(--warn-soft); border-color: rgba(228, 185, 95, .3); padding-left: 9px; }
.fstatus .wchip { font-size: 11.5px; font-weight: 600; letter-spacing: .02em; cursor: default; }   /* in a card the chip is a status, not a control */
@media (min-width: 1440px) { .files { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); } }
@media (max-width: 768px) {
  .files { grid-template-columns: repeat(auto-fill, minmax(164px, 1fr)); gap: 10px; }
  .fbody { padding: 9px 10px 10px; }
}
/* Touch targets: 44px on small screens and on any coarse pointer (a phone in landscape is wider than 768px). */
@media (max-width: 768px), (hover: none) and (pointer: coarse) {
  .factions .btn, .freq-actions .btn, .menu-item { min-height: 44px; }
  .factions .iconbtn, .factions .act-view { min-height: 44px; }
  .factions .iconbtn { width: 44px; }
}
@media (max-width: 400px) { .files { grid-template-columns: 1fr 1fr; } .fbody { padding: 9px 8px 10px; } }
/* Narrow cards (two-up on a phone) drop the View label, size the three actions to fit, and let the request buttons take the full row. */
.fcard { container-type: inline-size; }
@container (max-width: 200px) {
  .factions { gap: 4px; }
  .factions .act-view, .factions .iconbtn { width: 40px; padding: 0; flex: none; }
  .factions .act-view .lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .freq-actions .btn { flex: 1 1 100%; }
  .fmeta .when { margin-left: 0; }
}
@container (max-width: 150px) {
  .factions .act-view, .factions .iconbtn { width: 36px; }
  .fcard.has-check .kindtag { display: none; }
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; } }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 11.5px; color: var(--muted); font-weight: 500; letter-spacing: .06em; text-transform: uppercase; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.actions { text-align: right; white-space: nowrap; }
@media (max-width: 640px) {
  .tbl thead { display: none; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  .tbl tr:last-child { border-bottom: 0; }
  .tbl td { border: 0; padding: 3px 0; display: flex; gap: 12px; justify-content: space-between; align-items: baseline; }
  .tbl td[data-label]::before { content: attr(data-label); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); flex: none; }
  .tbl td.actions { justify-content: flex-start; flex-wrap: wrap; gap: 4px; padding-top: 8px; }
  .tbl td.actions::before { display: none; }
}
.kv { display: grid; grid-template-columns: minmax(120px, 170px) 1fr; gap: 7px 14px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) { .kv { grid-template-columns: 1fr; gap: 2px 0; } .kv dt { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; margin-top: 8px; } }
.meter { height: 8px; background: var(--surface-3); border-radius: 4px; overflow: hidden; margin: 8px 0 4px; }
.meter > i { display: block; height: 100%; background: var(--accent); }
.meter.warn > i { background: var(--warn); } .meter.danger > i { background: var(--danger); }

/* ---------- modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .62); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); z-index: 80; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-lg); padding: 24px; width: 100%; max-width: 460px; max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); overflow: auto; box-shadow: var(--shadow-2); animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.modal h2 { margin-bottom: 8px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.modal form { display: flex; flex-direction: column; gap: 14px; }
.modal.picker { max-width: 760px; }
@media (max-width: 560px) {
  .modal-back { padding: 0; align-items: flex-end; }
  .modal { max-width: none; border-radius: 18px 18px 0 0; max-height: 92vh; max-height: 92dvh; padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); animation: sheet .2s ease-out; }
  @keyframes sheet { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
  .modal .actions .btn { flex: 1 1 auto; }
}
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 90; display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 32px)); }
.toast { background: var(--surface-2); border: 1px solid var(--border-strong); border-left: 3px solid var(--accent); border-radius: 10px; padding: 11px 14px; font-size: 14px; box-shadow: var(--shadow-2); animation: toast-in .2s ease-out; }
.toast.danger { border-left-color: var(--danger); } .toast.ok { border-left-color: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- watch picker ---------- */
.picker-body { margin-top: 12px; max-height: 60vh; overflow: auto; overscroll-behavior: contain; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 8px; }
.ptile, .vtile { background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 10px; padding: 8px; text-align: left; color: var(--text); cursor: pointer; display: flex; flex-direction: column; gap: 6px; transition: border-color .12s, background .12s; min-width: 0; }
.ptile:hover, .vtile:hover { border-color: var(--accent); }
.ptile.sel, .vtile.sel { border-color: var(--accent); background: var(--accent-soft); }
.ptile.other { border-style: dashed; }
.pimg { display: flex; aspect-ratio: 1; background: #fff; border-radius: 7px; overflow: hidden; align-items: center; justify-content: center; }
.pimg img { width: 100%; height: 100%; object-fit: contain; display: block; }
.pimg.big { width: 140px; flex: none; }
.pimg .noimg { color: var(--faint); font-size: 12px; background: var(--surface-3); width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.ptitle { font-size: 13px; font-weight: 500; line-height: 1.3; overflow-wrap: anywhere; }
.pvar { font-size: 11.5px; color: var(--muted); }
.variant-list { display: flex; flex-wrap: wrap; gap: 8px; }
.vtile { flex-direction: row; align-items: center; padding: 6px 10px 6px 6px; font-size: 13px; }
.vtile img { width: 28px; height: 28px; border-radius: 5px; object-fit: cover; background: #fff; }
@media (max-width: 560px) { .picker-body { max-height: 62vh; } .picker-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; } .ptile { padding: 6px; } .pimg.big { width: 96px; } }
@media (max-width: 380px) { .picker-grid { grid-template-columns: repeat(2, 1fr); } }

/* ---------- viewer (lightbox) ---------- */
.fthumb.clickable { cursor: zoom-in; }
.fthumb:focus-visible { outline-offset: -3px; }   /* the card clips overflow: draw the ring inside */
.viewer-nav .ic { width: 24px; height: 24px; }
.viewer-top .ico .ic { width: 16px; height: 16px; vertical-align: -3px; }
.fthumb .zoom { position: absolute; left: 8px; bottom: 8px; width: 26px; height: 26px; border-radius: 7px; background: rgba(0, 0, 0, .55); color: #eee; display: flex; align-items: center; justify-content: center; font-size: 13px; opacity: 0; transition: opacity .15s; }
.fcard:hover .fthumb .zoom, .fthumb:focus-visible .zoom { opacity: 1; }
@media (hover: none) { .fthumb .zoom { opacity: .9; } }
.fthumb .dur { bottom: 8px; }
/* Opaque: on a bright phone screen a translucent backdrop lets the list behind read through the picture. */
.viewer { position: fixed; inset: 0; z-index: 70; background: #060607; display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: 56px 1fr 56px; animation: toast-in .15s ease-out both; }
.viewer-top { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(12px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) 12px calc(16px + env(safe-area-inset-left, 0px)); border-bottom: 1px solid rgba(255,255,255,.06); }
.viewer-actions { display: flex; align-items: center; gap: 6px; flex: none; }   /* never wraps: the title gives way instead */
.viewer-actions .iconbtn { width: 36px; padding: 0; }
.viewer-actions #vw-drive { gap: 6px; }
.viewer-top #vw-dl .ico { display: none; }
.viewer-stage { position: relative; overflow: hidden; }
.viewer-placeholder { position: absolute; max-width: 100%; max-height: calc(100vh - 140px); filter: blur(6px) brightness(.7); opacity: .8; pointer-events: none; }
.viewer-spinner { position: relative; z-index: 1; width: 28px; height: 28px; border-width: 3px; }
.viewer-stage.zoomed { overflow: auto; align-items: flex-start; justify-content: flex-start; touch-action: pan-x pan-y; }
.viewer-stage.zoomed .viewer-media { max-width: none; max-height: none; cursor: zoom-out; border-radius: 0; }
img.viewer-media { cursor: zoom-in; }
.viewer-title { min-width: 0; }
.viewer-title .fname { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-stage { grid-column: 2; display: flex; align-items: center; justify-content: center; min-height: 0; min-width: 0; padding: 8px; }
.viewer-media { max-width: 100%; max-height: calc(100vh - 140px); max-height: calc(100dvh - 140px); object-fit: contain; border-radius: 6px; background: #000; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.viewer-nav { grid-row: 2; align-self: center; width: 44px; height: 64px; margin: 0 6px; border: 0; border-radius: 10px; background: rgba(255,255,255,.06); color: var(--text); font-size: 34px; line-height: 1; cursor: pointer; }
.viewer-nav:hover { background: rgba(255,255,255,.12); }
.viewer-nav.prev { grid-column: 1; } .viewer-nav.next { grid-column: 3; }
.viewer-count { grid-column: 1 / -1; text-align: center; padding: 8px 0 calc(12px + env(safe-area-inset-bottom)); }
.viewer-fallback { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.viewer-fallback img { max-width: min(90vw, 720px); max-height: 60vh; border-radius: 8px; opacity: .85; }
.viewer-kind { width: 160px; height: 120px; border-radius: 12px; background: var(--surface-3); display: flex; align-items: center; justify-content: center; color: var(--faint); font-weight: 700; letter-spacing: .1em; }
@media (max-width: 720px) {
  .viewer { grid-template-columns: 1fr; }
  .viewer-nav { position: fixed; top: 50%; transform: translateY(-50%); width: 38px; height: 56px; background: rgba(0,0,0,.45); }
  .viewer-nav.prev { left: 4px; } .viewer-nav.next { right: 4px; }
  .viewer-stage { grid-column: 1; padding: 4px; }
  .viewer-media { max-height: calc(100dvh - 120px); }
  .viewer-top #vw-dl .lbl, .viewer-top #vw-drive .lbl { display: none; }
  .viewer-top #vw-dl .ico { display: inline; font-size: 16px; }
  .viewer-actions .btn { min-height: 44px; }
  .viewer-actions #vw-dl, .viewer-actions #vw-drive, .viewer-actions .iconbtn { width: 44px; padding: 0; }
  .viewer-title .fname { font-size: 14px; }
  .viewer-title .small { font-size: 12px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .viewer-nav.prev { left: calc(4px + env(safe-area-inset-left)); } .viewer-nav.next { right: calc(4px + env(safe-area-inset-right)); }
}
/* Phone offsets for fixed bars (last, so they win over the base rules above): content clears the tab bar, floating bars sit above it. */
@media (max-width: 768px) {
  main.content { padding-bottom: calc(112px + env(safe-area-inset-bottom, 0px)); }
  .select-bar { bottom: calc(78px + env(safe-area-inset-bottom, 0px)); }
  .toasts { bottom: calc(86px + env(safe-area-inset-bottom, 0px)); }
  .upload-banner { top: calc(56px + env(safe-area-inset-top, 0px)); }   /* the phone topbar is 56px */
}
