/* ========================================
   Shelf UI Overhaul 2026
   ======================================== */

* {
  box-sizing: border-box;
}

body {
  background-color: var(--bg-page);
  color: var(--text-primary);
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-family-main, var(--font-sans));
  font-size: 14px;
  line-height: 1.6;
}

button, input, select, textarea, summary {
  font-family: inherit;
}

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

:root {
  /* shelf2 variables mapped to Reader First light cream/beige theme */
  --bg: #f2efe9;
  --bg2: #f9f6ee;
  --bg3: #fffdf8;
  --bg4: #ddd5ca;
  --border: #ddd5ca;
  --border2: #c4bab0;
  --text: #1d2a26;
  --text2: #6f7a76;
  --text3: #a0a9a6;
  --accent: #c8a96e;
  --accent2: #e8c98a;
  --accent-bg: #f5f0e6;
  --purple: #9b8fcc;
  --purple-bg: #f2eff9;
  --red: #cc8a7a;
  --green: #247062;
  --green-bg: #eef3f1;
  --blue: #7aacc8;
  --r: 8px;
  --r2: 12px;
  --r3: 16px;
  --font-sans: 'DM Sans', sans-serif;
  --font-serif: 'Newsreader', Georgia, serif;
  --font-mono: 'DM Mono', monospace;
  --sidebar: 240px;

  /* shelf2 font stack (header may override via data-font) */
  --font-family-main: var(--font-sans);
  --font-family-display: var(--font-serif);
  --font-family-mono: var(--font-mono);

  /* Backward compatibility mappings for older selectors */
  --bg-page: var(--bg);
  --bg-card: var(--bg3);
  --bg-gradient-a: var(--bg);
  --bg-gradient-b: var(--bg);
  --bg-tertiary: var(--bg2);
  --surface-0: var(--bg3);
  --surface-1: var(--bg3);
  --surface-2: var(--bg2);
  --surface-dark: #1d2a26;
  --ink: var(--text);
  --ink-0: var(--text);
  --ink-1: var(--text);
  --ink-2: var(--text2);
  --text-primary: var(--text);
  --text-secondary: var(--text2);
  --text-muted: var(--text3);
  --border-color: var(--border);
  --line: var(--border);
  --paper: var(--bg3);
  --panel: var(--bg);
  --accent-soft: var(--accent-bg);
  --accent-strong: var(--accent);
}

:root[data-theme='dark'] {
  /* shelf2 dark mode palette */
  --bg: #0f0e0d;
  --bg2: #161512;
  --bg3: #1e1c19;
  --bg4: #252320;
  --border: #2e2b27;
  --border2: #3a3731;
  --text: #e8e4de;
  --text2: #a09890;
  --text3: #6a6460;
  --accent: #c8a96e;
  --accent2: #e8c98a;
  --accent-bg: #1e1a11;
  --purple: #9b8fcc;
  --purple-bg: #16141e;
  --red: #cc8a7a;
  --green: #7ab896;
  --green-bg: #0e1812;
  --blue: #7aacc8;

  /* Backward compatibility mappings for older selectors */
  --bg-page: var(--bg);
  --bg-card: var(--bg3);
  --bg-gradient-a: var(--bg);
  --bg-gradient-b: var(--bg);
  --bg-tertiary: var(--bg2);
  --surface-0: var(--bg3);
  --surface-1: var(--bg3);
  --surface-2: var(--bg2);
  --surface-dark: #e8e4de;
  --ink: var(--text);
  --ink-0: var(--text);
  --ink-1: var(--text);
  --ink-2: var(--text2);
  --text-primary: var(--text);
  --text-secondary: var(--text2);
  --text-muted: var(--text3);
  --border-color: var(--border);
  --line: var(--border);
  --paper: var(--bg3);
  --panel: var(--bg);
  --accent-soft: var(--accent-bg);
  --accent-strong: var(--accent);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-strong);
}

/* --- Navigation --- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--line);
  background: var(--surface-1);
}

.nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
}

.logo {
  font-family: var(--font-family-display);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink-0) !important;
}

.nav-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.nav-links > a {
  color: var(--ink-1);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 999px;
  transition: all 0.2s ease;
}

.nav-links > a:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.search-form {
  display: flex;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid var(--line);
}

.tag {
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 500;
}

.settings-btn {
  border: 1px solid var(--line);
  background: var(--surface-1);
  border-radius: 999px;
  color: var(--ink-1);
  cursor: pointer;
  font-size: 1rem;
  padding: 8px 10px;
}

/* --- Main container --- */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 20px 42px;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 9px 16px;
  font-size: 0.84rem;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #1c948a);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.25);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #0d6d65, #15877e);
  color: #ffffff;
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--text-primary);
}

.btn-secondary:hover {
  border-color: rgba(15, 118, 110, 0.32);
  color: var(--accent-strong);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-warning {
  background: #eba53f;
  color: #fff;
}

.btn-sm {
  font-size: 0.75rem;
  padding: 5px 10px;
}

.btn-lg {
  font-size: 0.9rem;
  padding: 11px 22px;
}

/* --- Alerts --- */
.alert {
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 14px 16px;
  margin-bottom: 20px;
}

.alert-error {
  border-color: rgba(208, 66, 67, 0.34);
  background: rgba(208, 66, 67, 0.1);
  color: #912d2e;
}

.alert-success {
  border-color: rgba(23, 138, 84, 0.3);
  background: rgba(23, 138, 84, 0.1);
  color: #0f6d41;
}

.status-msg {
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 12px 14px;
}

.status-msg.error {
  background: rgba(176, 0, 32, 0.1);
  border-color: rgba(176, 0, 32, 0.35);
  color: #b00020;
}

.status-msg.success {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-color: rgba(23, 138, 84, 0.3);
  background: rgba(23, 138, 84, 0.1);
  color: #0f6d41;
  margin-bottom: 18px;
}

/* --- Dashboard --- */
.dashboard-shell {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 24px;
}

/* Tidy sidebar: lighter surface, clearer sections */
.dashboard-sidebar {
  position: sticky;
  top: 24px;
  height: fit-content;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-1);
  color: var(--ink-0);
  box-shadow: var(--shadow-soft);
  padding: 18px;
}

.sidebar-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.dashboard-logo {
  font-family: var(--font-family-display);
  font-size: 1.35rem;
  margin: 0;
  color: var(--ink-0);
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.dashboard-sidebar .dashboard-launch-fab,
.dashboard-sidebar .dashboard-search-fab {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 999px;
  box-shadow: 0 10px 20px rgba(18, 35, 32, 0.12);
}

.dashboard-sidebar .dashboard-launch-fab {
  background: linear-gradient(135deg, var(--accent), #1c948a) !important;
  color: #ffffff !important;
  border-color: transparent !important;
}

.dashboard-sidebar .dashboard-launch-fab:hover {
  background: linear-gradient(135deg, #0d6d65, #15877e) !important;
  color: #ffffff !important;
}

.dashboard-sidebar .dashboard-launch-fab {
  font-size: 1.05rem;
}

.dashboard-sidebar .dashboard-search-fab {
  background: var(--surface-1) !important;
  color: var(--ink-1) !important;
  border-color: var(--line) !important;
  font-size: 0.95rem;
}

.dashboard-launch-btn {
  justify-content: center;
}

.dashboard-launch-plus {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 1rem;
  line-height: 1;
}

.sidebar-nav {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.sidebar-link {
  border: none;
  background: transparent;
  color: var(--ink-1);
  border-radius: 8px;
  text-align: left;
  padding: 10px 12px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s ease;
}

.sidebar-link:hover,
.sidebar-link.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.sidebar-link.is-active {
  font-weight: 700;
}

.sidebar-group-toggle.sidebar-link {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sidebar-sub-link {
  margin-left: 14px;
  padding-left: 14px;
  width: calc(100% - 14px);
  font-weight: 600;
}

.sidebar-group {
  display: grid;
  gap: 8px;
}

.sidebar-group-toggle,
.sidebar-group-menu {
  appearance: none;
  cursor: pointer;
}

.sidebar-group-toggle {
  font-size: 0.92rem;
  font-weight: 800;
}

.sidebar-group-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-group-header.sidebar-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  cursor: pointer;
  gap: 12px;
}

.sidebar-group-toggle-content {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.sidebar-group-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sidebar-group-caret {
  border: 0;
  background: transparent;
  color: var(--ink-2);
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.8rem;
}

.sidebar-group-caret:hover {
  background: rgba(15, 118, 110, 0.08);
  color: var(--ink-0);
}

.sidebar-group-menu {
  border: 0;
  background: transparent;
  color: var(--ink-1);
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.sidebar-group-header:hover .sidebar-group-menu,
.sidebar-group-header:focus-within .sidebar-group-menu {
  opacity: 1;
  transform: translateX(0);
}

.sidebar-group-menu:hover {
  background: rgba(15, 118, 110, 0.08);
}

.sidebar-group-menu-popover {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  min-width: 180px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  box-shadow: var(--shadow-soft);
}

.sidebar-group-menu-popover button {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  color: var(--ink-1);
  cursor: pointer;
}

.sidebar-group-menu-popover button:hover {
  background: rgba(15, 118, 110, 0.08);
}

.sidebar-group-panel {
  display: grid;
  gap: 8px;
}



.sidebar-group.is-collapsed .sidebar-group-panel {
  display: none;
}

.sidebar-group.is-collapsed .sidebar-group-caret {
  transform: rotate(-90deg);
}

/* Section container used within sidebar for clearer grouping */
.sidebar-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(22, 46, 40, 0.04);
}

.dashboard-launch-plus {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 1rem;
  line-height: 1;
}

.dashboard-launch-hint {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.45;
  color: rgba(221, 240, 235, 0.78);
}

.sidebar-quick-actions .btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
  color: #def0eb;
}

.sidebar-quick-actions .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* Compact search in sidebar */
.sidebar-search {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 8px 0 6px;
}

.sidebar-search input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.sidebar-search button {
  border: none;
  background: transparent;
  font-size: 1rem;
  cursor: pointer;
  padding: 6px 8px;
}

/* Settings control in sidebar */
.sidebar-settings {
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-1);
}

/* Library group pills */
.sidebar-library-groups {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.sidebar-library-groups h4 {
  margin: 0;
  font-size: 0.78rem;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar-library-groups .library-tab {
  border-radius: 999px;
  padding: 8px 10px;
  font-size: 0.85rem;
  border: 1px solid var(--line);
  background: transparent;
  width: 100%;
  text-align: left;
}

.sidebar-library-groups .library-tab.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: rgba(15, 118, 110, 0.28);
}

/* Ensure main-pane library tabs keep the original 'pill' style */
.dashboard-main .library-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 12px;
}

.dashboard-main .library-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-0);
  color: var(--ink-1);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 7px 12px;
}

.dashboard-main .library-tab.is-active,
.dashboard-main .library-tab:hover {
  border-color: rgba(15, 118, 110, 0.4);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

/* Tags list: compact, scrollable */
.sidebar-tags {
  margin-top: 12px;
}

.sidebar-tags h4 {
  margin: 0 0 8px 0;
  font-size: 0.78rem;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar-tags ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
  padding-right: 6px;
}

.sidebar-tags li a {
  display: inline-block;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.04);
  color: var(--accent-strong);
  font-weight: 700;
  font-size: 0.85rem;
}

.sidebar-tags li a:hover {
  background: rgba(15, 118, 110, 0.08);
}

.sidebar-tag-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.12);
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 800;
}

.create-overlay {
  --create-bg: #1a1814;
  --create-bg-2: #24221d;
  --create-border: #3a3832;
  --create-text: #fdfcf0;
  --create-muted: #8c887d;
  --create-gold: #d4b475;
  --create-gold-text: #1a1510;
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  background: rgba(10, 9, 8, 0.72);
  backdrop-filter: blur(8px);
  z-index: 2500;
}

.create-overlay[hidden] {
  display: none;
}

.create-modal {
  width: min(560px, 100%);
  max-height: min(88vh, 720px);
  overflow: auto;
  border: 1px solid var(--create-border);
  border-radius: 24px;
  background: var(--create-bg);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.45);
  padding: 32px;
  color: var(--create-text);
  font-family: var(--font-family-main, var(--font-sans));
}

.create-modal-title {
  margin: 0 0 24px;
  font-family: var(--font-family-display, var(--font-serif));
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--create-text);
  letter-spacing: -0.02em;
}

.create-tabs {
  display: flex;
  gap: 4px;
  padding: 5px;
  border-radius: 12px;
  background: var(--create-bg-2);
  margin-bottom: 24px;
}

.create-tab {
  flex: 1;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--create-muted);
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.create-tab:hover:not(.is-active) {
  color: var(--create-text);
}

.create-tab.is-active {
  background: #1c1a17;
  border-color: var(--create-border);
  color: var(--create-text);
}

.create-panel {
  display: none;
}

.create-panel.is-active {
  display: block;
}

.create-form {
  display: grid;
  gap: 16px;
}

.create-upload-form {
  max-width: none;
}

.create-destination { display: grid; gap: 8px; margin: 0; padding: 0; border: 0; }
.create-destination-card { display: grid; grid-template-columns: 18px 1fr; gap: 10px; align-items: start; padding: 12px; border: 1px solid var(--create-border); border-radius: 10px; background: var(--create-bg-2); cursor: pointer; }
.create-destination-card.is-selected { border-color: var(--create-gold); box-shadow: inset 3px 0 0 var(--create-gold); }
.create-destination-card input { margin: 3px 0 0; accent-color: var(--create-gold); }
.create-destination-card span { display: grid; gap: 3px; }
.create-destination-card strong { color: var(--create-text); font-size: 13px; }
.create-destination-card small { color: var(--create-muted); font-size: 11px; line-height: 1.4; }
.create-manga-options { display: grid; gap: 8px; padding: 12px; border-left: 3px solid var(--create-gold); background: color-mix(in srgb, var(--create-gold) 7%, transparent); border-radius: 0 10px 10px 0; }
.create-manga-options[hidden] { display: none; }
.create-manga-options .create-helper { margin: 0; }

.create-field {
  display: grid;
  gap: 8px;
}

.create-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--create-muted);
}

.create-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--create-border);
  border-radius: 10px;
  background: var(--create-bg-2);
  color: var(--create-text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease;
}

.create-input::placeholder {
  color: #5c5850;
}

.create-input:focus {
  border-color: #524e46;
}

.create-helper {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--create-muted);
}

.create-modal-footer {
  display: flex;
  flex-shrink: 0;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 28px;
  padding-top: 4px;
}

.create-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--create-border);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.create-btn-ghost {
  background: transparent;
  color: var(--create-text);
}

.create-btn-ghost:hover {
  background: var(--create-bg-2);
}

.create-btn-primary {
  background: var(--create-gold);
  border-color: var(--create-gold);
  color: var(--create-gold-text);
  font-weight: 700;
}

.create-btn-primary:hover {
  background: #dfc288;
  border-color: #dfc288;
}

.create-btn-sm {
  min-width: unset;
  padding: 8px 14px;
  font-size: 12px;
}

.create-modal .dropzone {
  border: 1px dashed var(--create-border);
  border-radius: 12px;
  background: var(--create-bg-2);
  padding: 22px;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.create-modal .dropzone.is-dragging {
  border-color: var(--create-gold);
  background: #2a2722;
}

.create-modal .dropzone-title {
  margin: 0;
  font-weight: 600;
  font-size: 14px;
  color: var(--create-text);
}

.create-modal .dropzone-copy {
  margin: 6px 0 14px;
  color: var(--create-muted);
  font-size: 12px;
}

.create-modal .dropzone-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.create-modal .dropzone-file {
  font-size: 12px;
  color: var(--create-muted);
}

body.modal-open {
  overflow: hidden;
}

.dashboard-main {
  min-width: 0;
}

.dashboard-view {
  display: none;
}

.dashboard-view.is-active {
  display: block;
}

.dashboard-panel-header {
  margin-bottom: 16px;
}

.dashboard-panel-header h2 {
  font-family: var(--font-family-display);
  font-size: 2rem;
  font-weight: 600;
}

.dashboard-panel-header p {
  color: var(--ink-2);
  margin-top: 6px;
  font-size: 0.96rem;
}

.search-panel-header {
  display: grid;
  gap: 12px;
}

.search-panel-toolbar {
  max-width: 680px;
}

.dashboard-search-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-1);
  padding: 14px 16px;
  font-size: 0.96rem;
  color: var(--ink-0);
  outline: none;
  box-shadow: var(--shadow-soft);
}

.dashboard-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-soft);
}

.search-panel-status {
  margin-bottom: 14px;
  color: var(--ink-2);
  font-size: 0.9rem;
}

.search-filters-ref {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md, 10px);
  background: var(--bg3, var(--surface-1));
  font-size: 12px;
  line-height: 1.45;
  color: var(--text2, var(--ink-2));
}

.search-filters-ref-heading {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text, var(--ink-0));
}

.search-filters-ref-lead {
  margin: 0 0 10px;
  font-size: 11px;
}

.search-filters-ref-list {
  margin: 0;
  display: grid;
  gap: 8px;
}

.search-filters-ref-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 8px 12px;
  align-items: baseline;
}

.search-filters-ref-row dt {
  margin: 0;
  font-weight: 500;
}

.search-filters-ref-row dt code,
.search-filters-ref-example code {
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg4, rgba(0, 0, 0, 0.06));
  color: var(--text, var(--ink-0));
}

.search-filters-example {
  opacity: 0.75;
}

.search-filters-ref-row dd {
  margin: 0;
  font-size: 11px;
  color: var(--text3, var(--ink-2));
}

.search-filters-ref-example {
  margin: 10px 0 0;
  font-size: 11px;
}

@media (max-width: 640px) {
  .search-filters-ref-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

.search-panel-results {
  display: grid;
  gap: 10px;
}

.dashboard-sections {
  display: grid;
  gap: 18px;
}

.dashboard-section {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-0);
  box-shadow: 0 6px 18px rgba(32, 51, 48, 0.06);
  padding: 18px;
}

.section-header {
  margin-bottom: 12px;
}

.section-header h3 {
  font-size: 1.06rem;
  color: var(--ink-1);
}

.card-list {
  display: grid;
  gap: 10px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.dashboard-stats {
  margin-top: 18px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-1);
  box-shadow: 0 6px 14px rgba(32, 51, 48, 0.06);
  text-align: center;
  padding: 16px;
}

.stat-number {
  display: block;
  font-size: 1.85rem;
  line-height: 1;
  color: var(--accent-strong);
  font-weight: 800;
}

.stat-label {
  display: block;
  margin-top: 7px;
  font-size: 0.8rem;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.library-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 12px;
}

.library-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-0);
  color: var(--ink-1);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 7px 12px;
}

.library-tab.is-active,
.library-tab:hover {
  border-color: rgba(15, 118, 110, 0.4);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.library-panel {
  display: none;
}

.library-panel.is-active {
  display: block;
}

.compact-empty {
  padding: 20px 14px;
}

/* --- Cards --- */
.passage-list {
  margin-top: 8px;
}

.passage-list h2 {
  margin-bottom: 12px;
  color: var(--ink-1);
}

.passage-card {
  position: relative;
  display: block;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-1);
  box-shadow: 0 6px 14px rgba(32, 51, 48, 0.06);
  padding: 16px;
  transition: transform 0.2s ease, border-color 0.2s ease;
  cursor: pointer;
}

.passage-card:hover {
  color: inherit;
  text-decoration: none;
  transform: translateY(-2px);
  border-color: rgba(15, 118, 110, 0.3);
  z-index: 10;
}

.passage-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.passage-card-header h3 {
  font-size: 1rem;
}

.passage-source {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  background: var(--surface-1);
  color: var(--accent-strong);
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--accent-soft);
  transition: all 0.2s ease;
  line-height: 1.2;
  white-space: nowrap;
}

.tag:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.passage-card-preview {
  font-size: 0.9rem;
  color: var(--ink-2);
  margin-bottom: 8px;
}

.passage-card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--ink-2);
  font-size: 0.78rem;
}

.passage-card-meta .status-bubble {
  margin-left: auto;
  white-space: nowrap;
}

.passage-card-progress {
  position: relative;
  height: 2px;
  background: var(--line);
  margin-top: 16px;
  border-radius: 1px;
}

.passage-card-progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: #3b82f6;
  border-radius: 1px;
}

.passage-card-progress-dot {
  position: absolute;
  top: 50%;
  width: 3px;
  height: 3px;
  background: #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.2);
}

.unread-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background-color: #3b82f6;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}

.passage-card-actions {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 4px;
  background: var(--surface-1);
  padding: 4px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  border: 1px solid var(--line);
  z-index: 100;
}

.passage-card:hover .passage-card-actions {
  opacity: 1;
  pointer-events: auto;
}

.action-btn {
  background: transparent;
  border: none;
  padding: 6px;
  cursor: pointer;
  border-radius: 4px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-2);
  transition: background 0.2s ease;
}

.action-btn:hover {
  background: var(--surface-2);
  color: var(--ink-1);
}

.action-btn-icon:hover {
  background: var(--surface-2);
  color: var(--ink-1);
}

.btn-icon.is-active {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: var(--accent-soft);
}

.btn-icon svg {
  display: block;
}

.action-btn.is-active {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: var(--accent-soft);
}

.action-btn svg {
  display: block;
}

.action-menu-container {
  position: relative;
}

.action-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 4px;
  min-width: 160px;
  z-index: 200;
  display: none;
  flex-direction: column;
}

.action-menu.is-open {
  display: flex;
}

.action-menu button, .action-menu a {
  background: transparent;
  border: none;
  padding: 8px 12px;
  text-align: left;
  font-size: 0.88rem;
  font-family: inherit;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
  border-radius: 4px;
  color: var(--ink-1);
  text-decoration: none;
  display: block;
  width: 100%;
  box-sizing: border-box;
}

.action-menu button:hover, .action-menu a:hover {
  background: var(--surface-2);
}

.action-menu .danger {
  color: #ef4444;
}

.passage-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.tag {
  background: #f1f5f9;
  color: #475569;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
  border: 1px solid #e2e8f0;
}

.passage-card {
  position: relative;
}

/* Status bubble for card state (Inbox / Read Later / Archived) */
.passage-card-status {
  position: absolute;
  right: 0.75rem;
  bottom: 1.65rem;
  display: flex;
  align-items: center;
  pointer-events: none;
  z-index: 1;
}

.passage-card-status .status-bubble {
  display: inline-block;
  white-space: nowrap;
}

.passage-card-status .tag {
  margin: 0;
}

.status-inbox,
.status-read-later,
.status-archived {
  background: rgba(59, 130, 246, 0.12);
  color: #1d4ed8;
  border-color: rgba(59, 130, 246, 0.28);
}

.status-bubble {
  white-space: nowrap;
}

.fav-badge {
  color: #a7601a;
  font-size: 0.9rem;
}

/* --- Forms and pages --- */
.upload-page,
.search-page,
.collections-page,
.collection-detail,
.form-container,
.passage-detail {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-0);
  box-shadow: var(--shadow-soft);
  padding: 22px;
}

.upload-page h1,
.search-page h1,
.collections-page h1,
.form-container h1,
.collection-header h1 {
  font-family: var(--font-family-display);
  font-size: 1.8rem;
  margin-bottom: 6px;
}

.upload-page > p,
.query-info,
.form-container > p {
  color: var(--ink-2);
  margin-bottom: 18px;
}

.upload-form,
.passage-form {
  max-width: 780px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--ink-1);
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="file"],
.form-group textarea,
.form-group select,
.passage-notes textarea,
.note-form textarea,
.highlight-toolbar textarea,
.add-to-col-form select,
#hl-manager-note,
#chat-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-1);
  color: var(--ink-0);
  outline: none;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
}

#passage-notes {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ink-0);
  outline: none;
  padding: 0;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.6;
}

.notes-form {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 32px;
}

.notes-form button {
  width: fit-content;
  padding: 8px 18px;
  font-size: 0.88rem;
}

.notes-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.btn-icon-sm {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.btn-icon-xs {
  width: 24px;
  height: 24px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.spin {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus,
.passage-notes textarea:focus,
.note-form textarea:focus,
.highlight-toolbar textarea:focus,
.add-to-col-form select:focus,
#hl-manager-note:focus,
#chat-input:focus,
#passage-notes:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.manual-entry {
  margin-top: 28px;
}

.manual-entry hr {
  border: none;
  border-top: 1px solid var(--line);
  margin-bottom: 22px;
}

.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.info-card {
  margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-1);
  padding: 16px;
}

.info-card ul {
  margin-top: 8px;
  margin-left: 18px;
  color: var(--ink-2);
}

.page-header,
.collection-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}

.collection-desc,
.collection-header .subtitle {
  color: var(--ink-2);
}

.collection-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.collection-card {
  text-decoration: none;
  color: inherit;
}

.collection-remove-form {
  margin-top: -8px;
  margin-bottom: 18px;
  text-align: right;
}

.collection-empty {
  text-align: center;
}

/* --- Passage detail --- */
.passage-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

.passage-shell {
  --sidebar-width: 270px;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.passage-shell.is-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.passage-shell.is-collapsed .passage-sidebar {
  display: none;
}

.passage-main {
  min-width: 0;
  max-width: 840px;
  margin: 0 auto;
  width: 100%;
}

.passage-sidebar {
  position: sticky;
  top: 24px;
  height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-1);
  color: var(--ink-0);
  box-shadow: var(--shadow-soft);
  padding: 18px;
  direction: rtl; /* Move scrollbar to left */
}

.sidebar-content-wrapper {
  direction: ltr; /* Content remains left-to-right */
  height: 100%;
}

.passage-sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.sidebar-kicker {
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-2);
}

.passage-sidebar-header h2 {
  font-family: var(--font-family-display);
  font-size: 1.5rem;
}

.sidebar-toggle-btn,
.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: rgba(15, 118, 110, 0.32);
}

.btn-icon.is-disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

.nav-pill-group {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px;
}

.nav-pill-group .btn-icon {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
}

.nav-pill-group .btn-icon:hover {
  background: var(--accent-soft);
}

#settings-btn {
  font-family: var(--font-family-display);
  font-weight: bold;
}

.btn-icon.is-active {
  background: var(--accent-soft);
  border-color: rgba(15, 118, 110, 0.32);
  color: var(--accent-strong);
}

.sidebar-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 14px;
}

.sidebar-tab {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-0);
  color: var(--ink-1);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 6px 4px;
}

.sidebar-tab.is-active {
  border-color: rgba(15, 118, 110, 0.35);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.sidebar-panel {
  display: none;
}

.sidebar-panel.is-active {
  display: block;
}

.sidebar-panel-body {
  padding-right: 4px;
}

.sidebar-stack {
  display: grid;
  gap: 14px;
}

.info-hero h3 {
  font-family: var(--font-family-display);
  font-size: 1.35rem;
}

.info-hero p {
  margin-top: 6px;
  color: var(--ink-2);
}

.btn-block {
  width: 100%;
}

.summary-card,
.progress-card,
.chat-box {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-1);
  padding: 12px;
}

.highlights-section {
  margin-bottom: 32px;
}

.summary-card-header,
.progress-row,
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.summary-card-header h4,
.section-heading h4 {
  font-size: 0.92rem;
}

.summary-body {
  color: var(--ink-1);
  font-size: 0.92rem;
  line-height: 1.55;
}

.meta-grid {
  display: grid;
  gap: 8px;
}

.meta-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-0);
  padding: 8px 10px;
  font-size: 0.84rem;
}

.meta-item span {
  color: var(--ink-2);
}

.meta-item strong {
  color: var(--ink-0);
  text-align: right;
}

.progress-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #1c948a);
}

.progress-helper {
  margin-top: 8px;
  color: var(--ink-2);
  font-size: 0.82rem;
}

.notes-form label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-2);
}

.chat-panel {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 160px); /* Fill available sidebar height */
}

.chat-box {
  flex: 1;
  overflow: auto;
  padding: 12px;
  background: var(--surface-0);
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 16px;
}

.chat-box div {
  margin-bottom: 12px;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink-0);
}

.chat-box strong {
  color: var(--accent);
  display: block;
  margin-bottom: 4px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chat-composer {
  position: relative;
  display: flex;
  flex-direction: column;
  margin-top: auto;
}

.chat-composer #chat-input {
  width: 100%;
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-1);
  color: var(--ink-0);
  outline: none;
  padding: 14px 16px 50px;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  resize: none;
  transition: all 0.2s ease;
}

.chat-composer #chat-input:focus {
  border-color: var(--accent);
  background: var(--surface-2);
  box-shadow: 0 8px 24px -8px rgba(0,0,0,0.12);
}

.chat-composer-actions {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.chat-composer-actions > * {
  pointer-events: auto;
}

.composer-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-0);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-1);
  cursor: pointer;
  transition: all 0.2s;
}

.composer-pill:hover {
  background: var(--surface-2);
  color: var(--accent);
  border-color: var(--accent);
}

.composer-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 10px rgba(15, 118, 110, 0.2);
}

.composer-send-btn:hover {
  background: var(--accent-strong);
  transform: translateY(-1px) scale(1.05);
  box-shadow: 0 6px 14px rgba(15, 118, 110, 0.3);
}

.composer-send-btn:active {
  transform: translateY(0) scale(0.95);
}

/* Chat Presets Menu */
.chat-presets-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 20px 40px -10px rgba(0,0,0,0.25);
  z-index: 50;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-presets-menu[hidden] {
  display: none;
}

.preset-option {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
  color: var(--ink-1);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.15s;
}

.preset-option:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.preset-icon {
  font-size: 1.1rem;
}

.highlights-section .highlights-list {
  margin-top: 12px;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 4px;
}

.toc-item {
  margin: 0;
}

.toc-item a {
  display: block;
  border-radius: 10px;
  color: var(--ink-1);
  padding: 8px 10px;
  font-size: 0.88rem;
}

.toc-item a:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.toc-item.level-2 {
  padding-left: 10px;
}

.toc-item.level-3 {
  padding-left: 20px;
}

.toc-item.level-4 {
  padding-left: 30px;
}

.toc-item.level-5,
.toc-item.level-6 {
  padding-left: 40px;
}

.passage-menu {
  position: relative;
}

.passage-menu summary {
  list-style: none;
}

.passage-menu summary::-webkit-details-marker {
  display: none;
}

.passage-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  min-width: 200px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  box-shadow: var(--shadow-mid);
  padding: 8px;
  display: grid;
  gap: 6px;
}

.menu-link {
  display: block;
  width: 100%;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-1);
  cursor: pointer;
  font: inherit;
  padding: 10px 12px;
  text-align: left;
}

.menu-link:hover {
  background: rgba(15, 118, 110, 0.1);
  color: var(--accent-strong);
}

.menu-link.danger {
  color: var(--danger);
}

.menu-link.danger:hover {
  background: rgba(208, 66, 67, 0.1);
  color: var(--danger);
}

.content-block.document-content {
  background: rgba(255, 255, 255, 0.96);
}

.pdf-viewer {
  display: grid;
  gap: 18px;
}

.pdf-pages {
  display: grid;
  gap: 20px;
}

.pdf-page {
  position: relative;
  margin: 0 auto;
  background: var(--surface-2);
  box-shadow: var(--shadow-mid);
  border-radius: 14px;
  overflow: hidden;
}

.pdf-canvas {
  display: block;
}

.pdf-text-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: auto;
  opacity: 1;
  line-height: 1;
  -webkit-text-size-adjust: none;
     -moz-text-size-adjust: none;
          text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  z-index: 2;
}

.pdf-text-layer :is(span, br) {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
  user-select: text;
  -webkit-user-select: text;
}

.passage-detail-header h1 {
  font-family: var(--font-family-display);
  font-size: 2rem;
}

.passage-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  margin-bottom: 10px;
}

.badge {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.74rem;
  font-weight: 700;
}

.badge-source {
  background: rgba(29, 58, 51, 0.09);
  color: #304742;
}

.badge-fav {
  background: rgba(178, 106, 25, 0.14);
  color: #8f5513;
}

.badge-archived {
  background: rgba(61, 78, 73, 0.11);
  color: #425651;
}

.source-link {
  font-size: 0.85rem;
}

.passage-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}

.passage-actions form {
  margin: 0;
}

.add-to-col-form {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-0);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 8px;
}

.add-to-col-form label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-1);
  white-space: nowrap;
}

.add-to-col-form select {
  min-width: 170px;
  border-radius: 999px;
  padding: 7px 10px;
}

.content-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  box-shadow: 0 6px 14px rgba(32, 51, 48, 0.06);
  padding: 18px;
}

.passage-content,
.passage-highlights,
.passage-collections,
.passage-notes,
.passage-ocr {
  margin-top: 18px;
}

.passage-content h3,
.passage-highlights h3,
.passage-collections h3,
.passage-notes h3,
.passage-ocr h3 {
  margin-bottom: 10px;
  color: var(--ink-1);
}

.passage-highlights {
  border-top: 1px dashed var(--line);
  padding-top: 18px;
}

.highlights-list {
  display: grid;
  gap: 12px;
}

.highlight-item {
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  box-shadow: var(--shadow-soft);
}

.highlight-item blockquote {
  margin: 0;
  padding: 12px;
  color: var(--ink-1);
  border-bottom: 1px solid var(--line);
}

.highlight-footer {
  padding: 10px 12px;
}

.note-form {
  display: grid;
  gap: 8px;
}

.highlight-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.empty-msg {
  color: var(--ink-2);
  font-style: italic;
}

.ocr-preview {
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  padding: 12px;
  max-height: 320px;
  overflow-y: auto;
  color: var(--ink-1);
}

/* --- Highlight tooling --- */
.hl-inline {
  padding: 0;
  font-size: inherit;
  line-height: inherit;
  border-radius: 3px;
  cursor: pointer;
  transition: filter 0.12s ease;
}

.hl-inline:hover {
  filter: brightness(0.9);
}

.highlight-toolbar {
  position: fixed;
  z-index: 1000;
  display: none;
  animation: pill-fade-in 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes pill-fade-in {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.highlight-toolbar.pill-style {
  background: var(--surface-2);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  padding: 6px 10px;
  align-items: center;
  gap: 4px;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.15), 0 4px 12px -4px rgba(0, 0, 0, 0.1);
  width: auto;
}

.highlight-toolbar.pill-style[style*="flex"] {
  display: flex;
}

.highlight-toolbar.is-vertical {
  flex-direction: column;
  padding: 10px 6px;
  border-radius: 24px;
  z-index: 1100;
}

.highlight-toolbar.is-vertical .pill-divider {
  width: 20px;
  height: 1px;
  margin: 6px 0;
}

.highlight-toolbar.is-vertical .pill-colors {
  flex-direction: column;
  padding: 8px 0;
  gap: 10px;
}

.highlight-toolbar.is-vertical .pill-popover {
  bottom: unset;
  top: 50%;
  left: calc(100% + 12px);
  transform: translateY(-50%);
}

.highlight-toolbar.is-vertical .pill-popover::after {
  top: 50%;
  left: unset;
  right: 100%;
  margin-left: 0;
  margin-top: -6px;
  border-color: transparent var(--surface-2) transparent transparent;
}

.pill-btn {
  background: transparent;
  border: none;
  color: #64748b; /* Slate 500 */
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0;
}

.pill-btn:hover {
  background: #f1f5f9; /* Slate 100 */
  color: #0f172a; /* Slate 900 */
}

.pill-btn.delete-trigger {
  background: var(--accent);
  color: #ffffff;
  width: 32px;
  height: 32px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.pill-btn.delete-trigger:hover {
  transform: scale(1.1);
  filter: brightness(1.05);
}

.pill-divider {
  width: 1px;
  height: 20px;
  background: #e2e8f0; /* Slate 200 */
  margin: 0 6px;
}

.pill-colors {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
}

.color-btn,
.color-btn-mgr {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: all 0.2s ease;
  position: relative;
  flex-shrink: 0;
}

.color-btn:hover,
.color-btn-mgr:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.color-btn.is-active,
.color-btn-mgr.is-active {
  border-color: #64748b; /* Slate 500 ring */
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #e2e8f0;
}

/* Note Popover */
.pill-popover {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow-lg);
  width: 240px;
  display: none;
  flex-direction: column;
  gap: 8px;
  z-index: 1001;
}

.pill-popover::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -6px;
  border-width: 6px;
  border-style: solid;
  border-color: #ffffff transparent transparent transparent;
}

.pill-popover.is-visible {
  display: flex;
  animation: pop-up 0.15s ease-out;
}

@keyframes pop-up {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.pill-popover textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font-size: 0.85rem;
  resize: vertical;
  min-height: 60px;
  outline: none;
}

.color-btn:hover,
.color-btn-mgr:hover {
  transform: scale(1.09);
}

.toolbar-actions {
  display: flex;
  justify-content: space-between;
  gap: 7px;
}

.hl-manager-title {
  margin-bottom: 8px;
  font-size: 0.8rem;
  color: var(--ink-2);
}

/* --- Empty state --- */
.empty-state {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.56);
  padding: 34px 16px;
  text-align: center;
  color: var(--ink-2);
}

.empty-state p {
  margin: 0 0 10px;
}

/* --- Article content cleanup --- */
#passage-content p,
#passage-content li,
#passage-content blockquote {
  margin-bottom: 0.8em;
}

#passage-content h1,
#passage-content h2,
#passage-content h3,
#passage-content h4 {
  margin-top: 1.2em;
  margin-bottom: 0.5em;
  color: var(--ink-0);
}

#passage-content img,
#passage-content figure {
  max-width: 100% !important;
}

#passage-content img {
  height: auto !important;
  border-radius: 8px;
}

#passage-content table {
  max-width: 100%;
  display: block;
  overflow-x: auto;
  margin: 1em 0;
}

#passage-content th,
#passage-content td {
  border: 1px solid var(--line);
  padding: 6px 10px;
}

/* HTML articles use normal flow; pre-wrap only for plain/OCR text */
#passage-content {
  white-space: normal;
}

body.source-image #passage-content,
.content-block.ocr-block {
  white-space: pre-wrap;
}

/* ── Reader Display Settings ──────────────────────────────────────── */
:root {
  --reader-font-size: 17px;
  --reader-line-height: 1.75;
  --reader-para-spacing: 1em;
  --reader-font-family: var(--font-serif);
}

/* Apply reader typography variables to all long-form content */
body.source-epub #passage-content,
body.source-webpage #passage-content,
body.source-fic #passage-content {
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
  font-family: var(--reader-font-family);
}

/* Force inline text elements to inherit so the container vars cascade */
body.source-epub #passage-content p,
body.source-epub #passage-content div,
body.source-epub #passage-content span {
  font-size: inherit !important;
  line-height: inherit !important;
  font-family: inherit !important;
}

/* Paragraph spacing — covers both <p> and epub's block <div> paragraphs */
body.source-epub #passage-content p,
body.source-epub #passage-content div:not(section):not([class*="toc"]):not([class*="nav"]):not([class*="head"]):not(.end) {
  margin-bottom: var(--reader-para-spacing) !important;
}

/* Preserve heading sizes despite the inherit override */
body.source-epub #passage-content h1 { font-size: 1.8em !important; }
body.source-epub #passage-content h2 { font-size: 1.4em !important; }
body.source-epub #passage-content h3 { font-size: 1.15em !important; }
body.source-epub #passage-content h4 { font-size: 1em !important; font-weight: 700 !important; }

/* --- Footer --- */
body > div:last-of-type {
  color: var(--ink-2) !important;
}

/* --- Mobile --- */
@media (max-width: 980px) {
  .dashboard-shell {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .passage-shell {
    grid-template-columns: 1fr;
  }

  .passage-sidebar {
    position: static;
    height: auto;
  }

  .page-header,
  .collection-header,
  .passage-detail-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 760px) {
  .nav-inner {
    flex-direction: column;
    align-items: stretch;
    padding: 12px 14px;
  }

  .logo {
    text-align: center;
  }

  .nav-links {
    justify-content: center;
  }

  .search-form input {
    width: 100%;
    min-width: 0;
  }

  .container {
    padding: 20px 14px 30px;
  }

  .dashboard-sidebar {
    padding: 16px;
  }

  .sidebar-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    display: grid;
  }

  .sidebar-link {
    text-align: center;
    padding: 10px 8px;
  }

  .sidebar-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .upload-page,
  .search-page,
  .collections-page,
  .collection-detail,
  .form-container,
  .passage-detail {
    padding: 16px;
  }

  .passage-card {
    padding: 14px;
  }

  .add-to-col-form {
    width: 100%;
  }

  .add-to-col-form select {
    min-width: 0;
    width: 100%;
  }

  .passage-actions {
    gap: 6px;
  }

  .passage-menu-panel {
    right: auto;
    left: 0;
  }

  .library-tabs {
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 2px;
  }

  .search-panel-toolbar {
    max-width: none;
  }
}

.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;
}

/* === Action Button States === */

.action-btn.is-disabled,
.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.action-menu.is-open {
  display: block !important;
  opacity: 1;
  visibility: visible;
}

/* === Notification Toast === */

.notification-toast {
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: var(--ink-0);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-mid);
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  transform: translateY(100px);
  transition: all 300ms ease;
  pointer-events: none;
}

.notification-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

@media (max-width: 640px) {
  .notification-toast {
    left: 10px;
    right: 10px;
    bottom: 10px;
  }
}

/* --- Tag Popup --- */
.tags-popup {
  position: absolute;
  width: 280px;
  background: var(--surface-2);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.1), 0 0 1px rgba(0,0,0,0.2);
  z-index: 1000;
  color: #1f2937;
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #e5e7eb;
}

.tags-popup.is-open {
  display: flex;
}

.tags-popup-header {
  padding: 12px;
  border-bottom: 1px solid #f3f4f6;
}

.tags-selected {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.tags-selected:empty {
  margin-bottom: 0;
}

.tag-pill {
  background: #f3f4f6;
  color: #374151;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid #e5e7eb;
}

.tag-pill .remove-tag {
  cursor: pointer;
  opacity: 0.7;
}

.tag-pill .remove-tag:hover {
  opacity: 1;
}

.tags-popup-input {
  background: transparent;
  border: none;
  color: var(--ink-0);
  font-size: 0.95rem;
  width: 100%;
  outline: none;
}

.tags-popup-input::placeholder {
  color: var(--text-muted);
}

.tags-list {
  max-height: 200px;
  overflow-y: auto;
  padding: 8px 0;
}

.tag-option {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--ink-1);
}

.tag-option:hover, .tag-option.is-focused {
  background: var(--surface-0);
  color: var(--ink-0);
}

.tags-suggestions {
  padding: 8px 12px 4px;
  border-bottom: 1px solid var(--border);
}

.tags-suggestions-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 6px;
}

.tags-suggestions-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-suggestion-chip {
  border: 1px solid var(--border2);
  background: var(--bg3);
  color: var(--accent);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11.5px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s, border-color 0.12s;
}

.tag-suggestion-chip:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
}

.tag-option .tag-option-name {
  background: var(--bg-tertiary);
  border-radius: 4px;
  padding: 2px 6px;
}



/* Premium Sidebar Highlights Context Menu & Hover Actions */
.highlights-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 0;
}

.highlight-item {
  position: relative;
  background: transparent;
  padding: 0;
  margin-bottom: 24px;
  transition: all 0.2s ease;
  border: none;
  cursor: pointer;
}



.sidebar-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-2);
  margin-bottom: 6px;
  display: block;
}

.highlight-text {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--ink-0);
  margin-bottom: 0;
  border-radius: 4px;
}

.highlight-note {
  font-size: 0.85rem;
  color: var(--ink-2);
  margin-top: 12px;
  padding-left: 12px;
  border-left: 2px solid var(--line);
}

.hl-note-editor {
  margin-top: 12px;
}

.hl-note-input {
  width: 100%;
  min-height: 32px;
  background: transparent;
  border: none;
  border-left: 2px solid var(--line);
  padding: 4px 0 4px 12px;
  font-size: 0.86rem;
  color: var(--ink-2);
  resize: vertical;
  font-family: inherit;
  outline: none;
  transition: all 0.2s;
}

.hl-note-input:focus {
  border-left-color: var(--accent);
  color: var(--ink-0);
  background: var(--surface-0);
}

.hl-note-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  padding-left: 12px;
}

.btn-xs {
  padding: 4px 10px;
  font-size: 0.75rem;
  border-radius: 6px;
}

/* Floating Action Trigger */
.highlight-actions-trigger {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transform: translateY(4px);
  transition: all 0.2s ease;
  pointer-events: none;
}

.highlight-item:hover .highlight-actions-trigger {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.action-btn-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #1e293b;
  color: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
  transition: all 0.2s;
}

.action-btn-circle:hover {
  background: #0f172a;
  transform: scale(1.1);
}

.action-btn-circle.primary {
  background: var(--accent);
  color: white;
}
.action-btn-circle.primary:hover {
  filter: brightness(1.1);
}
.action-btn-circle.secondary {
  background: #f1f5f9;
  color: #64748b;
  box-shadow: none;
}
.action-btn-circle.secondary:hover {
  background: #e2e8f0;
}

.action-btn-circle.delete {
  background: #fee2e2;
  color: #ef4444;
}

.action-btn-circle.delete:hover {
  background: #fecaca;
}

/* Dark Context Menu */
.hl-context-menu {
  position: fixed;
  width: 240px;
  background: rgba(24, 26, 31, 0.9);
  backdrop-filter: blur(20px);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.1);
  padding: 8px 0;
  z-index: 2000;
  display: none;
  flex-direction: column;
  border: 1px solid rgba(255,255,255,0.05);
}

.hl-context-menu.is-visible {
  display: flex;
  animation: hl-menu-reveal 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes hl-menu-reveal {
  from { opacity: 0; transform: scale(0.95) translateY(-10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.hl-menu-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  color: #d1d5db;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.1s;
}

.hl-menu-item:hover {
  background: #272a30;
  color: #ffffff;
}

.hl-menu-item.danger {
  color: #f87171;
}

.hl-menu-item.danger:hover {
  background: #451a1a;
  color: #fca5a5;
}

.hl-menu-item .shortcut {
  color: #63666b;
  font-size: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.hl-menu-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 6px 0;
}

.hl-menu-footer {
  padding: 10px 16px;
  font-size: 0.7rem;
  color: #6b7280;
  background: rgba(0,0,0,0.1);
  border-top: 1px solid rgba(255,255,255,0.05);
  margin-top: 4px;
}

/* Remove obstructing bottom bar in passage view */
.passage-shell::after {
  display: none !important;
}

/* ========================================
   NEW SHELF UI - DASHBOARD (LIBRARY CALM)
   ======================================== */
.icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  vertical-align: middle;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 12px;
  font-weight: 750;
  font-size: 13px;
  transition: all 0.2s ease;
}

.btn:hover {
  background: var(--panel);
}

.btn.primary {
  border-color: var(--green);
  background: var(--green);
  color: var(--white);
}

.btn.primary:hover {
  background: var(--teal);
  border-color: var(--teal);
}

.btn.icon-only {
  width: 36px;
  justify-content: center;
  padding: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--green);
  padding: 4px 7px;
  font-size: 12px;
  font-weight: 700;
}

.progress {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,0.2);
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.doc-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  padding: 15px;
  display: grid;
  gap: 10px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.02);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s, transform 0.15s;
}

.doc-card:hover {
  border-color: var(--green);
  transform: translateY(-1px);
}

.doc-card h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
  letter-spacing: 0;
  color: var(--ink);
}

.doc-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.doc-meta {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--quiet);
  font-size: 12px;
  flex-wrap: wrap;
}

.concept-a {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  background: var(--panel);
  min-height: 100vh;
}

.a-sidebar {
  min-height: 100vh;
  padding: 20px 16px;
  border-right: 1px solid var(--line);
  background: var(--bg-tertiary);
  position: sticky;
  top: 0;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
  color: var(--ink);
}

.side-nav {
  display: grid;
  gap: 5px;
}

.side-nav button {
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  padding: 0 10px;
  text-align: left;
  font-weight: 700;
  transition: all 0.2s ease;
}

.side-nav button:hover {
  background: rgba(0,0,0,0.04);
}

.side-nav button.active {
  background: var(--line);
  color: var(--ink);
}

.side-label {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.count {
  color: var(--quiet);
  font-size: 12px;
  font-weight: 800;
}

.a-main {
  padding: 24px 30px 42px;
}

.a-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 20px;
}

.a-search {
  position: relative;
  flex: 1;
  max-width: 560px;
}

.a-search input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  padding: 0 14px 0 40px;
  outline: none;
  color: var(--ink);
  transition: border-color 0.2s;
}

.a-search input:focus {
  border-color: var(--green);
}

.a-search svg {
  position: absolute;
  left: 13px;
  top: 12px;
  color: var(--quiet);
}

.a-title-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 20px;
  margin-bottom: 20px;
}

.a-heading {
  border-radius: 8px;
  background: var(--white);
  border: 1px solid var(--line);
  padding: 20px;
}

.a-heading h2 {
  margin: 0 0 6px;
  font-size: 30px;
  letter-spacing: 0;
  color: var(--ink);
}

.a-heading p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.today-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-dark);
  color: var(--white);
  padding: 16px;
}

.today-panel strong {
  display: block;
  margin-bottom: 10px;
}

.today-panel p {
  margin: 0 0 12px;
  color: inherit;
  opacity: 0.8;
  font-size: 13px;
  line-height: 1.5;
}

.a-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 20px;
  align-items: start;
}

.section {
  display: grid;
  gap: 10px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.library-section-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.library-sort-wrap {
  position: relative;
}

.library-sort-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg3, var(--white));
  color: var(--text, var(--ink));
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.library-sort-trigger:hover {
  border-color: var(--accent, var(--green));
}

.library-sort-icon {
  width: 14px;
  height: 14px;
  opacity: 0.75;
}

.library-sort-chevron {
  width: 14px;
  height: 14px;
  opacity: 0.6;
}

.library-sort-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 120;
  min-width: 200px;
  padding: 6px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg3);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.library-sort-section-label {
  padding: 6px 12px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted, var(--text3));
}

.library-sort-option {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text, var(--ink));
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.library-sort-option:hover {
  background: var(--bg2, rgba(0, 0, 0, 0.04));
}

.library-sort-option.is-active::before {
  content: '✓';
  display: inline-block;
  width: 16px;
  margin-right: 4px;
  font-size: 12px;
  color: var(--accent, var(--green));
}

.library-sort-option:not(.is-active)::before {
  content: '';
  display: inline-block;
  width: 16px;
  margin-right: 4px;
}

.library-sort-divider {
  height: 1px;
  margin: 6px 0;
  background: var(--line);
}

.section-head h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
  color: var(--ink);
}

.reading-list {
  display: grid;
  gap: 10px;
}

.queue-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  padding: 12px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.2s;
}

.queue-card:hover {
  border-color: var(--green);
}

.source-tile {
  width: 42px;
  height: 42px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  color: var(--white);
  font-weight: 850;
  text-transform: uppercase;
}

.source-tile.blue { background: var(--blue); }
.source-tile.green { background: var(--green); }
.source-tile.rose { background: var(--rose); }
.source-tile.gold { background: var(--gold); }

.queue-card h3 {
  margin: 0 0 4px;
  font-size: 15px;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}

.queue-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.view-panel {
  display: none;
}

.view-panel.is-active {
  display: block;
}

@media (max-width: 980px) {
  .concept-a {
    grid-template-columns: 1fr;
  }
  .a-sidebar {
    display: none;
  }
  .a-title-row,
  .a-grid {
    grid-template-columns: 1fr;
  }
  .a-main {
    padding: 20px 16px;
  }
}

/* ========================================
   OVERHAUL SHELF DASHBOARD (SHELF2 STYLE)
   ======================================== */

/* --- Container breakout rules using :has --- */
body:has(#app) {
  overflow: hidden;
  background: var(--bg);
}
body:has(#app) .container {
  max-width: none;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
}
body:has(#app) div[style*="text-align:center"] {
  display: none !important;
}

/* Layout */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}
#sidebar {
  width: var(--sidebar);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Sidebar Components */
.sidebar-logo {
  padding: 20px 16px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.sidebar-logo:hover {
  opacity: 0.85;
}
.logo-mark {
  width: 30px;
  height: 30px;
  background: var(--accent);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  color: #0f0e0d;
  flex-shrink: 0;
}
.logo-text {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}
.sidebar-section {
  padding: 8px 8px;
  border-bottom: 1px solid var(--border);
}
.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  padding: 10px 10px 5px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: var(--r);
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text2);
  transition: all 0.12s;
  user-select: none;
  position: relative;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  text-decoration: none;
  box-sizing: border-box;
}
.nav-item:hover {
  background: var(--bg3);
  color: var(--text);
}
.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 500;
}
.nav-item svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  opacity: 0.8;
}
.nav-item.active svg {
  opacity: 1;
}
.nav-badge {
  margin-left: auto;
  background: var(--bg4);
  color: var(--text3);
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
  font-family: var(--font-mono);
}
.nav-item.active .nav-badge {
  background: var(--accent-bg);
  color: var(--accent);
}

/* Topbar */
#topbar {
  height: 52px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  flex-shrink: 0;
}
.topbar-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  font-family: var(--font-serif);
}
.search-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 5px 11px;
  width: 220px;
  transition: border-color 0.15s;
}
.search-wrap:focus-within {
  border-color: var(--border2);
}
.search-wrap input {
  background: transparent;
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--text);
  width: 100%;
  font-family: var(--font-sans);
}
.search-wrap input::placeholder {
  color: var(--text3);
}

/* Overriding and adding dashboard buttons */
#app .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: var(--r);
  border: 1px solid var(--border2);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: all 0.12s;
  font-family: var(--font-sans);
  white-space: nowrap;
  font-weight: 500;
  min-height: unset;
  height: 32px;
}
#app .btn:hover {
  background: var(--bg3);
  border-color: var(--border2);
  color: var(--text);
}
#app .btn-gold {
  background: var(--accent);
  color: #0f0e0d;
  border-color: var(--accent);
}
#app .btn-gold:hover {
  background: var(--accent2);
  border-color: var(--accent2);
  color: #0f0e0d;
}
#app #btn-add {
  width: 30px;
  height: 30px;
  padding: 0;
  justify-content: center;
}
#app .btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  height: 26px;
}
#app .btn-icon {
  padding: 6px 8px;
  width: auto;
}

/* Content */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}

/* Filter row */
.filter-row {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
#app .chip {
  height: 28px;
  padding: 0 11px;
  border-radius: 20px;
  font-size: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text2);
  background: transparent;
  transition: all 0.12s;
  font-family: var(--font-sans);
  font-weight: 500;
  display: inline-flex;
  line-height: 1;
  white-space: nowrap;
}
#app .chip:hover {
  border-color: var(--border2);
  color: var(--text);
}
#app .chip.on {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}

/* Continue reading */
.section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.continue-rail {
  display: flex;
  gap: 10px;
  margin-bottom: 28px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.continue-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  padding: 12px 14px;
  cursor: pointer;
  flex: 0 0 240px;
  transition: border-color 0.12s;
}
.continue-card:hover {
  border-color: var(--border2);
}
.continue-card-title {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--text);
}
.continue-card-sub {
  font-size: 11.5px;
  color: var(--text3);
  margin-bottom: 8px;
}
.prog-bar {
  position: relative;
  height: 2px;
  background: var(--bg4);
  border-radius: 2px;
  overflow: visible;
}
.prog-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}
.prog-position-dot {
  position: absolute;
  top: 50%;
  width: 3px;
  height: 3px;
  background: #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.2);
  z-index: 2;
  pointer-events: none;
}

/* Passages grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}
.pcard {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  padding: 15px 16px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  display: flex;
  flex-direction: column;
  gap: 0;
  text-decoration: none;
  color: var(--text);
}
.pcard:hover {
  border-color: var(--border2);
  background: var(--bg3);
}
.pcard-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
}
.type-pill {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  font-family: var(--font-mono);
  letter-spacing: 0.3px;
}
.tp-article {
  background: rgba(122, 184, 150, 0.15);
  color: var(--green);
}
.tp-fic {
  background: rgba(196, 120, 160, 0.18);
  color: #d48ab8;
}
.tp-pdf {
  background: rgba(200, 169, 110, 0.15);
  color: var(--accent);
}
.tp-epub {
  background: rgba(155, 143, 204, 0.15);
  color: var(--purple);
}
.tp-rss {
  background: rgba(122, 172, 200, 0.15);
  color: var(--blue);
}
.tp-video {
  background: rgba(220, 80, 80, 0.15);
  color: #e57373;
}
.tp-podcast {
  background: rgba(180, 130, 220, 0.15);
  color: #b39ddb;
}
.tp-tweet {
  background: rgba(29, 155, 240, 0.15);
  color: #1d9bf0;
}
.pcard-domain {
  font-size: 11px;
  color: var(--text3);
}
.pcard-date {
  font-size: 11px;
  color: var(--text3);
  margin-left: auto;
}
.pcard-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-family: var(--font-serif);
  color: var(--text);
}
.pcard-summary {
  font-size: 12.5px;
  color: var(--text2);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 10px;
}
.pcard-bottom {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: auto;
}
#app .tag {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 500;
  border: none;
  line-height: 1;
  display: inline-block;
}
.pcard-actions {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

/* Keyboard shortcut hints on hover */
[data-kbd] {
  position: relative;
}

[data-kbd]::after {
  content: attr(data-kbd);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 7px;
  border-radius: 6px;
  background: var(--bg4);
  border: 1px solid var(--border2);
  color: var(--text2);
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease, visibility 0.12s ease;
  z-index: 20;
}

[data-kbd]:hover::after,
[data-kbd]:focus-visible::after {
  opacity: 1;
  visibility: visible;
}

#app .btn[data-kbd]::after {
  bottom: calc(100% + 8px);
}

.search-wrap[data-kbd] {
  position: relative;
  cursor: pointer;
}

.search-wrap[data-kbd]::after {
  bottom: calc(100% + 6px);
}

.passage-card.is-kbd-target {
  box-shadow: inset 0 0 0 1px var(--accent);
}

.action-menu button[data-kbd],
.action-menu a[data-kbd] {
  position: relative;
}

.action-menu [data-kbd]::after {
  bottom: auto;
  top: 50%;
  left: auto;
  right: calc(100% + 8px);
  transform: translateY(-50%);
}
.pcard .icon-btn,
.pcard .icon-btn.action-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 5px;
  border-radius: 5px;
  color: var(--text3);
  transition: all 0.12s;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: auto;
  line-height: 1;
}
.pcard .icon-btn svg,
.pcard .icon-btn.action-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  display: block;
}
.pcard .icon-btn:hover,
.pcard .icon-btn.action-btn:hover {
  background: var(--bg4);
  color: var(--text);
}
.pcard .icon-btn.is-active,
.pcard .icon-btn.on,
.pcard .icon-btn.action-btn.is-active,
.pcard .icon-btn.action-btn.on {
  color: var(--accent);
  background: transparent;
}
.pcard .icon-btn.on-red,
.pcard .icon-btn.action-btn.on-red {
  color: var(--red);
  background: transparent;
}

/* RSS */
.feed-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  margin-bottom: 8px;
  transition: border-color 0.12s;
  color: var(--text);
}
.feed-item:hover {
  border-color: var(--border2);
}
.feed-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--r);
  background: rgba(122, 172, 200, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue);
  flex-shrink: 0;
}
.feed-name {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
}
.feed-url {
  font-size: 11.5px;
  color: var(--text3);
  margin-top: 1px;
}
.feed-count {
  font-size: 12px;
  color: var(--text3);
  font-family: var(--font-mono);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Feed reader */
.feed-reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.feed-reader-toolbar-left,
.feed-reader-toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.feed-filter-wrap,
.feed-sort-wrap {
  position: relative;
}
.feed-filter-trigger,
.feed-sort-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.feed-filter-trigger:hover,
.feed-sort-trigger:hover {
  border-color: var(--border2);
}
.feed-filter-menu,
.feed-sort-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 40;
  min-width: 200px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  padding: 4px;
}
.feed-filter-option,
.feed-sort-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--r);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.feed-filter-option:hover,
.feed-sort-option:hover,
.feed-filter-option.is-active,
.feed-sort-option.is-active {
  background: var(--bg3);
}
.feed-filter-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--accent);
  margin-left: 8px;
}
.feed-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid transparent;
}
.feed-tab {
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--text3);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -13px;
}
.feed-tab.is-active {
  color: var(--text);
  border-bottom-color: var(--text);
}
.feed-article-list {
  display: flex;
  flex-direction: column;
}
.feed-article-row {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 14px;
  align-items: start;
  padding: 16px 8px;
  border-bottom: 1px solid var(--border);
  position: relative;
  transition: background 0.12s;
}
.feed-article-row:hover {
  background: var(--bg2);
}
.feed-article-row.is-saved-flash {
  background: rgba(122, 172, 200, 0.08);
}
.feed-article-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r);
  background: var(--bg3);
  overflow: hidden;
  flex-shrink: 0;
  text-decoration: none;
}
.feed-article-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.feed-article-thumb-fallback {
  font-size: 18px;
}
.feed-article-body {
  min-width: 0;
  text-decoration: none;
  color: inherit;
}
.feed-article-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 4px;
  line-height: 1.35;
}
.feed-article-snippet {
  font-size: 13px;
  color: var(--text3);
  margin: 0 0 6px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.feed-article-meta {
  font-size: 12px;
  color: var(--text3);
}
.feed-article-meta-sep {
  margin: 0 4px;
  opacity: 0.6;
}
.feed-article-side {
  text-align: right;
  flex-shrink: 0;
  padding-top: 2px;
}
.feed-article-type {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text3);
  text-transform: uppercase;
}
.feed-article-date {
  display: block;
  font-size: 12px;
  color: var(--text3);
  margin-top: 2px;
  white-space: nowrap;
}
.feed-article-actions {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  gap: 2px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  padding: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.feed-article-row:hover .feed-article-actions {
  display: flex;
}
.feed-article-row:hover .feed-article-side {
  opacity: 0;
}
.feed-action-btn {
  color: var(--text3);
}
.feed-action-btn:hover {
  color: var(--text);
}
.feed-action-delete:hover {
  color: var(--red);
}
.feed-empty-hint {
  font-size: 13px;
  color: var(--text3);
  margin-top: 8px;
  max-width: 360px;
}
.feed-manage-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
}
.feed-manage-overlay[hidden] {
  display: none !important;
}
.feed-manage-dialog {
  width: 100%;
  max-width: 820px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.feed-manage-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.feed-manage-header h2 {
  margin: 0;
  font-size: 20px;
  flex: 1;
}
.feed-manage-tab {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  border-bottom: 2px solid var(--text);
  padding-bottom: 4px;
}
.feed-manage-toolbar {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.feed-manage-subscribe {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.feed-manage-subscribe input[type="url"] {
  flex: 2;
  min-width: 200px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg3);
  color: var(--text);
}
.feed-manage-subscribe input[type="text"] {
  flex: 1;
  min-width: 120px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--bg3);
  color: var(--text);
}
.feed-manage-table-wrap {
  padding: 0 24px 24px;
  overflow-x: auto;
}
.feed-manage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.feed-manage-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text3);
  padding: 12px 8px;
  border-bottom: 1px solid var(--border);
}
.feed-manage-table td {
  padding: 14px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.feed-manage-name {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.feed-manage-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--r);
  background: rgba(122, 172, 200, 0.15);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.feed-manage-title {
  font-weight: 500;
  color: var(--text);
}
.feed-manage-url {
  font-size: 11px;
  color: var(--text3);
  margin-top: 2px;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.feed-manage-count {
  font-family: var(--font-mono);
  color: var(--text2);
}
.feed-manage-updated {
  color: var(--text3);
  white-space: nowrap;
}
.feed-manage-actions {
  text-align: right;
  white-space: nowrap;
}
body.feed-manage-open {
  overflow: hidden;
}

@media (max-width: 720px) {
  .feed-article-row {
    grid-template-columns: 40px 1fr;
  }
  .feed-article-side {
    display: none;
  }
  .feed-article-actions {
    display: flex;
    position: static;
    transform: none;
    margin-top: 8px;
    grid-column: 1 / -1;
    justify-content: flex-end;
    box-shadow: none;
    border: none;
    background: transparent;
    padding: 0;
  }
  .feed-article-row:hover .feed-article-side {
    opacity: 1;
  }
}

/* Tags */
.tag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.tag-card {
  display: block;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.12s;
  color: var(--text);
  text-decoration: none;
}
.tag-card:hover {
  border-color: var(--accent);
}
.tag-card-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 3px;
}
.tag-card-count {
  font-size: 12px;
  color: var(--text3);
  font-family: var(--font-mono);
}

/* Empty State */
.empty {
  text-align: center;
  padding: 64px 20px;
  color: var(--text3);
}
.empty-icon {
  font-size: 36px;
  margin-bottom: 12px;
  display: block;
  opacity: 0.4;
}
.empty p {
  font-size: 15px;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.section-head h2 {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.count-pill {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text3);
  background: var(--bg3);
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

/* Custom styling override for search results input inside main views */
.dashboard-search-input {
  background: var(--bg3) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
.dashboard-search-input::placeholder {
  color: var(--text3) !important;
}
.search-panel-status {
  color: var(--text2) !important;
}

/* Actions Menu adaptation */
.pcard .action-menu-container {
  position: relative;
  display: inline-block;
}
.pcard .action-menu {
  position: absolute;
  top: auto;
  bottom: calc(100% + 8px);
  right: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  z-index: 100;
  min-width: 140px;
  overflow: hidden;
}
.pcard .action-menu.is-open {
  display: flex !important;
}
.pcard:has(.action-menu.is-open) {
  position: relative;
  z-index: 50;
  overflow: visible;
}
.pcard .action-menu button,
.pcard .action-menu a {
  border: none;
  background: transparent;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text2);
  text-align: left;
  cursor: pointer;
  width: 100%;
  display: block;
}
.pcard .action-menu button:hover,
.pcard .action-menu a:hover {
  background: var(--bg3);
  color: var(--text);
}
.pcard .action-menu button.danger {
  color: var(--red);
}
.pcard .action-menu button.danger:hover {
  background: rgba(204, 138, 122, 0.1);
}
.pcard .unread-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

/* --- Inline visible actions override for dashboard card bottom-right --- */
.pcard .passage-card-actions {
  position: static;
  opacity: 1;
  pointer-events: auto;
  background: transparent;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  border: none;
  display: flex;
  gap: 2px;
  margin-left: auto;
}

/* ── Dashboard Display Settings ── */

/* Card Layout: List mode */
#content.layout-list .grid {
  grid-template-columns: 1fr !important;
  gap: 6px;
}
#content.layout-list .pcard {
  flex-direction: row;
  align-items: flex-start;
  gap: 14px;
  padding: 11px 14px;
}
#content.layout-list .pcard-summary { display: none; }
#content.layout-list .prog-bar { display: none; }
#content.layout-list .pcard-title {
  -webkit-line-clamp: 1;
  margin-bottom: 2px;
  font-size: 13.5px;
}
#content.layout-list .pcard-top { margin-bottom: 3px; }
#content.layout-list .pcard-bottom { margin-top: 4px; }

/* Card Density: Compact */
#content.density-compact .pcard { padding: 10px 12px; }
#content.density-compact .pcard-title { font-size: 13px; }
#content.density-compact .pcard-summary { -webkit-line-clamp: 2; }
#content.density-compact .grid { gap: 8px; }

/* Card Density: Comfortable */
#content.density-comfortable .pcard { padding: 20px 22px; }
#content.density-comfortable .grid { gap: 16px; }
#content.density-comfortable .pcard-title { font-size: 15px; }
#content.density-comfortable .pcard-summary { -webkit-line-clamp: 4; }

/* Unread dot */
.unread-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  margin-right: 5px;
  vertical-align: middle;
  position: relative;
  top: -1px;
}

/* ── Timeline view ── */

.timeline-section-head {
  align-items: flex-start;
}

.timeline-subtitle {
  font-size: 13px;
  color: var(--text2);
  margin: 6px 0 0;
  max-width: 520px;
}

.timeline-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 12px 0 16px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.timeline-mode-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.timeline-scrubber-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.timeline-scrubber {
  flex: 1;
  accent-color: var(--accent);
  height: 4px;
}

.timeline-scrubber-label {
  font-size: 12px;
  color: var(--text2);
  white-space: nowrap;
  min-width: 140px;
  text-align: right;
}

.timeline-rail {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 44px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.timeline-rail-seg {
  flex: 1 1 4px;
  min-width: 4px;
  max-width: 24px;
  height: var(--seg-h, 16px);
  border: none;
  border-radius: 3px 3px 1px 1px;
  background: var(--border2);
  cursor: pointer;
  padding: 0;
  transition: background 0.15s, transform 0.15s;
}

.timeline-rail-seg:hover,
.timeline-rail-seg.is-active {
  background: var(--accent);
  transform: scaleY(1.05);
}

.timeline-stream {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding-bottom: 48px;
}

.timeline-day {
  scroll-margin-top: 120px;
  border-left: 2px solid var(--border);
  padding-left: 18px;
  margin-left: 4px;
  transition: border-color 0.3s;
}

.timeline-day-highlight {
  border-left-color: var(--accent);
}

.timeline-day-header {
  margin-bottom: 10px;
}

.timeline-day-title {
  font-family: var(--font-family-display);
  font-size: 17px;
  font-weight: 500;
  margin: 0 0 4px;
  color: var(--text);
}

.timeline-day-meta {
  font-size: 12px;
  color: var(--text3);
}

.timeline-day-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.timeline-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--r);
  background: var(--bg3);
  border: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.timeline-item:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.timeline-item-type {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text3);
  flex-shrink: 0;
}

.timeline-item-title {
  font-size: 14px;
  flex: 1 1 200px;
  min-width: 0;
}

.timeline-item-domain {
  font-size: 12px;
  color: var(--text2);
}

.timeline-item-fallback {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text3);
  background: var(--bg2);
  padding: 2px 6px;
  border-radius: 4px;
}

/* ── Topic map ── */

.topics-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.topics-lead {
  font-size: 13px;
  color: var(--text2);
  margin: 8px 0 0;
  max-width: 560px;
  line-height: 1.55;
}

.topics-meta {
  font-size: 11px;
  color: var(--text3);
  margin: 8px 0 0;
}

.topics-header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.topics-view-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.topics-map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 12px;
}

.topics-map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.legend-cluster {
  background: var(--accent);
}

.legend-hub {
  background: var(--green);
  border: 2px solid var(--bg3);
}

.legend-line {
  width: 18px;
  height: 0;
  border-top: 2px dashed var(--purple);
  display: inline-block;
}

.topics-map-layout {
  display: grid;
  grid-template-columns: 1fr minmax(220px, 280px);
  gap: 16px;
  align-items: start;
}

@media (max-width: 900px) {
  .topics-map-layout {
    grid-template-columns: 1fr;
  }
}

.topics-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  margin: 12px 0 16px;
}

.topics-controls .topics-view-toggle {
  margin: 0;
}

.topics-graph-wrap {
  border: 1px solid var(--border);
  border-radius: var(--r2);
  background: var(--bg3);
  overflow: hidden;
  min-height: 360px;
}

.topics-graph-svg {
  display: block;
  width: 100%;
}

.topics-graph-edge {
  stroke: var(--border2);
  stroke-width: 1.2;
}

.topics-graph-edge.is-hub {
  stroke: var(--accent);
  stroke-opacity: 0.45;
}

.topics-graph-edge.is-member {
  stroke: var(--text3);
  stroke-opacity: 0.35;
}

.topics-graph-edge.is-bridge {
  stroke: var(--purple);
  stroke-dasharray: 5 4;
  stroke-opacity: 0.7;
}

.topics-graph-node .node-cluster {
  fill: var(--accent-bg);
  stroke: var(--accent);
  stroke-width: 2.5;
}

.topics-graph-node .node-highlight {
  fill: #7aacc8;
  stroke: var(--bg, #111);
  stroke-width: 1.5;
}

.topics-graph-node .node-highlight.node-hub {
  fill: #c8a96e;
  stroke-width: 2;
}

.topics-detail-quote {
  margin: 8px 0;
  padding: 8px 10px;
  border-left: 3px solid var(--accent, #c8a96e);
  font-style: italic;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text2, inherit);
}

.topics-detail-note {
  font-size: 12px;
  color: var(--muted, #888);
  margin: 6px 0;
}

.topics-detail-sub {
  font-size: 11px;
  color: var(--muted, #888);
  margin-top: 2px;
}

.topics-graph-node .node-passage {
  stroke: var(--bg3);
  stroke-width: 2;
}

.topics-graph-node .node-hub {
  stroke: var(--green);
  stroke-width: 2.5;
}

.topics-graph-label {
  font-size: 10px;
  fill: var(--text2);
  pointer-events: none;
  font-family: var(--font-sans);
}

.topics-graph-node.is-selected .node-cluster,
.topics-graph-node.is-selected .node-hub {
  filter: url(#topic-glow);
}

.topics-graph-node.is-dimmed {
  opacity: 0.25;
}

.topics-graph-detail {
  border: 1px solid var(--border);
  border-radius: var(--r2);
  background: var(--bg2);
  padding: 16px;
  min-height: 200px;
}

.topics-graph-detail h3 {
  font-family: var(--font-family-display);
  font-size: 16px;
  margin: 0 0 6px;
}

.topics-graph-detail-empty,
.topics-detail-meta {
  font-size: 12px;
  color: var(--text3);
  margin: 0;
}

.topics-detail-list {
  list-style: none;
  margin: 12px 0;
  padding: 0;
  font-size: 13px;
}

.topics-detail-list li {
  padding: 6px 0;
  border-top: 1px solid var(--line);
}

.topics-detail-list a {
  color: inherit;
  text-decoration: none;
}

.topics-detail-list a:hover {
  color: var(--accent);
}

.hub-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--green);
  margin-right: 4px;
}

.topics-theme-card {
  border: 1px solid var(--border);
  border-radius: var(--r2);
  background: var(--bg3);
  padding: 16px 18px;
}

.topics-theme-card-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.topics-theme-card h2 {
  font-family: var(--font-family-display);
  font-size: 17px;
  margin: 0 0 4px;
}

.topics-theme-card-meta {
  font-size: 12px;
  color: var(--text3);
  margin: 0;
}

.topics-theme-card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.topics-theme-tags {
  margin-bottom: 12px;
}

.topics-theme-passages {
  list-style: none;
  margin: 0;
  padding: 0;
}

.topics-theme-passages li {
  border-top: 1px solid var(--line);
  padding: 8px 0;
}

.topics-theme-passages li.is-hub a {
  font-weight: 500;
}

.topics-theme-passages a {
  color: inherit;
  text-decoration: none;
  font-size: 14px;
}

.topics-theme-passages .source-label {
  font-size: 11px;
  color: var(--text3);
  margin-left: 6px;
}

.topics-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.reader-related-hint {
  font-size: 12px;
  color: var(--text3);
  margin: 0 0 10px;
  line-height: 1.45;
}

/* ========================================
   MOBILE — Shelf dashboard (#app)
   ======================================== */

/* Higher specificity than #app .btn so the toggle stays hidden on desktop */
#app .mobile-nav-toggle {
  display: none;
  flex-shrink: 0;
  padding: 6px 8px;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 768px) {
  #app .mobile-nav-toggle {
    display: inline-flex;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(15, 14, 13, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  body.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 160;
    width: min(280px, 88vw);
    max-width: 100%;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.18);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  body.sidebar-open #sidebar {
    transform: translateX(0);
  }

  #topbar {
    height: auto;
    min-height: 52px;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top, 0));
    gap: 8px;
    flex-wrap: wrap;
  }

  .topbar-title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .search-wrap {
    order: 3;
    flex: 1 1 100%;
    width: 100%;
    max-width: none;
  }

  #topbar .btn-gold {
    flex-shrink: 0;
    padding: 6px 10px;
  }

  #content {
    padding: 16px 12px 24px;
    padding-bottom: max(24px, env(safe-area-inset-bottom, 0));
    -webkit-overflow-scrolling: touch;
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .continue-card {
    flex: 0 0 min(220px, 78vw);
  }

  .section-head {
    flex-wrap: wrap;
    gap: 8px;
  }

  .filter-row {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-right: -12px;
    padding-right: 12px;
  }

  .filter-row::-webkit-scrollbar {
    display: none;
  }

  #content.layout-list .pcard {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .feed-item {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .feed-count {
    margin-left: auto;
  }

  .tag-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }

  .timeline-scrubber-wrap {
    flex-wrap: wrap;
  }

  .timeline-scrubber-label {
    min-width: 0;
    flex: 1 1 100%;
    text-align: left;
  }

  #global-tags-popup.tags-popup {
    position: fixed;
    width: min(280px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    max-height: min(360px, calc(100dvh - 24px));
    overflow: hidden;
  }

  #global-tags-popup .tags-popup-header,
  #global-tags-popup .tags-suggestions {
    flex-shrink: 0;
  }

  #global-tags-popup .tags-selected {
    max-height: 82px;
    margin-top: 8px;
    margin-bottom: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  #global-tags-popup .tags-popup-scroll {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 230px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }

  #global-tags-popup .tags-list {
    max-height: none;
    overflow: visible;
  }

  .create-overlay {
    inset: auto 0 auto 0;
    top: var(--create-viewport-top, 0px);
    height: var(--create-viewport-height, 100dvh);
    padding: 12px;
    align-items: flex-end;
    box-sizing: border-box;
  }

  .create-modal {
    width: 100%;
    max-height: calc(var(--create-viewport-height, 100dvh) - 24px);
    border-radius: 20px 20px 0 0;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .create-modal-title {
    font-size: 22px;
    margin-bottom: 20px;
  }

  .create-tabs {
    width: 100%;
  }

  .create-tab {
    font-size: 10px;
    padding: 9px 8px;
  }

  .create-modal-footer {
    margin-top: 22px;
    position: sticky;
    bottom: 0;
    z-index: 1;
    background: var(--create-bg);
  }

  .create-panel.is-active {
    min-height: 0;
    overflow-y: auto;
  }

  .ds-modal {
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
  }

  .settings-overlay {
    align-items: stretch;
    padding: 0;
  }

  .notification-toast {
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom, 0));
  }
}

@media (max-width: 480px) {
  .pcard {
    padding: 12px 14px;
  }

  .pcard-actions {
    flex-wrap: wrap;
  }
}

/* Calibre → Kindle: a compact editorial shelf, designed for phone-first queueing. */
.calibre-browser { max-width: 1120px; margin: 0 auto; }
.calibre-hero {
  display: flex; align-items: end; justify-content: space-between; gap: 24px;
  padding: 28px; margin-bottom: 16px; border: 1px solid var(--border);
  background: linear-gradient(135deg, var(--bg2) 0 70%, var(--accent-bg) 100%);
  border-radius: 6px;
}
.calibre-kicker { margin: 0 0 8px; color: var(--accent); text-transform: uppercase; letter-spacing: .14em; font: 600 10px var(--font-mono); }
.calibre-hero h2 { margin: 0; max-width: 680px; font: 600 clamp(24px, 4vw, 42px)/1.05 var(--font-serif); letter-spacing: -.035em; }
.calibre-hero p:last-child { margin: 12px 0 0; max-width: 620px; color: var(--text2); font-size: 13px; }
.calibre-queue-count { flex: none; padding: 8px 11px; border: 1px solid var(--border2); border-radius: 999px; color: var(--text2); font: 600 11px var(--font-mono); }
.calibre-search { display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 15px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg2); }
.calibre-search:focus-within { border-color: var(--accent); }
.calibre-search svg { width: 17px; color: var(--text3); }
.calibre-search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font: 14px var(--font-sans); }
.calibre-status { min-height: 38px; padding: 12px 2px 8px; color: var(--text3); font: 11px var(--font-mono); }
.calibre-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.calibre-book { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 14px; min-height: 112px; padding: 12px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg2); }
.calibre-cover { width: 72px; height: 104px; overflow: hidden; border-radius: 2px; background: var(--bg4); box-shadow: 0 7px 16px rgba(0,0,0,.2); }
.calibre-cover img { width: 100%; height: 100%; object-fit: cover; }
.calibre-cover.is-placeholder { display: grid; place-items: center; color: var(--text3); font: 600 28px var(--font-serif); }
.calibre-book-copy { min-width: 0; display: flex; flex-direction: column; align-items: start; }
.calibre-book h3 { margin: 2px 0 5px; font: 600 15px/1.2 var(--font-serif); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.calibre-book p { margin: 0; color: var(--text3); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.calibre-send { margin-top: auto; padding: 6px 9px; border: 1px solid var(--accent); border-radius: 3px; background: transparent; color: var(--accent); cursor: pointer; font: 600 11px var(--font-sans); }
.calibre-send:hover { background: var(--accent-bg); }
.calibre-send.is-queued { border-color: var(--border2); color: var(--text2); }
.calibre-send:disabled { opacity: .65; cursor: wait; }
.calibre-more-row { display: flex; justify-content: center; padding: 24px 0 8px; }
.calibre-more-row[hidden] { display: none; }
.calibre-more { min-width: 210px; padding: 10px 18px; border: 1px solid var(--border2); border-radius: 3px; background: var(--bg2); color: var(--text2); cursor: pointer; font: 600 12px var(--font-sans); }
.calibre-more:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-bg); }
.calibre-more:disabled { opacity: .55; cursor: wait; }

@media (max-width: 600px) {
  .calibre-hero { align-items: start; padding: 20px; flex-direction: column; }
  .calibre-grid { grid-template-columns: 1fr; }
  .calibre-book { grid-template-columns: 64px minmax(0, 1fr); }
  .calibre-cover { width: 64px; height: 94px; }
}

/* Standalone pages (upload, search, settings) without #app */
@media (max-width: 768px) {
  .navbar .nav-inner {
    flex-direction: column;
    align-items: stretch;
    min-height: auto;
    padding: 12px 14px;
    gap: 10px;
  }

  .navbar .logo {
    text-align: center;
  }

  .navbar .nav-links {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .navbar .search-form {
    width: 100%;
  }

  .navbar .search-form input {
    flex: 1;
    min-width: 0;
    width: 100%;
  }

  .container {
    padding: 16px 14px 28px;
  }

  .upload-page,
  .search-page,
  .form-container,
  .passage-detail {
    padding: 14px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}
