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

:root {
  --red:        #B31B1B;
  --red-dark:   #8a1414;
  --red-light:  #f5e0e0;
  --navy:       #1a2a3a;
  --navy-mid:   #243447;
  --text:       #1c1c1e;
  --text-muted: #6b7280;
  --border:     #e5e7eb;
  --bg:         #f8f7f4;
  --card-bg:    #ffffff;
  --mono:       'JetBrains Mono', monospace;
  --serif:      'Playfair Display', Georgia, serif;
  --sans:       'Inter', system-ui, sans-serif;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
}

a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ── */
header {
  background: var(--navy);
  border-bottom: 3px solid var(--red);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.shield {
  width: 36px;
  height: 44px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 6px rgba(179,27,27,0.5));
}

.site-title {
  font-family: var(--serif);
  font-size: 1.45rem;
  color: #fff;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.site-tagline {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.55);
  margin-top: 2px;
  letter-spacing: 0.02em;
}

.header-nav {
  display: flex;
  gap: 24px;
}

.header-nav a {
  color: rgba(255,255,255,0.65);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  transition: color 0.15s;
}

.header-nav a:hover,
.header-nav a.active { color: #fff; text-decoration: none; }

/* ── Stats bar ── */
.stats-bar {
  background: var(--navy-mid);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 48px;
}

.stat-num {
  font-family: var(--serif);
  font-size: 1.5rem;
  color: #fff;
  font-weight: 700;
  line-height: 1;
}

.stat-label {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 4px;
}

.stat-divider {
  width: 1px;
  height: 36px;
  background: rgba(255,255,255,0.1);
}

.stat-arrow {
  font-size: 0.85rem;
  color: var(--red);
  opacity: 0.8;
  margin: 0 2px;
}

/* ── Page layout with collapsible filter pane ── */
.page-layout {
  display: flex;
  align-items: flex-start;
  width: 100%;
}

/* ── Filter pane ── */
.filter-pane {
  width: 260px;
  flex-shrink: 0;
  position: sticky;
  top: 73px;                         /* below sticky header */
  min-height: calc(100vh - 73px);
  max-height: calc(100vh - 73px);
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--card-bg);
  padding: 20px 16px 40px;
  transition: width 0.2s ease, padding 0.2s ease;
}

.filter-pane.collapsed {
  width: 44px;
  padding: 12px 0;
  overflow: hidden;
}

.filter-pane.collapsed .pane-inner {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s;
}

.pane-inner {
  transition: opacity 0.2s;
}

.pane-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-left: auto;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
  font-size: 0.72rem;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.filter-pane.collapsed .pane-toggle {
  margin: 0 auto 0;
}
.pane-toggle:hover {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.pane-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Hide pane on non-articles tabs */
.filter-pane.pane-hidden {
  display: none;
}

/* ── Main layout ── */
main {
  flex: 1;
  min-width: 0;
  padding: 40px 32px 80px;
  display: flex;
  flex-direction: column;
  gap: 64px;
}

/* ── Section header + controls ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--red);
}

.section-header h2 {
  font-family: var(--serif);
  font-size: 1.5rem;
  color: var(--navy);
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.controls input,
.controls select {
  font-family: var(--sans);
  font-size: 0.82rem;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.controls input:focus,
.controls select:focus { border-color: var(--red); }

/* ── Chip filter picker ── */
.chip-filter-section {
  margin-bottom: 20px;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.active-filters.hidden { display: none; }

.active-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--navy);
  color: #fff;
  border-radius: 999px;
  padding: 3px 10px 3px 12px;
  font-size: 0.78rem;
  font-weight: 500;
}
.active-chip-rm {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  transition: color 0.1s;
}
.active-chip-rm:hover { color: #fff; }

/* ── Date range filter ── */
.date-range-section {
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.date-range-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.date-field {
  display: flex;
  align-items: center;
  gap: 7px;
}

.date-label {
  font-size: 0.67rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  width: 28px;
  flex-shrink: 0;
}

.date-input {
  font-family: var(--sans);
  font-size: 0.78rem;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
  flex: 1;
  min-width: 0;
  transition: border-color 0.15s;
  cursor: pointer;
}
.date-input:focus { border-color: var(--red); }
.date-input::-webkit-calendar-picker-indicator { opacity: 0.5; cursor: pointer; }

.active-chip-date {
  background: #0e7490;
}

.active-date-rm {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  transition: color 0.1s;
}
.active-date-rm:hover { color: #fff; }

.chip-search-row {
  margin-bottom: 10px;
}
.chip-search-row input {
  font-family: var(--sans);
  font-size: 0.82rem;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
  width: 220px;
  transition: border-color 0.15s;
}
.chip-search-row input:focus { border-color: var(--red); }

.chip-pool {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.chip-group {
  margin-bottom: 14px;
}

.chip-group-title {
  font-size: 0.67rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  margin-bottom: 6px;
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 5px;
}
.chip-group-title::-webkit-details-marker { display: none; }
.chip-group-title::before {
  content: "▸";
  font-size: 0.6rem;
  transition: transform 0.15s;
  display: inline-block;
}
.chip-group[open] > .chip-group-title::before {
  transform: rotate(90deg);
}

.chip-group-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding-top: 6px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 13px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  user-select: none;
}
.filter-chip-keyword {
  background: var(--red-light);
  color: var(--red-dark);
  border-color: transparent;
}
.filter-chip-keyword:hover { border-color: var(--red); }
.filter-chip-keyword.active {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.filter-chip-tag {
  background: #e0e7ff;
  color: #3730a3;
  border-color: transparent;
}
.filter-chip-tag:hover { border-color: #6366f1; }
.filter-chip-tag.active {
  background: #4f46e5;
  color: #fff;
  border-color: #4f46e5;
}

.filter-chip-section {
  background: #fef3c7;
  color: #92400e;
  border-color: transparent;
}
.filter-chip-section:hover { border-color: #f59e0b; }
.filter-chip-section.active {
  background: #f59e0b;
  color: #fff;
  border-color: #f59e0b;
}

.filter-chip-author {
  background: #ccfbf1;
  color: #115e59;
  border-color: transparent;
}
.filter-chip-author:hover { border-color: #14b8a6; }
.filter-chip-author.active {
  background: #0d9488;
  color: #fff;
  border-color: #0d9488;
}

.chip-empty {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Article list ── */
.articles-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-bottom: 18px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.legend-tag-sample {
  pointer-events: none;
}
.legend-sep {
  color: var(--border);
  font-size: 1rem;
}

.article-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.loading {
  color: var(--text-muted);
  font-style: italic;
  padding: 24px 0;
}

/* ── Article card ── */
.article-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 8px 16px;
  align-items: start;
  transition: box-shadow 0.15s, border-color 0.15s;
  position: relative;
}

.article-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.07);
  border-color: #d1d5db;
}

.article-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--red);
  border-radius: 10px 0 0 10px;
  opacity: 0;
  transition: opacity 0.15s;
}

.article-card:hover::before { opacity: 1; }

.card-pdot { margin-top: 5px; grid-column: 1; }
.card-main { grid-column: 2; }
.card-meta-col { grid-column: 3; text-align: right; }

.card-title {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.35;
  margin-bottom: 6px;
}

.card-title a {
  color: inherit;
  text-decoration: none;
}

.card-title a:hover { color: var(--red); }

.card-summary {
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-keywords { display: flex; flex-wrap: wrap; gap: 6px; }

/* Clickable topic + tag labels on article cards */
.card-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}
.card-label {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  user-select: none;
}
.card-label-tag {
  background: #e0e7ff;
  color: #3730a3;
}
.card-label-tag:hover { border-color: #6366f1; }
.card-label-tag.active {
  background: #4f46e5;
  color: #fff;
}
.card-label-keyword {
  background: var(--red-light);
  color: var(--red-dark);
  font-family: var(--mono);
  font-size: 0.68rem;
}
.card-label-keyword:hover { border-color: var(--red); }
.card-label-keyword.active {
  background: var(--red);
  color: #fff;
}
.card-label-section {
  background: #fef3c7;
  color: #92400e;
}
.card-label-section:hover { border-color: #f59e0b; }
.card-label-section.active {
  background: #f59e0b;
  color: #fff;
}
.card-label-author {
  background: #ccfbf1;
  color: #115e59;
}
.card-label-author:hover { border-color: #14b8a6; }
.card-label-author.active {
  background: #0d9488;
  color: #fff;
}

/* Legacy non-clickable kw-tag (legend sample, etc.) */
.kw-tag {
  font-family: var(--mono);
  font-size: 0.68rem;
  background: var(--red-light);
  color: var(--red-dark);
  border-radius: 4px;
  padding: 2px 7px;
  font-weight: 400;
  letter-spacing: 0.01em;
}

.card-date {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.card-author {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.no-results {
  color: var(--text-muted);
  font-style: italic;
  padding: 24px 0;
}

.load-more-wrap {
  text-align: center;
  padding: 28px 0 8px;
}
.load-more-btn {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 9px 24px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.load-more-btn:hover { border-color: var(--red); background: #fdf5f5; }
.load-more-count { font-weight: 400; color: var(--text-muted); margin-left: 4px; }

/* ── Statistics section ── */
.stats-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 4px 0 20px;
}
.stats-filter-count {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-left: 10px;
  font-variant-numeric: tabular-nums;
}

.stats-grid-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 20px;
}
.stats-grid-top .stat-card { margin-bottom: 0; }

.stat-card-title {
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 16px;
}

.chart-wrap {
  position: relative;
  width: 100%;
}
.chart-wrap-sq  { height: 280px; }
.chart-wrap-auto { /* height set dynamically by JS */ }

@media (max-width: 640px) {
  .stats-grid-top { grid-template-columns: 1fr; }
}

/* ── Inline charts in Articles section ── */
.inline-charts {
  margin-bottom: 28px;
  padding-bottom: 28px;
  border-bottom: 2px solid var(--border);
}

/* ── About section ── */
.about-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 36px 40px;
  max-width: 720px;
}

.about-card h2 {
  font-family: var(--serif);
  font-size: 1.5rem;
  color: var(--navy);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--red);
}

.about-card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 24px 0 10px;
}

.about-card p {
  font-size: 0.9rem;
  color: #374151;
  line-height: 1.7;
  margin-bottom: 12px;
}

.about-card ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.about-card ul li {
  font-size: 0.88rem;
  color: #374151;
  padding-left: 18px;
  position: relative;
  line-height: 1.5;
}

.about-card ul li::before {
  content: '–';
  position: absolute;
  left: 0;
  color: var(--red);
}

.about-disclaimer {
  margin-top: 24px;
  font-size: 0.78rem !important;
  color: #9ca3af !important;
}

/* ── Section switching ── */
.section-panel.hidden { display: none !important; }

/* ── Dashboard ── */
:root {
  --pp: #22C55E;
  --pi: #3B82F6;
  --nn: #EAB308;
}

.overview-card {
  background: var(--navy);
  border-radius: 10px;
  padding: 28px 32px;
  margin-bottom: 32px;
}

.overview-label {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 16px;
}

.pbar {
  height: 14px;
  border-radius: 7px;
  overflow: hidden;
  display: flex;
  background: rgba(255,255,255,0.08);
  margin-bottom: 14px;
}

.pbar-pp { background: var(--pp); height: 100%; }
.pbar-pi { background: var(--pi); height: 100%; }
.pbar-nn { background: var(--nn); height: 100%; opacity: 0.8; }

.plegend {
  display: flex;
  gap: 24px;
  font-size: 0.82rem;
  flex-wrap: wrap;
}

.overview-card .plegend { color: rgba(255,255,255,0.65); }

.pdot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}
.pdot-pp       { background: var(--pp); }
.pdot-pi       { background: var(--pi); }
.pdot-nn       { background: var(--nn); opacity: 0.75; }
.pdot-unlabeled{ background: #9ca3af; opacity: 0.5; }

.cluster-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 26px;
  margin-bottom: 14px;
}

.cluster-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}

.cluster-name {
  font-family: var(--serif);
  font-size: 1.1rem;
  color: var(--navy);
  font-weight: 700;
}

.cluster-count {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.cluster-card .pbar { background: var(--border); }

.cluster-card .plegend {
  color: var(--text-muted);
  margin-top: 2px;
}

.dim { opacity: 0.35; }

details { margin-top: 16px; }

details summary {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-muted);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

details summary::before {
  content: "▸";
  font-size: 0.7rem;
  transition: transform 0.15s;
}

details[open] summary::before { transform: rotate(90deg); }

.cluster-articles {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.cluster-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.84rem;
}

.cluster-row-body { flex: 1; }

.cluster-row-top {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.cluster-row a { color: var(--text); flex: 1; }
.cluster-row a:hover { color: var(--red); text-decoration: none; }

.cluster-date {
  font-size: 0.74rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.cluster-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.45;
}

/* ── Footer ── */
footer {
  background: var(--navy);
  border-top: 2px solid var(--red);
  text-align: center;
  padding: 20px 24px;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.35);
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .article-card { grid-template-columns: 10px 1fr; }
  .card-meta-col { grid-column: 2; text-align: left; }
  .stat { padding: 12px 24px; }
  .header-nav { display: none; }
  .about-card { padding: 24px 20px; }
}
