/* ─── Theme Variables ───────────────────────────────────────────────── */

:root, [data-theme="dark"] {
  --bg:        #0f0f17;
  --surface:   #181824;
  --surface2:  #1e1e2e;
  --border:    rgba(255,255,255,0.07);
  --accent:    #c8b4ff;
  --accent2:   #7ee8c2;
  --text:      #e8e3f0;
  --muted:     #7a7a9a;
  --danger:    #ff6b7a;
  --sidebar-w: 220px;
}

[data-theme="light"] {
  --bg:       #f5f5f2;
  --surface:  #ffffff;
  --surface2: #ebebeb;
  --border:   rgba(0,0,0,0.08);
  --accent:   #7c4dff;
  --accent2:  #00897b;
  --text:     #1a1a2e;
  --muted:    #757590;
  --danger:   #e53935;
}

[data-theme="sepia"] {
  --bg:       #f4ece0;
  --surface:  #fdf6ec;
  --surface2: #ede4d4;
  --border:   rgba(100,70,30,0.12);
  --accent:   #8b5e3c;
  --accent2:  #4a7c59;
  --text:     #3b2a1a;
  --muted:    #8a7060;
  --danger:   #c0392b;
}

[data-theme="hc-dark"] {
  --bg:       #000000;
  --surface:  #0a0a0a;
  --surface2: #111111;
  --border:   rgba(255,255,255,0.25);
  --accent:   #ffffff;
  --accent2:  #ffff00;
  --text:     #ffffff;
  --muted:    #aaaaaa;
  --danger:   #ff4444;
}

[data-theme="hc-light"] {
  --bg:       #ffffff;
  --surface:  #ffffff;
  --surface2: #f0f0f0;
  --border:   rgba(0,0,0,0.5);
  --accent:   #0000cc;
  --accent2:  #006600;
  --text:     #000000;
  --muted:    #333333;
  --danger:   #cc0000;
}

/* Deuteranopia — replaces red/green with blue/yellow */
[data-theme="deuteranopia"] {
  --bg:       #0f0f17;
  --surface:  #181824;
  --surface2: #1e1e2e;
  --border:   rgba(255,255,255,0.07);
  --accent:   #4fc3f7;
  --accent2:  #ffd54f;
  --text:     #e8e3f0;
  --muted:    #7a7a9a;
  --danger:   #ff9800;
}

/* Protanopia — similar to deuteranopia */
[data-theme="protanopia"] {
  --bg:       #0f0f17;
  --surface:  #181824;
  --surface2: #1e1e2e;
  --border:   rgba(255,255,255,0.07);
  --accent:   #81d4fa;
  --accent2:  #ffe082;
  --text:     #e8e3f0;
  --muted:    #7a7a9a;
  --danger:   #ffb74d;
}

/* Tritanopia — replaces blue/yellow with red/teal */
[data-theme="tritanopia"] {
  --bg:       #0f0f17;
  --surface:  #181824;
  --surface2: #1e1e2e;
  --border:   rgba(255,255,255,0.07);
  --accent:   #ef9a9a;
  --accent2:  #80cbc4;
  --text:     #e8e3f0;
  --muted:    #7a7a9a;
  --danger:   #ef5350;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Syne', sans-serif;
  height: 100dvh;
  overflow: hidden;
  transition: background 0.2s ease, color 0.2s ease;
}

/* ─── Screens ────────────────────────────────────────────────────────── */
.screen { height: 100dvh; }

/* ─── Login ──────────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 40px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.login-logo {
  font-size: 36px;
  color: var(--accent);
  margin-bottom: 4px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.login-sub {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.field-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  padding: 11px 14px;
  outline: none;
  transition: border-color 0.15s ease;
}

.field-input::placeholder { color: var(--muted); }
.field-input:focus { border-color: var(--accent); }

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 10px;
  font-family: 'Syne', sans-serif;
  font-size: 14px;
  font-weight: 700;
  padding: 12px;
  cursor: pointer;
  transition: opacity 0.15s ease;
  letter-spacing: 0.02em;
  margin-top: 4px;
}

.btn-primary:hover { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.login-error {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: var(--danger);
  text-align: center;
}

/* ─── App Layout ─────────────────────────────────────────────────────── */
#app-screen {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  height: 100dvh;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
}

.logo-mark {
  font-size: 20px;
  color: var(--accent);
}

.logo-text {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.sidebar-nav {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--muted);
  font-family: 'Syne', sans-serif;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: all 0.12s ease;
  width: 100%;
  letter-spacing: 0.02em;
}

.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface2); color: var(--accent); }
.nav-item.danger:hover { color: var(--danger); }

.nav-icon { font-size: 14px; width: 16px; }

.sidebar-categories {
  padding: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}

.category-label {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  padding: 4px 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-footer {
  margin-top: auto;
  padding: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ─── Main ───────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ─── Top bar ────────────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-wrap {
  position: relative;
  flex: 1;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 16px;
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  padding: 9px 12px 9px 36px;
  outline: none;
  transition: border-color 0.15s ease;
}

.search-input::placeholder { color: var(--muted); }
.search-input:focus { border-color: var(--accent); background: var(--surface2); }

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-badge {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 20px;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.icon-btn:hover { background: var(--surface2); color: var(--text); }

/* ─── Links Grid ─────────────────────────────────────────────────────── */
.links-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
  align-content: start;
}

.links-grid::-webkit-scrollbar { width: 5px; }
.links-grid::-webkit-scrollbar-track { background: transparent; }
.links-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── Link Card ──────────────────────────────────────────────────────── */
.link-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.15s ease, transform 0.1s ease;
  animation: fadeUp 0.2s ease;
}

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

.link-card:hover { border-color: rgba(200,180,255,0.25); }

.card-body { padding: 14px 16px; }

.card-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.type-badge {
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  flex-shrink: 0;
  margin-top: 2px;
}

.type-badge.section {
  background: rgba(200,180,255,0.12);
  color: var(--accent);
  border: 1px solid rgba(200,180,255,0.2);
}

.type-badge.page {
  background: rgba(126,232,194,0.1);
  color: var(--accent2);
  border: 1px solid rgba(126,232,194,0.2);
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}

.card-ai-title {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--accent);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.ai-badge {
  font-size: 9px;
  background: rgba(200,180,255,0.1);
  border: 1px solid rgba(200,180,255,0.2);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--accent);
}

.card-excerpt {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 8px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  border-left: 2px solid rgba(200,180,255,0.2);
  padding-left: 8px;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.card-domain {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  opacity: 0.6;
}

.card-date {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--muted);
  opacity: 0.5;
  margin-left: auto;
}

.card-category {
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.card-note {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  padding: 6px 9px;
  outline: none;
  resize: none;
  margin-top: 8px;
  line-height: 1.4;
  transition: border-color 0.15s ease;
}

.card-note::placeholder { color: var(--muted); }
.card-note:focus { border-color: var(--accent); }

.card-actions {
  display: flex;
  border-top: 1px solid var(--border);
}

.card-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  font-family: 'Syne', sans-serif;
  font-size: 11px;
  font-weight: 600;
  padding: 8px 4px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: all 0.12s ease;
}

.card-btn + .card-btn { border-left: 1px solid var(--border); }
.card-btn:hover { background: var(--surface2); color: var(--text); }
.card-btn.open:hover { color: var(--accent); }
.card-btn.copy:hover { color: var(--accent2); }
.card-btn.delete:hover { color: var(--danger); }

/* ─── Empty State ────────────────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px 24px;
  text-align: center;
  color: var(--muted);
}

.empty-icon { font-size: 40px; opacity: 0.3; }
.empty-state p { font-size: 14px; }
.empty-hint { font-family: 'DM Mono', monospace; font-size: 12px; }

/* ─── Settings Panel ─────────────────────────────────────────────────── */
.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.settings-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  max-height: 80dvh;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-header h2 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-section h3 {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.theme-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: 'Syne', sans-serif;
  font-size: 11px;
  font-weight: 600;
  padding: 8px 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.12s ease;
  letter-spacing: 0.01em;
  text-align: center;
}

.theme-btn:hover { color: var(--text); border-color: var(--accent); }
.theme-btn.active { background: var(--accent); color: var(--bg); border-color: var(--accent); }

.btn-secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Syne', sans-serif;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.12s ease;
  text-align: left;
}

.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger {
  background: rgba(255,107,122,0.08);
  border: 1px solid rgba(255,107,122,0.2);
  color: var(--danger);
  font-family: 'Syne', sans-serif;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.12s ease;
  text-align: left;
}

.btn-danger:hover { background: rgba(255,107,122,0.15); }

.settings-info {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: var(--muted);
}

.settings-info strong { color: var(--text); }
.settings-info.muted { opacity: 0.6; }

/* ─── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  padding: 8px 18px;
  border-radius: 20px;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .sidebar { display: none; }
  .links-grid { grid-template-columns: 1fr; padding: 12px; }
  .theme-grid { grid-template-columns: repeat(2, 1fr); }
}
[hidden] { display: none !important; }
