:root {
  --bg:          #0f0f0f;
  --surface:     #181818;
  --surface2:    #222222;
  --border:      #2a2a2a;
  --text:        #e8e6e1;
  --text-muted:  #888880;
  --accent:      #d97706;
  --accent-dim:  #92400e;
  --accent-glow: rgba(217,119,6,0.15);
  --success:     #22c55e;
  --danger:      #ef4444;
  --warning:     #f59e0b;
  --radius:      8px;
  --radius-sm:   4px;
}

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

html { font-size: 16px; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ── Nav ────────────────────────────────────── */
.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 2rem;
}
.nav-brand {
  font-family: 'Playfair Display', serif;
  font-size: 1.25rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}
.nav-links {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}
.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.nav-link:hover, .nav-link.active {
  color: var(--text);
  background: var(--surface2);
}
.nav-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  white-space: nowrap;
}
.nav-username { font-size: 0.875rem; color: var(--text-muted); }

/* ── Layout ─────────────────────────────────── */
main { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; }
.hidden { display: none !important; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-title { font-size: 1.5rem; font-weight: 600; }

/* ── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary   { background: var(--accent); color: #000; }
.btn-primary:hover:not(:disabled) { background: #f59e0b; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #2e2e2e; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn-icon { padding: 0.3rem; width: 28px; height: 28px; justify-content: center; }

/* ── Forms ───────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }
.form-label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.4rem; color: var(--text-muted); }
.form-control {
  width: 100%;
  padding: 0.55rem 0.8rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.15s;
}
.form-control:focus { outline: none; border-color: var(--accent); }
.form-control::placeholder { color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 100px; }
select.form-control { cursor: pointer; }
.form-control option { background: var(--surface2); color: var(--text); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.form-error { color: var(--danger); font-size: 0.8rem; margin-top: 0.3rem; }
.form-hint  { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.3rem; }

.input-with-btn { display: flex; gap: 0.5rem; }
.input-with-btn .form-control { flex: 1; }

.inline-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 0.5rem;
}

/* ── Tags input ──────────────────────────────── */
.tags-input-wrapper {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  min-height: 40px;
  cursor: text;
}
.tags-input-wrapper:focus-within { border-color: var(--accent); }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  font-size: 0.8rem;
}
.tag-chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  padding: 0;
  font-size: 0.9rem;
  line-height: 1;
}
.tags-input-inner {
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  flex: 1;
  min-width: 120px;
}
.tag-suggestions {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  z-index: 200;
  max-height: 160px;
  overflow-y: auto;
  min-width: 160px;
}
.tag-suggestion-item {
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.tag-suggestion-item:hover { background: var(--surface2); color: var(--text); }

/* ── Multi-select checkboxes ─────────────────── */
.multi-check-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.35rem 0;
}
.multi-check-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: 99px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}
.multi-check-item.checked { border-color: var(--accent); background: var(--accent-glow); color: var(--accent); }
.multi-check-item input { display: none; }

/* ── Cards ───────────────────────────────────── */
.citation-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  transition: border-color 0.15s;
}
.citation-card:hover { border-color: #3a3a3a; }
.citation-content {
  font-family: 'Playfair Display', serif;
  font-style: italic;
  font-size: 1.05rem;
  color: var(--text);
  line-height: 1.7;
  margin-bottom: 0.75rem;
  white-space: pre-line;
}
.citation-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.citation-meta strong { color: var(--text); }
.citation-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.citation-tags { display: flex; flex-wrap: wrap; gap: 0.35rem; flex: 1; }
.tag-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface2);
  padding: 0.1rem 0.5rem;
  border-radius: 99px;
}
.tag-badge.cat-badge {
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid var(--accent-dim);
}
.citation-actions { display: flex; gap: 0.35rem; }

.card-grid { display: grid; gap: 1rem; }
@media (min-width: 768px) { .card-grid { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); } }

/* ── Stats cards ─────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}
.stat-value { font-size: 2rem; font-weight: 600; color: var(--accent); }
.stat-label { font-size: 0.875rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ── Filters bar ─────────────────────────────── */
.filters-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  align-items: flex-end;
}
.filters-bar .form-control { min-width: 140px; }
.search-input { flex: 1; min-width: 200px; }

/* ── Table ───────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.65rem 0.85rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.875rem; }
th { color: var(--text-muted); font-weight: 500; background: var(--surface); }
tr:hover td { background: var(--surface); }

/* ── Pagination ──────────────────────────────── */
.pagination { display: flex; gap: 0.35rem; margin-top: 1.5rem; justify-content: center; }
.page-btn {
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  transition: all 0.15s;
}
.page-btn:hover { border-color: var(--accent); color: var(--accent); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #000; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Notices ─────────────────────────────────── */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
.alert-error   { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: #fca5a5; }
.alert-success { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.3); color: #86efac; }
.alert-warning { background: rgba(245,158,11,0.1); border: 1px solid rgba(245,158,11,0.3); color: #fcd34d; }
.alert-info    { background: rgba(217,119,6,0.1); border: 1px solid var(--border); color: var(--text-muted); }

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}
.empty-state p { margin-bottom: 1rem; }

/* ── Auth pages ──────────────────────────────── */
.auth-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 2rem; }
.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}
.auth-title { font-family: 'Playfair Display', serif; font-size: 1.75rem; margin-bottom: 0.25rem; }
.auth-subtitle { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 2rem; }

/* ── Import ──────────────────────────────────── */
.import-step { display: none; }
.import-step.active { display: block; }
.step-indicators { display: flex; gap: 0.5rem; margin-bottom: 2rem; }
.step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.2s;
}
.step-dot.active { background: var(--accent); border-color: var(--accent); color: #000; }
.step-dot.done { background: var(--surface2); border-color: var(--accent); color: var(--accent); }
.step-line { flex: 1; height: 1px; background: var(--border); align-self: center; }

.import-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.import-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}
.import-item.skip { opacity: 0.5; }
.import-item-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.import-status { font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.status-new      { color: var(--success); }
.status-warning  { color: var(--warning); }
.status-skip     { color: var(--text-muted); }
.import-warnings { margin-top: 0.5rem; }
.import-warning  { font-size: 0.8rem; color: var(--warning); padding: 0.25rem 0; }

/* ── Detail pages ────────────────────────────── */
.detail-header { margin-bottom: 2rem; }
.detail-title { font-family: 'Playfair Display', serif; font-size: 2rem; font-weight: 600; margin-bottom: 0.5rem; }
.detail-meta { color: var(--text-muted); font-size: 0.9rem; }

.citation-full {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 2rem;
  margin-bottom: 1.5rem;
}
.citation-full .citation-content { font-size: 1.25rem; }

.color-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.color-preview { width: 32px; height: 32px; border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* ── Progress bar ────────────────────────────── */
.progress-bar { width: 100%; height: 6px; background: var(--surface2); border-radius: 99px; margin: 1rem 0; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.3s; }

/* ── Section heading ─────────────────────────── */
.section-title { font-size: 1rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 1rem; }

/* ── List items ──────────────────────────────── */
.list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--surface); }
.list-item-title { flex: 1; font-weight: 500; }
.list-item-meta  { font-size: 0.8rem; color: var(--text-muted); }
.list-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

/* ── Spinner ─────────────────────────────────── */
.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 2rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-center { display: flex; justify-content: center; padding: 3rem; }

/* ── Scrollbar ───────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a3a; }

/* ── Hamburger nav toggle ────────────────────────── */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  line-height: 1;
}
.nav-toggle:hover { background: var(--surface2); }

/* ── Mobile responsive ───────────────────────────── */
@media (max-width: 767px) {
  .nav-inner {
    padding: 0 1rem;
    flex-wrap: wrap;
    height: auto;
    min-height: 56px;
    gap: 0;
  }
  .nav-brand { order: 1; padding: 1rem 0; }
  .nav-toggle { display: flex; order: 2; margin-left: auto; align-items: center; }
  .nav-links {
    display: none;
    order: 3;
    flex-direction: column;
    width: 100%;
    padding: 0.5rem 0 0.75rem;
    gap: 0.15rem;
    border-top: 1px solid var(--border);
  }
  .nav-user {
    display: none;
    order: 4;
    width: 100%;
    padding: 0.5rem 0 0.75rem;
    border-top: 1px solid var(--border);
  }
  .nav.nav-open .nav-links { display: flex; }
  .nav.nav-open .nav-user  { display: flex; }

  main { padding: 1rem; }

  .form-row,
  .form-row-3 { grid-template-columns: 1fr; }

  .filters-bar { flex-direction: column; }
  .filters-bar .form-control,
  .search-input { min-width: unset; width: 100%; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .auth-box { padding: 1.5rem; }
  .citation-full { padding: 1.25rem; }
  .detail-title { font-size: 1.5rem; }
}
