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

:root {
  --sidebar-w: 280px;
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3150;
  --accent: #5b6af0;
  --accent-hover: #4a59e0;
  --accent-soft: rgba(91,106,240,0.12);
  --text: #e2e4f0;
  --text-muted: #7c82a8;
  --text-dim: #4a5080;
  --danger: #e05c6a;
  --danger-soft: rgba(224,92,106,0.12);
  --success: #4caf8a;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body.light {
  --bg: #f0f2f8;
  --surface: #ffffff;
  --surface2: #e8eaf4;
  --border: #d0d4e8;
  --accent: #4a59e0;
  --accent-hover: #3a49d0;
  --accent-soft: rgba(74,89,224,0.10);
  --text: #1a1d2e;
  --text-muted: #4a5280;
  --text-dim: #9098bc;
  --danger: #c0394a;
  --danger-soft: rgba(192,57,74,0.10);
  --success: #2e8a65;
  --shadow: 0 4px 24px rgba(0,0,0,0.10);
}

/* smooth theme transitions */
body { transition: background .25s, color .25s; }
.topbar, .sidebar, .modal, .bookmark-card, .toast,
.tree-item, .btn, .form-input, .form-select,
.sidebar-header, .main-header { transition: background .25s, border-color .25s, color .25s; }

/* theme toggle button */
.theme-toggle {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all .15s;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
body.light .theme-toggle .icon-sun  { display: block; }
body.light .theme-toggle .icon-moon { display: none; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Top Bar ── */
.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  flex-shrink: 0;
  z-index: 10;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.3px;
}

.topbar-logo svg { color: var(--accent); }

.topbar-spacer { flex: 1; }

.hub-link {
  margin-left: 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
}
.hub-link:hover { color: var(--accent); }

.topbar-search {
  position: relative;
  width: 260px;
}

.topbar-search input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px 7px 34px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color .2s;
}

.topbar-search input::placeholder { color: var(--text-dim); }
.topbar-search input:focus { border-color: var(--accent); }

.topbar-search svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.btn-icon {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all .15s;
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* ── Layout ── */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 14px 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.sidebar-header span {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.btn-add-folder {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  border: none;
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  cursor: pointer;
  font-weight: 500;
  transition: all .15s;
}
.btn-add-folder:hover { background: var(--accent); color: #fff; }

.folder-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.folder-tree::-webkit-scrollbar { width: 4px; }
.folder-tree::-webkit-scrollbar-track { background: transparent; }
.folder-tree::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.tree-item {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  margin: 1px 8px;
  cursor: pointer;
  gap: 6px;
  font-size: 13.5px;
  color: var(--text-muted);
  transition: all .15s;
  user-select: none;
  position: relative;
}

.tree-item:hover { background: var(--surface2); color: var(--text); }
.tree-item.active { background: var(--accent-soft); color: var(--accent); }
.tree-item.active .tree-icon { color: var(--accent); }

.tree-indent { display: flex; align-items: center; gap: 0; }
.tree-indent-line {
  width: 16px; height: 100%;
  display: inline-block;
  border-left: 1px solid var(--border);
  margin-left: 8px;
  flex-shrink: 0;
  min-height: 22px;
}

.tree-toggle {
  width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--text-dim);
  transition: transform .2s;
}
.tree-toggle.open { transform: rotate(90deg); }
.tree-toggle-placeholder { width: 16px; flex-shrink: 0; }

.tree-icon { flex-shrink: 0; color: var(--text-dim); }

.tree-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-count {
  font-size: 11px;
  background: var(--surface2);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
}

.tree-actions {
  display: none;
  gap: 2px;
  align-items: center;
}
.tree-item:hover .tree-actions { display: flex; }

.tree-action-btn {
  width: 22px; height: 22px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all .15s;
}
.tree-action-btn:hover { background: var(--surface); color: var(--text); }
.tree-action-btn.delete:hover { color: var(--danger); background: var(--danger-soft); }

/* ── Main Content ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.main-header {
  padding: 20px 28px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}
.breadcrumb-sep { color: var(--text-dim); }
.breadcrumb-current { color: var(--text); font-weight: 600; font-size: 16px; }

.main-header-spacer { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }
.btn-secondary:hover { color: var(--text); border-color: var(--accent); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border: 1px solid transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; }

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
}

.main-content::-webkit-scrollbar { width: 5px; }
.main-content::-webkit-scrollbar-track { background: transparent; }
.main-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  color: var(--text-dim);
  gap: 12px;
  text-align: center;
}
.empty-state svg { color: var(--text-dim); opacity: .5; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text-muted); }
.empty-state p { font-size: 13px; }

/* ── Bookmark Grid ── */
.bookmarks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.bookmark-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color .2s, box-shadow .2s;
  position: relative;
}
.bookmark-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow);
}

.bookmark-card-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.bookmark-favicon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.bookmark-favicon img { width: 20px; height: 20px; }

.bookmark-info { flex: 1; min-width: 0; }
.bookmark-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}
.bookmark-url {
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bookmark-actions {
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity .15s;
}
.bookmark-card:hover .bookmark-actions { opacity: 1; }

.bookmark-action-btn {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
}
.bookmark-action-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.bookmark-action-btn.delete:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

/* ── Search Results ── */
.search-results-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.search-results-label strong { color: var(--text); }

.bookmark-folder-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--surface2);
  border-radius: 4px;
  padding: 2px 7px;
  margin-top: 4px;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: 420px;
  max-width: 95vw;
  box-shadow: var(--shadow);
  transform: scale(.96) translateY(8px);
  transition: transform .2s;
}
.modal-overlay.open .modal { transform: scale(1) translateY(0); }

.modal-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}

.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.form-input, .form-select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font-size: 13.5px;
  outline: none;
  transition: border-color .2s;
  font-family: inherit;
}
.form-input:focus, .form-select:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-dim); }
.form-select { cursor: pointer; }
.form-select option { background: var(--surface2); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex; flex-direction: column;
  gap: 8px;
  z-index: 200;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 10px;
  animation: toastIn .25s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.idle-lock-toast { border-left: 3px solid var(--accent); align-items: flex-start; gap: 10px; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── No folder selected ── */
.no-selection {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%;
  color: var(--text-dim);
  gap: 14px;
}
.no-selection svg { opacity: .3; }
.no-selection p { font-size: 14px; }

/* ── Real-time Validators ── */

/* character counter */
.char-counter {
  font-size: 11px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-dim);
  transition: color .2s;
}
.char-counter.warn  { color: #e0a050; }
.char-counter.limit { color: var(--danger); }

/* inline field feedback (folder name) */
.field-feedback {
  min-height: 18px;
  margin-top: 5px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all .2s;
}
.field-feedback.ok      { color: var(--success); }
.field-feedback.warn    { color: #e0a050; }
.field-feedback.error   { color: var(--danger); }
.field-feedback.neutral { color: var(--text-dim); }

/* URL checker panel */
.url-checker {
  margin-top: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  overflow: hidden;
  transition: border-color .2s;
}
.url-checker.ok   { border-color: var(--success); }
.url-checker.warn { border-color: #e0a050; }
.url-checker.error{ border-color: var(--danger); }
.url-checker.checking { border-color: var(--accent); }

.url-checker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
}

.url-checker-icon { display: flex; align-items: center; flex-shrink: 0; }

.url-checker-msg { color: var(--text-muted); flex-shrink: 0; }

.url-checker-domain {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-left: auto;
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

/* spinner */
.spinner {
  width: 13px; height: 13px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* URL preview strip */
.url-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.url-favicon {
  width: 16px; height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
}
.url-preview-domain {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* input state borders */
.form-input.input-ok    { border-color: var(--success) !important; }
.form-input.input-warn  { border-color: #e0a050 !important; }
.form-input.input-error { border-color: var(--danger) !important; }
.form-input.input-checking { border-color: var(--accent) !important; }

/* ── Password Protection ── */
.password-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.password-input-wrap .form-input {
  padding-right: 38px;
}
.pwd-toggle-btn {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  padding: 0;
  transition: color .15s;
}
.pwd-toggle-btn:hover { color: var(--text-muted); }

.pwd-hint {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.pwd-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
  animation: shake .3s ease;
}

@keyframes shake {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-6px); }
  75%      { transform: translateX(6px); }
}

/* lock icon on folder tree */
.tree-lock {
  color: var(--accent);
  opacity: .75;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.tree-item.locked .tree-icon { color: var(--accent); opacity: .8; }

/* lock circle on prompt modal */
.lock-icon-circle {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* locked overlay on main panel */
.locked-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  gap: 14px;
  color: var(--text-dim);
  text-align: center;
}
.locked-overlay .lock-big {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.locked-overlay h3 { font-size: 16px; font-weight: 600; color: var(--text-muted); }
.locked-overlay p  { font-size: 13px; }

/* ── Settings Modal ── */
.settings-section {
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  padding-bottom: 20px;
}

.settings-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.settings-section-desc {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

.settings-path-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.settings-path-display {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12px;
  font-family: monospace;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.settings-import-mode {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.settings-radio {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

.settings-radio input[type="radio"] {
  margin-top: 2px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.settings-radio strong { color: var(--text); }

/* password badge in breadcrumb */
.pwd-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 20px;
  padding: 2px 8px;
  font-weight: 500;
  margin-left: 4px;
  cursor: pointer;
  transition: background .15s;
}
.pwd-badge:hover { background: var(--accent); color: #fff; }
