/* =========================================
   DESIGN TOKENS — LIGHT THEME
========================================= */

:root {
  --bg:             #f0f2f7;
  --bg-secondary:   #e8eaf0;
  --panel:          #ffffff;
  --panel-soft:     #f8f9fc;
  --panel-raised:   #ffffff;

  --border:         #e2e5ed;
  --border-light:   #edf0f5;

  --text:           #0f1117;
  --text-soft:      #6b7280;
  --text-xsoft:     #9ca3af;

  --accent:         #3b5bdb;
  --accent-soft:    #e8edff;
  --accent-hover:   #2f4ac7;
  --accent-active:  #2540b0;

  --success:        #0d9488;
  --success-soft:   #e0f7f4;
  --warning:        #d97706;
  --warning-soft:   #fef3c7;
  --danger:         #dc2626;
  --danger-soft:    #fee2e2;
  --info:           #0284c7;
  --info-soft:      #e0f2fe;

  --hover:          #eef1ff;
  --focus-ring:     rgba(59, 91, 219, 0.35);

  --shadow-xs:      0 1px 2px rgba(0,0,0,.04);
  --shadow-sm:      0 1px 3px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  --shadow:         0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.07);
  --shadow-md:      0 4px 20px rgba(0,0,0,.10);
  --shadow-hover:   0 8px 28px rgba(0,0,0,.12);
  --shadow-float:   0 16px 48px rgba(0,0,0,.14);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;

  --radius-xs:   6px;
  --radius-sm:   10px;
  --radius:      14px;
  --radius-lg:   20px;
  --radius-pill: 999px;

  --font-sans: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'DM Mono', 'Fira Code', ui-monospace, monospace;

  --text-xs:   11px;
  --text-sm:   13px;
  --text-base: 14px;
  --text-md:   15px;
  --text-lg:   17px;
  --text-xl:   20px;

  --topbar-height: 68px;
  --sidebar-width: 300px;
  --details-width: 340px;

  --transition:        0.18s ease;
  --transition-slow:   0.28s ease;
  --transition-spring: 0.28s cubic-bezier(.4, 0, .2, 1);
}

/* =========================================
   DESIGN TOKENS — DARK THEME
========================================= */

[data-theme="dark"] {
  --bg:           #0c1220;
  --bg-secondary: #101826;
  --panel:        #131d2e;
  --panel-soft:   #162031;
  --panel-raised: #1a2840;

  --border:       #1e2d42;
  --border-light: #1a2638;

  --text:       #e8edf5;
  --text-soft:  #8a9ab8;
  --text-xsoft: #5a6b85;

  --accent:        #6585f5;
  --accent-soft:   rgba(101, 133, 245, .14);
  --accent-hover:  #7898f8;
  --accent-active: #8aaafa;

  --success:      #14b8a6;
  --success-soft: rgba(20, 184, 166, .12);
  --warning:      #fbbf24;
  --warning-soft: rgba(251, 191, 36, .10);
  --danger:       #f87171;
  --danger-soft:  rgba(248, 113, 113, .12);
  --info:         #38bdf8;
  --info-soft:    rgba(56, 189, 248, .12);

  --hover:      #1a2840;
  --focus-ring: rgba(101, 133, 245, .40);

  --shadow-xs:    0 1px 2px rgba(0,0,0,.30);
  --shadow-sm:    0 1px 3px rgba(0,0,0,.35), 0 2px 8px rgba(0,0,0,.25);
  --shadow:       0 1px 3px rgba(0,0,0,.40), 0 6px 20px rgba(0,0,0,.35);
  --shadow-md:    0 6px 24px rgba(0,0,0,.45);
  --shadow-hover: 0 10px 32px rgba(0,0,0,.55);
  --shadow-float: 0 20px 60px rgba(0,0,0,.65);
}

/* =========================================
   RESET & BASE
========================================= */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition-slow), color var(--transition-slow);
}

img {
  display: block;
  max-width: 100%;
}

button, input, select, textarea {
  font: inherit;
}

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

a:hover {
  text-decoration: underline;
}

[hidden] {
  display: none !important;
}

/* =========================================
   ICON SYSTEM
========================================= */

.icon {
  display: inline-flex;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  stroke-width: 2;
  vertical-align: middle;
  pointer-events: none;
}

.icon-sm { width: 14px; height: 14px; }
.icon-md { width: 18px; height: 18px; }
.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 24px; height: 24px; }

/* =========================================
   BUTTON SYSTEM
========================================= */

.btn,
label.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 40px;
  min-width: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  cursor: pointer;
  outline: none;
  transition:
    background var(--transition),
    color var(--transition),
    border-color var(--transition),
    box-shadow var(--transition),
    transform var(--transition),
    opacity var(--transition);
}

.btn:focus-visible {
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(59, 91, 219, .20);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 4px 14px rgba(59, 91, 219, .28);
  transform: translateY(-1px);
}
.btn-primary:active {
  background: var(--accent-active);
  transform: translateY(0);
  box-shadow: none;
}

.btn-secondary {
  background: var(--panel-soft);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover {
  background: var(--hover);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.btn-secondary:active {
  transform: translateY(0);
  box-shadow: none;
}

.btn-ghost {
  background: transparent;
  color: var(--text-soft);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--hover);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:active {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}
.btn-danger:hover {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 14px rgba(220, 38, 38, .25);
  transform: translateY(-1px);
}
.btn-danger:active {
  transform: translateY(0);
  box-shadow: none;
}

.btn-sm {
  height: 34px;
  padding: 0 12px;
  font-size: var(--text-xs);
  border-radius: var(--radius-xs);
}

.btn-icon-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  outline: none;
  transition:
    background var(--transition),
    color var(--transition),
    border-color var(--transition),
    box-shadow var(--transition);
}
.btn-icon-only:hover {
  background: var(--hover);
  color: var(--text);
}
.btn-icon-only:focus-visible {
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.btn-icon-only:active {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-label {
  font-size: var(--text-sm);
  font-weight: 600;
}

.back-btn {
  padding: 0 10px;
  color: var(--accent);
  background: transparent;
  border-color: transparent;
}
.back-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-hover);
  border-color: transparent;
}

/* =========================================
   TOPBAR
========================================= */

.topbar {
  position: relative;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  height: var(--topbar-height);
  padding: 0 var(--space-5);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  flex-shrink: 0;
  transition: background var(--transition-slow), border-color var(--transition-slow);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex-shrink: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: nowrap;
}

.topbar-divider {
  width: 1px;
  height: 22px;
  margin: 0 var(--space-1);
  background: var(--border);
  flex-shrink: 0;
}

.topbar-btn {
  height: 38px;
  padding: 0 14px;
  font-size: var(--text-sm);
}

/* =========================================
   BRAND
========================================= */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.brand-icon {
  width: 22px;
  height: 22px;
  color: var(--accent);
  flex-shrink: 0;
}

.brand-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
  white-space: nowrap;
}

.mobile-menu-btn {
  display: none;
}

.hamburger {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 20px;
  height: 20px;
}
.hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: all 0.2s ease;
  transform-origin: center;
}

.icon-sun,
.icon-moon {
  width: 16px;
  height: 16px;
}

/* =========================================
   UNSAVED BANNER
========================================= */

.unsaved-banner {
  position: relative;
  z-index: 190;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 9px var(--space-5);
  background: var(--warning-soft);
  border-bottom: 1px solid #f6d860;
  color: var(--warning);
  font-size: var(--text-sm);
  font-weight: 500;
  flex-shrink: 0;
  animation: bannerSlideIn 0.22s ease;
}

.unsaved-banner[hidden] {
  display: none;
}

@keyframes bannerSlideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

[data-theme="dark"] .unsaved-banner {
  background: rgba(217, 119, 6, 0.15);
  border-bottom-color: rgba(217, 119, 6, 0.35);
}

.unsaved-banner-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.unsaved-banner-text {
  flex: 1;
}

.unsaved-banner-dismiss {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--warning);
  cursor: pointer;
  transition: background var(--transition);
}
.unsaved-banner-dismiss:hover {
  background: rgba(217, 119, 6, 0.12);
}
.unsaved-banner-dismiss svg {
  width: 13px;
  height: 13px;
}

.btn-unsaved-dot {
  display: inline-block;
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  margin-left: 5px;
  border-radius: 50%;
  background: var(--warning);
  animation: dotPulse 1.8s ease-in-out infinite;
}

@keyframes dotPulse {
  0%, 100% { opacity: 1;    transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.75); }
}

/* =========================================
   MAIN LAYOUT
========================================= */

.main-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--details-width);
  gap: 16px;
  padding: 16px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* =========================================
   MOBILE OVERLAY
========================================= */

.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-spring);
}
.mobile-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* =========================================
   SIDEBAR
========================================= */

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition:
    background var(--transition-slow),
    border-color var(--transition-slow),
    transform var(--transition-spring),
    box-shadow var(--transition-spring);
}

.sidebar-search {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-field {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  z-index: 1;
  width: 15px;
  height: 15px;
  color: var(--text-xsoft);
  pointer-events: none;
  flex-shrink: 0;
}

#searchInput {
  width: 100%;
  height: 40px;
  padding: 0 36px 0 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: var(--text-base);
  outline: none;
  transition:
    border-color var(--transition),
    box-shadow var(--transition),
    background var(--transition);
}
#searchInput::placeholder {
  color: var(--text-xsoft);
}
#searchInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
  background: var(--panel);
}

.search-clear {
  position: absolute;
  right: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  min-width: 22px;
  border: none;
  border-radius: 50%;
  background: var(--text-xsoft);
  color: var(--panel);
  cursor: pointer;
  outline: none;
  transition: background var(--transition);
}
.search-clear svg {
  width: 10px;
  height: 10px;
}
.search-clear:hover {
  background: var(--text-soft);
}
.search-clear:focus-visible {
  box-shadow: 0 0 0 2px var(--focus-ring);
}

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

.sidebar-section-label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-xsoft);
}

.sidebar-actions {
  display: flex;
  gap: var(--space-1);
}

.sidebar-action-btn {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: var(--radius-xs);
  color: var(--text-xsoft);
}
.sidebar-action-btn svg {
  width: 14px;
  height: 14px;
}
.sidebar-action-btn:hover {
  background: var(--hover);
  color: var(--text);
}

.folder-tree {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-2);
}

/* =========================================
   FOLDER TREE NODES
========================================= */

.folder-node {
  min-width: 0;
  margin-bottom: 3px;
}

.folder-children {
  margin-left: 14px;
  padding-left: var(--space-1);
  border-left: 1px solid var(--border-light);
}
.folder-node.collapsed > .folder-children {
  display: none;
}

.folder-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 7px 10px;
  margin-bottom: 3px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  outline: none;
  transition:
    background var(--transition),
    border-color var(--transition),
    color var(--transition);
}
.folder-row:hover {
  background: var(--hover);
}
.folder-row.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.folder-row:focus-visible {
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.folder-chevron {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  color: var(--text-xsoft);
  transition: transform var(--transition);
}
.folder-chevron svg {
  width: 12px;
  height: 12px;
}
.folder-node.expanded > .folder-row > .folder-chevron {
  transform: rotate(90deg);
}

.folder-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--text-soft);
}
.folder-icon svg {
  width: 16px;
  height: 16px;
}
.folder-row.active .folder-icon {
  color: var(--accent);
}

.folder-label {
  flex: 1;
  min-width: 0;
  font-size: var(--text-base);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.folder-row.active .folder-label {
  color: var(--accent);
}

.folder-count-badge {
  flex-shrink: 0;
  min-width: 24px;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: var(--bg-secondary);
  color: var(--text-xsoft);
  font-size: var(--text-xs);
  font-weight: 600;
  text-align: center;
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
}
.folder-row.active .folder-count-badge {
  background: var(--accent);
  color: #fff;
}

/* =========================================
   CONTENT AREA
========================================= */

.content {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  overflow: hidden;
  height: 100%;
}

/* =========================================
   STATS GRID
========================================= */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  flex-shrink: 0;
}

.stat-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
  overflow: hidden;
  text-align: left;
  cursor: default;
  transition:
    background var(--transition-slow),
    border-color var(--transition),
    box-shadow var(--transition),
    transform var(--transition);
}

.stat-card-action {
  cursor: pointer;
}
.stat-card-action:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.stat-card-action:active {
  transform: translateY(0);
}
.stat-card-action:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.stat-card-disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

.stat-icon-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  transition: background var(--transition-slow);
}
.stat-icon-wrap svg {
  width: 20px;
  height: 20px;
  color: var(--accent);
  stroke-width: 1.8;
}

.stat-body {
  flex: 1;
  min-width: 0;
}

.stat-label {
  margin-bottom: 4px;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color var(--transition-slow);
}

.stat-value {
  font-size: clamp(22px, 2.5vw, 28px);
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  transition: color var(--transition-slow);
}

.stat-arrow {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--accent);
  opacity: 0;
  transition: opacity var(--transition), transform var(--transition);
}
.stat-card-action:hover .stat-arrow {
  opacity: 1;
  transform: translateX(2px);
}

/* =========================================
   VIEW HEADER
========================================= */

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 12px 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-shrink: 0;
  transition: background var(--transition-slow), border-color var(--transition-slow);
}

.view-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.view-title-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.view-title {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.2px;
  line-height: 1.3;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view-count {
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--text-soft);
}

.view-badge {
  flex-shrink: 0;
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
  transition: background var(--transition-slow), color var(--transition-slow);
}

/* =========================================
   BOOKMARK LIST
========================================= */

.bookmark-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-2);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background var(--transition-slow), border-color var(--transition-slow);
}

/* =========================================
   BOOKMARK ITEM
========================================= */

.bookmark-item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  outline: none;
  transition:
    background var(--transition),
    border-color var(--transition),
    box-shadow var(--transition),
    transform var(--transition);
}
.bookmark-item + .bookmark-item {
  margin-top: 3px;
}
.bookmark-item:hover {
  background: var(--hover);
  border-color: var(--border);
  transform: translateY(-1px);
  box-shadow: var(--shadow-xs);
}
.bookmark-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.bookmark-item:focus-visible {
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.bookmark-favicon-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  margin-top: 1px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg);
  overflow: hidden;
  transition: border-color var(--transition-slow);
}

.bookmark-favicon {
  display: block;
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.bookmark-favicon-fallback {
  display: none;
  width: 20px;
  height: 20px;
  color: var(--text-xsoft);
}
.bookmark-favicon-fallback svg {
  width: 16px;
  height: 16px;
}

.bookmark-body {
  flex: 1;
  min-width: 0;
}

.bookmark-title {
  margin-bottom: 2px;
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bookmark-url {
  font-size: 12px;
  font-family: var(--font-mono);
  line-height: 1.4;
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bookmark-chips {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.bookmark-chip {
  display: inline-flex;
  align-items: center;
  max-width: 160px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--text-soft);
  font-size: var(--text-xs);
  font-weight: 500;
  line-height: 1.6;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition:
    background var(--transition-slow),
    border-color var(--transition-slow),
    color var(--transition-slow);
}

.chip-domain {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.bookmark-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition);
}
.bookmark-item:hover .bookmark-actions,
.bookmark-item.active .bookmark-actions {
  opacity: 1;
}

.bookmark-item-actions-crud {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.bookmark-open-btn,
.bookmark-edit-btn,
.bookmark-delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  min-width: 30px;
  border: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.bookmark-open-btn {
  background: var(--accent-soft);
  color: var(--accent);
}
.bookmark-open-btn svg {
  width: 14px;
  height: 14px;
}
.bookmark-open-btn:hover {
  background: var(--accent);
  color: #fff;
}

.bookmark-edit-btn {
  background: var(--accent-soft);
  color: var(--accent);
}
.bookmark-edit-btn svg {
  width: 13px;
  height: 13px;
}
.bookmark-edit-btn:hover {
  background: var(--accent);
  color: #fff;
}

.bookmark-delete-btn {
  background: var(--danger-soft);
  color: var(--danger);
}
.bookmark-delete-btn svg {
  width: 13px;
  height: 13px;
}
.bookmark-delete-btn:hover {
  background: var(--danger);
  color: #fff;
}

/* =========================================
   DETAILS PANEL
========================================= */

.details-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition:
    background var(--transition-slow),
    border-color var(--transition-slow),
    transform var(--transition-spring),
    box-shadow var(--transition-spring);
}

.details-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.details-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--text);
}

.close-panel-btn {
  display: none;
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: 50%;
}
.close-panel-btn svg {
  width: 14px;
  height: 14px;
}

.details-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
}

.detail-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.detail-label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-xsoft);
}

.detail-value {
  font-size: var(--text-base);
  line-height: 1.55;
  word-break: break-word;
  color: var(--text);
}

.detail-favicon-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.detail-favicon-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  overflow: hidden;
}

.detail-favicon {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.detail-favicon-fb {
  width: 20px;
  height: 20px;
  color: var(--text-xsoft);
}

.detail-domain {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-url-link {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  word-break: break-all;
  color: var(--accent);
}
.detail-url-link:hover {
  text-decoration: underline;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding-top: var(--space-2);
  margin-top: auto;
  border-top: 1px solid var(--border-light);
}

.detail-btn {
  flex: 1;
  min-width: 0;
  height: 38px;
  font-size: var(--text-sm);
}

/* =========================================
   DOMAIN VIEW
========================================= */

.domain-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  outline: none;
  transition:
    background var(--transition),
    border-color var(--transition),
    box-shadow var(--transition),
    transform var(--transition);
}
.domain-item + .domain-item {
  margin-top: 5px;
}
.domain-item:hover {
  background: var(--hover);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-xs);
}
.domain-item:focus-visible {
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.domain-item-favicon-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  overflow: hidden;
}

.domain-favicon {
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.domain-item-body {
  flex: 1;
  min-width: 0;
}

.domain-name {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.domain-count {
  margin-top: 2px;
  font-size: var(--text-sm);
  color: var(--text-soft);
}

.domain-arrow {
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  color: var(--accent);
  opacity: 0;
  transition: opacity var(--transition), transform var(--transition);
}
.domain-item:hover .domain-arrow {
  opacity: 1;
  transform: translateX(2px);
}

/* =========================================
   DUPLICATE GROUPS VIEW
========================================= */

.dup-group {
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition:
    background var(--transition-slow),
    border-color var(--transition),
    box-shadow var(--transition);
}
.dup-group + .dup-group {
  margin-top: var(--space-2);
}
.dup-group:hover {
  border-color: var(--accent);
}

.dup-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 13px 16px;
  background: var(--panel);
  border-bottom: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  outline: none;
  transition: background var(--transition), border-color var(--transition);
}
.dup-group.expanded .dup-header {
  border-bottom-color: var(--border-light);
}
.dup-header:hover {
  background: var(--hover);
}
.dup-header:focus-visible {
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

.dup-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: var(--text-soft);
  transition: transform var(--transition);
}
.dup-toggle svg {
  width: 14px;
  height: 14px;
}
.dup-group.expanded .dup-toggle {
  transform: rotate(90deg);
}

.dup-info {
  flex: 1;
  min-width: 0;
}

.dup-title {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dup-url {
  margin-top: 2px;
  font-size: var(--text-xs);
  font-family: var(--font-mono);
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dup-count-badge {
  flex-shrink: 0;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1.6;
  white-space: nowrap;
}

.dup-items {
  display: none;
  flex-direction: column;
  gap: 5px;
  padding: 8px 12px 12px;
}
.dup-group.expanded .dup-items {
  display: flex;
}

.dup-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  outline: none;
  transition:
    background var(--transition),
    border-color var(--transition);
}
.dup-item:hover {
  background: var(--hover);
  border-color: var(--accent);
}
.dup-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.dup-item:focus-visible {
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.dup-favicon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  border-radius: 4px;
  object-fit: contain;
}

.dup-item-body {
  flex: 1;
  min-width: 0;
}

.dup-item-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dup-item-path {
  margin-top: 2px;
  font-size: var(--text-xs);
  color: var(--text-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dup-item-date {
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 2px;
  font-size: var(--text-xs);
  color: var(--text-xsoft);
  white-space: nowrap;
}

/* =========================================
   EMPTY STATES
========================================= */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 40px var(--space-5);
  text-align: center;
  color: var(--text-soft);
}

.empty-state.large {
  padding: 80px var(--space-5);
  gap: var(--space-3);
}

.empty-state.small {
  padding: 24px var(--space-5);
}

.empty-illustration {
  width: 80px;
  height: 80px;
  margin-bottom: var(--space-1);
  color: var(--text-xsoft);
  opacity: 0.7;
}

.empty-icon {
  width: 40px;
  height: 40px;
  color: var(--text-xsoft);
  opacity: 0.6;
}

.empty-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-soft);
}

.empty-desc {
  margin: 0;
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-xsoft);
  max-width: 280px;
}

.empty-hint {
  margin: 0;
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--text-xsoft);
  max-width: 220px;
}

.empty-cta {
  margin-top: var(--space-2);
}

/* =========================================
   TOAST
========================================= */

.toast-container {
  position: fixed;
  bottom: 28px;
  left: 50%;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  font-size: var(--text-base);
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  max-width: calc(100vw - 40px);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(16px);
  pointer-events: none;
  transition:
    transform var(--transition-spring),
    opacity var(--transition-spring);
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success { background: var(--success); color: #fff; }
.toast-error   { background: var(--danger);  color: #fff; }
.toast-info    { background: var(--text);    color: var(--panel); }

.toast-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.toast-icon svg {
  width: 15px;
  height: 15px;
}

.toast-msg {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================
   LOADING OVERLAY
========================================= */

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 8000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.loading-overlay[hidden] {
  display: none;
}

.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-width: 180px;
  padding: 32px 40px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-float);
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

.loading-text {
  font-size: var(--text-base);
  font-weight: 600;
  text-align: center;
  color: var(--text-soft);
}

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

/* =========================================
   CONFIRM DIALOG
========================================= */

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: rgba(0, 0, 0, .45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.dialog-backdrop[hidden] {
  display: none;
}

.dialog-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 420px;
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
  text-align: center;
  animation: dialogIn var(--transition-spring);
}

@keyframes dialogIn {
  from { opacity: 0; transform: scale(.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}

.dialog-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  margin-bottom: var(--space-1);
  border-radius: 50%;
  background: var(--warning-soft);
}
.dialog-icon svg {
  width: 26px;
  height: 26px;
  color: var(--warning);
}

.dialog-title {
  font-size: var(--text-lg);
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
}

.dialog-desc {
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-soft);
  max-width: 340px;
}

.dialog-actions {
  display: flex;
  gap: var(--space-2);
  width: 100%;
  margin-top: var(--space-2);
}
.dialog-actions .btn {
  flex: 1;
}

/* =========================================
   CRUD MODAL
========================================= */

.crud-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: rgba(0, 0, 0, .45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn var(--transition-spring);
}
.crud-modal-backdrop[hidden] {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.crud-modal-box {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  width: 100%;
  max-width: 460px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
  animation: dialogIn var(--transition-spring);
}

.crud-modal-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text);
}

.crud-form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.crud-form-label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-xsoft);
}

.crud-form-input,
.crud-form-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  outline: none;
  resize: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.crud-form-input:focus,
.crud-form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.crud-form-textarea {
  height: 72px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.crud-form-input[readonly] {
  background: var(--bg-secondary);
  color: var(--text-soft);
  cursor: default;
  pointer-events: none;
}
.crud-form-input[readonly]:focus {
  border-color: var(--border);
  box-shadow: none;
}

.crud-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}
.crud-modal-actions .btn {
  min-width: 100px;
}

/* =========================================
   SCROLLBARS
========================================= */

::-webkit-scrollbar        { width: 5px; height: 5px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--border); border-radius: var(--radius-pill); }
::-webkit-scrollbar-thumb:hover { background: var(--text-xsoft); }

/* =========================================
   RESPONSIVE — 1440px
========================================= */

@media (max-width: 1440px) {
  :root {
    --sidebar-width: 280px;
    --details-width: 320px;
  }
}

/* =========================================
   RESPONSIVE — 1280px
========================================= */

@media (max-width: 1280px) {
  :root {
    --sidebar-width: 260px;
    --details-width: 300px;
  }
  .stat-label {
    font-size: 10px;
  }
}

/* =========================================
   RESPONSIVE — 1200px
========================================= */

@media (max-width: 1200px) {
  .main-layout {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }
  .details-panel {
    display: none;
  }
  .details-panel.mobile-open {
    display: flex;
    position: fixed;
    top: var(--topbar-height);
    right: 0;
    bottom: 0;
    z-index: 160;
    width: min(360px, 95vw);
    border-radius: var(--radius) 0 0 var(--radius);
    box-shadow: var(--shadow-float);
    animation: slideInRight var(--transition-spring);
  }
  .details-panel.mobile-open .close-panel-btn {
    display: inline-flex;
  }
}

@keyframes slideInRight {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

/* =========================================
   RESPONSIVE — 1024px
========================================= */

@media (max-width: 1024px) {
  :root {
    --sidebar-width: 240px;
  }
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .stat-arrow {
    display: none;
  }
}

/* =========================================
   RESPONSIVE — 820px
========================================= */

@media (max-width: 820px) {
  .main-layout {
    grid-template-columns: minmax(0, 1fr);
    padding: var(--space-3);
    gap: var(--space-3);
  }
  .mobile-overlay {
    display: block;
  }
  .mobile-menu-btn {
    display: inline-flex;
  }
  .sidebar {
    display: none;
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    z-index: 160;
    width: min(300px, 85vw);
    border-radius: 0 var(--radius) var(--radius) 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-float);
  }
  .sidebar.open {
    display: flex;
    transform: translateX(0);
  }
}

/* =========================================
   RESPONSIVE — 768px
========================================= */

@media (max-width: 768px) {
  :root {
    --topbar-height: 60px;
  }
  .topbar {
    gap: var(--space-2);
    padding: 0 14px;
  }
  .topbar-right {
    gap: 5px;
  }
  .btn-label {
    display: none;
  }
  .topbar-divider {
    display: none;
  }
  .topbar-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    padding: 0;
  }
  .stats-grid {
    gap: var(--space-2);
  }
  .stat-card {
    gap: 10px;
    padding: 13px;
  }
  .stat-icon-wrap {
    width: 34px;
    height: 34px;
  }
  .stat-icon-wrap svg {
    width: 17px;
    height: 17px;
  }
  .stat-value {
    font-size: 22px;
  }
}

/* =========================================
   RESPONSIVE — 480px
========================================= */

@media (max-width: 480px) {
  :root {
    --topbar-height: 56px;
  }
  .main-layout {
    padding: var(--space-2);
    gap: var(--space-2);
  }
  .brand-name {
    font-size: 15px;
  }
  .stats-grid {
    gap: 6px;
  }
  .stat-card {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
    padding: 12px;
  }
  .stat-value {
    font-size: 22px;
  }
  .view-header {
    padding: 10px 14px;
  }
  .view-title {
    font-size: var(--text-md);
  }
  .bookmark-list {
    padding: var(--space-2);
  }
  .bookmark-item {
    padding: 10px 12px;
  }
  .bookmark-actions {
    display: none;
  }
  .dialog-box {
    padding: 24px 20px;
  }
}

/* =========================================
   RESPONSIVE — 375px
========================================= */

@media (max-width: 375px) {
  .brand-name {
    font-size: 14px;
  }
  .brand-icon {
    width: 18px;
    height: 18px;
  }
  .stat-card {
    padding: 10px;
  }
  .stat-value {
    font-size: 20px;
  }
  .stat-icon-wrap {
    display: none;
  }
  .stat-label {
    font-size: 10px;
  }
}

/* =========================================
   RESPONSIVE — 320px
========================================= */

@media (max-width: 320px) {
  .topbar {
    padding: 0 10px;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* =========================================
   PRINT
========================================= */

@media print {
  .topbar,
  .sidebar,
  .details-panel,
  .stats-grid,
  .view-header {
    display: none !important;
  }
  .main-layout {
    display: block;
    height: auto;
    overflow: visible;
    padding: 0;
  }
  .content {
    display: block;
    overflow: visible;
  }
  .bookmark-list {
    overflow: visible;
    padding: 0;
    border: none;
    box-shadow: none;
  }
  .bookmark-item {
    margin-bottom: 4px;
    border: 1px solid #ccc;
    border-radius: 0;
    break-inside: avoid;
  }
  .bookmark-actions {
    display: none !important;
  }
}