/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg:           #0f172a;
  --bg-2:         #1e293b;
  --bg-3:         #334155;
  --border:       #334155;
  --text:         #f1f5f9;
  --text-muted:   #94a3b8;
  --primary:      #6366f1;
  --primary-hover:#4f46e5;
  --success:      #22c55e;
  --danger:       #ef4444;
  --radius:       10px;
  --sidebar-w:    260px;
  --topbar-h:     56px;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
a { color: inherit; cursor: pointer; text-decoration: none; }
img { max-width: 100%; display: block; }
input, select, button { font-family: inherit; font-size: 14px; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Auth ──────────────────────────────────────────────────────────────────── */
.auth-screen {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
}
.auth-box {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 360px;
  text-align: center;
  display: flex; flex-direction: column; gap: 16px;
}
.auth-logo { font-size: 48px; }
.auth-box h1 { font-size: 24px; }
.auth-box p { color: var(--text-muted); }
.auth-box input {
  width: 100%; padding: 10px 14px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
}
.auth-box button {
  padding: 10px; background: var(--primary); color: white;
  border: none; border-radius: var(--radius); cursor: pointer; font-weight: 600;
}
.auth-box button:hover { background: var(--primary-hover); }
.error-msg { color: var(--danger); font-size: 13px; }

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  transition: transform 0.2s;
}
.sidebar-header {
  padding: 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.logo { font-size: 16px; font-weight: 700; }
.sidebar-nav { padding: 8px 0; flex: 1; }
.nav-section { padding: 8px 0; border-bottom: 1px solid var(--border); }
.nav-section:last-child { border-bottom: none; }
.nav-label {
  padding: 4px 16px 6px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em;
  color: var(--text-muted); text-transform: uppercase;
  display: flex; align-items: center; justify-content: space-between;
}
.nav-section a {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 16px;
  border-radius: 6px; margin: 1px 8px;
  color: var(--text-muted); font-size: 14px;
  cursor: pointer; transition: background 0.1s;
}
.nav-section a:hover, .nav-section a.active {
  background: var(--bg-3); color: var(--text);
}
.nav-section a.clear-filter { color: var(--danger); font-size: 12px; }
.collection-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 6px;
  margin: 1px 8px; cursor: pointer; transition: background 0.1s;
  color: var(--text-muted); font-size: 14px;
}
.collection-item:hover, .collection-item.active { background: var(--bg-3); color: var(--text); }
.coll-name { flex: 1; }
.coll-count { font-size: 11px; color: var(--text-muted); }
.tag-cloud { padding: 4px 16px; display: flex; flex-wrap: wrap; gap: 6px; }

/* ── Tags ──────────────────────────────────────────────────────────────────── */
.tag {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 8px;
  font-size: 12px; cursor: pointer;
  color: var(--text-muted); transition: all 0.1s;
}
.tag:hover, .tag.active { background: var(--primary); border-color: var(--primary); color: white; }
.tag small { opacity: 0.7; margin-left: 2px; }

/* ── Main ──────────────────────────────────────────────────────────────────── */
.main {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column;
}

/* ── Topbar ────────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  height: var(--topbar-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex; align-items: center; gap: 12px;
}
.search-bar {
  flex: 1; display: flex; align-items: center;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.search-icon { padding: 0 10px; color: var(--text-muted); }
.search-bar input {
  flex: 1; background: transparent; border: none;
  color: var(--text); padding: 8px 12px 8px 0; outline: none;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--primary); color: white;
  border: none; border-radius: var(--radius);
  padding: 8px 16px; cursor: pointer; font-weight: 600;
  white-space: nowrap; transition: background 0.1s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary {
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 16px; cursor: pointer; transition: background 0.1s;
}
.btn-secondary:hover { background: var(--bg-3); }
.icon-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 6px;
  border-radius: 6px; transition: all 0.1s; font-size: 16px;
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.icon-btn.small { font-size: 14px; padding: 2px 6px; }

/* ── List header ───────────────────────────────────────────────────────────── */
.list-header {
  padding: 20px 20px 12px;
  display: flex; align-items: center; gap: 12px;
}
.list-header h2 { font-size: 20px; font-weight: 700; }
.count { color: var(--text-muted); font-size: 13px; }

/* ── Bookmarks grid ────────────────────────────────────────────────────────── */
.bookmarks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  padding: 0 20px 20px;
}

/* ── Bookmark card ─────────────────────────────────────────────────────────── */
.bookmark-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  position: relative;
}
.bookmark-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.bookmark-card.read { opacity: 0.65; }
.bookmark-card.tweet { border-left: 3px solid #1d9bf0; }

.card-thumb { aspect-ratio: 16/9; overflow: hidden; background: var(--bg-3); }
.card-thumb img { width: 100%; height: 100%; object-fit: cover; }

.card-body { padding: 14px; }
.card-meta {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 8px; font-size: 12px; color: var(--text-muted);
}
.card-favicon { width: 14px; height: 14px; border-radius: 2px; }
.card-site { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-time { white-space: nowrap; }
.card-title {
  font-size: 15px; font-weight: 600; line-height: 1.4;
  margin-bottom: 6px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-excerpt {
  font-size: 13px; color: var(--text-muted); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  margin-bottom: 8px;
}
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.card-date { font-size: 11px; color: var(--text-muted); }

.card-actions {
  position: absolute; top: 8px; right: 8px;
  display: none;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-direction: row;
}
.bookmark-card:hover .card-actions { display: flex; }
.card-actions button, .card-actions a {
  background: none; border: none; cursor: pointer;
  padding: 6px 8px; font-size: 14px;
  color: var(--text-muted); transition: all 0.1s;
  display: flex; align-items: center;
}
.card-actions button:hover, .card-actions a:hover { background: var(--bg-3); color: var(--text); }
.card-actions .btn-danger:hover { background: var(--danger); color: white; }

/* ── Empty state ───────────────────────────────────────────────────────────── */
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  padding: 60px 20px; color: var(--text-muted); text-align: center;
}
.empty-icon { font-size: 64px; }

/* ── Loader ────────────────────────────────────────────────────────────────── */
.loader { padding: 40px; text-align: center; color: var(--text-muted); }
.load-more { padding: 20px; text-align: center; }

/* ── Reader view ───────────────────────────────────────────────────────────── */
.reader-view { flex: 1; padding: 0; }
.reader-header {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.reader-actions { display: flex; gap: 4px; }
.reader-content {
  max-width: 700px; margin: 0 auto;
  padding: 40px 24px 80px;
}
.reader-meta {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-muted); font-size: 13px; margin-bottom: 20px;
}
.reader-favicon { width: 16px; height: 16px; }
.reading-time { margin-left: auto; }
.reader-title { font-size: 28px; font-weight: 700; line-height: 1.3; margin-bottom: 8px; }
.reader-author { color: var(--text-muted); margin-bottom: 32px; }
.reader-excerpt { font-size: 16px; color: var(--text-muted); margin-bottom: 32px; }

/* ── Reader body (article) ─────────────────────────────────────────────────── */
.reader-body {
  font-size: 17px; line-height: 1.8; color: #e2e8f0;
}
.reader-body h1, .reader-body h2, .reader-body h3 {
  margin: 32px 0 16px; line-height: 1.3;
}
.reader-body p { margin-bottom: 20px; }
.reader-body a { color: var(--primary); text-decoration: underline; }
.reader-body img { border-radius: var(--radius); margin: 24px 0; }
.reader-body blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 20px; margin: 24px 0;
  color: var(--text-muted); font-style: italic;
}
.reader-body pre, .reader-body code {
  background: var(--bg-2); border-radius: 6px;
  font-family: 'Fira Code', monospace; font-size: 14px;
}
.reader-body pre { padding: 16px; overflow-x: auto; margin: 24px 0; }
.reader-body code { padding: 2px 6px; }

/* ── Tweet card ────────────────────────────────────────────────────────────── */
.tweet-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px; padding: 20px;
  max-width: 560px;
}
.tweet-author {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px;
}
.tweet-avatar { width: 48px; height: 48px; border-radius: 50%; }
.tweet-handle { display: block; color: var(--text-muted); font-size: 14px; }
.tweet-text { font-size: 16px; line-height: 1.5; margin-bottom: 12px; }
.tweet-media { border-radius: 12px; margin-top: 12px; max-height: 400px; object-fit: cover; }
.tweet-thread-post {
  border-top: 1px solid var(--border);
  padding-top: 16px; margin-top: 16px;
}

/* ── Highlights ────────────────────────────────────────────────────────────── */
.highlights-section { margin-top: 48px; padding-top: 32px; border-top: 1px solid var(--border); }
.highlights-section h3 { margin-bottom: 20px; }
.highlight-item { margin-bottom: 16px; padding: 16px; border-radius: var(--radius); }
.highlight-item[data-color="yellow"] { background: rgba(234, 179, 8, 0.12); border-left: 3px solid #eab308; }
.highlight-item[data-color="green"]  { background: rgba(34, 197, 94, 0.12);  border-left: 3px solid #22c55e; }
.highlight-item[data-color="blue"]   { background: rgba(59, 130, 246, 0.12); border-left: 3px solid #3b82f6; }
.highlight-item[data-color="pink"]   { background: rgba(236, 72, 153, 0.12); border-left: 3px solid #ec4899; }
.highlight-item[data-color="purple"] { background: rgba(168, 85, 247, 0.12); border-left: 3px solid #a855f7; }
.highlight-item blockquote { font-style: italic; color: var(--text); }
.highlight-note { margin-top: 8px; font-size: 13px; color: var(--text-muted); }

/* ── Modals ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%; max-width: 480px;
  overflow: hidden;
}
.modal-sm { max-width: 360px; }
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.form-group label small { font-weight: 400; opacity: 0.7; }
.form-group input, .form-group select {
  padding: 9px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  width: 100%; outline: none; transition: border-color 0.1s;
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Add preview ───────────────────────────────────────────────────────────── */
.add-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex; gap: 12px; align-items: center;
}
.preview-thumb { width: 72px; height: 54px; object-fit: cover; border-radius: 6px; }
.preview-info { flex: 1; min-width: 0; }
.preview-info strong { display: block; font-size: 13px; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-info span { font-size: 11px; color: var(--text-muted); }

/* ── Share target page ─────────────────────────────────────────────────────── */
.share-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.share-page .modal { max-width: 100%; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.5); }
  .bookmarks-grid { grid-template-columns: 1fr; padding: 0 12px 20px; }
  .reader-content { padding: 24px 16px 60px; }
  .reader-title { font-size: 22px; }
  .reader-body { font-size: 16px; }
}
