:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: #1f2937;
  --bg-card-hover: #283548;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(56, 189, 248, 0.4);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent-blue: #38bdf8;
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --accent-purple: #a855f7;
  --accent-amber: #f59e0b;
  --accent-danger: #ef4444;
  --accent-danger-bg: rgba(239, 68, 68, 0.15);
  --accent-glow: rgba(56, 189, 248, 0.15);
  --sidebar-width: 270px;
  --header-height: 70px;
  --radius: 12px;
  --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.25);
  --shadow-hover: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 0 15px rgba(56, 189, 248, 0.15);
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --border-color: #e2e8f0;
  --border-hover: #38bdf8;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent-glow: rgba(56, 189, 248, 0.1);
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-hover: 0 10px 20px -3px rgba(0, 0, 0, 0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: #374151;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #4b5563;
}

/* Header */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 20px;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 250px;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 19px;
  box-shadow: 0 0 15px var(--accent-glow);
}

.brand-title h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(90deg, #fff, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
[data-theme="light"] .brand-title h1 {
  background: linear-gradient(90deg, #0f172a, #334155);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-title span {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
}

/* Search bar */
.search-container {
  flex: 1;
  max-width: 640px;
  position: relative;
}

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

.search-icon {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  pointer-events: none;
  width: 18px;
  height: 18px;
}

.search-input {
  width: 100%;
  height: 42px;
  padding: 0 42px 0 42px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: all 0.2s ease;
}

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

.search-kbd {
  position: absolute;
  right: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 11px;
  font-family: monospace;
}

.search-clear {
  position: absolute;
  right: 42px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: none;
  padding: 4px;
}
.search-clear:hover {
  color: var(--text-primary);
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.btn-icon:hover {
  color: var(--text-primary);
  border-color: var(--accent-blue);
}

.btn-text {
  padding: 0 14px;
  height: 38px;
  border-radius: 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-text:hover {
  color: var(--text-primary);
  border-color: var(--accent-blue);
}

.admin-badge-pill {
  padding: 4px 10px;
  border-radius: 8px;
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fbbf24;
  font-size: 12px;
  font-weight: 600;
  display: none;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.admin-badge-pill:hover {
  background: rgba(245, 158, 11, 0.25);
  transform: translateY(-1px);
}

.badge-count {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--accent-danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
}

/* Layout */
.app-container {
  display: flex;
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  position: fixed;
  top: var(--header-height);
  bottom: 0;
  left: 0;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 40;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.nav-item:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.15), transparent);
  color: var(--accent-blue);
  border-left: 3px solid var(--accent-blue);
}

.nav-item-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--bg-primary);
  color: var(--text-muted);
}
.nav-item.active .nav-badge {
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent-blue);
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 24px 32px 60px 32px;
  min-width: 0;
}

/* Banner bar */
.stats-banner {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.08), rgba(168, 85, 247, 0.08));
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.stats-info {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.stat-chip strong {
  color: var(--text-primary);
  font-weight: 600;
}

.stat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.stat-dot.green { background: var(--accent-green); box-shadow: 0 0 8px var(--accent-green); }
.stat-dot.blue { background: var(--accent-blue); box-shadow: 0 0 8px var(--accent-blue); }
.stat-dot.purple { background: var(--accent-purple); box-shadow: 0 0 8px var(--accent-purple); }

/* Subcategories Pill Bar */
.subcat-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 12px;
  margin-bottom: 20px;
}
.subcat-pill {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.subcat-pill:hover, .subcat-pill.active {
  background: var(--accent-blue);
  color: #0b0f19;
  font-weight: 600;
  border-color: var(--accent-blue);
}

/* Category Section Header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-title {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-count {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 400;
}

/* Card Grid */
.bookmarks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* Card */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s ease, opacity 0.25s ease, transform 0.25s ease;
  position: relative;
  box-shadow: var(--shadow-card);
}

.card:hover {
  transform: translateY(-3px);
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
  box-shadow: var(--shadow-hover);
}

.card.deleting {
  opacity: 0;
  transform: scale(0.9);
  pointer-events: none;
}

.card-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.card-favicon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-blue);
}

.card-favicon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-content {
  flex: 1;
  min-width: 0;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
  word-break: break-all;
}

.card-domain {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}

.card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 11px;
}

.card-bottom-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.card-tag {
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 2px 8px;
  border-radius: 4px;
  max-width: 110px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-status {
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
}
.card-status.direct {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}
.card-status.proxy {
  background: rgba(168, 85, 247, 0.15);
  color: #c084fc;
}

/* Card Delete Button (Hidden for visitors, displayed for Admin) */
.card-actions {
  display: none;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

body.is-admin .card-actions {
  display: flex;
}

.card-btn-delete {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  height: 22px;
  padding: 0 7px;
  border-radius: 4px;
  color: #ef4444;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0.85;
}

.card:hover .card-btn-delete {
  opacity: 1;
}

.card-btn-delete:hover {
  background: #ef4444;
  color: #ffffff;
  border-color: #ef4444;
  transform: translateY(-1px);
}

.card-btn-delete svg {
  width: 12px;
  height: 12px;
}

/* Compact List View */
.bookmarks-grid.list-view {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bookmarks-grid.list-view .card {
  flex-direction: row;
  align-items: center;
  padding: 10px 16px;
  gap: 16px;
}
.bookmarks-grid.list-view .card:hover {
  transform: translateX(4px);
}
.bookmarks-grid.list-view .card-top {
  align-items: center;
  flex: 1;
}
.bookmarks-grid.list-view .card-title {
  -webkit-line-clamp: 1;
  margin-bottom: 0;
}
.bookmarks-grid.list-view .card-domain {
  min-width: 180px;
}
.bookmarks-grid.list-view .card-bottom {
  border-top: none;
  padding-top: 0;
  gap: 12px;
}

/* Loading & Empty State */
.loading-indicator {
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
  font-size: 14px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state svg {
  width: 56px;
  height: 56px;
  margin-bottom: 16px;
  opacity: 0.5;
}

/* Highlight search */
mark {
  background: rgba(234, 179, 8, 0.3);
  color: #fef08a;
  border-radius: 2px;
  padding: 0 2px;
}

/* Back to top */
.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
  z-index: 60;
}
.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}
.back-to-top:hover {
  color: var(--accent-blue);
  border-color: var(--accent-blue);
  transform: translateY(-2px);
}

/* Toast Notifications */
.nav-toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
  pointer-events: none;
}

.nav-toast {
  pointer-events: auto;
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: 0 10px 25px -5px rgba(0,0,0,0.5);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 14px;
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.toast-undo-btn {
  background: var(--accent-blue);
  color: #0b0f19;
  border: none;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.toast-undo-btn:hover {
  background: #7dd3fc;
}

/* Modal Backdrop & Dialog */
.nav-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 110;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.nav-modal-backdrop.open {
  display: flex;
}

.nav-modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 100%;
  max-width: 620px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}
.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.deleted-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--bg-card);
  margin-bottom: 8px;
  gap: 12px;
}
.deleted-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}
.deleted-item-url {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}
.btn-restore {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-restore:hover {
  background: #10b981;
  color: white;
}

.deleted-item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-purge {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-purge:hover {
  background: #ef4444;
  color: white;
}

.btn-danger-outline {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}
.btn-danger-outline:hover {
  background: #ef4444;
  color: white;
  border-color: #ef4444;
}

/* Primary Action Buttons in Modal */
.btn-primary {
  background: var(--accent-blue);
  color: #0b0f19;
  font-weight: 600;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.btn-primary:hover {
  background: #7dd3fc;
}

.btn-secondary {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.btn-secondary:hover {
  color: var(--text-primary);
  border-color: var(--accent-blue);
}

.form-input {
  width: 100%;
  height: 40px;
  padding: 0 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  margin-top: 8px;
}
.form-input:focus {
  border-color: var(--accent-blue);
}

/* Responsive */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
    padding: 16px;
  }
  .menu-toggle {
    display: flex !important;
  }
}

.menu-toggle {
  display: none;
}
