/* ── Reset & base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Themes ──────────────────────────────────────────────────
 * Every visual color/shape in this stylesheet is driven by the CSS
 * custom properties below — nothing else in this file hardcodes a
 * color. A "theme" is just one named set of values for these
 * properties, selected by `data-theme="<name>"` on <html> (see
 * public/app.js::applyTheme, which also owns the `<meta name="theme-color">`
 * mapping and the account-settings <select>). The bare `:root` block
 * (no attribute selector) is the fallback used before a theme is known
 * (first paint, logged-out) — keep it identical to the "dark" block.
 *
 * Users can also author their own themes at runtime (Settings → Customize
 * themes…). Those aren't blocks in this file: they're stored per-account and
 * applied as `data-theme="custom"` plus the full property set written inline
 * on <html> by app.js::applyTheme, so they override the `:root` fallback
 * below. If you add a new property to the blocks here, add it to
 * THEME_FIELDS/themeToVars in app.js too, or custom themes won't define it.
 *
 * TEMPLATE — to add a new *built-in* theme "myTheme":
 *   1. Copy one of the `:root[data-theme="..."]` blocks below and
 *      rename it to `:root[data-theme="myTheme"]`, then tweak the values.
 *      Every property must be re-declared — there's no partial
 *      inheritance between themes.
 *   2. Add 'myTheme' to VALID_THEMES in routes/settings.py (backend
 *      validation — PUT /api/settings silently falls back to 'dark'
 *      for anything not in that tuple).
 *   3. Add an <option value="myTheme"> to #settings-theme in
 *      public/index.html.
 *   4. Add a 'myTheme': '#rrggbb' entry to THEME_COLORS in
 *      public/app.js (used for <meta name="theme-color">; pick the
 *      theme's --bg or --surface value).
 *
 * Property reference:
 *   --bg            page background
 *   --surface       cards / modals / raised panels
 *   --surface2      nested panels inside a surface (e.g. field rows)
 *   --border        hairline borders/dividers
 *   --accent        primary actions, active states, links
 *   --accent-hover  hover/focus state of --accent
 *   --accent-rgb    --accent as "r,g,b" (no alpha) — for rgba(var(--accent-rgb), X)
 *                   tint effects; must always match --accent
 *   --danger        destructive actions, error text
 *   --danger-rgb    --danger as "r,g,b" — same purpose as --accent-rgb
 *   --success       done/positive states
 *   --text          primary text color
 *   --text-muted    secondary/hint text
 *   --hover-tint    subtle highlight overlay for hovering over a --surface
 *                   row/cell (white-ish on dark themes, black-ish on light
 *                   ones — must darken/lighten *away* from --surface)
 *   --radius        corner radius, cards/modals/buttons
 *   --radius-sm     corner radius, small controls (chips, inputs)
 *   --shadow        elevation shadow for modals/cards
 *   --font          font-family stack for the whole app (html, body). Keep
 *                   to system-available fonts only — no @import/@font-face
 *                   or CDN font loading (this app makes no external network
 *                   calls by design, see ARCHITECTURE.md §1).
 * ──────────────────────────────────────────────────────────── */

:root,
:root[data-theme="dark"] {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #22223b;
  --border: #2d2d4a;
  --accent: #7c6af7;
  --accent-hover: #9a8bff;
  --accent-rgb: 124,106,247;
  --danger: #e05260;
  --danger-rgb: 224,82,96;
  --success: #4caf87;
  --text: #e8e8f0;
  --text-muted: #8888aa;
  --hover-tint: rgba(255,255,255,.03);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0,0,0,.4);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

:root[data-theme="light"] {
  --bg: #f5f5fa;
  --surface: #ffffff;
  --surface2: #eef0f7;
  --border: #dcdce6;
  --accent: #6c5ce7;
  --accent-hover: #5849c4;
  --accent-rgb: 108,92,231;
  --danger: #d63447;
  --danger-rgb: 214,52,71;
  --success: #2f9e6e;
  --text: #1a1a2e;
  --text-muted: #6b6b85;
  --hover-tint: rgba(0,0,0,.035);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0,0,0,.08);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

:root[data-theme="forest"] {
  --bg: #0f1a14;
  --surface: #16241c;
  --surface2: #1c2e22;
  --border: #2a4034;
  --accent: #4caf87;
  --accent-hover: #6fc9a3;
  --accent-rgb: 76,175,135;
  --danger: #e07856;
  --danger-rgb: 224,120,86;
  --success: #7cd992;
  --text: #e6f0ea;
  --text-muted: #7fa08c;
  --hover-tint: rgba(255,255,255,.03);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0,0,0,.4);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

:root[data-theme="pixel"] {
  --bg: #0a0a12;
  --surface: #16162a;
  --surface2: #21213d;
  --border: #4a4a6a;
  --accent: #ff2e63;
  --accent-hover: #ff6b93;
  --accent-rgb: 255,46,99;
  --danger: #ff5252;
  --danger-rgb: 255,82,82;
  --success: #39ff14;
  --text: #f0f0ff;
  --text-muted: #8888cc;
  --hover-tint: rgba(255,255,255,.05);
  --radius: 0px;
  --radius-sm: 0px;
  --shadow: 4px 4px 0 rgba(0,0,0,.6);
  --font: 'Courier New', ui-monospace, 'Cascadia Mono', 'Consolas', monospace;
}

:root[data-theme="neon"] {
  --bg: #05010d;
  --surface: #12002b;
  --surface2: #1d0942;
  --border: #3d1a75;
  --accent: #00f0ff;
  --accent-hover: #6cf9ff;
  --accent-rgb: 0,240,255;
  --danger: #ff2d95;
  --danger-rgb: 255,45,149;
  --success: #39ff88;
  --text: #f2e9ff;
  --text-muted: #9d7ad4;
  --hover-tint: rgba(0,240,255,.07);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 0 24px rgba(0,240,255,.35);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100dvh; display: flex; flex-direction: column; }

/* ── Screens ────────────────────────────────────────────── */
.screen { display: none; flex-direction: column; min-height: 100dvh; }
.screen.active { display: flex; }

/* ── Auth ───────────────────────────────────────────────── */
.auth-wrap {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 2rem 1.25rem;
  max-width: 400px; margin: 0 auto; min-height: 100dvh; width: 100%;
}

.logo {
  font-size: 3rem; font-weight: 800; letter-spacing: -.05em;
  background: linear-gradient(135deg, var(--accent), #c084fc);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; margin-bottom: .25rem;
}

.tagline { color: var(--text-muted); margin-bottom: 2rem; text-align: center; }

.tab-bar {
  display: flex; gap: .5rem; background: var(--surface2);
  border-radius: var(--radius); padding: .25rem; margin-bottom: 1.5rem; width: 100%;
}

.tab {
  flex: 1; padding: .55rem; border-radius: var(--radius-sm);
  border: none; background: transparent; color: var(--text-muted);
  cursor: pointer; font-size: .95rem; font-weight: 500; transition: .2s;
}
.tab.active { background: var(--accent); color: #fff; }

.auth-form { display: flex; flex-direction: column; gap: .75rem; width: 100%; }

.auth-error { color: var(--danger); font-size: .875rem; min-height: 1.2em; }
.auth-error:empty { min-height: 0; }

/* Sign-up honeypot (abuse.py): moved off-screen rather than display:none,
 * which some bots detect and skip. */
.hp-field { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }
.register-turnstile { display: flex; justify-content: center; min-height: 65px; }
#register-invite-wrap { display: flex; flex-direction: column; gap: .35rem; }

/* Text-style button used for "Forgot password?" / "Back to sign in" / "Remove" */
.auth-link {
  background: none; border: none; padding: 0; color: var(--accent);
  font: inherit; font-size: .875rem; cursor: pointer; align-self: center;
}
.auth-link:hover { text-decoration: underline; }

/* Success/info line under the auth forms (email sent, email confirmed, …) */
.auth-notice {
  width: 100%; margin-top: 1rem; padding: .75rem .9rem; font-size: .9rem;
  border-radius: var(--radius-sm); border: 1px solid var(--accent);
  background: rgba(var(--accent-rgb), .12); color: var(--text); line-height: 1.4;
}

/* ── Header ─────────────────────────────────────────────── */
.app-header {
  display: flex; align-items: center; gap: .5rem;
  padding: .75rem 1rem; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}

/* A long list name used to wrap the sticky header onto two lines and
   push the content down; truncate instead — the full name is one screen
   back, and in the list-settings modal. */
.app-title {
  font-size: 1.1rem; font-weight: 700; color: var(--text);
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.flex-1 { flex: 1; }

.header-actions { display: flex; align-items: center; gap: .5rem; margin-left: auto; }

.greeting { font-size: .8rem; color: var(--text-muted); white-space: nowrap; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: .4rem; border: none; border-radius: var(--radius-sm);
  padding: .65rem 1.25rem; font-size: .95rem; font-weight: 600;
  cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--surface2); color: var(--text); }
.btn-ghost:hover { background: var(--border); }
.btn-sm { padding: .45rem .9rem; font-size: .875rem; }
.btn-icon {
  background: none; border: none; color: var(--text-muted);
  font-size: 1.2rem; cursor: pointer; padding: .3rem .5rem;
  border-radius: var(--radius-sm); transition: .15s; line-height: 1;
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }
.btn-icon.danger:hover { color: var(--danger); }

/* ── Content ────────────────────────────────────────────── */
.content { flex: 1; padding: 1rem; max-width: 600px; margin: 0 auto; width: 100%; }

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem;
}
.section-header h2 { font-size: 1.1rem; color: var(--text-muted); font-weight: 600; }
.section-header-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.empty-hint { text-align: center; color: var(--text-muted); padding: 3rem 1rem; }

/* ── Lists grid ─────────────────────────────────────────── */
.lists-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: .75rem;
}

.list-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1rem;
  cursor: pointer; transition: .15s; display: flex; flex-direction: column; gap: .4rem;
}
.list-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.list-card:active { transform: scale(.98); }

.list-icon { font-size: 1.8rem; line-height: 1; }
.list-name { font-weight: 600; font-size: .95rem; word-break: break-word; }
.list-meta { font-size: .78rem; color: var(--text-muted); }
.list-kind-badge {
  font-size: .68rem; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent);
  padding: .1rem .4rem; border-radius: 4px; align-self: flex-start;
}
.list-card.all-done .list-name { color: var(--text-muted); }
.list-card.all-done .list-icon { filter: grayscale(.6) opacity(.8); }

.member-picker {
  display: flex; flex-direction: column; gap: .25rem;
  max-height: 220px; overflow-y: auto; margin-top: .5rem;
}
.member-row {
  display: flex; align-items: center; gap: .5rem; padding: .35rem .4rem;
  border-radius: var(--radius-sm); cursor: pointer; font-size: .9rem;
}
.member-row:hover { background: var(--surface2); }
.member-row input[type="checkbox"] { cursor: pointer; accent-color: var(--accent); }
.list-progress {
  height: 3px; background: var(--border); border-radius: 2px; margin-top: .3rem;
}
.list-progress-bar { height: 100%; background: var(--success); border-radius: 2px; transition: width .3s; }

/* ── Add item bar ───────────────────────────────────────── */
/* A folded Galaxy Fold is ~320 CSS px wide, where the text field plus
   Add / ↑ Import / 📦 Catalog cannot share one line: the three nowrap
   buttons took the whole row and squeezed the input to a ~30px sliver.
   Below 540px the input gets a full row of its own and the buttons wrap
   underneath, sharing the width evenly (which also enlarges them). */
.add-item-bar {
  display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem;
}
.add-item-bar input { flex: 1 1 100%; min-width: 0; }
.add-item-bar .btn { flex: 1 1 auto; }
@media (min-width: 540px) {
  .add-item-bar input { flex: 1 1 12rem; }
  .add-item-bar .btn { flex: 0 0 auto; }
}

/* ── Filter bar ─────────────────────────────────────────── */
.filter-bar { display: flex; gap: .4rem; margin-bottom: 1rem; }
.filter-btn {
  padding: .35rem .8rem; border: 1px solid var(--border); border-radius: 20px;
  background: none; color: var(--text-muted); font-size: .82rem; cursor: pointer; transition: .15s;
}
.filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Items list ─────────────────────────────────────────── */
.items-list { display: flex; flex-direction: column; gap: .5rem; }

.item-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .85rem 1rem;
  display: flex; align-items: flex-start; gap: .75rem; transition: .15s;
}
.item-card.done { opacity: .65; }
.item-card:hover { border-color: var(--border); }

.item-check {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border); background: none; cursor: pointer;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  transition: .15s; margin-top: 1px; color: #fff; font-size: .75rem;
}
.item-check:hover { border-color: var(--success); }
.item-check.checked { background: var(--success); border-color: var(--success); }

.item-body { flex: 1; min-width: 0; }
.item-title { font-weight: 500; word-break: break-word; }
.item-title.done-text { text-decoration: line-through; color: var(--text-muted); }
.item-notes { font-size: .82rem; color: var(--text-muted); margin-top: .15rem; word-break: break-word; }
.item-meta { font-size: .75rem; color: var(--text-muted); margin-top: .3rem; display: flex; gap: .75rem; flex-wrap: wrap; }

.item-actions { display: flex; gap: .1rem; flex-shrink: 0; }
.item-actions .btn-icon { font-size: 1rem; }

/* ── Inputs ─────────────────────────────────────────────── */
input[type="text"],
input[type="email"],
input[type="password"],
textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 1rem;
  padding: .65rem .9rem; outline: none; transition: border-color .15s;
  font-family: inherit; resize: vertical;
}
input:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--text-muted); }

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100; backdrop-filter: blur(4px);
  padding: 0;
}
@media (min-width: 480px) {
  .modal-overlay { align-items: center; padding: 1rem; }
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0; padding: 1.5rem;
  width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 1rem;
  max-height: 90dvh; overflow-y: auto;
}
@media (min-width: 480px) {
  .modal { border-radius: var(--radius); }
}
.modal.hidden { display: none; }
.modal h3 { font-size: 1.1rem; }

.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; }

/* ── Icon picker ────────────────────────────────────────── */
.icon-picker { display: flex; flex-wrap: wrap; gap: .4rem; }
.icon-opt {
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  border: 2px solid transparent; background: var(--surface2);
  font-size: 1.3rem; cursor: pointer; display: flex; align-items: center;
  justify-content: center; transition: .15s;
}
.icon-opt:hover { border-color: var(--border); }
.icon-opt.selected { border-color: var(--accent); background: rgba(var(--accent-rgb),.2); }

/* ── Settings ───────────────────────────────────────────── */
.setting-group { display: flex; flex-direction: column; gap: .5rem; }
.setting-label { font-size: .85rem; color: var(--text-muted); font-weight: 500; }

.toggle-group {
  display: flex; background: var(--surface2); border-radius: var(--radius);
  padding: .25rem; gap: .25rem;
}
.toggle-opt {
  flex: 1; padding: .55rem; border-radius: var(--radius-sm);
  border: none; background: transparent; color: var(--text-muted);
  cursor: pointer; font-size: .9rem; font-weight: 500; transition: .15s;
}
.toggle-opt.active { background: var(--accent); color: #fff; }

.setting-hint { font-size: .78rem; color: var(--text-muted); }

/* ── Star picker ────────────────────────────────────────── */
.star-picker { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: center; padding: .5rem 0; }
.star-opt {
  font-size: 2rem; cursor: pointer; transition: transform .1s;
  filter: grayscale(1) opacity(.5);
}
.star-picker[data-max="10"] .star-opt { font-size: 1.5rem; }
.star-opt.lit { filter: none; }
.star-opt:hover { transform: scale(1.15); }

.rating-item-name {
  font-size: .9rem; color: var(--text-muted); text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.closure-fields { display: flex; flex-direction: column; gap: .6rem; margin: .75rem 0; }
.closure-error { color: var(--danger); font-size: .875rem; text-align: center; }

/* ── Export ─────────────────────────────────────────────── */
.export-format-group { display: flex; gap: .75rem; }
.export-fmt-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: .25rem;
  padding: 1rem .75rem; border-radius: var(--radius); border: 2px solid var(--border);
  background: var(--surface2); cursor: pointer; transition: .15s; color: var(--text);
}
.export-fmt-btn:hover { border-color: var(--accent); background: rgba(var(--accent-rgb),.08); }
.export-fmt-icon { font-size: 1.75rem; line-height: 1; }
.export-fmt-name { font-weight: 700; font-size: .95rem; }
.export-fmt-desc { font-size: .75rem; color: var(--text-muted); text-align: center; }

/* ── Import ─────────────────────────────────────────────── */
.modal-wide { max-width: 540px; }

.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 2rem 1rem; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop-zone:hover, .drop-zone.dz-active {
  border-color: var(--accent); background: rgba(var(--accent-rgb),.06);
}
.dz-icon { font-size: 2.5rem; line-height: 1; margin-bottom: .5rem; }
.dz-hint { font-size: .8rem; color: var(--text-muted); margin-top: .4rem; }
.link { color: var(--accent); cursor: pointer; text-decoration: underline; }

.import-filename { font-size: .8rem; color: var(--text-muted); }

.mapping-grid { display: flex; flex-direction: column; gap: .5rem; }
.mapping-row {
  display: grid; grid-template-columns: 120px 1fr; align-items: center; gap: .5rem;
}
@media (max-width: 420px) {
  /* 120px of label left the <select> ~150px on a folded Fold. */
  .mapping-row { grid-template-columns: 1fr; gap: .25rem; align-items: stretch; }
  .mapping-sub { padding-left: .5rem; }
}
.mapping-sub { padding-left: 1rem; }
.mapping-label { font-size: .875rem; color: var(--text-muted); }
.req { color: var(--danger); }

.import-preview-wrap { margin-top: .5rem; }
.preview-label { font-size: .8rem; color: var(--text-muted); margin-bottom: .4rem; }
.preview-scroll { overflow-x: auto; }
.preview-table {
  width: 100%; border-collapse: collapse; font-size: .8rem;
}
.preview-table th {
  text-align: left; color: var(--text-muted); font-weight: 600;
  padding: .3rem .5rem; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.preview-table td {
  padding: .3rem .5rem; border-bottom: 1px solid var(--border);
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.preview-table td.muted { color: var(--text-muted); }

.status-pill {
  display: inline-block; padding: .1rem .45rem; border-radius: 20px;
  font-size: .75rem; font-weight: 600;
}
.status-pill.done { background: rgba(76,175,135,.2); color: var(--success); }
.status-pill.pending { background: rgba(136,136,170,.15); color: var(--text-muted); }

.import-result-msg { font-size: 1rem; color: var(--success); }

/* ── Import document modal ──────────────────────────────── */
.idoc-sheet-picker { display: flex; flex-direction: column; gap: .4rem; margin: .5rem 0; }
.idoc-sheet-btn {
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem .75rem; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; text-align: left; color: var(--text); width: 100%;
}
.idoc-sheet-btn:hover:not([disabled]) { border-color: var(--accent); }
.idoc-sheet-btn[disabled] { opacity: .45; cursor: default; }
/* The simple import wizards reuse this picker; `.current` marks the sheet
 * already loaded when the user steps back to change it. */
.idoc-sheet-btn.current { border-color: var(--accent); }
.idoc-sheet-picker.busy { opacity: .6; pointer-events: none; }
.idoc-sheet-btn .sheet-name { font-size: .95rem; }
.idoc-sheet-btn .sheet-count { font-size: .8rem; color: var(--text-muted); }
.idoc-extra-col-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  padding: .3rem 0; font-size: .9rem;
}
.idoc-extra-col-row label { flex: 1 1 8rem; min-width: 0; cursor: pointer; }
.idoc-ec-type { flex-shrink: 0; font-size: .82rem; padding: .25rem .4rem; }
.idoc-ec-scale { flex-shrink: 0; padding: .15rem; }
.idoc-ec-scale .toggle-opt { padding: .3rem .5rem; font-size: .78rem; }

/* ── Custom fields — list config ────────────────────────── */
.field-row {
  display: flex; align-items: center; gap: .5rem;
  padding: .45rem .5rem; border-radius: var(--radius-sm);
  background: var(--surface2); margin-bottom: .4rem;
}
.field-row-icon { font-size: .9rem; width: 1.2rem; text-align: center; flex-shrink: 0; }
.field-row-name { flex: 1; font-size: .9rem; }
.field-row-type {
  font-size: .75rem; color: var(--text-muted);
  background: var(--border); padding: .1rem .4rem; border-radius: 4px;
}

.field-row-edit {
  display: flex; flex-direction: column; gap: .4rem;
  padding: .5rem; background: var(--surface2); border-radius: var(--radius-sm);
  margin-bottom: .4rem;
}
.field-edit-actions { display: flex; gap: .5rem; justify-content: flex-end; }

.field-required-label {
  display: flex; align-items: center; gap: .4rem;
  font-size: .82rem; color: var(--text-muted); cursor: pointer; user-select: none;
}
.field-required-label input[type="checkbox"] { cursor: pointer; accent-color: var(--accent); }
.field-req-badge {
  font-size: .7rem; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent);
  padding: .1rem .4rem; border-radius: 4px; flex-shrink: 0;
}

.add-field-form { margin-top: .75rem; }
/* The type <select> is an unstyled native control, so its width is set
   by its longest option ("Multi-select") and varies by platform — on a
   narrow screen it used to crowd the field-name input. Now it wraps to
   its own full-width line instead of shrinking the input past 9rem. */
.add-field-row {
  display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem;
}
.add-field-row input { flex: 1 1 11rem; min-width: 9rem; }
.add-field-row select { flex: 1 1 auto; min-width: 0; max-width: 100%; }
.btn-sm { padding: .4rem .8rem; font-size: .85rem; }

/* ── Custom fields — item edit modal ───────────────────── */
#item-custom-fields { display: flex; flex-direction: column; gap: .6rem; margin-top: .25rem; }

.field-input-group { display: flex; flex-direction: column; gap: .3rem; }
.field-input-label {
  font-size: .8rem; color: var(--text-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .03em;
}

/* tag input */
.tag-input-wrap {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface2); padding: .4rem .5rem; min-height: 2.4rem;
  display: flex; flex-wrap: wrap; gap: .3rem; align-items: center;
}
.tag-chips-edit { display: flex; flex-wrap: wrap; gap: .3rem; }
.tag-chip-edit {
  display: inline-flex; align-items: center; gap: .25rem;
  background: var(--accent); color: #fff; font-size: .8rem;
  padding: .15rem .4rem; border-radius: 20px;
}
.tag-chip-del {
  background: none; border: none; color: rgba(255,255,255,.8); cursor: pointer;
  padding: 0; font-size: .85rem; line-height: 1; display: flex; align-items: center;
}
.tag-text-input {
  background: none; border: none; outline: none; color: var(--text);
  font-size: .9rem; min-width: 80px; flex: 1;
}

/* multi-select input — a fixed set of options toggled on/off as chips,
   unlike the free-text tag input above */
.multiselect-wrap { display: flex; flex-wrap: wrap; gap: .4rem; }
.multiselect-opt {
  border: 1px solid var(--border); border-radius: 20px; background: var(--surface2);
  color: var(--text-muted); font-size: .8rem; padding: .3rem .7rem;
  cursor: pointer; transition: .15s;
}
.multiselect-opt:hover { border-color: var(--accent); }
.multiselect-opt.selected { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Custom fields — item card display ─────────────────── */
.item-field-val {
  font-size: .82rem; color: var(--text-muted);
  display: flex; flex-wrap: wrap; align-items: center; gap: .3rem;
  margin-top: .15rem;
}
.item-field-name { font-weight: 600; color: var(--text-muted); }
.tag-chip {
  display: inline-block; background: rgba(var(--accent-rgb),.2);
  color: var(--accent); font-size: .75rem;
  padding: .1rem .4rem; border-radius: 20px; line-height: 1.4;
}

/* ── Kufaryk (object catalog) ───────────────────────────── */
/* Kind/object cards reuse .list-card/.lists-grid; this just adds the stat
   row underneath a card's meta line. */
.kufaryk-stats { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .1rem; }
.kufaryk-stat-badge {
  font-size: .68rem; color: var(--text-muted); background: var(--surface2);
  padding: .1rem .4rem; border-radius: 4px;
}

/* ── Kufaryk object card images ──────────────────────────
 * Three sizes of the same picture, all in the same 2:3 **poster** shape —
 * the format film posters, book covers, box art and game covers already come
 * in, so the common case is framed exactly as uploaded. object-fit: cover
 * does the framing, which means anything else (a square cover, a wide
 * screenshot) is centre-cropped to poster rather than letterboxed or
 * squashed. The catalog card's visual sits in the emoji's place; the list
 * item gets a small one beside its checkbox; the object modal shows the
 * preview. */
.card-thumb {
  width: 100%; aspect-ratio: 2 / 3; object-fit: cover; display: block;
  border-radius: var(--radius-sm); background: var(--surface2);
}
.list-card.all-done .card-thumb { filter: grayscale(.6) opacity(.8); }

.item-thumb {
  width: 36px; aspect-ratio: 2 / 3; flex-shrink: 0; object-fit: cover;
  border-radius: var(--radius-sm); background: var(--surface2);
}

.kufaryk-image-row {
  display: flex; align-items: flex-start; gap: .75rem; margin-top: .6rem;
}
.kufaryk-image-preview {
  width: 64px; aspect-ratio: 2 / 3; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface2); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.kufaryk-image-preview img { width: 100%; height: 100%; object-fit: cover; }
.kufaryk-image-placeholder { font-size: 1.6rem; line-height: 1; }
.kufaryk-image-actions { flex: 1; min-width: 0; }
.kufaryk-image-actions .setting-hint { margin-top: .25rem; }

/* Small inline indicator on an item card that's linked to a catalog object. */
.kufaryk-link-chip {
  font-size: .75rem; color: var(--accent); margin-top: .15rem;
  display: flex; align-items: center; gap: .25rem;
}

/* Link status row inside the item edit modal, with its Unlink action. */
.kufaryk-link-badge {
  display: flex; align-items: center; gap: .5rem; font-size: .85rem;
  color: var(--text-muted); background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .55rem .7rem;
}
.kufaryk-link-badge strong { color: var(--text); font-weight: 600; }
.kufaryk-link-badge button { flex-shrink: 0; margin-left: auto; }

input:disabled, textarea:disabled, select:disabled {
  opacity: .6; cursor: not-allowed;
}

/* Read-only mirrored Kufaryk kind-field value — item edit modal (any type
   except rating) and the object modal's rating row (see
   renderItemKufarykFields/renderKufarykObjectCustomFields). Same visual
   weight as a disabled input, without being one. */
#item-kufaryk-fields { display: flex; flex-direction: column; gap: .6rem; margin: .5rem 0; }
.kufaryk-field-readonly {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface2); color: var(--text-muted);
  font-size: .9rem; padding: .5rem .6rem; opacity: .8;
}

/* ── Admin console (full page, desktop-first) ─────────────────
 * Admins work from laptops, so this screen is laid out for ~1280px+:
 * sidebar + wide tables + a right-hand panel. Below 860px it only has to
 * stay usable (the sidebar becomes a row of tabs), not be pretty. The page
 * is a fixed-height column; .admin-main is the scroller, so sticky table
 * headers and the save bar stick inside it.
 * Colours come from the theme variables only (see the Themes note at the top).
 * ─────────────────────────────────────────────────────────── */
#screen-admin.active { height: 100dvh; min-height: 0; overflow: hidden; }
.admin-title-sep { color: var(--text-muted); font-weight: 400; margin: 0 .15rem; }
.btn-admin-label { display: none; font-size: .85rem; font-weight: 600; margin-left: .35rem; }
@media (min-width: 900px) {
  .btn-admin { display: inline-flex; align-items: center; }
  .btn-admin.hidden { display: none; }
  .btn-admin-label { display: inline; }
}

.admin-layout { flex: 1; display: flex; min-height: 0; }

.admin-nav {
  width: 220px; flex-shrink: 0; display: flex; flex-direction: column; gap: .2rem;
  padding: 1rem .75rem; background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto;
}
.admin-nav-item {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem;
  border-radius: var(--radius-sm); color: var(--text-muted); text-decoration: none;
  font-size: .92rem; font-weight: 500; transition: background .15s, color .15s;
}
.admin-nav-item:hover { background: var(--surface2); color: var(--text); }
.admin-nav-item.active { background: rgba(var(--accent-rgb), .16); color: var(--text); }
.admin-nav-item.active .admin-nav-icon { color: var(--accent); }
.admin-nav-icon { width: 1.25rem; text-align: center; font-size: 1rem; }
.admin-nav-badge {
  margin-left: auto; min-width: 1.4rem; padding: 0 .4rem; border-radius: 999px;
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  font-size: .72rem; font-weight: 700; text-align: center; line-height: 1.35rem;
}
.admin-nav-flag { margin-left: auto; font-size: .7rem; color: var(--text-muted); }
.admin-nav-foot {
  margin-top: auto; padding: .75rem .5rem 0; border-top: 1px solid var(--border);
  font-size: .75rem; color: var(--text-muted); display: flex; flex-direction: column; gap: .3rem;
}
kbd {
  display: inline-block; min-width: 1.3em; padding: 0 .35em; border-radius: 4px;
  border: 1px solid var(--border); border-bottom-width: 2px; background: var(--surface2);
  font: 600 .72rem/1.5 var(--font); color: var(--text-muted); text-align: center;
}
.btn kbd { background: transparent; border-color: currentColor; color: inherit; opacity: .7; margin-left: .35rem; }

.admin-main {
  flex: 1; min-width: 0; overflow-y: auto; display: flex; flex-direction: column;
  padding: 1.5rem 2rem 2rem;
}
.admin-section { width: 100%; max-width: 1320px; margin: 0 auto; flex: 0 0 auto; }
.admin-section-fill { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

.admin-sec-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 1rem;
}
.admin-sec-head h2 { font-size: 1.35rem; font-weight: 700; color: var(--text); }
.admin-sec-sub { font-size: .85rem; color: var(--text-muted); margin-top: .1rem; }
.admin-sec-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

.admin-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.admin-card h3 { font-size: .95rem; font-weight: 600; }
.admin-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; }
.admin-card-head .auth-link { align-self: flex-start; white-space: nowrap; text-decoration: none; }
.admin-card-sub { font-size: .78rem; color: var(--text-muted); }

.admin-search {
  width: 280px; max-width: 100%; padding: .45rem .75rem !important; font-size: .9rem !important;
  background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); outline: none; font-family: inherit;
}
.admin-search:focus { border-color: var(--accent); }
.admin-toolbar {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem;
}
.admin-toolbar select {
  padding: .4rem .5rem; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: .85rem; font-family: inherit;
}
.admin-check {
  display: inline-flex; align-items: center; gap: .35rem; font-size: .85rem;
  color: var(--text-muted); cursor: pointer; user-select: none; white-space: nowrap;
}
.admin-check input { accent-color: var(--accent); cursor: pointer; }

.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:hover:not(:disabled) { filter: brightness(1.1); }

.badge {
  display: inline-block; padding: .05rem .45rem; border-radius: 999px; font-size: .72rem;
  font-weight: 600; border: 1px solid var(--border); color: var(--text-muted);
  background: var(--surface2); white-space: nowrap; vertical-align: middle;
}
.badge-accent { border-color: var(--accent); color: var(--accent); background: rgba(var(--accent-rgb), .12); }
.badge-warn { border-color: var(--danger); color: var(--danger); background: rgba(var(--danger-rgb), .1); }
.admin-sub { color: var(--text-muted); font-size: .8rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Tables (users, recent sign-ups, chart table) */
.admin-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.admin-table th {
  text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border);
  color: var(--text-muted); font-weight: 600; font-size: .78rem; white-space: nowrap;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.admin-table th.num, .admin-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.admin-table td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover td { background: var(--hover-tint); }
.admin-table tr.clickable { cursor: pointer; }
.admin-username { font-weight: 600; }
.admin-email { color: var(--text-muted); font-size: .85rem; }
.admin-date { color: var(--text-muted); font-size: .82rem; white-space: nowrap; }
.role-user { color: var(--text-muted); font-size: .82rem; }

.admin-table-card { padding: 0; }
.users-table th[data-sort] { cursor: pointer; user-select: none; }
.users-table th[data-sort]:hover, .users-table th[data-sort]:focus-visible { color: var(--text); outline: none; }
.users-table th[data-sort]::after { content: ' ↕'; opacity: .35; font-size: .85em; }
.users-table th.sorted { color: var(--text); }
.users-table th.sorted[data-dir="asc"]::after { content: ' ↑'; opacity: 1; color: var(--accent); }
.users-table th.sorted[data-dir="desc"]::after { content: ' ↓'; opacity: 1; color: var(--accent); }
.users-table th:first-child { border-top-left-radius: var(--radius); }
.users-table th:last-child { border-top-right-radius: var(--radius); }
.users-table tbody tr { cursor: pointer; }
.users-table tbody tr.selected td { background: rgba(var(--accent-rgb), .08); }
.users-table tbody tr.open td { background: rgba(var(--accent-rgb), .14); }
.users-table tbody tr.open td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.col-check { width: 2.25rem; text-align: center !important; }
.col-check input { accent-color: var(--accent); cursor: pointer; width: 15px; height: 15px; vertical-align: middle; }
.col-menu { width: 2.5rem; text-align: right !important; }
.row-menu-btn { font-size: 1.1rem; padding: .1rem .45rem; letter-spacing: .05em; }

.users-filters { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin-bottom: .75rem; }
.chip-count { opacity: .7; font-variant-numeric: tabular-nums; margin-left: .15rem; }
.filter-btn.active .chip-count { opacity: .9; }

.users-bulkbar {
  position: sticky; bottom: 1rem; margin: 1rem auto 0; width: max-content; max-width: 100%;
  display: flex; align-items: center; gap: .6rem; padding: .55rem .6rem .55rem 1rem;
  background: var(--surface); border: 1px solid var(--accent); border-radius: 999px;
  box-shadow: var(--shadow); z-index: 5;
}
.users-bulk-count { font-weight: 600; font-size: .9rem; margin-right: .25rem; }

/* Row action menu */
.admin-menu {
  position: fixed; z-index: 60; min-width: 230px; padding: .35rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.admin-menu-item {
  text-align: left; padding: .5rem .7rem; border: none; background: none; color: var(--text);
  font: inherit; font-size: .88rem; border-radius: calc(var(--radius-sm) - 2px); cursor: pointer;
}
.admin-menu-item:hover:not(:disabled), .admin-menu-item:focus-visible { background: var(--surface2); outline: none; }
.admin-menu-item:disabled { color: var(--text-muted); opacity: .6; cursor: not-allowed; }
.admin-menu-item.danger { color: var(--danger); }
.admin-menu-sep { height: 1px; background: var(--border); margin: .3rem .2rem; }

/* User detail side panel */
.admin-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 440px; max-width: 100vw; z-index: 50;
  display: flex; flex-direction: column; background: var(--surface);
  border-left: 1px solid var(--border); box-shadow: var(--shadow);
  transform: translateX(105%); transition: transform .2s ease; visibility: hidden;
}
.admin-drawer.open { transform: none; visibility: visible; }
.drawer-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem;
  padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.drawer-head h3 { font-size: 1.15rem; word-break: break-word; }
.drawer-badges { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: .3rem; }
.drawer-body { flex: 1; overflow-y: auto; padding: 1rem 1.25rem 1.5rem; display: flex; flex-direction: column; gap: 1.25rem; }
.drawer-facts { display: grid; grid-template-columns: 7rem 1fr; gap: .45rem .75rem; font-size: .88rem; }
.drawer-facts dt { color: var(--text-muted); }
.drawer-facts dd { word-break: break-word; }
.drawer-section h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: .5rem; }
.drawer-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.drawer-lists { list-style: none; display: flex; flex-direction: column; gap: .15rem; max-height: 240px; overflow-y: auto; }
.drawer-lists li { display: flex; align-items: center; gap: .5rem; padding: .3rem .4rem; border-radius: var(--radius-sm); font-size: .88rem; }
.drawer-lists li:hover { background: var(--surface2); }
.drawer-list-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-activity {
  list-style: none; display: flex; flex-direction: column; gap: .3rem; margin-bottom: .5rem;
  font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace; font-size: .74rem; color: var(--text-muted);
  max-height: 260px; overflow-y: auto;
}
.drawer-activity li { word-break: break-word; }
.drawer-activity time { color: var(--text); margin-right: .5rem; }
.drawer-activity li.lv-warning, .drawer-activity li.lv-error { color: var(--danger); }
.drawer-danger { padding-top: 1rem; border-top: 1px solid var(--border); }

/* Overview */
.ov-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1rem; }
@media (max-width: 1000px) { .ov-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.ov-tile {
  display: flex; flex-direction: column; gap: .15rem; text-align: left; font: inherit; color: var(--text);
  padding: .9rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.ov-tile.clickable { cursor: pointer; transition: border-color .15s, transform .15s; }
.ov-tile.clickable:hover { border-color: var(--accent); }
.ov-tile.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ov-tile-label { font-size: .8rem; color: var(--text-muted); }
.ov-tile-value { font-size: 1.75rem; font-weight: 650; line-height: 1.2; }
.ov-tile-value.is-text { font-size: 1.25rem; padding: .15rem 0 .1rem; }
.ov-tile-note { font-size: .76rem; color: var(--text-muted); }
.ov-tile.tone-warn, .ov-tile.tone-bad { border-color: rgba(var(--danger-rgb), .55); }
.ov-tile.tone-bad .ov-tile-value { color: var(--danger); }

.ov-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: .75rem; align-items: start; }
@media (max-width: 1100px) { .ov-grid { grid-template-columns: 1fr; } }
.ov-recent-table { table-layout: fixed; }
.ov-recent-table td { padding: .45rem .4rem; }
.ov-recent-table td:first-child { width: auto; }
.ov-recent-table td.ov-recent-meta { width: 7.5rem; text-align: right; white-space: nowrap; }
.ov-recent-table .ov-recent-name { display: flex; align-items: center; gap: .4rem; min-width: 0; }
.ov-recent-table .admin-username { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ov-recent-table .admin-sub { display: block; font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ov-chart { position: relative; min-height: 220px; }
.ov-chart-svg { display: block; outline: none; }
.ov-chart-svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-peak { fill: var(--text); font-size: 11px; font-weight: 600; }
.chart-bar { fill: var(--accent); transition: filter .1s; }
.chart-bar.hover { filter: brightness(1.2); }
.chart-hit { fill: transparent; }
.chart-hit.hover { fill: var(--hover-tint); }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 2; padding: .35rem .6rem;
  display: flex; flex-direction: column; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: .78rem; color: var(--text-muted);
  white-space: nowrap;
}
.chart-tip strong { color: var(--text); font-size: .9rem; }
.chart-empty {
  position: absolute; inset: 0 0 26px 30px; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: .88rem; pointer-events: none;
}
.ov-chart-table { max-height: 260px; overflow-y: auto; }

/* Mail */
.mail-layout { display: grid; grid-template-columns: minmax(0, 640px) minmax(240px, 340px); gap: 1rem; align-items: start; }
.mail-form { display: flex; flex-direction: column; gap: .9rem; }
.mail-grid { display: flex; flex-wrap: wrap; gap: .9rem; }
.mail-grid > .mail-field { flex: 1 1 200px; min-width: 0; }
.mail-grid > .mail-port { flex: 0 1 110px; min-width: 90px; }
.mail-field { display: flex; flex-direction: column; gap: .35rem; }
.mail-field .auth-link { font-size: .78rem; }
.mail-form input[type="number"] {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 1rem;
  padding: .65rem .9rem; outline: none; font-family: inherit;
}
.mail-optional { font-weight: 400; opacity: .8; }
.mail-aside { display: flex; flex-direction: column; gap: .75rem; position: sticky; top: 0; }
.mail-aside h3 { margin-bottom: .4rem; }
.mail-status { font-size: .88rem; line-height: 1.45; }
.mail-status.ok { color: var(--text); }
.mail-status.off { color: var(--text-muted); }
.mail-presets { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .6rem; }
.mail-preset-hint {
  margin-top: .6rem; padding: .55rem .7rem; font-size: .8rem; line-height: 1.45;
  border-radius: var(--radius-sm); background: rgba(var(--accent-rgb), .1); border: 1px solid rgba(var(--accent-rgb), .4);
}
.mail-test {
  display: flex; flex-direction: column; gap: .35rem;
  padding-top: .9rem; border-top: 1px solid var(--border);
}
.mail-test-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.mail-test-row input { flex: 1 1 200px; min-width: 0; }
.mail-test-row .btn { flex: 0 0 auto; }
.mail-result { font-size: .875rem; min-height: 1.2em; }
.mail-result:empty { display: none; }
.mail-result.ok { color: var(--text); }
.mail-result.err { color: var(--danger); }
.admin-savebar {
  position: sticky; bottom: 0; z-index: 5; margin-top: 1rem; max-width: 640px;
  display: flex; align-items: center; justify-content: flex-end; gap: .5rem;
  padding: .6rem .75rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.admin-savebar-text { margin-right: auto; font-size: .85rem; color: var(--text-muted); }
.admin-savebar.dirty { border-color: var(--accent); }
.admin-savebar.dirty .admin-savebar-text { color: var(--text); font-weight: 600; }
@media (max-width: 1100px) { .mail-layout { grid-template-columns: 1fr; } .mail-aside { position: static; } }
.mail-limit input { max-width: 160px; }

/* Sign-ups */
.signups-layout { display: grid; grid-template-columns: minmax(0, 500px) minmax(0, 1fr); gap: 1rem; align-items: start; }
.signups-main { display: flex; flex-direction: column; gap: 1rem; }
.signups-main .admin-card { display: flex; flex-direction: column; gap: .75rem; }
.signups-main input[type="number"], .invite-form input[type="number"], .invite-form select {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 1rem;
  padding: .65rem .9rem; outline: none; font-family: inherit;
}
#signup-mode-toggle { flex-wrap: wrap; }
.signup-pending {
  padding: .55rem .7rem; font-size: .85rem; border-radius: var(--radius-sm);
  background: rgba(var(--accent-rgb), .1); border: 1px solid rgba(var(--accent-rgb), .4);
}
.signup-limits summary { cursor: pointer; font-size: .85rem; color: var(--text-muted); }
.signup-limits ul { margin: .5rem 0 0 1.1rem; font-size: .82rem; line-height: 1.6; color: var(--text-muted); }
.signups-invites { display: flex; flex-direction: column; gap: .75rem; min-width: 0; }
#invites-list { overflow-x: auto; }
#signup-mode-toggle .toggle-opt { white-space: normal; }
.invite-form { display: flex; flex-wrap: wrap; gap: .6rem .75rem; align-items: flex-end; }
.invite-form .invite-wide { flex: 1 1 200px; min-width: 0; }
.invite-form .invite-small { flex: 0 1 120px; min-width: 90px; }
.invite-form .btn { flex: 0 0 auto; margin-bottom: 2px; }
.invites-table { width: 100%; }
.invites-table code { font-size: .78rem; }
.invites-table .admin-sub { display: block; }
.invite-actions { white-space: nowrap; text-align: right; padding-right: 0 !important; }
.invite-actions .btn { padding-left: .6rem; padding-right: .6rem; }
.invite-inactive td { opacity: .6; }
#signup-savebar { max-width: 500px; }
.invites-table th, .invites-table td { padding-left: .5rem; padding-right: .5rem; }
@media (max-width: 1100px) { .signups-layout { grid-template-columns: 1fr; } }

/* Logs */
.log-presets { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem; }
.log-presets .setting-label { margin-right: .2rem; }
.log-card { flex: 1 1 auto; min-height: 260px; overflow: auto; padding: 0; }
.log-table {
  width: 100%; border-collapse: collapse; font-size: .78rem; line-height: 1.5;
  font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
}
.log-table th {
  position: sticky; top: 0; z-index: 1; background: var(--surface); text-align: left;
  font-family: var(--font); font-size: .75rem; font-weight: 600; color: var(--text-muted);
  padding: .5rem .6rem; border-bottom: 1px solid var(--border);
}
.log-table td { padding: .25rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.log-table tbody tr:hover td { background: var(--hover-tint); }
.log-time { white-space: nowrap; color: var(--text-muted); width: 1%; }
.log-level { width: 1%; }
.log-source { white-space: nowrap; color: var(--text-muted); width: 1%; }
.log-msg { color: var(--text); word-break: break-word; white-space: pre-wrap; }
.log-card.nowrap .log-msg, .log-card.nowrap .log-extra { white-space: pre; word-break: normal; }
.log-extra { margin-top: .25rem; font: inherit; color: var(--text-muted); white-space: pre-wrap; }
.lv-error td, .lv-critical td { background: rgba(var(--danger-rgb), .07); }
.lvl {
  display: inline-block; min-width: 5.9rem; text-align: center; padding: 0 .35rem; white-space: nowrap;
  border-radius: 4px; font-family: var(--font); font-size: .68rem; font-weight: 700; letter-spacing: .02em;
  border: 1px solid var(--border); color: var(--text-muted);
}
.lvl-warning { border-color: var(--text-muted); color: var(--text); }
.lvl-warning::before { content: '⚠ '; }
.lvl-error, .lvl-critical { border-color: var(--danger); color: var(--danger); background: rgba(var(--danger-rgb), .1); }
.lvl-error::before, .lvl-critical::before { content: '⛔ '; }
.log-table mark { background: rgba(var(--accent-rgb), .35); color: var(--text); border-radius: 2px; }
.log-placeholder { padding: 2rem; text-align: center; color: var(--text-muted); font-style: italic; }
.log-placeholder.log-error { color: var(--danger); }

/* Set-password modal */
.pw-row { display: flex; gap: .4rem; flex-wrap: wrap; }
.pw-row input { flex: 1 1 200px; min-width: 0; font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace; }
.admin-pw-tip {
  font-size: .85rem; padding: .55rem .7rem; border-radius: var(--radius-sm);
  background: rgba(var(--accent-rgb), .1); border: 1px solid rgba(var(--accent-rgb), .4);
}
.admin-pw-tip .auth-link { font-size: .85rem; }

/* Confirm dialog — above the modal overlay (z 100) */
.dialog-overlay {
  position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center;
  padding: 1rem; background: rgba(0,0,0,.55); backdrop-filter: blur(3px);
}
.dialog-overlay.hidden { display: none; }
/* Not a .modal: showModal()/closeModal() hide every .modal, and this has to
   survive both (it can confirm something started inside a modal). */
.dialog {
  width: 100%; max-width: 460px; max-height: 90dvh; overflow-y: auto; padding: 1.5rem;
  display: flex; flex-direction: column; gap: 1rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.dialog h3 { font-size: 1.1rem; }
.dialog-message { font-size: .92rem; color: var(--text-muted); line-height: 1.5; }
.dialog-list { list-style: none; margin-top: .6rem; padding: .5rem .7rem; max-height: 180px; overflow-y: auto;
  background: var(--surface2); border-radius: var(--radius-sm); display: flex; flex-direction: column; gap: .2rem; }
.dialog-list strong { color: var(--text); }
.dialog-confirm { display: flex; flex-direction: column; gap: .35rem; }

/* Toasts */
.toasts {
  position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 300;
  display: flex; flex-direction: column; gap: .5rem; align-items: flex-end; pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: .6rem; max-width: 420px;
  padding: .65rem .7rem .65rem .8rem; font-size: .88rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); animation: toast-in .18s ease-out;
}
.toast-err { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--text-muted); }
.toast-icon {
  flex: 0 0 auto; width: 1.2rem; height: 1.2rem; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; font-size: .72rem; font-weight: 800;
  background: var(--accent); color: #fff; margin-top: .05rem;
}
.toast-err .toast-icon { background: var(--danger); }
.toast-info .toast-icon { background: var(--text-muted); }
.toast-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: .8rem; padding: 0 .1rem; margin-left: auto; }
.toast-close:hover { color: var(--text); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast, .admin-drawer { animation: none; transition: none; } }

.btn-accent { background: rgba(var(--accent-rgb),.25); color: var(--accent); border: 1px solid var(--accent); }
.btn-accent:hover { background: rgba(var(--accent-rgb),.4); }
.btn-danger { background: rgba(var(--danger-rgb),.15); color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(var(--danger-rgb),.3); }

/* Narrow screens: not a target (admins use laptops), just keep it usable. */
@media (max-width: 860px) {
  #screen-admin.active { height: auto; min-height: 100dvh; overflow: visible; }
  .admin-layout { flex-direction: column; }
  .admin-nav {
    width: auto; flex-direction: row; overflow-x: auto; padding: .5rem;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .admin-nav-item { white-space: nowrap; }
  .admin-nav-foot { display: none; }
  .admin-main { overflow: visible; padding: 1rem; }
  .admin-table-card { overflow-x: auto; }
  .admin-drawer { width: 100vw; }
  .log-card { max-height: 70vh; }
}

/* ── Admin: Backup & restore ────────────────────────────── */
.backup-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem; align-items: start; margin-bottom: 1rem;
}
.backup-schedule, .backup-restore-card { display: flex; flex-direction: column; gap: .85rem; }
.backup-schedule form { display: flex; flex-direction: column; gap: .85rem; }
.backup-schedule input[type="time"], .backup-schedule input[type="number"] {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 1rem;
  padding: .65rem .9rem; outline: none; font-family: inherit;
}
.backup-schedule input:focus { border-color: var(--accent); }
#btn-backup-settings-save { align-self: flex-start; }

/* Drop target for an archive from the admin's own computer. */
.backup-drop {
  border: 1px dashed var(--border); border-radius: var(--radius-sm);
  padding: 1.4rem 1rem; text-align: center; display: flex;
  flex-direction: column; gap: .35rem; transition: border-color .15s, background .15s;
}
.backup-drop.dragover { border-color: var(--accent); background: rgba(var(--accent-rgb), .08); }
.backup-progress { display: flex; flex-direction: column; gap: .35rem; }
.backup-progress-bar {
  height: 6px; border-radius: 3px; background: var(--surface2); overflow: hidden;
}
.backup-progress-bar span {
  display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s;
}
.backup-warning {
  padding: .55rem .7rem; border-radius: var(--radius-sm);
  background: rgba(var(--danger-rgb), .08); border: 1px solid rgba(var(--danger-rgb), .35);
  color: var(--text);
}

.backups-table td { vertical-align: middle; }
.backups-table td.num { white-space: nowrap; }
.backups-table .backup-actions { text-align: right; white-space: nowrap; }
.backups-table .backup-actions .btn { margin-left: .2rem; }
/* The copies Larnik takes for itself sit quieter than the admin's own. */
.backup-safety td { opacity: .78; }

/* Contents of an archive, listed in the restore confirmation. */
.backup-confirm {
  display: grid; grid-template-columns: auto 1fr; gap: .25rem .9rem;
  margin-top: .8rem; text-align: left; font-size: .9rem;
}
.backup-confirm dt { color: var(--text-muted); }
.backup-confirm dd { color: var(--text); }

@media (max-width: 1100px) { .backup-layout { grid-template-columns: 1fr; } }

/* ── Utility ────────────────────────────────────────────── */
/* ── Theme builder ──────────────────────────────────────── */
#modal-theme-builder { max-width: 520px; }

.tb-theme-row {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem; border-radius: var(--radius-sm);
  background: var(--surface2); margin-bottom: .4rem;
}
.tb-theme-name { flex: 1; font-size: .9rem; }
.tb-theme-name .tb-active-tag {
  font-size: .7rem; color: var(--accent); margin-left: .4rem;
}

/* Five stacked chips previewing the theme's main colors. */
.tb-swatches { display: flex; gap: 3px; flex-shrink: 0; }
.tb-swatch {
  width: 14px; height: 14px; border-radius: 3px;
  border: 1px solid var(--border);
}

.tb-list-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.tb-empty { font-size: .8rem; color: var(--text-muted); margin: .25rem 0 .5rem; }

.tb-color-grid { display: flex; flex-direction: column; gap: .35rem; }
.tb-color-row {
  display: flex; align-items: center; gap: .5rem;
  padding: .35rem .5rem; border-radius: var(--radius-sm);
  background: var(--surface2);
}
.tb-color-row > span { flex: 1; font-size: .85rem; }
.tb-color-row input[type="color"] {
  width: 38px; height: 28px; padding: 0; flex-shrink: 0;
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
}
.tb-color-row input[type="text"] {
  width: 5.8rem; flex-shrink: 0; padding: .3rem .45rem;
  font-size: .8rem; font-family: ui-monospace, monospace;
}

.tb-shape-grid { display: flex; flex-direction: column; gap: .35rem; }
.tb-shape-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  padding: .35rem .5rem; border-radius: var(--radius-sm);
  background: var(--surface2);
}
.tb-shape-row > span { flex: 1 1 6rem; min-width: 0; font-size: .85rem; }
.tb-shape-row select { width: auto; min-width: 0; max-width: 100%; flex: 1 1 9rem; }
.tb-shape-row input[type="range"] { flex: 1 1 6rem; width: auto; max-width: 8rem; accent-color: var(--accent); }
.tb-num {
  width: 2.6rem; text-align: right; font-size: .8rem;
  color: var(--text-muted); font-family: ui-monospace, monospace;
}

.hidden { display: none !important; }

/* ── Touch targets ──────────────────────────────────────── */
/* Scoped to coarse pointers so desktop keeps its denser sizing. The
   ~44px floor is the WCAG 2.5.5 / platform-HIG target size. */
@media (pointer: coarse) {
  .btn-icon {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 44px; min-height: 44px; padding: .3rem;
  }
  /* Edit/delete sit side by side inside an item card, where two 44px
     buttons would eat the title's width — give them a real 40px target
     and a visible gap instead, so ✎ and 🗑 can't be confused by a thumb. */
  .item-actions { gap: .25rem; }
  .item-actions .btn-icon { min-width: 40px; min-height: 40px; }

  /* The done-toggle circle stays 22px visually; ::after extends only its
     hit area to 44px, so card density is unchanged. */
  .item-check { position: relative; }
  .item-check::after { content: ''; position: absolute; inset: -11px; }

  .btn-sm { padding: .55rem .9rem; }
  .filter-btn { padding: .5rem 1rem; }
  .toggle-opt { padding: .7rem .5rem; }
  .icon-opt { width: 44px; height: 44px; }
}

/* ── Mobile tweaks ──────────────────────────────────────── */
@media (max-width: 380px) {
  .lists-grid { grid-template-columns: 1fr 1fr; }
  .btn { padding: .6rem 1rem; }
  /* Modal padding is 1.5rem a side — a quarter of a 320px screen. */
  .modal { padding: 1.15rem; }
  .content { padding: .75rem; }
  /* Three 44px icon buttons + 1rem padding a side left ~130px for the
     list name; claw some of it back so a normal title still fits. */
  .app-header { padding: .6rem .5rem; gap: .25rem; }
  .app-title { font-size: 1rem; }
  /* Give the title/notes column back the width the action buttons take. */
  .item-card { padding: .8rem .7rem; gap: .6rem; }
}
