:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #697386;
  --line: #e2e7ef;
  --brand: #3157d5;
  --brand-dark: #2445b7;
  --danger: #c43c3c;
  --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.brand { font-size: 28px; font-weight: 800; letter-spacing: -0.04em; color: var(--brand); text-decoration: none; }
.brand-small { font-size: 20px; }
.home-body { min-height: 100vh; background: radial-gradient(circle at top, #eef2ff, var(--bg) 52%); }
.home-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.home-card { width: min(100%, 510px); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 34px; box-shadow: 0 18px 50px rgba(34, 48, 82, .08); }
h1 { font-size: clamp(28px, 5vw, 38px); line-height: 1.08; letter-spacing: -.035em; margin: 14px 0 12px; }
.lead { color: var(--muted); line-height: 1.55; margin: 0 0 24px; }
.stack { display: grid; gap: 10px; }
.stack label { display: grid; gap: 6px; font-size: 13px; font-weight: 650; }
input, select, textarea { width: 100%; border: 1px solid #ccd4e0; border-radius: 9px; padding: 10px 11px; background: #fff; color: var(--text); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(49, 87, 213, .12); }
.input-with-action { position: relative; display: block; }
.input-with-action input { padding-right: 38px; }
.clear-field { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; padding: 0; border-radius: 6px; background: transparent; color: #8a94a5; font-size: 20px; line-height: 1; }
.clear-field:hover, .clear-field:focus { background: #eef1f7; color: #4e5a70; }
button { border: 0; border-radius: 9px; padding: 9px 13px; font-weight: 650; }
.primary { background: var(--brand); color: white; }
.primary:hover { background: var(--brand-dark); }
.secondary { background: #eef1f7; color: #26344f; }
.ghost { background: transparent; color: var(--muted); }
.danger { background: #feecec; color: var(--danger); }
.compact { padding: 7px 10px; font-size: 13px; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
.divider { display: flex; align-items: center; gap: 10px; color: #98a1b1; margin: 22px 0; }
.divider::before, .divider::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.privacy-note, .hint { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 18px 0 0; }
.error { color: #a92424; background: #fff0f0; border: 1px solid #ffd1d1; border-radius: 8px; padding: 9px 11px; }
.topbar { height: 52px; background: var(--panel); border-bottom: 1px solid var(--line); display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 0 18px; position: sticky; top: 0; z-index: 10; }
.collection-title-wrap { min-width: 0; }
.title-button { background: transparent; padding: 6px 8px; max-width: 100%; display: inline-flex; align-items: center; gap: 6px; }
.title-button span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edit-glyph { color: #9aa4b3; }
.icon-button { background: #eef1f7; padding: 7px 11px; }
.icon-button.icon-only,
.tool-icon-button,
.app-menu-close {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}
.ui-icon {
  width: 19px;
  height: 19px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.grip-icon circle { fill: currentColor; stroke: none; }
.tool-icon-group { display: inline-flex; align-items: center; gap: 5px; }
.tool-icon-button { background: #eef1f7; color: #4f5d73; }
.tool-icon-button:hover:not(:disabled), .icon-button.icon-only:hover { background: #e2e7f0; color: #26344f; }
.tool-icon-button[aria-pressed="true"] { background: var(--brand); color: #fff; }
.tool-icon-button[aria-pressed="true"]:hover { background: var(--brand-dark); color: #fff; }
.tool-icon-button:disabled { opacity: .4; cursor: default; }
#collapse-all .expand-all-icon { display: none; }
#collapse-all[data-action="expand"] .collapse-all-icon { display: none; }
#collapse-all[data-action="expand"] .expand-all-icon { display: block; }
.link-target-toggle .same-window-icon { display: none; }
.link-target-toggle[aria-pressed="false"] .new-window-icon { display: none; }
.link-target-toggle[aria-pressed="false"] .same-window-icon { display: block; }

body.menu-open { overflow: hidden; }
.app-menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(18, 25, 38, .58);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.app-menu-overlay[hidden] { display: none !important; }
.app-menu-panel {
  width: min(100%, 360px);
  background: var(--panel);
  border: 1px solid rgba(226, 231, 239, .9);
  border-radius: 18px;
  padding: 14px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .28);
}
.app-menu-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 2px 12px 8px; }
.app-menu-header h2 { margin: 0; font-size: 18px; }
.app-menu-close { background: transparent; color: #697386; }
.app-menu-close:hover, .app-menu-close:focus-visible { background: #eef1f7; color: #26344f; }
.app-menu-actions { display: grid; gap: 8px; }
.app-menu-action {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  background: #f2f4f8;
  color: #26344f;
  text-align: left;
  border: 1px solid transparent;
}
.app-menu-action .ui-icon { width: 20px; height: 20px; color: #5d6b82; }
.app-menu-action:hover, .app-menu-action:focus-visible { background: #eaf0ff; border-color: #d6e0ff; color: #1f3f9e; }
.app-menu-action:hover .ui-icon, .app-menu-action:focus-visible .ui-icon { color: currentColor; }
.app-shell { width: min(100%, 980px); margin: 0 auto; padding: 14px 16px 40px; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.share-strip { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 8px 10px; background: #eef2ff; border: 1px solid #dbe3ff; border-radius: 10px; margin-top: 10px; }
.share-label { font-size: 12px; font-weight: 700; color: #4c5b82; }
.share-strip input { padding: 6px 8px; background: rgba(255,255,255,.72); font-size: 12px; }
.bookmark-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; min-height: 120px; }
.tree-row { min-height: 34px; display: flex; align-items: center; gap: 5px; border-bottom: 1px solid #edf0f4; padding: 2px 7px 2px calc(7px + var(--depth) * 22px); }
.tree-row:last-child { border-bottom: 0; }
.tree-row:hover { background: #f8faff; }
.tree-toggle { width: 24px; height: 28px; padding: 0; background: transparent; color: #6f7888; border-radius: 5px; flex: 0 0 auto; }
.tree-toggle:disabled { cursor: default; color: #c2c7d0; }
.tree-toggle.spacer { display: grid; place-items: center; }
.row-icon { width: 20px; text-align: center; font-size: 14px; flex: 0 0 auto; }
.folder-name { min-width: 0; flex: 1; background: transparent; text-align: left; padding: 5px 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #25314a; }
.bookmark-link { min-width: 0; flex: 1; text-decoration: none; padding: 5px 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #243a79; }
.bookmark-link:hover { text-decoration: underline; }
.bookmark-host { color: #99a2b1; font-size: 11px; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edit-button { opacity: .25; background: transparent; color: #55627a; font-size: 11px; padding: 5px 7px; flex: 0 0 auto; }
.tree-row:hover .edit-button, .edit-button:focus { opacity: 1; background: #eef1f7; }
.empty-state, .loading { min-height: 160px; display: grid; place-items: center; align-content: center; gap: 6px; color: var(--muted); }
.empty-state strong { color: var(--text); }
.modal { width: min(calc(100% - 28px), 520px); border: 0; border-radius: 14px; padding: 0; box-shadow: 0 24px 80px rgba(0,0,0,.25); }
.modal::backdrop { background: rgba(18, 25, 38, .45); }
.modal form { padding: 18px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.modal-header h2 { margin: 0; font-size: 19px; }
.close-button { font-size: 24px; line-height: 1; background: transparent; color: #727d8f; padding: 3px 7px; }
.modal-actions { display: flex; gap: 8px; align-items: center; margin-top: 18px; }
.modal-spacer { flex: 1; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #172033; color: white; padding: 9px 13px; border-radius: 9px; box-shadow: 0 8px 30px rgba(0,0,0,.2); z-index: 100; }
@media (max-width: 640px) {
  .home-shell { padding: 14px; }
  .home-card { padding: 24px 20px; }
  .topbar { padding: 0 10px; gap: 8px; }
  .app-shell { padding: 10px 8px 28px; }
  .share-strip { grid-template-columns: 1fr auto; }
  .share-label { display: none; }
  .bookmark-host { display: none; }
  .tree-row { padding-left: calc(4px + var(--depth) * 16px); gap: 2px; min-height: 38px; }
  .edit-button { opacity: .7; }
  .toolbar { position: sticky; top: 52px; z-index: 9; background: var(--bg); padding: 6px 0; margin-top: -4px; }
}

/* Pointer-based drag and drop for mouse, touch and pen. */
.drag-handle {
  width: 30px;
  height: 30px;
  padding: 0;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: transparent;
  color: #7c8799;
  border-radius: 6px;
  font-size: 17px;
  line-height: 1;
  cursor: grab;
  touch-action: none;
  user-select: none;
  opacity: .38;
}
.tree-row:hover .drag-handle,
.drag-handle:focus { opacity: 1; background: #eef1f7; }
.dragging { user-select: none; }
.dragging .drag-handle { cursor: grabbing; }
.drag-source { opacity: .22; pointer-events: none; }
.drag-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  opacity: .9;
  background: #fff;
  border: 1px solid #cdd6e4;
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(27, 38, 62, .2);
}
.tree-row.drop-before { box-shadow: inset 0 3px 0 #3157d5; }
.tree-row.drop-after { box-shadow: inset 0 -3px 0 #3157d5; }
.tree-row.drop-inside { background: #eaf0ff; box-shadow: inset 0 0 0 2px #3157d5; }
.tree-row.drop-invalid { background: #fff1f1; box-shadow: inset 0 0 0 2px #c43c3c; }
.bookmark-panel.root-drop-active { box-shadow: inset 0 0 0 2px #3157d5; }

@media (max-width: 640px) {
  .drag-handle { width: 34px; height: 34px; opacity: .72; font-size: 19px; }
  .tool-icon-button { width: 38px; height: 38px; }
  .app-menu-overlay { padding: 16px; }
  .app-menu-panel { width: 100%; }
}

/* Offline/PWA state. Collection contents are read-only when served from IndexedDB. */
.offline-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid #ead7a0;
  border-radius: 9px;
  background: #fff9e8;
  color: #6d5720;
  font-size: 12px;
  font-weight: 650;
}
.offline-status[hidden] { display: none !important; }
.offline-status .ui-icon { width: 16px; height: 16px; flex: 0 0 auto; }
.offline-mode .title-button:disabled,
.edit-button:disabled,
.app-menu-action:disabled {
  cursor: not-allowed;
  opacity: .42;
}
.offline-mode .title-button:disabled { background: transparent; }
.app-menu-action:disabled:hover,
.app-menu-action:disabled:focus-visible {
  background: #f2f4f8;
  border-color: transparent;
  color: #26344f;
}

@media (max-width: 640px) {
  .offline-status { margin-bottom: 8px; }
}
