:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e2e8f0;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(99, 102, 241, 0.10);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --tile-tint-alpha: 0.08;
  --color-indigo:  #6366f1;
  --color-amber:   #f59e0b;
  --color-rose:    #f43f5e;
  --color-emerald: #10b981;
  --color-sky:     #0ea5e9;
  --color-slate:   #64748b;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111a2c;
  --surface-2: #182238;
  --surface-3: #1f2a44;
  --border: #25304a;
  --border-strong: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-soft: rgba(129, 140, 248, 0.16);
  --danger: #f87171;
  --danger-hover: #ef4444;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.55);
  --tile-tint-alpha: 0.18;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

/* Off-screen but still focusable / triggerable. Used for file inputs that
   live inside a <label> -- iOS Safari refuses to open the picker for inputs
   marked with the `hidden` attribute or `display:none`, but is fine with
   this technique. */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }

button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }

input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 100px; font-family: inherit; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  /* iOS PWA in standalone mode renders content UNDER the status bar
     (because we set apple-mobile-web-app-status-bar-style = black-translucent).
     env(safe-area-inset-top) is the height of that translucent bar — add it
     to the top so the actual controls don't hide under it. */
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
  height: calc(56px + env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, var(--color-indigo), var(--color-sky));
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.35);
}

.view-tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 3px;
}
.tab {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  transition: background 150ms ease, color 150ms ease;
}
.tab:hover:not(:disabled) { color: var(--text); }
.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* Buttons */
.primary-btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 13px;
  transition: background 150ms ease, transform 100ms ease;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:active { transform: translateY(1px); }

.ghost-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 13px;
  transition: color 150ms ease, border-color 150ms ease, background 150ms ease;
}
.ghost-btn:hover { color: var(--text); border-color: var(--text-muted); background: var(--surface-2); }

.danger-btn {
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 13px;
  transition: background 150ms ease;
}
.danger-btn:hover { background: rgba(239, 68, 68, 0.1); }

.icon-btn {
  background: transparent;
  border: 0;
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  transition: background 150ms ease, color 150ms ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Theme toggle: show sun in dark mode, moon in light mode */
.icon-sun { display: none; }
.icon-moon { display: block; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* Main + views */
main { flex: 1; min-height: 0; position: relative; }
.view {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  padding: 16px 20px 20px;
  /* Bottom safe-area for the iOS home indicator */
  padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
  overflow: hidden;
}
.view.is-active { display: flex; }

.placeholder {
  margin: auto;
  color: var(--text-muted);
  font-size: 14px;
}

/* Board */
.board-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex: 0 0 auto;
}

.board {
  flex: 1;
  display: flex;
  gap: 14px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 8px;
  align-items: flex-start;
}

.column {
  flex: 0 0 290px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.column-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 10px;
  flex: 0 0 auto;
}
.column-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.column-count {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-faint);
  background: var(--surface-3);
  padding: 1px 8px;
  border-radius: 99px;
}
.column-edit {
  background: transparent;
  border: 0;
  color: var(--text-faint);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  line-height: 1;
}
.column-edit:hover { color: var(--text); background: var(--surface-3); }

.column-tiles {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 30px;
}

.column-footer {
  padding: 8px 10px 12px;
  flex: 0 0 auto;
}
.column-add-tile {
  width: 100%;
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 8px;
  color: var(--text-muted);
  font-size: 13px;
  transition: color 150ms ease, border-color 150ms ease, background 150ms ease;
}
.column-add-tile:hover { color: var(--text); border-color: var(--text-muted); background: var(--surface); }

/* Tile */
.tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px 10px 14px;
  box-shadow: var(--shadow-sm);
  cursor: grab;
  transition: box-shadow 150ms ease, transform 150ms ease, border-color 150ms ease;
}
.tile:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  border-color: var(--border-strong);
}
.tile:active { cursor: grabbing; }

.tile::before {
  content: "";
  position: absolute;
  top: 8px; bottom: 8px; left: 4px;
  width: 3px;
  border-radius: 2px;
  background: var(--tile-color, var(--color-indigo));
}

.tile[data-color="indigo"]  { --tile-color: var(--color-indigo);  background: color-mix(in srgb, var(--color-indigo)  calc(var(--tile-tint-alpha) * 100%), var(--surface)); }
.tile[data-color="amber"]   { --tile-color: var(--color-amber);   background: color-mix(in srgb, var(--color-amber)   calc(var(--tile-tint-alpha) * 100%), var(--surface)); }
.tile[data-color="rose"]    { --tile-color: var(--color-rose);    background: color-mix(in srgb, var(--color-rose)    calc(var(--tile-tint-alpha) * 100%), var(--surface)); }
.tile[data-color="emerald"] { --tile-color: var(--color-emerald); background: color-mix(in srgb, var(--color-emerald) calc(var(--tile-tint-alpha) * 100%), var(--surface)); }
.tile[data-color="sky"]     { --tile-color: var(--color-sky);     background: color-mix(in srgb, var(--color-sky)     calc(var(--tile-tint-alpha) * 100%), var(--surface)); }
.tile[data-color="slate"]   { --tile-color: var(--color-slate);   background: color-mix(in srgb, var(--color-slate)   calc(var(--tile-tint-alpha) * 100%), var(--surface)); }

.tile-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  word-wrap: break-word;
}
.tile-body {
  font-size: 13px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.tile-meta {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.tile-status {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--surface-3);
  color: var(--text-muted);
  text-transform: capitalize;
}
.tile-status[data-status="exploring"] { color: var(--color-sky); background: color-mix(in srgb, var(--color-sky) 14%, transparent); }
.tile-status[data-status="locked-in"] { color: var(--color-emerald); background: color-mix(in srgb, var(--color-emerald) 14%, transparent); }
.tile-status[data-status="scrapped"]  { color: var(--text-faint); text-decoration: line-through; }

/* SortableJS classes */
.sortable-ghost {
  opacity: 0.4;
  background: var(--surface-3) !important;
}
.sortable-chosen { cursor: grabbing; }
.sortable-drag {
  box-shadow: var(--shadow-lg) !important;
  transform: rotate(1.5deg);
}

/* Modal (<dialog>) */
.modal {
  border: 0;
  padding: 0;
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  max-width: 540px;
  width: calc(100% - 32px);
  max-height: calc(100vh - 32px);
}
.modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}
[data-theme="dark"] .modal::backdrop { background: rgba(0, 0, 0, 0.6); }

.modal form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.modal-header h2 { font-size: 15px; font-weight: 600; }

.modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px 18px;
  /* Keep CTA buttons clear of the iOS home indicator */
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
}
.modal-spacer { flex: 1; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }

.color-swatches { display: flex; gap: 8px; }
.swatch {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  background-clip: content-box;
  padding: 2px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 150ms ease;
}
.swatch:hover { transform: scale(1.1); }
.swatch.is-selected { border-color: var(--text); }
.swatch-indigo  { background-color: var(--color-indigo);  }
.swatch-amber   { background-color: var(--color-amber);   }
.swatch-rose    { background-color: var(--color-rose);    }
.swatch-emerald { background-color: var(--color-emerald); }
.swatch-sky     { background-color: var(--color-sky);     }
.swatch-slate   { background-color: var(--color-slate);   }

/* Merge */
.merge-link-box {
  display: flex;
  gap: 6px;
  align-items: center;
}
.merge-link-box input {
  flex: 1;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
}
.merge-summary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.merge-summary-name { font-size: 14px; }
.merge-summary-counts { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.merge-summary-expires { font-size: 11px; color: var(--text-faint); margin-top: 4px; }

/* Admin */
.admin-page { max-width: 1100px; margin: 0 auto; width: 100%; }
.admin-header { margin-bottom: 14px; }
.admin-header h2 { font-size: 20px; font-weight: 600; }
.admin-sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.admin-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.admin-tab {
  background: var(--surface-2);
  border: 0;
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 13px;
}
.admin-tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.admin-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.admin-table th, .admin-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table thead th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--surface-2);
}
.admin-table tbody tr:last-child td { border-bottom: 0; }
.admin-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.admin-table .muted { color: var(--text-muted); }
.admin-table .danger-btn,
.admin-table .ghost-btn { padding: 4px 10px; font-size: 12px; }
.admin-row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.admin-table input[type="checkbox"] { accent-color: var(--accent); transform: scale(1.1); }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.checkbox-row input[type="checkbox"] { accent-color: var(--accent); }

.install-steps { margin: 12px 0 0 18px; padding: 0; font-size: 13px; line-height: 1.55; color: var(--text); }
.install-steps li { margin-bottom: 8px; }
.install-steps strong { color: var(--text); }
.install-steps code {
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

.invite-form-wrap { padding: 18px 20px; max-width: 520px; }
.invite-form-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
#admin-invite-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
#admin-invite-form .primary-btn { align-self: flex-start; }
#admin-invite-result code {
  display: inline-block;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
}

/* Graph view */
#view-graph { padding: 0; }
.graph-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex: 0 0 auto;
}
.graph-help {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.graph-toolbar .ghost-btn.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.graph-canvas {
  flex: 1;
  min-height: 0;
  background: var(--bg);
}

/* List view */
.list-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
  flex: 0 0 auto;
}
#list-search {
  width: 100%;
  max-width: 520px;
  padding: 10px 12px;
  font-size: 14px;
}
.list-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
}
.filter-group { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filter-group::before {
  content: attr(data-label);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin-right: 4px;
}
.filter-chip {
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 99px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.filter-chip:hover { color: var(--text); border-color: var(--text-muted); }
.filter-chip.is-active { background: var(--accent); color: #fff; border-color: var(--accent); }
.filter-empty { font-size: 12px; color: var(--text-faint); }

.list-results {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 720px;
}
.list-item {
  cursor: pointer;
}
.list-cat {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
}
.link-btn {
  background: transparent;
  border: 0;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  padding: 0;
}

/* Tag chips */
.tag-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 22px;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid transparent;
  background: var(--surface-3);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease, transform 80ms ease;
}
.tag-chip:hover { transform: translateY(-1px); }
.tag-chip-static { cursor: default; }
.tag-chip-static:hover { transform: none; }
.tag-chip-more { background: transparent; border-color: var(--border-strong); }

/* Color variants for chips (faint by default, solid when selected) */
.tag-chip[data-color="indigo"]  { color: var(--color-indigo);  background: color-mix(in srgb, var(--color-indigo)  14%, transparent); }
.tag-chip[data-color="amber"]   { color: var(--color-amber);   background: color-mix(in srgb, var(--color-amber)   14%, transparent); }
.tag-chip[data-color="rose"]    { color: var(--color-rose);    background: color-mix(in srgb, var(--color-rose)    14%, transparent); }
.tag-chip[data-color="emerald"] { color: var(--color-emerald); background: color-mix(in srgb, var(--color-emerald) 14%, transparent); }
.tag-chip[data-color="sky"]     { color: var(--color-sky);     background: color-mix(in srgb, var(--color-sky)     14%, transparent); }
.tag-chip[data-color="slate"]   { color: var(--color-slate);   background: color-mix(in srgb, var(--color-slate)   16%, transparent); }

.tag-chip.is-selected[data-color="indigo"]  { background: var(--color-indigo);  color: #fff; }
.tag-chip.is-selected[data-color="amber"]   { background: var(--color-amber);   color: #fff; }
.tag-chip.is-selected[data-color="rose"]    { background: var(--color-rose);    color: #fff; }
.tag-chip.is-selected[data-color="emerald"] { background: var(--color-emerald); color: #fff; }
.tag-chip.is-selected[data-color="sky"]     { background: var(--color-sky);     color: #fff; }
.tag-chip.is-selected[data-color="slate"]   { background: var(--color-slate);   color: #fff; }

.tag-add { margin-top: 8px; }
.tag-add input { width: 100%; }
.tag-empty { font-size: 12px; color: var(--text-faint); }

/* PWA install how-to overlay (iOS instructions) */
.install-howto-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.install-howto-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.install-howto-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.install-howto-card ol { margin: 0 0 14px 18px; padding: 0; color: var(--text-muted); font-size: 13px; line-height: 1.6; }
.install-howto-card ol li { margin-bottom: 4px; }
.install-howto-card strong { color: var(--text); }
.install-howto-card .primary-btn { width: 100%; }

/* Link previews */
.link-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}
.link-list:empty { display: none; }
.link-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.link-row .link-preview { flex: 1; min-width: 0; }
.link-row .link-remove {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 0 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.link-row .link-remove:hover { color: var(--danger); border-color: var(--danger); }
.link-add { display: flex; gap: 6px; }
.link-add input { flex: 1; }

.link-preview { border-radius: var(--radius-md); overflow: hidden; }

.link-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text);
  transition: background 120ms ease, border-color 120ms ease;
  min-width: 0;
}
.link-card:hover { background: var(--surface-3); border-color: var(--border-strong); }
.link-favicon {
  width: 16px; height: 16px;
  flex: 0 0 auto;
  border-radius: 3px;
}
.link-thumb {
  width: 80px; height: 45px;
  object-fit: cover;
  border-radius: 4px;
  flex: 0 0 auto;
  background: var(--surface-3);
}
.link-meta { min-width: 0; flex: 1; }
.link-host {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.link-url {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-image img {
  display: block;
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.yt-embed {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
}
.yt-embed iframe {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border: 0;
}

/* Tile-card link previews are always compact */
.tile-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

/* Image upload + thumbnails */
/* Image viewer (lightbox) */
.image-viewer {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 100vw;
  max-height: 100vh;
  width: 100vw;
  height: 100vh;
  margin: 0;
  color: #fff;
}
.image-viewer::backdrop {
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(2px);
}
.image-viewer-stage {
  position: absolute;
  inset: 56px 80px 56px 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.image-viewer-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  background: var(--surface-3);
}
.image-viewer-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}
.image-viewer-close:hover { background: rgba(255, 255, 255, 0.22); }
.image-viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  display: none;
}
.image-viewer.is-multi .image-viewer-nav { display: block; }
.image-viewer-nav:hover { background: rgba(255, 255, 255, 0.22); }
.image-viewer-prev { left: 14px; }
.image-viewer-next { right: 14px; }
.image-viewer-counter {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.78);
  background: rgba(0, 0, 0, 0.45);
  padding: 4px 10px;
  border-radius: 99px;
  pointer-events: none;
}
.image-viewer:not(.is-multi) .image-viewer-counter { display: none; }

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}
.image-grid:empty { display: none; }
.image-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-3);
  border: 1px solid var(--border);
}
.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}
.image-thumb .image-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.75);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.image-thumb .image-remove:hover { background: var(--danger); }
.image-thumb.uploading::after {
  content: "Uploading…";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

.image-drop {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  text-align: center;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: border-color 150ms ease, background 150ms ease;
}
.image-drop:hover, .image-drop.is-drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

/* Tile card image strip (under body, before meta) */
.tile-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 4px;
  margin-top: 8px;
}
.tile-images .tile-image {
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-3);
  cursor: zoom-in;
  transition: transform 100ms ease, box-shadow 100ms ease;
}
.tile-images .tile-image:hover {
  transform: scale(1.04);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.2);
}
.tile-images .tile-image img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.tile-images .tile-image-more {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: 6px;
}

/* Quick-capture modal */
.modal-compact { max-width: 480px; }
.qc-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
#qc-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 15px;
  background: var(--surface);
  color: var(--text);
}
#qc-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.qc-hint {
  font-size: 11px;
  color: var(--text-faint);
  display: flex;
  gap: 6px;
  align-items: center;
  padding-left: 2px;
}
.kbd {
  display: inline-block;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10px;
  background: var(--surface-3);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

/* Scrollbars (subtle) */
.column-tiles::-webkit-scrollbar,
.board::-webkit-scrollbar,
.modal-body::-webkit-scrollbar { height: 8px; width: 8px; }
.column-tiles::-webkit-scrollbar-thumb,
.board::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }
.column-tiles::-webkit-scrollbar-track,
.board::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track { background: transparent; }

/* Auth gate */
.auth-gate {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 24px;
  /* Respect notch + home indicator in iOS standalone PWA */
  padding-top: max(24px, env(safe-area-inset-top, 0px));
  padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
  padding-left: max(24px, env(safe-area-inset-left, 0px));
  padding-right: max(24px, env(safe-area-inset-right, 0px));
  z-index: 10;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px 26px 24px;
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.auth-brand .brand-name { font-size: 18px; }
.auth-tagline { color: var(--text-muted); font-size: 13px; margin-bottom: 18px; }
.auth-warning {
  background: color-mix(in srgb, var(--color-amber) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-amber) 35%, transparent);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 14px;
}
.auth-warning code {
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}
.auth-tabs {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 3px;
  margin-bottom: 16px;
}
.auth-tab {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  padding: 7px 0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  transition: background 150ms ease, color 150ms ease;
}
.auth-tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-submit { margin-top: 4px; padding: 10px; }
.auth-foot {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 4px;
}
.auth-error {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.field-hint { font-size: 11px; color: var(--text-faint); }

.tile-banner {
  font-size: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tile-banner[data-kind="locked"] {
  background: color-mix(in srgb, var(--color-amber) 14%, transparent);
  color: var(--text);
  border-color: color-mix(in srgb, var(--color-amber) 35%, transparent);
}
.tile-banner[data-kind="readonly"] {
  background: var(--surface-2);
  color: var(--text-muted);
  border-color: var(--border);
}
.tile-banner strong { color: var(--text); }

.tile-lock-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--color-amber) 16%, transparent);
  color: var(--color-amber);
}

.field-with-status {
  position: relative;
  display: block;
}
.field-with-status input { padding-right: 32px; }
.field-status {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
}
.field-status[data-state="ok"]      { color: var(--color-emerald); }
.field-status[data-state="taken"],
.field-status[data-state="invalid"] { color: var(--danger); }
.field-status[data-state="checking"]::before {
  content: "";
  display: inline-block;
  width: 10px; height: 10px;
  border: 2px solid var(--text-faint);
  border-top-color: transparent;
  border-radius: 50%;
  animation: ic-spin 700ms linear infinite;
}
@keyframes ic-spin { to { transform: rotate(360deg); } }

.field-msg {
  font-size: 11px;
  margin-top: 2px;
}
.field-msg[data-kind="ok"] { color: var(--color-emerald); }
.field-msg[data-kind="error"] { color: var(--danger); }

/* Picker (project switcher + user menu) */
.project-picker, .user-menu { position: relative; }
.picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid transparent;
  color: var(--text);
  padding: 7px 10px 7px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  max-width: 200px;
  transition: background 150ms ease, border-color 150ms ease;
}
.picker-btn:hover { background: var(--surface-3); }
.picker-btn[aria-expanded="true"] { border-color: var(--border-strong); }
.picker-btn > span:first-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.picker-chev { color: var(--text-muted); font-size: 11px; }
.picker-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 4px;
  z-index: 50;
}
.user-menu .picker-menu { left: auto; right: 0; min-width: 200px; }
.picker-list { display: flex; flex-direction: column; gap: 1px; max-height: 280px; overflow-y: auto; }
.picker-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  background: transparent;
  border: 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  text-align: left;
  transition: background 120ms ease;
}
.picker-item:hover { background: var(--surface-2); }
.picker-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.picker-item .role-chip {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--surface-3);
  color: var(--text-muted);
}
.picker-item .role-chip[data-role="admin"]  { color: var(--color-rose);    background: color-mix(in srgb, var(--color-rose) 14%, transparent); }
.picker-item .role-chip[data-role="editor"] { color: var(--color-sky);     background: color-mix(in srgb, var(--color-sky) 14%, transparent); }
.picker-item .role-chip[data-role="viewer"] { color: var(--color-emerald); background: color-mix(in srgb, var(--color-emerald) 14%, transparent); }
.picker-divider { height: 1px; background: var(--border); margin: 4px 2px; }

/* User avatar */
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  background: linear-gradient(135deg, var(--color-indigo), var(--color-sky));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.user-info { padding: 8px 10px; }
.user-name { font-size: 13px; font-weight: 600; }
.user-handle { font-size: 12px; color: var(--text-muted); }

/* Settings page */
#view-settings { overflow-y: auto; }
.settings-page {
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  padding-bottom: 76px; /* space for sticky footer */
}
.settings-footer {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  margin-top: 16px;
  padding: 12px 0;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 5;
}
.settings-footer .dirty-hint {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
}
.settings-footer .dirty-hint strong { color: var(--text); }
.settings-input {
  width: 100%;
  max-width: 360px;
}
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.settings-section h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.settings-row:first-of-type { border-top: 0; }
.settings-row .who { flex: 1; min-width: 0; }
.settings-row .who-name { font-size: 13px; font-weight: 500; }
.settings-row .who-handle { font-size: 12px; color: var(--text-muted); }
.settings-row select { padding: 6px 8px; }
.settings-actions { margin-top: 8px; display: flex; gap: 8px; }

/* ============================ MOBILE ============================ */
@media (max-width: 640px) {
  /* Topbar: stack onto two rows. Row 1 = brand + project picker + actions.
     Row 2 = view tabs (horizontally scrollable when many). */
  .topbar {
    flex-wrap: wrap;
    height: auto;
    min-height: 56px;
    padding: 8px 10px;
    /* Respect notch / status bar in iOS standalone PWA mode */
    padding-top: max(8px, env(safe-area-inset-top, 0px));
    padding-left: max(10px, env(safe-area-inset-left, 0px));
    padding-right: max(10px, env(safe-area-inset-right, 0px));
    gap: 8px;
    align-items: center;
  }
  .brand-name { display: none; }
  .brand { flex: 0 0 auto; }

  .project-picker { flex: 1 1 auto; min-width: 0; }
  .picker-btn { width: 100%; max-width: 100%; justify-content: space-between; }

  .topbar-actions { margin-left: auto; gap: 4px; flex: 0 0 auto; }

  /* Hide non-essential top-row buttons on mobile (still reachable via menus) */
  #install-btn, #theme-toggle { display: none; }

  /* "+ New tile" becomes icon-only */
  #new-tile-btn {
    padding: 8px 10px;
    font-size: 0;
    line-height: 1;
  }
  #new-tile-btn::before {
    content: "+";
    font-size: 18px;
    font-weight: 700;
  }

  /* View tabs go on their own row, scroll horizontally if needed */
  .view-tabs {
    order: 99;
    flex: 1 1 100%;
    overflow-x: auto;
    overflow-y: hidden;
    background: var(--surface-2);
    border-radius: var(--radius-md);
    padding: 3px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .view-tabs::-webkit-scrollbar { display: none; }
  .view-tabs .tab { flex: 0 0 auto; padding: 6px 12px; }

  /* User-menu dropdown anchored to right edge of viewport, compact */
  .user-menu .picker-menu { right: 0; min-width: 220px; }

  /* Views: tighter padding on mobile */
  .view { padding: 12px; }

  /* Board: columns become near-viewport width with scroll-snap so users
     swipe one column at a time. */
  .board {
    scroll-snap-type: x mandatory;
    scroll-padding: 0 12px;
    gap: 10px;
  }
  .column {
    flex: 0 0 88vw;
    max-width: 360px;
    scroll-snap-align: start;
  }

  /* List view: prevent iOS zoom on input focus */
  #list-search { font-size: 16px; }

  /* Modals: take more of the screen, scroll inside */
  .modal {
    width: calc(100vw - 12px);
    max-width: none;
    max-height: calc(100vh - 12px);
  }
  .modal-body { padding: 12px; }
  .modal-header, .modal-footer { padding: 10px 12px; }

  /* Field row stacks (Status + Category, etc.) */
  .field-row { flex-direction: column; }

  /* Modal footer wraps so multiple buttons fit */
  .modal-footer { flex-wrap: wrap; gap: 6px; }
  .modal-footer .ghost-btn,
  .modal-footer .danger-btn,
  .modal-footer .primary-btn { padding: 8px 12px; font-size: 13px; }
  .modal-spacer { flex-basis: 100%; height: 0; margin: 0; }

  /* Settings rows stack on narrow screens */
  .settings-section { padding: 14px; }
  .settings-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .settings-row > select,
  .settings-row > .ghost-btn,
  .settings-row > .danger-btn,
  .settings-row > .primary-btn,
  .settings-row > .role-chip,
  .settings-row > .role-select,
  .settings-row > .member-toggle-remove,
  .settings-row > .remove-member-btn,
  .settings-input { width: 100%; }
  .settings-footer { flex-wrap: wrap; }

  /* Admin tables: scroll horizontally so wide rows don't break the layout */
  .admin-panel { overflow-x: auto; }
  .admin-table { min-width: 540px; }

  /* Image lightbox: keep some padding for the close button */
  .image-viewer-stage { inset: 56px 12px 56px 12px; }
  .image-viewer-prev { left: 6px; }
  .image-viewer-next { right: 6px; }
}
