/* Collections Plus mobile web app. Follows the OS light/dark setting and keeps
   the extension's look: neutral surfaces, Collections blue as the accent. */

:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dde2e9;
  --text: #16191d;
  --muted: #5d6773;
  --faint: #8b95a1;
  --accent: #0f6cbd;
  --accent-text: #ffffff;
  --accent-soft: rgba(15, 108, 189, 0.12);
  --danger: #c42b1c;
  --shadow: 0 8px 28px rgba(16, 24, 40, 0.18);
  --radius: 14px;
  --bar-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #1f2227;
    --surface-2: #2a2e35;
    --border: #30353d;
    --text: #eef1f4;
    --muted: #a3acb7;
    --faint: #7c8692;
    --accent: #4cc2ff;
    --accent-text: #08131d;
    --accent-soft: rgba(76, 194, 255, 0.14);
    --danger: #ff6b6b;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- App bar ------------------------------------------------------------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid transparent;
}
.appbar.scrolled { border-bottom-color: var(--border); }
.appbar h1 {
  flex: 1;
  min-width: 0;
  margin: 0 8px;
  font-size: 1.25rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }

.searchbar { padding: 4px 16px 8px; position: sticky; top: calc(var(--bar-h) + env(safe-area-inset-top)); z-index: 4; background: var(--bg); }
.searchbar input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  outline: none;
}
.searchbar input:focus { border-color: var(--accent); }

.sync-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 16px 4px;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: left;
}
.sync-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.sync-chip.ok .dot { background: #2ea043; }
.sync-chip.busy .dot { background: var(--accent); }
.sync-chip.error { color: var(--danger); }
.sync-chip.error .dot { background: var(--danger); }
.sync-chip.cta { color: var(--accent); font-weight: 600; }

main {
  padding: 4px max(16px, env(safe-area-inset-right)) calc(110px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  max-width: 760px;
  margin: 0 auto;
}

/* ---- Lists ---------------------------------------------------------------- */
.section-label {
  margin: 18px 4px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}
.stack { display: grid; gap: 8px; }

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  text-decoration: none;
}
.card:active { background: var(--surface-2); }
.cover {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface-2);
}
.cover.letter {
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.3rem;
  color: #fff;
}
.card-main { flex: 1; min-width: 0; }
.card-title { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.card-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title svg { width: 14px; height: 14px; color: var(--accent); flex: none; }
.meta { color: var(--muted); font-size: 0.85rem; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag { font-size: 0.72rem; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.chev { color: var(--faint); flex: none; }

.folder {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 6px;
  padding: 10px 6px;
  border: 0;
  background: none;
  font-weight: 600;
  text-align: left;
}
.folder .swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); flex: none; }
.folder .count { color: var(--faint); font-weight: 400; margin-left: auto; }
.folder svg { width: 18px; height: 18px; color: var(--faint); transition: transform 0.15s; }
.folder.collapsed svg { transform: rotate(-90deg); }
.folder-kids { display: grid; gap: 8px; padding-left: 12px; border-left: 2px solid var(--border); margin-left: 10px; }

.reading-link .cover { display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }

/* Items */
.item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.item-link { display: flex; gap: 12px; flex: 1; min-width: 0; text-decoration: none; }
.item-link:active { opacity: 0.7; }
.thumb { flex: none; width: 64px; height: 48px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.thumb.fav { width: 48px; padding: 12px; object-fit: contain; }
.thumb.blank { display: grid; place-items: center; color: var(--faint); }
.item-body { flex: 1; min-width: 0; }
.item-title {
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.item.done .item-title, .item.done .note-text { text-decoration: line-through; color: var(--muted); }
.host { color: var(--muted); font-size: 0.82rem; display: flex; align-items: center; gap: 6px; min-width: 0; }
.host span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.item-note { color: var(--muted); font-size: 0.88rem; margin-top: 2px; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.note-text { white-space: pre-wrap; word-break: break-word; }
.quote { border-left: 3px solid var(--accent); padding-left: 10px; font-style: italic; white-space: pre-wrap; word-break: break-word; }
.item-img { display: block; max-width: 100%; max-height: 260px; border-radius: 10px; margin-bottom: 4px; }
.from { color: var(--faint); font-size: 0.8rem; margin-top: 4px; }
.more-btn { flex: none; width: 36px; height: 36px; margin: -4px -4px 0 0; color: var(--muted); }
.more-btn svg { width: 20px; height: 20px; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
}
.empty h2 { color: var(--text); font-size: 1.15rem; margin: 12px 0 6px; }
.empty p { margin: 0 0 18px; }
.empty .art { width: 72px; height: 72px; margin: 0 auto; border-radius: 18px; }
.empty .stack { max-width: 320px; margin: 0 auto; }

.row-actions { display: flex; gap: 8px; margin: 4px 0 12px; }

/* ---- Buttons & forms ------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-weight: 600;
  text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.9rem; }
.btn:active { filter: brightness(0.95); }

.fab {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 6;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: var(--shadow);
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.4; }
.fab:active { transform: scale(0.96); }

/* ---- Bottom sheet --------------------------------------------------------- */
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
.sheet[open] { animation: sheet-in 0.18s ease-out; }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.sheet form { padding: 8px 18px calc(18px + env(safe-area-inset-bottom)); }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 4px auto 10px; }
.sheet h2 { font-size: 1.1rem; margin: 0 0 12px; word-break: break-word; }
.sheet h2:empty { display: none; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  outline: none;
}
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
.sheet-actions .btn { flex: 1; }
.menu-list { display: grid; margin: 0 -6px; }
.menu-list button, .menu-list a {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 50px;
  padding: 0 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  text-decoration: none;
  font-weight: 500;
}
.menu-list button:active, .menu-list a:active { background: var(--surface-2); }
.menu-list svg { color: var(--muted); }
.menu-list .danger, .menu-list .danger svg { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 0; }
.sheet-note { color: var(--muted); font-size: 0.9rem; margin: 0 0 12px; }
.segmented { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); margin-bottom: 14px; }
.segmented button { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: none; font-weight: 600; color: var(--muted); }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.share-preview { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); margin-bottom: 12px; font-size: 0.9rem; word-break: break-word; }
.share-preview b { display: block; }

/* ---- Toast ---------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 20;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 12px;
  background: #24282e;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 0.95rem;
}
.toast button { border: 0; background: none; color: #7fd3ff; font-weight: 700; padding: 0; }

/* ---- Toolbar chips (sort, tags, read through, checklist) ------------------ */
.toolbar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 2px -16px 10px;
  padding: 2px 16px;
}
.toolbar::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}
.chip svg { width: 16px; height: 16px; color: var(--muted); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip.on svg, .chip.accent svg { color: inherit; }
.chip.accent { background: var(--accent); border-color: transparent; color: var(--accent-text); }
.tag[data-tag] { cursor: pointer; }
.menu-list .current { color: var(--accent); font-weight: 700; }
.menu-list .current svg { color: var(--accent); }

/* ---- Checklists ------------------------------------------------------------ */
.check {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin: 10px 0 0;
  padding: 0;
  border: 2px solid var(--faint);
  border-radius: 8px;
  background: none;
  color: transparent;
}
.check svg { width: 18px; height: 18px; stroke-width: 3; }
.check.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.checklist-progress { margin: 0 4px 8px; }

/* ---- Custom fields ---------------------------------------------------------- */
.fields { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 6px; }
.fld { font-size: 0.8rem; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text); }
.fld .k { color: var(--muted); }
.field-row { display: flex; align-items: flex-end; gap: 4px; }
.field-row .field { flex: 1; }
.field-row .icon-btn { margin-bottom: 13px; color: var(--muted); }
.field-new { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheet .section-label { margin: 6px 0 8px; }

/* ---- Read through ------------------------------------------------------------ */
.reader { display: grid; gap: 14px; padding-top: 6px; }
.reader-top { display: flex; align-items: center; gap: 12px; }
.reader-bar { flex: 1; height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.reader-bar span { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.reader-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  touch-action: pan-y;
}
.reader-card.done .item-title { text-decoration: line-through; color: var(--muted); }
.reader-img { display: block; width: 100%; max-height: 240px; object-fit: cover; border-radius: 12px; margin-bottom: 14px; background: var(--surface-2); }
.reader-card h2.item-title { font-size: 1.25rem; line-height: 1.3; margin: 0 0 6px; -webkit-line-clamp: 4; }
.reader-note { margin: 10px 0 0; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.reader-open { width: 100%; min-height: 52px; font-size: 1.05rem; }
.reader-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.reader-nav .btn svg { width: 18px; height: 18px; }
.btn[disabled] { opacity: 0.4; }

/* ---- Archive & Trash -------------------------------------------------------- */
.bin-row { align-items: center; }
.bin-row .card-main { display: grid; gap: 1px; }
.bin-row .btn.small { flex: none; }
.bin-row .more-btn { margin: 0; }
.bin-icon { display: grid; place-items: center; color: var(--muted); }
.bin-note { margin: 0 4px 10px; }
.chip.danger { color: var(--danger); }
.chip.danger svg { color: var(--danger); }
