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

:root {
  --bg: #080c14;
  --surface: #0f1623;
  --border: #1e2d45;
  --text: #e2e8f0;
  --muted: #4a6080;
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.15);
  --blue: #3b82f6;
  --blue-glow: rgba(59, 130, 246, 0.15);
  --grey: #64748b;
  --grey-glow: rgba(100, 116, 139, 0.12);
  --action: #60a5fa;
  --action-glow: rgba(96, 165, 250, 0.15);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    sans-serif;
  min-height: 100vh;
  padding: 0 0 80px;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}
header h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #f8fafc;
}
header h1 span {
  color: var(--muted);
  font-weight: 400;
}
.header-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.header-nav a {
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition:
    color 0.15s,
    border-color 0.15s;
}
.header-nav a:hover {
  color: var(--text);
  border-color: #334155;
}
.last-fetch {
  font-size: 0.72rem;
  color: var(--muted);
  padding: 4px 6px;
  opacity: 0.7;
}

/* ── Timeline spine ── */
.timeline {
  max-width: 860px;
  margin: 0 auto;
  padding: 0px 16px 0;
  position: relative;
}
.timeline::before {
  display: none;
}

/* ── Date separator ── */
.entry:has(+ .date-separator) {
  margin-bottom: 0;
}

.date-separator {
  width: 100%;
  text-align: center;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 10px 0 10px;
  opacity: 0.6;
  transition:
    opacity 0.45s ease,
    transform 0.45s ease;
}

/* ── Empty state ── */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 80px 20px;
  font-size: 0.9rem;
}

/* ── Entry ── */
.entry {
  display: flex;
  margin-bottom: 10px;
  position: relative;
  align-items: flex-start;
}

/* spacer on opposite side */
.entry-spacer {
  flex: 1;
}

/* bubble */
.bubble {
  flex: 1;
  max-width: calc(50% - 28px);
  cursor: pointer;
  border-radius: 12px;
  padding: 14px 16px;
  border: 1px solid transparent;
  transition:
    transform 0.15s,
    box-shadow 0.15s;
  user-select: none;
}
.bubble:hover {
  transform: translateY(-1px);
}

.side-left .bubble {
  margin-right: auto;
  border-color: var(--blue);
  background: var(--blue-glow);
}
.side-left .bubble:hover {
  box-shadow: 0 4px 24px var(--blue-glow);
}

.side-right .bubble {
  margin-left: auto;
  border-color: var(--red);
  background: var(--red-glow);
}
.side-right .bubble:hover {
  box-shadow: 0 4px 24px var(--red-glow);
}

.side-center {
  justify-content: center;
}
.side-center .bubble {
  max-width: calc(50% - 28px);
  border-color: var(--grey);
  background: var(--grey-glow);
}
.side-center .bubble:hover {
  box-shadow: 0 4px 16px var(--grey-glow);
}

/* bubble content */
.bubble-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.flag {
  font-size: 1.3rem;
  line-height: 1;
  flex-shrink: 0;
}

/* Flag rendered outside the bubble, pinned to first-line height */
.entry-flag {
  flex-shrink: 0;
  align-self: flex-start;
  font-size: 1.4rem;
  line-height: 1;
  padding-top: 14px; /* matches bubble's top padding */
  width: 32px;
  text-align: center;
}

.stage-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}

.bubble-date {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}

/* ── Expand panel ── */
.detail {
  display: none;
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: #94a3b8;
  line-height: 1.6;
}
.detail.open {
  display: block;
}

.detail-speaker {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.detail-evidence {
  color: #cbd5e1;
  margin-bottom: 6px;
  word-break: break-word;
}
.detail-source {
  font-size: 0.72rem;
  color: var(--muted);
}

.detail a {
  color: #60a5fa;
  text-decoration: none;
}
.detail a:hover {
  text-decoration: underline;
}
.detail-source {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Hide spine while skeletons are present */
.js-timeline:has(.skel-item)::before {
  display: none;
}

/* ── Slide-up animation (JS-rendered timeline only) ── */
.js-timeline .entry {
  transition:
    opacity 0.45s ease,
    transform 0.45s ease;
}

/* ── Skeleton loading ── */
.skel-item {
  width: 100%;
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
  animation: skel-pulse 1.6s ease-in-out infinite;
  animation-delay: var(--d, 0s);
}
.skel-bar {
  height: 13px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  margin-bottom: 10px;
}
.skel-bar:last-child {
  margin-bottom: 0;
}

.admin-badge {
  font-size: 0.6em;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #facc15;
  opacity: 0.85;
  vertical-align: middle;
}

@keyframes skel-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

/* ── Toast ── */
.toast-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  pointer-events: none;
  backdrop-filter: blur(0px);
  transition: backdrop-filter 0.3s ease;
}
.toast-overlay.toast-show {
  backdrop-filter: blur(5px);
}
.toast {
  background: #1e293b;
  border: 1px solid #334155;
  color: var(--text);
  padding: 14px 36px;
  border-radius: 12px;
  font-size: 0.92rem;
  opacity: 0;
  transform: scale(0.88);
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
  white-space: nowrap;
}
.toast-overlay.toast-show .toast {
  opacity: 1;
  transform: scale(1);
}
.toast.toast-err {
  border-color: var(--red);
  color: #fca5a5;
}

/* ── Admin: date editor ── */
.date-year-label {
  font-size: 0.68rem;
  color: var(--muted);
}
.date-part-input {
  font-size: 0.68rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--blue);
  border-radius: 3px;
  color: var(--text);
  padding: 1px 4px;
  outline: none;
}
.date-day {
  width: 4ch;
}
.date-month {
  width: 4ch;
}
.date-time {
  width: 4ch;
}

/* ── Admin: inline editing (click when expanded) ── */
.flag-empty {
  display: none;
}

.entry:has(.detail.open) .stage-name,
.entry:has(.detail.open) .bubble-date {
  cursor: text;
}
.entry:has(.detail.open) .entry-flag,
.entry:has(.detail.open) .flag {
  cursor: pointer;
}
.entry:has(.detail.open) .flag-empty {
  display: inline;
  cursor: pointer;
  opacity: 0.35;
}
.entry:has(.detail.open) .stage-name:hover,
.entry:has(.detail.open) .bubble-date:hover,
.entry:has(.detail.open) .entry-flag:hover,
.entry:has(.detail.open) .flag:hover,
.entry:has(.detail.open) .flag-empty:hover {
  outline: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 3px;
}

.edit-confirm-btn {
  background: none;
  border: 1px solid #166534;
  border-radius: 4px;
  color: #4ade80;
  font-size: 0.75rem;
  padding: 1px 6px;
  cursor: pointer;
  margin-left: 4px;
  transition: background 0.15s;
  vertical-align: middle;
}
.edit-confirm-btn:hover {
  background: rgba(74, 222, 128, 0.1);
}

.country-edit-input {
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--blue);
  border-radius: 3px;
  color: var(--text);
  padding: 1px 4px;
  outline: none;
  width: 3ch;
  text-transform: uppercase;
}

.stage-edit-input {
  font-size: 0.88rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--blue);
  border-radius: 4px;
  color: var(--text);
  padding: 1px 6px;
  outline: none;
  width: 100%;
  min-width: 120px;
}

/* ── Admin: hide button (inside detail) ── */
.admin-actions {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.hide-btn,
.merge-this-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--muted);
  font-size: 0.72rem;
  padding: 3px 12px;
  cursor: pointer;
  transition:
    color 0.15s,
    border-color 0.15s;
}
.hide-btn:hover {
  color: var(--red);
  border-color: var(--red);
}

/* ── Admin: merge button states ── */
.merge-this-btn.chain-active {
  border-color: #facc15;
  background: rgba(250, 204, 21, 0.18);
  color: #facc15;
}

/* ── Mobile ── */
@media (max-width: 600px) {
  .timeline::before {
    display: none;
  }
  .bubble,
  .side-left .bubble,
  .side-right .bubble,
  .side-center .bubble {
    flex: 0 1 auto;
    max-width: 78%;
    margin: 0;
    border-radius: 8px;
    padding: 9px 11px;
  }

  .entry-flag {
    padding-top: 9px; /* match reduced bubble top padding */
    margin-left: 6px;
    margin-right: 6px;
  }
}
