:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --text-dim: #9aa3b2;
  --primary: #6366f1;
  --primary-hover: #545bdd;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --sidebar-w: 280px;
  --zoom: 1;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

/* Light theme overrides */
html[data-theme="light"] {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #d9dde3;
  --text: #1c2024;
  --text-dim: #66707d;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}
html[data-theme="nord"] {
  --bg: #e5e9f0;
  --surface: #eceff4;
  --surface-2: #d8dee9;
  --border: #c8d0de;
  --text: #2e3440;
  --text-dim: #4c566a;
  --shadow: 0 8px 30px rgba(46, 52, 64, 0.1);
}
html[data-theme="sepia"] {
  --bg: #f4ecd8;
  --surface: #fdf6e3;
  --surface-2: #e9dfc6;
  --border: #d3c7a8;
  --text: #433422;
  --text-dim: #7c6a52;
  --shadow: 0 8px 30px rgba(67, 52, 34, 0.08);
}
html[data-theme="cyberpunk"] {
  --bg: #0d0e15;
  --surface: #171925;
  --surface-2: #222538;
  --border: #ff0055; /* Neon Pink accent borders */
  --text: #00ffcc; /* Neon Cyan text */
  --text-dim: #94a3b8;
  --shadow: 0 8px 30px rgba(255, 0, 85, 0.25);
}

html, body {
  margin: 0;
  height: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
}

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; max-width: 100vw; overflow-x: hidden; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px 18px;
  overflow-y: auto;
  overflow-x: hidden;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
}

.main {
  flex: 1;
  padding: 26px 30px 60px;
  min-width: 0;
  margin-left: var(--sidebar-w);
}

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 16px; }
.brand-mark { font-size: 22px; }
.brand-name { font-size: 19px; font-weight: 700; letter-spacing: 0.2px; }
.settings-gear {
  margin-left: auto; background: transparent; border: none; color: var(--text-dim);
  font-size: 18px; line-height: 1; cursor: pointer; padding: 6px; border-radius: 8px;
}
.settings-gear:hover { color: var(--text); background: var(--surface-2); }

/* ---------- Nav ---------- */
.nav-section { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: transparent; border: none; color: var(--text-dim);
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 500;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; }

/* ---------- Sidebar Footer ---------- */
.sidebar-footer-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  margin-top: 14px;
  transition: all 0.15s;
}
.sidebar-footer-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--primary);
}
.footer-icon {
  font-size: 18px;
  line-height: 1;
}
.footer-text {
  flex: 1;
}

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  text-transform: uppercase; letter-spacing: 0.08em;
  font-size: 11px; font-weight: 700; color: var(--text-dim);
  margin: 16px 8px 6px;
}

.settings-form { display: flex; flex-direction: column; gap: 14px; }
.settings-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); font-weight: 500; }
.settings-form select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: 9px; font-size: 14px; cursor: pointer; font-family: inherit;
}
.settings-form select:focus { outline: none; border-color: var(--primary); }
.settings-form input[type="password"], .settings-form input[type="email"], .settings-form input[type="text"] {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: 9px; font-size: 14px; font-family: inherit;
}
.settings-form input[type="password"]:focus, .settings-form input[type="email"]:focus, .settings-form input[type="text"]:focus {
  outline: none; border-color: var(--primary);
}
.modal-hint { margin: 0 0 4px; font-size: 13px; color: var(--text-dim); }
.settings-section { border-top: 1px solid var(--border); padding-top: 16px; margin-top: 4px; display: flex; flex-direction: column; gap: 12px; }
.settings-section h3 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text); }
.settings-divider { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.settings-subhead { margin: 0; font-size: 15px; font-weight: 600; color: var(--text); }
.import-action { align-self: flex-end; }
.import-status { margin: 4px 0 0; font-size: 13px; color: var(--text); min-height: 18px; }
.settings-form input[type="file"] {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 9px 12px; border-radius: 9px; font-size: 13px; font-family: inherit; cursor: pointer;
}
.settings-form input[type="file"]::file-selector-button {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 6px 10px; border-radius: 7px; margin-right: 10px; cursor: pointer; font-size: 13px;
}

.section-actions { display: flex; gap: 4px; }

.mini-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  width: 22px; height: 22px; border-radius: 6px; cursor: pointer; line-height: 1;
  font-size: 15px;
}
.mini-btn:hover { color: var(--text); border-color: var(--primary); }

/* ---------- Tree ---------- */
.tree { display: flex; flex-direction: column; gap: 1px; }
.tree-row {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 8px; border-radius: 8px; cursor: pointer; color: var(--text-dim);
  font-size: 14px; position: relative; min-height: 34px;
}
.tree-row:hover { background: var(--surface-2); color: var(--text); }
.tree-row.active { background: var(--surface-2); color: var(--text); }
.tree-row .twisty { width: 14px; text-align: center; font-size: 10px; color: var(--text-dim); flex-shrink: 0; }
.tree-row .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.tree-row .col-icon { width: 16px; text-align: center; font-size: 14px; line-height: 1; flex-shrink: 0; }
.tree-row .label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-row .count { font-size: 11px; color: var(--text-dim); background: var(--surface-2); padding: 1px 6px; border-radius: 10px; }
.tree-row .row-actions { display: none; gap: 2px; }
.tree-row:hover .row-actions { display: flex; }
.row-actions button {
  background: transparent; border: none; color: var(--text-dim); cursor: pointer;
  font-size: 12px; border-radius: 4px;
  width: 20px; height: 20px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  line-height: 1; overflow: hidden;
}
.row-actions button:hover { color: var(--text); background: var(--bg); }
.tree-children { margin-left: 12px; border-left: 1px solid var(--border); padding-left: 4px; }

/* ---------- Tags ---------- */
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 6px; }
.tag-chip {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  padding: 3px 10px; border-radius: 999px; font-size: 12px; cursor: pointer;
}
.tag-chip:hover { color: var(--text); border-color: var(--primary); }
.tag-chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Main header ---------- */
.main-title-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.main-title-row h1 { font-size: 24px; margin: 0; }
.main-title-actions { display: flex; gap: 8px; align-items: center; }

.controls { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search {
  flex: 1; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 10px 14px; border-radius: 10px; font-size: 14px;
}
.search:focus, .select:focus { outline: none; border-color: var(--primary); }
.select {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: 10px; font-size: 14px; cursor: pointer;
}

/* View toggle (segmented control) */
.view-toggle { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.view-toggle button {
  background: transparent; border: none; color: var(--text-dim);
  padding: 10px 12px; font-size: 15px; cursor: pointer; line-height: 1;
}
.view-toggle button:hover { color: var(--text); }
.view-toggle button.active { background: var(--primary); color: #fff; }

.select-toggle {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-dim);
  padding: 10px 12px; border-radius: 10px; font-size: 15px; line-height: 1; cursor: pointer;
}
.select-toggle:hover { color: var(--text); }
.select-toggle.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.options-menu { position: relative; }
.options-dropdown {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 40;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px; min-width: 210px;
  display: flex; flex-direction: column; gap: 2px;
}
.option-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  background: transparent; border: none; color: var(--text);
  padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.option-item:hover { background: var(--surface-2); }
.option-check { width: 14px; color: var(--primary); opacity: 0; flex-shrink: 0; }
.option-item.active .option-check { opacity: 1; }

/* List view layout (reuses the same .card markup) */
.bookmark-grid.list-view { grid-template-columns: 1fr; gap: 8px; }
.list-view .card { flex-direction: row; align-items: center; gap: 14px; padding: 10px 14px; }
.list-view .card:hover { transform: none; }
.list-view .card-top { flex: 1 1 auto; min-width: 0; }
.list-view .card-desc { display: none; }
.list-view .card-tags { flex: 0 0 auto; margin: 0; position: relative; display: inline-flex; }
.list-view .card-tags-trigger {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; font-size: 11px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  cursor: default; white-space: nowrap;
}
.list-view .card-tags:hover .card-tags-trigger { color: var(--text); border-color: var(--primary); }
.list-view .card-tags-list {
  display: none;
  position: absolute; top: calc(100% + 4px); right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px; box-shadow: var(--shadow); max-width: 280px;
}
.list-view .card-tags:hover .card-tags-list { display: flex; flex-wrap: wrap; gap: 5px; }
.list-view .card-meta { margin: 0; padding: 0; flex: 0 0 auto; gap: 14px; }
@media (max-width: 640px) {
  .list-view .card-tags { display: none; }
}

.active-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.filter-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--primary); color: #fff; padding: 4px 10px; border-radius: 999px; font-size: 12px;
}
.filter-pill button { background: transparent; border: none; color: #fff; cursor: pointer; font-size: 13px; line-height: 1; }

/* ---------- Bookmark grid ---------- */
.bookmark-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0;
  transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: #3a4150; transform: translateY(-2px); }
.card { cursor: grab; }
.card.dragging { opacity: 0.5; cursor: grabbing; border-color: var(--primary); }
.tree-row.drop-target {
  background: var(--primary); color: #fff;
  outline: 2px dashed rgba(255,255,255,0.6); outline-offset: -2px;
}
.tree-row.drop-target .count { background: rgba(255,255,255,0.25); color: #fff; }
.tree-item.reorder-mode {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  background: rgba(99, 102, 241, 0.12);
  border-radius: 6px;
}
/* Cross-collection folder move: highlight target collection row */
.tree-row.cross-collection-drop-target {
  background: rgba(99, 102, 241, 0.15);
  outline: 2px dashed var(--primary);
  outline-offset: -2px;
  border-radius: 6px;
}
.drag-handle:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 2px;
}
.card-top { display: flex; align-items: flex-start; gap: 10px; }
.favicon {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  background: var(--surface-2); display: grid; place-items: center; font-size: 16px;
  overflow: hidden;
}
.favicon img { width: 100%; height: 100%; object-fit: cover; }
.card-titles { min-width: 0; flex: 1; }
.card-title { font-weight: 600; font-size: 15px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-title a { color: var(--text); text-decoration: none; }
.card-title a:hover { color: var(--primary); }
.card-url { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-desc { font-size: 13px; color: var(--text-dim); margin: 0; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.card-tags-trigger { display: none; }
.card-tags-list { display: contents; }
.card-tags .tag-chip { padding: 2px 8px; font-size: 11px; }
.card-meta { display: flex; align-items: center; justify-content: flex-end; margin-top: auto; padding-top: 4px; cursor: default; }
.card-actions { display: flex; gap: 4px; flex-shrink: 0; }
.card-actions button {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  width: 32px; height: 32px; border-radius: 7px; cursor: pointer; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1; padding: 0;
}
.card-actions button:hover { color: var(--text); border-color: var(--primary); }
.card-actions button.fav-active { color: #f5b50a; border-color: #f5b50a; }

/* Bulk selection */
.card { position: relative; }
.card.selected { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.card-select { display: flex; align-items: center; padding-top: 4px; cursor: pointer; flex-shrink: 0; }
.card-select input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); margin: 0; }
.bookmark-grid:not(.selecting) .card-select { display: none; }

.bulk-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--primary);
  border-radius: 10px; padding: 8px 12px; margin-bottom: 12px;
}
.bulk-count { font-size: 13px; font-weight: 600; margin-right: 2px; }
.bulk-bar .select { padding: 7px 10px; }
.bulk-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 7px 11px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.bulk-btn:hover { border-color: var(--primary); }
.bulk-btn.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.bulk-btn#bulkClear { margin-left: auto; }

/* Export */
.export-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tag manager */
.tag-manager { 
  display: flex; 
  flex-direction: column; 
  gap: 8px; 
  max-height: 340px; 
  overflow-y: auto; 
  overflow-x: hidden;
  margin: 12px 0 4px;
  padding-right: 4px; /* Space for scrollbar */
}
.tag-row { 
  display: flex; 
  gap: 8px; 
  align-items: center;
  padding-right: 4px; /* Ensure delete button stays visible */
}
.tag-row input {
  flex: 1;
  min-width: 0; /* Allow flex shrinking */
  max-width: calc(100% - 50px); /* Reserve space for delete button and gap */
  background: var(--bg); 
  border: 1px solid var(--border); 
  color: var(--text);
  padding: 8px 10px; 
  border-radius: 8px; 
  font-size: 14px; 
  font-family: inherit;
}
.tag-row input:focus { outline: none; border-color: var(--primary); }
.tag-row-del {
  width: 34px; 
  height: 34px; 
  background: var(--surface-2); 
  border: 1px solid var(--border);
  color: var(--text-dim); 
  border-radius: 8px; 
  cursor: pointer; 
  flex-shrink: 0;
}
.tag-row-del:hover { color: var(--text); border-color: var(--danger); }

.nav-item.drop-target {
  background: var(--primary); color: #fff;
  outline: 2px dashed rgba(255,255,255,0.6); outline-offset: -2px;
}

/* ---------- Context Menu ---------- */
.context-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 200px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.context-menu[hidden] { display: none; }
.context-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 9px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}
.context-item:hover { background: var(--surface-2); }
.context-item.context-danger { color: var(--danger); }
.context-item.context-danger:hover { background: rgba(239, 68, 68, 0.1); }
.context-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ---------- Toast Notification ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Duplicate Detection ---------- */
.duplicate-info {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin: 12px 0;
}
.duplicate-info-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 6px;
  word-break: break-word;
}
.duplicate-info-url {
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-all;
  margin-bottom: 6px;
}
.duplicate-info-location {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

/* ---------- Keyboard Shortcuts ---------- */
.shortcuts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px 0;
}
.shortcut-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 8px;
}
.shortcut-keys {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.shortcut-keys kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, "Courier New", monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  min-width: 28px;
  text-align: center;
}
.shortcut-desc {
  flex: 1;
  font-size: 14px;
  color: var(--text-dim);
  text-align: right;
}

/* ---------- Buttons ---------- */
.btn-primary {
  background: var(--primary); color: #fff; border: none; padding: 10px 16px;
  border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost {
  background: transparent; color: var(--text-dim); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; cursor: pointer;
}
.btn-ghost:hover { color: var(--text); }
.btn-danger {
  background: var(--danger); color: #fff; border: none; padding: 10px 16px;
  border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-danger:hover { filter: brightness(1.1); }
.icon-btn {
  background: transparent; border: none; color: var(--text); font-size: 22px;
  cursor: pointer; width: 40px; height: 40px; border-radius: 8px;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 80px 20px; color: var(--text-dim); }
.empty-emoji { font-size: 52px; margin-bottom: 12px; }
.empty-state p { margin: 0 0 18px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: grid; place-items: center; padding: 20px; z-index: 100;
  overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: min(460px, calc(100vw - 40px)); padding: 24px; box-shadow: var(--shadow);
}
.modal-sm { max-width: 380px; }
.modal h2 { margin: 0 0 16px; font-size: 19px; }
.modal form { display: flex; flex-direction: column; gap: 14px; }
#bmExtraFields { display: flex; flex-direction: column; gap: 14px; }
#bmExtraFields[hidden] { display: none; }
.modal label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); font-weight: 500; }
.modal input[type="text"], .modal input[type="url"], .modal input[type="password"], .modal input[type="email"], .modal textarea, .modal select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: 9px; font-size: 14px; font-family: inherit;
}
.modal input:focus, .modal textarea:focus, .modal select:focus { outline: none; border-color: var(--primary); }
.modal input[type="color"] { width: 48px; height: 36px; padding: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }

.icon-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); font-weight: 500; }
.icon-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.icon-opt {
  width: 36px; height: 36px; font-size: 18px; line-height: 1; padding: 0;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-opt:hover { border-color: var(--primary); }
.icon-opt.active { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.icon-opt.none { color: var(--text-dim); font-size: 14px; }
.icon-custom {
  margin-top: 2px; width: 140px; background: var(--bg); border: 1px solid var(--border);
  color: var(--text); padding: 8px 10px; border-radius: 8px; font-size: 16px; font-family: inherit;
}
.icon-custom:focus { outline: none; border-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

.tag-suggest { display: flex; flex-direction: column; gap: 6px; margin-top: -6px; }
.tag-suggest-label { font-size: 13px; color: var(--text-dim); font-weight: 500; }
.tag-suggest-chips { display: flex; flex-wrap: wrap; gap: 6px; max-height: 96px; overflow-y: auto; }
.tag-suggest-chips .tag-chip { font-size: 12px; padding: 3px 10px; }

/* ---------- Topbar (mobile) ---------- */
.topbar { display: none; }
.sidebar-overlay { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 50;
  }
  .topbar-title { font-weight: 700; font-size: 17px; }
  #addBookmarkTop { display: none; }

  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 60;
    height: 100vh; transform: translateX(-100%); transition: transform 0.22s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay.show {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 55;
  }

  .main { padding: 18px 16px 60px; margin-left: 0; }
  .main-title-row h1 { font-size: 20px; }
  .main-title-actions .btn-primary {
    font-size: 0;
    line-height: 0;
    padding: 9px 11px;
  }
  .main-title-actions #addBookmark::before {
    content: "+";
    font-size: 18px;
    line-height: 1;
    font-weight: 700;
  }
  .bookmark-grid { grid-template-columns: 1fr; }
  .controls .view-toggle { flex-shrink: 0; width: auto; }
}

@media (max-width: 480px) {
  .controls { flex-wrap: wrap; }
  .controls .search { flex: 1 1 100%; }
  .controls .select { width: auto; flex: none; }
  .controls .view-toggle { flex-shrink: 0; width: auto; }
  .controls .options-menu { flex-shrink: 0; }
}


/* ---------- Trash card icon (shared) ---------- */
.note-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-size: 16px;
}


/* ---------- Trash View ---------- */
.trash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.trash-retention {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
}
.trash-empty-btn {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 8px;
  white-space: nowrap;
}
.trash-card .trash-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.trash-type-badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}
.trash-date {
  font-size: 12px;
  color: var(--text-dim);
}
.trash-days-left {
  font-size: 12px;
  color: var(--danger);
  font-weight: 500;
}
.trash-action-btn {
  padding: 6px 12px !important;
  font-size: 12px !important;
  width: auto !important;
  height: auto !important;
  border-radius: 7px !important;
}
.trash-card .card-meta {
  gap: 8px;
}
.trash-card .card-actions {
  gap: 8px;
}

.trash-retention-hint {
  background: transparent !important;
  border: none !important;
  color: var(--text-dim) !important;
  font-size: 13px !important;
  cursor: default !important;
  pointer-events: none;
}

/* ---------- Nav Count Badges ---------- */
.nav-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--surface-2);
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 500;
}
.nav-item.active .nav-count {
  background: rgba(255,255,255,0.2);
  color: #fff;
}


/* ---------- Sync Folder ---------- */
.sync-folder-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.sync-folder-path {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


/* ---------- Settings Dropdown ---------- */
.settings-menu-wrap {
  margin-left: auto;
  position: relative;
}
.settings-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 180px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.settings-dropdown[hidden] { display: none; }
.settings-dropdown button {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 9px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}
.settings-dropdown button:hover { background: var(--surface-2); }


/* ---------- Auth Overlay ---------- */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 500;
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-overlay[hidden] { display: none; }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 24px;
}
.auth-brand .brand-mark { font-size: 28px; }
.auth-brand .brand-name { font-size: 22px; font-weight: 700; }

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 4px;
}
.auth-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 10px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.active { background: var(--primary); color: #fff; }

.auth-overlay form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-overlay form[hidden] { display: none; }
.auth-overlay label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
}
.auth-overlay input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 14px;
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
}
.auth-overlay input:focus { outline: none; border-color: var(--primary); }

.auth-submit {
  margin-top: 6px;
  width: 100%;
  padding: 12px;
  font-size: 15px;
}

.auth-msg {
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 8px;
  margin: 0 0 12px;
}
.auth-error { background: rgba(239,68,68,0.1); color: #f87171; border: 1px solid rgba(239,68,68,0.2); }
.auth-success { background: rgba(16,185,129,0.1); color: #34d399; border: 1px solid rgba(16,185,129,0.2); }

.auth-mfa-prompt {
  font-size: 14px;
  color: var(--text-dim);
  margin: 0 0 14px;
}

/* ---------- User Menu ---------- */
.user-menu-wrap {
  margin-left: 6px;
  position: relative;
}
.user-avatar-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: grid;
  place-items: center;
}
.user-avatar-btn:hover { border-color: var(--primary); }

.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px;
  min-width: 200px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.user-menu-dropdown[hidden] { display: none; }

.user-email {
  font-size: 12px;
  color: var(--text-dim);
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  word-break: break-all;
}

.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 9px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}
.user-menu-item:hover { background: var(--surface-2); }
.user-menu-signout { color: var(--danger); }
.user-menu-signout:hover { background: rgba(239,68,68,0.1); }

/* ---------- MFA Enrollment ---------- */
.mfa-qr-wrap {
  display: flex;
  justify-content: center;
  margin: 16px 0;
}
.mfa-qr-img {
  width: 200px;
  height: 200px;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}
.mfa-secret-label {
  font-size: 13px;
  color: var(--text-dim);
  margin: 8px 0 4px;
}
.mfa-secret {
  display: block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
  color: var(--text);
  word-break: break-all;
  margin-bottom: 16px;
}
.mfa-verify-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.mfa-verify-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
}
.mfa-verify-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 9px;
  font-size: 16px;
  font-family: inherit;
  letter-spacing: 4px;
  text-align: center;
}
.mfa-verify-form input:focus { outline: none; border-color: var(--primary); }


/* ---------- Settings Dropdown: User Email & Sign Out ---------- */
.dropdown-user-email {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px 10px 6px;
  word-break: break-all;
  font-weight: 500;
}
.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}
.dropdown-signout {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--danger);
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}
.dropdown-signout:hover {
  background: rgba(239, 68, 68, 0.1);
}


/* ---------- Recovery Key Modal ---------- */
.recovery-key-warning {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
}
.recovery-key-warning p {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--text);
}
.recovery-key-warning ul {
  margin: 0;
  padding-left: 20px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.7;
}
.recovery-key-warning li {
  margin-bottom: 4px;
}

.recovery-key-display {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.recovery-key-value {
  flex: 1;
  display: block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12px;
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
  color: var(--text);
  word-break: break-all;
  line-height: 1.6;
  user-select: all;
}
.recovery-key-copy {
  flex-shrink: 0;
  padding: 10px 14px;
}

.recovery-key-confirm {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 8px;
  margin-bottom: 16px;
}
.recovery-key-confirm input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 1px;
  accent-color: var(--primary);
  flex-shrink: 0;
}
.recovery-key-confirm span {
  line-height: 1.5;
}

/* ---------- Forgot Password / Reset Request View ---------- */
.auth-forgot-password {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  margin-top: -4px;
  align-self: flex-end;
  font-family: inherit;
}
.auth-forgot-password:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

#authResetRequestSection {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#authResetRequestSection[hidden] { display: none; }

.auth-back-to-signin {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  font-family: inherit;
  text-decoration: underline;
  align-self: center;
  margin-top: 4px;
}
.auth-back-to-signin:hover {
  color: var(--primary-hover);
}

/* Recovery prompt in auth overlay */
.recovery-help-text {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.6;
}
.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
  font-family: inherit;
}
.btn-link:hover {
  color: var(--primary-hover);
}

/* Auth overlay textarea for recovery key */
.auth-overlay textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 14px;
  border-radius: 9px;
  font-size: 13px;
  font-family: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
  resize: vertical;
  width: 100%;
}
.auth-overlay textarea:focus {
  outline: none;
  border-color: var(--primary);
}


/* ---------- Pagination ---------- */
.pagination-bar {
  margin-bottom: 14px;
  padding-top: 0;
}
.pagination-bar .card-actions {
  align-items: center;
}
.pagination-label {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  color: var(--text-dim);
  padding: 0 6px;
  line-height: 32px;
}
html[data-theme="light"] .pagination-bar .card-actions button {
  background: #ffffff;
}


/* ---------- Results Total Count ---------- */
.results-total-count {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 16px 0 0;
  margin: 0;
}


/* ---------- Drag-and-Drop Reorder ---------- */
.drag-handle {
  cursor: grab;
  opacity: 0;
  font-size: 12px;
  line-height: 1;
  color: var(--text-dim);
  flex-shrink: 0;
  width: 14px;
  text-align: center;
  user-select: none;
  transition: opacity 0.15s;
}
.tree-row:hover .drag-handle { opacity: 0.5; }
.drag-handle:hover { opacity: 1 !important; }
.drag-handle:focus { opacity: 1 !important; outline: 2px solid var(--primary); outline-offset: 1px; border-radius: 3px; }

.tree-row.dragging { opacity: 0.4; }

.drop-indicator {
  height: 2px;
  background: var(--primary);
  border-radius: 1px;
  pointer-events: none;
  margin: -1px 8px;
  position: relative;
  z-index: 10;
}

.reorder-active {
  outline: 2px solid #6366f1;
  outline-offset: -1px;
  border-radius: 8px;
}

body.grabbing { cursor: grabbing !important; }
body.grabbing * { cursor: grabbing !important; }
body.no-select { user-select: none; }

/* ---------- Danger Zone ---------- */
.danger-zone {
  margin-top: 24px;
}
.danger-zone-title {
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}
.danger-zone-bordered {
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 16px;
}
.danger-zone-warning {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 12px;
}
