:root {
  --bg: #f5f5f5;
  --bg-card: #fff;
  --bg-sidebar: #fafafa;
  --text: #222;
  --text-muted: #666;
  --border: #e0e0e0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 6px;
  --sidebar-width: 260px;
  --topbar-height: 52px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Auth screen */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.auth-card {
  background: var(--bg-card);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(0,0,0,.1);
  width: 100%;
  max-width: 360px;
}
.auth-card h1 { margin-bottom: 1.5rem; font-size: 1.5rem; text-align: center; }
.auth-card input {
  width: 100%;
  padding: .6rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  margin-bottom: 1rem;
}
.auth-card button {
  width: 100%;
  padding: .6rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
}
.auth-card button:hover { background: var(--primary-hover); }
.error-text { color: var(--danger); font-size: .875rem; margin-top: .5rem; text-align: center; }

/* Layout */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 0 1rem;
  height: var(--topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
}
#search-input {
  flex: 1;
  max-width: 400px;
  padding: .4rem .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
}
.topbar-actions { display: flex; align-items: center; gap: .4rem; margin-left: auto; }
.topbar-actions button, .btn-import {
  padding: .35rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  cursor: pointer;
  font-size: .8rem;
  white-space: nowrap;
}
.topbar-actions button:hover, .btn-import:hover { background: var(--bg); }
.btn-import { display: inline-block; }

.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { font-size: 1rem; }
.sidebar-header button {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  width: 28px;
  height: 28px;
  font-size: 1.1rem;
  line-height: 1;
}

/* Folder tree */
.folder-tree { padding: .5rem 0; }
.folder-item {
  display: flex;
  align-items: center;
  padding: .35rem .8rem;
  cursor: pointer;
  font-size: .9rem;
  border-left: 3px solid transparent;
  user-select: none;
}
.folder-item:hover { background: var(--border); }
.folder-item.active { background: #dbeafe; border-left-color: var(--primary); font-weight: 600; }
.folder-item.drop-target { background: #bfdbfe; }
.folder-toggle {
  width: 18px;
  font-size: .7rem;
  text-align: center;
  flex-shrink: 0;
  color: var(--text-muted);
}
.folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-actions {
  display: none;
  gap: .3rem;
}
.folder-item:hover .folder-actions { display: flex; }
.folder-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .75rem;
  padding: 0 2px;
  color: var(--text-muted);
}
.folder-children { display: none; }
.folder-children.expanded { display: block; }

/* Content */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}
.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.content-header h2 { font-size: 1.1rem; }
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: .4rem .8rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .85rem;
}
.btn-primary:hover { background: var(--primary-hover); }

/* Bookmark list */
.bookmark-list { display: flex; flex-direction: column; gap: .5rem; }
.bookmark-item {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .6rem .8rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: grab;
}
.bookmark-item.dragging { opacity: .4; }
.bookmark-item.drag-over { border-color: var(--primary); border-style: dashed; }
.bookmark-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  object-fit: contain;
}
.bookmark-icon-placeholder {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  background: var(--border);
  border-radius: 3px;
}
.bookmark-info { flex: 1; min-width: 0; }
.bookmark-title {
  display: block;
  color: var(--primary);
  text-decoration: none;
  font-size: .9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bookmark-title:hover { text-decoration: underline; }
.bookmark-url {
  font-size: .75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bookmark-folder-badge {
  font-size: .7rem;
  color: var(--primary);
  background: #eff6ff;
  padding: .1rem .4rem;
  border-radius: 3px;
  margin-top: .15rem;
  display: inline-block;
}
.bookmark-actions { display: flex; gap: .3rem; flex-shrink: 0; }
.bookmark-actions button {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: .2rem .5rem;
  font-size: .75rem;
}
.bookmark-actions .btn-delete { color: var(--danger); border-color: var(--danger); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.4);
}
.modal-content {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 90%;
  max-width: 440px;
  box-shadow: 0 4px 24px rgba(0,0,0,.15);
}
.modal-wide { max-width: 600px; }
.modal-content h3 { margin-bottom: 1rem; font-size: 1.1rem; }
.modal-content label {
  display: block;
  margin-bottom: .8rem;
  font-size: .85rem;
  font-weight: 500;
}
.modal-content input, .modal-content select {
  display: block;
  width: 100%;
  padding: .45rem .6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  margin-top: .25rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  margin-top: 1rem;
}
.btn-cancel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .4rem .8rem;
  cursor: pointer;
  font-size: .85rem;
}

/* Stats list */
#stats-list { max-height: 400px; overflow-y: auto; }
.stats-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
}
.stats-rank { width: 24px; font-weight: 600; color: var(--text-muted); flex-shrink: 0; }
.stats-count { color: var(--primary); font-weight: 600; flex-shrink: 0; margin-left: auto; }

/* Toast */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.toast {
  padding: .6rem 1rem;
  border-radius: var(--radius);
  background: #1e293b;
  color: #fff;
  font-size: .85rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  animation: slideIn .3s ease;
  max-width: 360px;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Error banner */
.error-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: .6rem 1rem;
  background: var(--danger);
  color: #fff;
  display: flex;
  align-items: center;
  gap: .5rem;
  z-index: 150;
  font-size: .85rem;
}
.error-banner button {
  background: rgba(255,255,255,.2);
  border: none;
  color: #fff;
  padding: .2rem .6rem;
  border-radius: var(--radius);
  cursor: pointer;
}
.error-banner span { flex: 1; }

/* Loading & empty */
.loading, .empty-state {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

.export-group { display: flex; gap: .2rem; }

/* Responsive */
@media (max-width: 768px) {
  .menu-toggle { display: block; }
  .sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 2px 0 8px rgba(0,0,0,.1);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar-actions { gap: .2rem; }
  .export-group { display: none; }
}
