/* ════════════════════════════════════════════
   BASE VARIABLES
   ════════════════════════════════════════════ */

:root {
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --surface-3: #f0f2f5;
  --border: #e2e6ea;
  --border-strong: #c9cdd2;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  font-size: 0.9rem;
  background: var(--surface-2);
  color: var(--text);
  line-height: 1.6;
  padding-top: 20px;
  -webkit-font-smoothing: antialiased;
}

/* ════════════════════════════════════════════
   STICKY HEADER
   ════════════════════════════════════════════ */

#stickyHeader {
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 0 6px;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

.nav-tabs {
  border-bottom: none;
  gap: 2px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }

.nav-tabs .nav-link {
  border: none !important;
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav-tabs .nav-link:hover { background: var(--surface-3); color: var(--text); }
.nav-tabs .nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

#globalSearchBar { padding: 4px 0 2px; }
#globalSearchBar .input-group-text {
  background: var(--surface-2); border-color: var(--border);
  color: var(--text-muted); font-size: .78rem;
}
#globalSearchBar .form-control { border-color: var(--border); font-size: .82rem; }
#globalSearchBar .form-control:focus { border-color: var(--accent); box-shadow: none; }

#globalSearchResults {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 0;
  margin-top: 6px;
}
#globalResultsList { max-height: 360px; overflow-y: auto; }
#globalResultsList .list-group-item {
  font-size: .83rem; padding: 7px 12px;
  border-color: var(--border); cursor: pointer; transition: background .1s;
}
#globalResultsList .list-group-item:hover { background: var(--surface-2); }
#globalResultsList .list-group-item .topic-input { width: 60% !important; }

#quickSubmitBar { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 6px; }

/* ════════════════════════════════════════════
   CARDS
   ════════════════════════════════════════════ */

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--surface);
  transition: box-shadow .2s;
}
.card:hover { box-shadow: var(--shadow); }
.card-header {
  background: var(--surface-2) !important;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0 !important;
  padding: .6rem 1rem;
}
.card-body { padding: .85rem 1rem; }

/* ════════════════════════════════════════════
   FORMS
   ════════════════════════════════════════════ */

.form-control, .form-select {
  border-color: var(--border);
  border-radius: var(--radius-sm);
  font-size: .875rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.input-group-text { background: var(--surface-2); border-color: var(--border); font-size: .82rem; }

/* ════════════════════════════════════════════
   BUTTONS
   ════════════════════════════════════════════ */

.btn { border-radius: var(--radius-sm); font-size: .83rem; font-weight: 500; }
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.badge { border-radius: 5px; font-weight: 500; font-size: .72rem; }

/* ════════════════════════════════════════════
   TABLES
   ════════════════════════════════════════════ */

.table { font-size: .83rem; }
.table th {
  font-size: .75rem; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .03em;
  background: var(--surface-2) !important;
}
.table td { vertical-align: middle; }

/* ════════════════════════════════════════════
   CLICKABLE
   ════════════════════════════════════════════ */

.clickable {
  cursor: pointer; background: var(--surface-2);
  padding: 5px 8px; border-radius: var(--radius-sm);
  transition: background .15s;
}
.clickable:hover { background: var(--surface-3); }

/* ════════════════════════════════════════════
   QUEUE PAGE
   ════════════════════════════════════════════ */

.tweet-images-grid { display: flex; flex-wrap: wrap; gap: 5px; }
.tweet-images-grid .img-thumb {
  width: 72px; height: 72px; object-fit: cover;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  cursor: pointer; transition: opacity .15s, transform .1s;
}
.tweet-images-grid .img-thumb:hover { opacity: .85; transform: scale(1.04); }
.copy-buffer-btn { font-weight: 500; }

.image-wrapper { position: relative; display: inline-block; }
.image-wrapper img {
  max-width: 160px; max-height: 160px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); object-fit: cover;
}
.image-delete-btn {
  position: absolute; top: -7px; right: -7px;
  background: var(--danger); color: white;
  border: 2px solid white; border-radius: 50%;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 13px; font-weight: bold;
  box-shadow: var(--shadow-sm);
}
.image-delete-btn:hover { background: #b91c1c; }

.spinner-border {
  display: inline-block; border: .15em solid currentColor;
  border-right-color: transparent; border-radius: 50%;
  animation: spin .75s linear infinite;
}
.spinner-border-sm { width: .85rem; height: .85rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ════════════════════════════════════════════
   REVIEW PAGE
   ════════════════════════════════════════════ */

.review-paste-bar {
  background: var(--surface); border-bottom: 2px solid var(--accent);
  padding: .6rem 0 .5rem; margin-bottom: 1rem;
}
.review-paste-bar textarea { resize: none; font-size: .85rem; }
.review-card { transition: opacity .2s, transform .2s; }
.review-card.removing { opacity: 0; transform: translateX(-20px); }
.score-bar { height: 3px; border-radius: 2px; margin-bottom: .4rem; }
.approve-row { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.approve-row input { min-width: 0; flex: 1 1 160px; font-size: .8rem; }
.approve-row .btn { font-size: .8rem; white-space: nowrap; }
@media (max-width: 576px) {
  .approve-row { flex-direction: column; align-items: stretch; }
  .approve-row .btn { width: 100%; }
}

/* ════════════════════════════════════════════
   MANAGE PAGE
   ════════════════════════════════════════════ */

.manage-grid {
  display: grid; grid-template-columns: 320px 1fr;
  gap: 1.25rem; align-items: start;
}
@media (max-width: 900px) { .manage-grid { grid-template-columns: 1fr; } }

.tag-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .65rem .85rem; margin-bottom: .4rem;
  background: var(--surface); transition: box-shadow .15s, border-color .15s;
}
.tag-card:hover { box-shadow: var(--shadow); border-color: var(--border-strong); }
.tag-card.is-special { border-left: 3px solid var(--text-muted); }
.tag-name { font-weight: 600; font-family: var(--mono); font-size: .88rem; }
.tag-meta { font-size: .75rem; color: var(--text-muted); }
.tag-desc-preview {
  font-size: .75rem; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 210px;
}

.topics-toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: 1rem; }
.topics-toolbar .form-select, .topics-toolbar .form-control { font-size: .82rem; }
#topicsTable { font-size: .82rem; }
#topicsTable th { position: sticky; top: 0; z-index: 1; }
#topicsTable td { vertical-align: middle; }
.topic-row td { padding: .3rem .55rem; }
.topic-year-badge {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  font-size: .72rem; background: var(--surface-3);
  color: var(--text-muted); font-family: var(--mono);
}
.editable-topic { cursor: pointer; }
.editable-topic:hover { text-decoration: underline dotted; }
.topic-edit-input {
  width: 100%; font-size: .83rem; padding: 2px 6px;
  border: 1px solid var(--accent); border-radius: 4px; outline: none;
}
.editable-year { cursor: pointer; }
.editable-year:hover .topic-year-badge { background: var(--accent-soft); color: var(--accent); }
.pagination { margin: 0; }
.page-link { font-size: .78rem; padding: .22rem .48rem; }
#newTagPanel { display: none; }
#newTagPanel.open { display: block; }

/* ════════════════════════════════════════════
   STATS PAGE
   ════════════════════════════════════════════ */

.stat-card {
  border-radius: var(--radius); padding: 1.1rem 1.25rem;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.stat-card .number { font-size: 1.9rem; font-weight: 700; line-height: 1; }
.stat-card .label { font-size: .77rem; color: var(--text-muted); margin-top: .2rem; }

.chart-card {
  border-radius: var(--radius); padding: 1.1rem 1.25rem;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm); margin-bottom: 1.25rem;
}
.chart-title { font-size: .88rem; font-weight: 600; margin-bottom: .85rem; display: flex; align-items: center; gap: .4rem; }
.chart-subtitle { font-size: .73rem; color: var(--text-muted); margin-left: auto; }

.heatmap-grid { display: flex; gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heatmap-week { display: flex; flex-direction: column; gap: 3px; }
.heatmap-cell { width: 12px; height: 12px; border-radius: 2px; background: #ebedf0; cursor: default; transition: transform .1s; }
.heatmap-cell:hover { transform: scale(1.5); }
.heatmap-cell[data-level="1"] { background: #9be9a8; }
.heatmap-cell[data-level="2"] { background: #40c463; }
.heatmap-cell[data-level="3"] { background: #30a14e; }
.heatmap-cell[data-level="4"] { background: #216e39; }
.heatmap-legend { display: flex; align-items: center; gap: 4px; margin-top: 6px; font-size: .7rem; color: var(--text-muted); }
.heatmap-legend-cell { width: 10px; height: 10px; border-radius: 2px; }

.word-cloud { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: .4rem 0; }
.word-chip { border-radius: 20px; padding: 3px 10px; font-weight: 500; cursor: default; transition: transform .15s; border: 1px solid transparent; }
.word-chip:hover { transform: scale(1.06); }
.inactive-tag {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: .78rem; background: var(--warning-soft); color: var(--warning);
  margin: 3px; border: 1px solid #fde68a;
}
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ════════════════════════════════════════════
   AUTH PAGES
   ════════════════════════════════════════════ */

.auth-card {
  max-width: 420px; margin: 60px auto;
  background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow-lg); padding: 2.5rem 2rem; border: 1px solid var(--border);
}
.auth-title { font-size: 1.4rem; font-weight: 700; margin-bottom: .25rem; }
.auth-subtitle { color: var(--text-muted); margin-bottom: 1.5rem; font-size: .9rem; }
.btn-google {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  display: flex; align-items: center; justify-content: center; gap: .6rem;
  font-size: .9rem; padding: .55rem 1rem; transition: background .15s; border-radius: var(--radius-sm);
}
.btn-google:hover { background: var(--surface-2); }
.divider { display: flex; align-items: center; gap: .75rem; margin: 1.25rem 0; color: var(--text-faint); font-size: .8rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.strength-bar { height: 4px; border-radius: 2px; transition: all .3s; background: var(--border); }

/* ════════════════════════════════════════════
   DARK TOGGLE
   ════════════════════════════════════════════ */

.dark-toggle {
  background: none; border: none; cursor: pointer; font-size: 1rem;
  padding: 3px 7px; border-radius: var(--radius-sm); transition: background .15s;
  line-height: 1; color: var(--text-muted);
}
.dark-toggle:hover { background: var(--surface-3); }

/* ════════════════════════════════════════════
   DARK MODE
   ════════════════════════════════════════════ */

[data-theme="dark"] {
  --surface: #1e2128;
  --surface-2: #252830;
  --surface-3: #2d3139;
  --border: #353840;
  --border-strong: #454850;
  --text: #e8eaed;
  --text-muted: #9aa0aa;
  --text-faint: #636870;
  --accent-soft: #1e2d4a;
  --success-soft: #0f2820;
  --warning-soft: #2d2210;
  --danger-soft: #2d1515;
  color-scheme: dark;
}
[data-theme="dark"] body { background: #16181d; }
[data-theme="dark"] #stickyHeader { background: #1e2128 !important; border-bottom-color: #353840; }
[data-theme="dark"] .nav-tabs .nav-link { color: #9aa0aa; }
[data-theme="dark"] .nav-tabs .nav-link:hover { background: #2d3139; color: #e8eaed; }
[data-theme="dark"] .nav-tabs .nav-link.active { background: #1e2d4a; color: #60a5fa; }
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="dark"] textarea { background: #252830; border-color: #454850; color: #e8eaed; }
[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus { background: #252830; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.2); }
[data-theme="dark"] .form-control::placeholder { color: #636870; }
[data-theme="dark"] .input-group-text { background: #2d3139; border-color: #454850; color: #9aa0aa; }
[data-theme="dark"] .card { background: #1e2128; border-color: #353840; color: #e8eaed; }
[data-theme="dark"] .card-header { background: #252830 !important; border-color: #353840; }
[data-theme="dark"] .table { --bs-table-bg: #1e2128; --bs-table-striped-bg: #252830; --bs-table-hover-bg: #2d3139; --bs-table-border-color: #353840; color: #e8eaed; }
[data-theme="dark"] .table th { background: #252830 !important; color: #9aa0aa; }
[data-theme="dark"] .modal-content { background: #1e2128; border-color: #353840; color: #e8eaed; }
[data-theme="dark"] .modal-header, [data-theme="dark"] .modal-footer { border-color: #353840; }
[data-theme="dark"] .list-group-item { background: #1e2128; border-color: #353840; color: #e8eaed; }
[data-theme="dark"] .list-group-flush .list-group-item { background: transparent; }
[data-theme="dark"] .alert-secondary { background: #252830; border-color: #353840; color: #9aa0aa; }
[data-theme="dark"] .alert-light { background: #252830; border-color: #353840; color: #9aa0aa; }
[data-theme="dark"] .alert-info { background: #1a3a4a; border-color: #1e4d70; color: #7dd3fc; }
[data-theme="dark"] .bg-light { background: #252830 !important; }
[data-theme="dark"] .text-muted { color: #9aa0aa !important; }
[data-theme="dark"] .border { border-color: #353840 !important; }
[data-theme="dark"] #globalSearchResults { background: #1e2128; border-color: #353840; }
[data-theme="dark"] .review-paste-bar { background: #1e2128 !important; border-bottom-color: #3b82f6; }
[data-theme="dark"] .tag-card { background: #1e2128; border-color: #353840; }
[data-theme="dark"] .heatmap-cell { background: #2d3139; }
[data-theme="dark"] .heatmap-cell[data-level="1"] { background: #0e4429; }
[data-theme="dark"] .heatmap-cell[data-level="2"] { background: #006d32; }
[data-theme="dark"] .heatmap-cell[data-level="3"] { background: #26a641; }
[data-theme="dark"] .heatmap-cell[data-level="4"] { background: #39d353; }
[data-theme="dark"] .word-chip { background: #2d3139 !important; border-color: #454850 !important; }
[data-theme="dark"] .inactive-tag { background: #2d2210; color: #fbbf24; border-color: #78350f; }
[data-theme="dark"] .skeleton { background: linear-gradient(90deg, #252830 25%, #2d3139 50%, #252830 75%); background-size: 200% 100%; }
[data-theme="dark"] .topic-year-badge { background: #2d3139; color: #9aa0aa; }
[data-theme="dark"] pre, [data-theme="dark"] code { background: #252830; color: #e8a87c; }
[data-theme="dark"] .auth-card { background: #1e2128; border-color: #353840; }
[data-theme="dark"] .btn-google { background: #252830; border-color: #454850; color: #e8eaed; }
[data-theme="dark"] .clickable { background: #252830; }
[data-theme="dark"] .clickable:hover { background: #2d3139; }
[data-theme="dark"] .dark-toggle:hover { background: #2d3139; }

/* ════════════════════════════════════════════
   MOBILE
   ════════════════════════════════════════════ */

@media (max-width: 768px) {
  body { font-size: .875rem; }
  .container-fluid { padding-left: 12px !important; padding-right: 12px !important; }
  .nav-tabs .nav-link { padding: 5px 9px; font-size: .78rem; }
  .card-body { padding: .7rem .8rem; }
  .btn { min-height: 36px; }
  .btn-sm { min-height: 32px; }
  .stat-card .number { font-size: 1.6rem; }
}
@media (max-width: 480px) {
  .auth-card { margin: 20px 12px; padding: 1.75rem 1.25rem; }
}

/* Focus accessibility */
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.modal-content { box-shadow: var(--shadow-lg) !important; }