/* ── Variables ── */
:root {
  --bg:          #ffffff;
  --surface:     #f7f8fa;
  --border:      #e5e7eb;
  --text:        #1f2328;
  --muted:       #57606a;
  --accent:      #3b82d4;
  --accent-dark: #2563b0;
  --danger:      #c0392b;
  --success:     #1a7f37;
  --radius:      6px;
  --topbar-h:    52px;
  --sidebar-w:   210px;
  --font:        -apple-system, "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:      #0d1117;
    --surface: #161b22;
    --border:  #30363d;
    --text:    #e6edf3;
    --muted:   #8b949e;
  }
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: var(--font); background: var(--bg); color: var(--text);
       line-height: 1.6; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; font-size: inherit; }
input, textarea, select {
  font-family: inherit; font-size: inherit;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .4rem .65rem; width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ── Utilities ── */
.hidden      { display: none !important; }
[hidden]     { display: none !important; }
.w-full   { width: 100%; }
.mt-1     { margin-top: .5rem; }
.mt-2     { margin-top: 1rem; }
.mt-3     { margin-top: 1.5rem; }
.mb-1     { margin-bottom: .5rem; }
.muted    { color: var(--muted); font-size: .85rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex     { display: flex; }
.gap-1    { gap: .5rem; }
.gap-2    { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1   { flex: 1 1 0; min-width: 0; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .4rem .85rem; border-radius: var(--radius);
  border: 1px solid transparent; font-weight: 500;
  white-space: nowrap; transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn-primary  { background: var(--accent); color: #fff; border-color: var(--accent-dark); }
.btn-ghost    { background: transparent; border-color: var(--border); color: var(--text); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-sm       { padding: .25rem .6rem; font-size: .85rem; }
.btn-icon     { padding: .3rem .5rem; font-size: 1rem; border: none; background: none; color: var(--muted); }
.btn-icon:hover { color: var(--text); }

/* ── Top bar ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .75rem; padding: 0 1rem;
  z-index: 100;
}
.topbar-left  { display: flex; align-items: center; gap: .75rem; flex-shrink: 0; }
.topbar-center { flex: 1; max-width: 520px; }
.topbar-right  { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; margin-left: auto; }
.brand { font-weight: 700; font-size: 1.05rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.search-input { padding: .35rem .75rem; }
.username-badge {
  font-size: .8rem; background: var(--border); border-radius: 99px;
  padding: .2rem .65rem; color: var(--muted);
}
.sidebar-toggle { background: none; border: none; font-size: 1.2rem; color: var(--muted); }

/* ── Layout ── */
.layout {
  display: flex;
  padding-top: var(--topbar-h);
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; padding: .75rem 0;
  transition: transform .2s; z-index: 90;
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); }

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 89;
  background: rgba(0,0,0,.35);
}
.sidebar-overlay.visible { display: block; }
.nav-list { list-style: none; }
.nav-link {
  display: block; padding: .5rem 1.25rem; color: var(--text);
  font-size: .9rem; border-radius: 0;
}
.nav-link:hover { background: var(--border); text-decoration: none; }
.nav-link.active { background: var(--accent); color: #fff; }

/* ── Main ── */
.main {
  flex: 1; margin-left: var(--sidebar-w);
  padding: 1.5rem 2rem;
  transition: margin-left .2s;
}
.main.full { margin-left: 0; }

/* ── Auth screen ── */
.auth-screen {
  min-height: 100vh; display: flex;
  align-items: center; justify-content: center;
  background: var(--surface); padding: 2rem 1rem;
}
.auth-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem 2.25rem;
  width: 100%; max-width: 380px;
}
.auth-logo    { font-size: 1.6rem; text-align: center; margin-bottom: .25rem; }
.auth-tagline { text-align: center; color: var(--muted); font-size: .9rem; margin-bottom: 1.5rem; }
.auth-form    { display: flex; flex-direction: column; gap: .85rem; }
.auth-form label { display: flex; flex-direction: column; gap: .3rem; font-size: .875rem; font-weight: 500; }
.tab-bar { display: flex; gap: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 1.25rem; }
.tab { flex: 1; padding: .5rem; background: var(--surface); border: none; font-size: .875rem; color: var(--muted); }
.tab.active { background: var(--bg); color: var(--text); font-weight: 600; }
.form-error { color: var(--danger); font-size: .8rem; min-height: 1.1em; }

/* ── Page header ── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem; flex-wrap: wrap; gap: .75rem;
}
.page-title { font-size: 1.25rem; font-weight: 700; }

/* ── Filter bar ── */
.filter-bar {
  display: flex; gap: .5rem; flex-wrap: wrap;
  margin-bottom: 1rem; align-items: center;
}
.filter-bar select, .filter-bar input { max-width: 180px; }

/* ── Bookmark list ── */
.bookmark-list { display: flex; flex-direction: column; gap: .4rem; }

.bookmark-item {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  align-items: flex-start; gap: .75rem;
  padding: .65rem .85rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg);
  transition: border-color .15s;
}
.bookmark-item:hover { border-color: var(--accent); }
.bookmark-favicon { width: 20px; height: 20px; flex-shrink: 0; margin-top: .15rem;
                    border-radius: 3px; object-fit: contain; }
.bookmark-favicon-placeholder {
  width: 20px; height: 20px; flex-shrink: 0; margin-top: .15rem;
  background: var(--border); border-radius: 3px; display: flex;
  align-items: center; justify-content: center; font-size: .65rem; color: var(--muted);
}
.bookmark-body  { min-width: 0; overflow: hidden; }
.bookmark-title { font-weight: 600; font-size: .95rem;
                  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bookmark-url   { font-size: .78rem; color: var(--muted);
                  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bookmark-desc  { font-size: .82rem; color: var(--muted); margin-top: .15rem;
                  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bookmark-meta  { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .3rem; align-items: center; }
.bookmark-actions { display: flex; gap: .15rem; flex-shrink: 0;
                    opacity: 0; transition: opacity .15s; align-self: flex-start; }
.bookmark-item:hover .bookmark-actions { opacity: 1; }

/* ── Duplicate review list ── */
.dup-list { display: flex; flex-direction: column; gap: .4rem; }
.dup-item {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  align-items: center; gap: .75rem;
  padding: .55rem .85rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg);
}
.dup-icon  { color: var(--muted); font-size: .85rem; flex-shrink: 0; }
.dup-body  { min-width: 0; overflow: hidden; }
.dup-title { font-weight: 600; font-size: .88rem;
             overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dup-url   { font-size: .75rem; color: var(--muted);
             overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dup-actions { display: flex; gap: .3rem; align-items: center; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

/* ── Tags / chips ── */
.tag-chip {
  display: inline-block; background: var(--surface);
  border: 1px solid var(--border); border-radius: 99px;
  font-size: .72rem; padding: .1rem .5rem; color: var(--muted);
}
.tag-chip.clickable:hover { background: var(--accent); color: #fff; border-color: var(--accent); cursor: pointer; }
.folder-chip {
  display: inline-block; font-size: .72rem; color: var(--accent);
  padding: .1rem .4rem;
}
.shared-badge {
  display: inline-block; font-size: .68rem; background: #fef9c3;
  color: #854d0e; border: 1px solid #fde68a; border-radius: 99px;
  padding: .05rem .45rem; vertical-align: middle;
}
.bookmark-item--shared { border-color: #fde68a; }
.bookmark-item--shared:hover { border-color: #f59e0b; }

/* ── Empty state ── */
.empty-state {
  text-align: center; padding: 3rem 1rem; color: var(--muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: .75rem; }

/* ── Pagination ── */
.pagination {
  display: flex; gap: .4rem; align-items: center;
  justify-content: center; margin-top: 1.25rem; flex-wrap: wrap;
}
.page-btn { padding: .3rem .65rem; }
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Forms ── */
.form-group { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .85rem; }
.form-group label { font-size: .875rem; font-weight: 500; }
.form-group .hint { font-size: .78rem; color: var(--muted); }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .5rem; }
.tag-input-wrap { display: flex; gap: .4rem; }
.tag-input-wrap input { flex: 1; }

/* ── Folder tree ── */
.folder-tree { list-style: none; }
.folder-tree li { padding: .1rem 0; }
.folder-row {
  display: flex; align-items: center; gap: .5rem;
  padding: .35rem .5rem; border-radius: var(--radius);
}
.folder-row:hover { background: var(--surface); }
.folder-row .folder-name { flex: 1; font-size: .9rem; }
.folder-children { margin-left: 1.25rem; }

/* ── Table ── */
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th { text-align: left; padding: .5rem .75rem; border-bottom: 2px solid var(--border);
                 color: var(--muted); font-weight: 600; }
.data-table td { padding: .5rem .75rem; border-bottom: 1px solid var(--border); }
.data-table tr:hover td { background: var(--surface); }

/* ── Badge ── */
.badge { display: inline-block; border-radius: 99px; padding: .1rem .55rem;
         font-size: .72rem; font-weight: 600; }
.badge-green  { background: #d3f4e0; color: #1a7f37; }
.badge-red    { background: #fde8e8; color: var(--danger); }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-gray   { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 1.25rem; right: 1.25rem; z-index: 999;
                   display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--text); color: var(--bg);
  padding: .6rem 1rem; border-radius: var(--radius);
  font-size: .875rem; max-width: 320px;
  animation: slideIn .2s ease;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Modal ── */
.modal {
  border: none; border-radius: var(--radius); padding: 0;
  box-shadow: 0 8px 32px rgba(0,0,0,.18); max-width: 520px; width: 95vw;
  /* centre in viewport */
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}
.modal::backdrop { background: rgba(0,0,0,.45); }
.modal-box { padding: 1.5rem; position: relative; }
.modal-close { position: absolute; top: .75rem; right: .75rem;
               background: none; border: none; font-size: 1.1rem;
               color: var(--muted); }
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 1rem; }

/* ── Stats grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border);
             border-radius: var(--radius); padding: 1rem; text-align: center; }
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.stat-label { font-size: .8rem; color: var(--muted); margin-top: .2rem; }

/* ── Import mode radio group ── */
.import-mode-label {
  display: flex; align-items: flex-start; gap: .55rem;
  cursor: pointer; font-size: .875rem;
}
.import-mode-label input[type="radio"] {
  width: auto; margin-top: .2rem; flex-shrink: 0;
}

/* ── File input ── */
.file-input-label {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .4rem .85rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: .875rem; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: border-color .15s;
}
.file-input-label:hover { border-color: var(--accent); }
.file-input-label input[type="file"] { display: none; }
.file-input-name {
  font-size: .82rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  :root { --sidebar-w: 200px; }
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding: .85rem; }
  .topbar-center { display: none; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .filter-bar { gap: .35rem; }
  .filter-bar select, .filter-bar input { max-width: 100%; flex: 1 1 120px; }
  .bookmark-url { max-width: 55vw; }
  .data-table { font-size: .8rem; }
  .data-table td, .data-table th { padding: .35rem .5rem; }
  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}

@media (max-width: 400px) {
  .topbar { padding: 0 .6rem; gap: .4rem; }
  .brand { font-size: .95rem; }
  .username-badge { display: none; }
}
