/* ── TIMELINE PAGE CUSTOMIZATIONS ──────────────────────────── */

html {
  height: 100%;
}

body {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.section-timeline {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-surface);
}

.section-timeline .container {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.nav-spacer {
  flex: 1;
}

.timeline-controls {
  display: flex;
  gap: var(--space-3);
  align-items: stretch;
  flex-wrap: wrap;
}

/* Action buttons group */
.timeline-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.nav-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all var(--transition-interactive);
}

.nav-btn:hover {
  color: var(--color-text);
  border-color: var(--color-primary);
  background: rgba(139, 32, 32, 0.05);
}

.nav-btn:active {
  transform: scale(0.95);
}

.nav-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  border-color: var(--color-border);
  color: var(--color-text-muted);
}

.nav-btn:disabled:hover {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text-muted);
}

.nav-btn[hidden] {
  display: none;
}

/* Fixed theme toggle in top-right corner */
.site-header .theme-toggle {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-interactive);
  margin: 0;
  padding: 0;
}

.site-header .theme-toggle:hover {
  color: var(--color-text);
  border-color: var(--color-primary);
  background: rgba(139, 32, 32, 0.05);
}

.site-header .theme-toggle:active {
  transform: scale(0.95);
}

#yearJump {
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text);
  font-family: var(--font-body);
  transition: border-color var(--transition-interactive);
}

#yearJump:focus {
  outline: 2px solid var(--color-primary);
  border-color: var(--color-primary);
}

#yearJump::placeholder {
  color: var(--color-text-faint);
}


/* ── TIMELINE WRAPPER ──────────────────────────────────────── */
.timeline-wrapper {
  flex: 1;
  overflow-y: auto;
  background: var(--color-surface);
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) var(--color-surface-offset);
}

.timeline-wrapper::-webkit-scrollbar {
  width: 8px;
}

.timeline-wrapper::-webkit-scrollbar-track {
  background: var(--color-surface-offset);
  border-radius: var(--radius-full);
}

.timeline-wrapper::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

.timeline-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--color-primary);
}

@media (max-width: 480px) {
  .timeline-wrapper {
    scrollbar-width: auto;
  }

  .timeline-wrapper::-webkit-scrollbar {
    width: 6px;
  }
}

/* ── TIMELINE ITEMS ────────────────────────────────────────── */
.timeline {
  position: relative;
  max-width: 900px;
  margin: 0 auto;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 50px;
  top: 0;
  bottom: 0;
  width: 1px;
  /* background: var(--color-border); */
}

.timeline-item {
  display: grid;
  grid-template-columns: 50px 1fr;
  gap: var(--space-6);
  margin-bottom: var(--space-8);
  position: relative;
  scroll-margin-top: 100px;
}

.timeline-item.filtered-out {
  display: none;
}

.timeline-year {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-primary);
  letter-spacing: 0.04em;
  text-align: left;
  padding-top: var(--space-1);
  margin-right: 28px;
}

.timeline-item.highlight .timeline-year {
  color: var(--color-gold);
}

.timeline-content {
  background: var(--color-bg);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: box-shadow var(--transition-interactive), border-color var(--transition-interactive);
  min-width: 0;
}

.timeline-item.highlight .timeline-content {
  border-color: var(--color-gold);
  box-shadow: 0 0 0 2px var(--color-gold);
}

.timeline-content:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}

.timeline-date {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  font-weight: 500;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-2);
  display: block;
}

.timeline-content h3 {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 600;
  margin: 0 0 var(--space-3) 0;
  color: var(--color-text);
}

.timeline-description {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
  line-height: 1.6;
  overflow-wrap: break-word;
}

.timeline-description strong {
  color: var(--color-text);
}

.timeline-description em {
  color: var(--color-primary);
  font-style: italic;
  font-weight: 900;
}

.timeline-categories {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}

.category-badge {
  font-size: 0.65rem;
  padding: 2px 5px;
  background: var(--color-green);
  color: var(--color-green-highlight);
  border: 1px solid var(--color-green-highlight);
  border-radius: var(--radius-sm);
  font-weight: 500;
  cursor: pointer;
  transition: outline 100ms, box-shadow 100ms;
}

.category-badge:hover {
  outline: 1px solid var(--color-green-highlight);
  outline-offset: 1px;
}

.category-badge.active {
  outline: 2px solid var(--color-green-highlight);
  outline-offset: 2px;
  font-weight: 700;
}

.timeline-labels {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  border-top: 1px solid var(--color-divider);
  padding-top: var(--space-3);
}

.label-group {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.label-group-title {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.label {
  font-size: 0.65rem;
  padding: 2px 5px;
  background: var(--color-surface-offset);
  color: var(--color-text-muted);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: outline 100ms, box-shadow 100ms;
}

.label:hover {
  outline: 1px solid var(--color-divider);
  outline-offset: 1px;
}

.label.active {
  outline: 2px solid currentColor;
  outline-offset: 2px;
  font-weight: 700;
}

.label.person {
  color: var(--color-primary);
  background: var(--color-primary-highlight);
  border-color: var(--color-primary);
}

.label.city {
  color: var(--color-cancel);
  background: var(--color-cancel-highlight);
  border-color: var(--color-cancel);
}

.label.country {
  color: var(--color-gold);
  background: color-mix(in oklab, var(--color-gold) 15%, transparent);
  border-color: var(--color-gold);
}

.timeline-link {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-decoration: none;
  display: inline-block;
}

.timeline-link:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

/* ── LOADING STATE ──────────────────────────────────────────── */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12);
  gap: var(--space-6);
  flex: 1;
}

.loading-spinner p {
  font-size: var(--text-base);
  color: var(--color-text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-spinner.hidden {
  display: none;
}

/* ── EMPTY STATE ───────────────────────────────────────────── */
.timeline-empty {
  text-align: center;
  padding: var(--space-12);
  color: var(--color-text-muted);
}

.timeline-empty p {
  font-size: var(--text-base);
  margin-bottom: var(--space-2);
}

/* ── MODAL DIALOG ──────────────────────────────────────────── */
.event-modal {
  max-width: 560px;
  width: 90vw;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 0;
  background: var(--color-bg);
}

.event-modal::backdrop {
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(2px);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-5);
  border-bottom: 1px solid var(--color-divider);
}

.modal-header h2 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 600;
  font-family: var(--font-display);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-interactive);
}

.modal-close:hover {
  color: var(--color-text);
}

.modal-body {
  padding: var(--space-5);
  max-height: 60vh;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-5);
  border-top: 1px solid var(--color-divider);
  gap: var(--space-4);
}

.modal-actions {
  display: flex;
  gap: var(--space-3);
  margin-left: auto;
}

.event-form {
  display: flex;
  flex-direction: column;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
}

.form-group label small {
  font-weight: 400;
  color: var(--color-text-faint);
}

.form-group input,
.form-group textarea {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition-interactive), box-shadow var(--transition-interactive);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(139, 32, 32, 0.1);
}

.form-group small:not(label small) {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: -var(--space-2);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.form-row .form-group {
  margin-bottom: 0;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  padding: var(--space-2) var(--space-4);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-interactive), transform 80ms;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--color-surface-offset);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-surface-dynamic);
}

.btn-danger {
  background: var(--color-cancel);
  color: var(--color-text-inverse);
}

.btn-danger:hover {
  background: var(--color-cancel-hover);
  transform: translateY(-1px);
}

.btn-danger:active {
  transform: translateY(0);
}

.btn-danger[hidden] {
  display: none;
}

/* ── TIMELINE FOOTER (tags + edit button) ───────────────────── */
.timeline-footer {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.timeline-tags {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.edit-btn {
  flex-shrink: 0;
  align-self: flex-end;
  width: 24px;
  height: 24px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: all var(--transition-interactive);
  opacity: 0.5;
}

.edit-btn:hover {
  opacity: 1;
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: rgba(139, 32, 32, 0.05);
}

.timeline-content:hover .edit-btn {
  opacity: 1;
}


/* ── RESPONSIVE ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .nav-inner {
    flex-wrap: wrap;
    height: auto;
    padding-block: var(--space-3);
  }

  .logo-link {
    order: 1;
  }

  .nav-spacer {
    order: 3;
    width: 100%;
  }

  .timeline-controls {
    order: 2;
    flex-direction: row;
    width: 100%;
    gap: var(--space-2);
  }

  .timeline-controls>* {
    flex: 1;
    min-width: 0;
  }

  #yearJump {
    min-width: 0;
    flex: 2;
  }

  .timeline-actions {
    order: 4;
    width: 100%;
    margin-top: var(--space-2);
    justify-content: flex-start;
  }

  .timeline-wrapper {
    padding: var(--space-5);
    border-radius: var(--radius-md);
  }

  .timeline::before {
    left: 30px;
    border: none;
  }

  .timeline-item {
    grid-template-columns: 30px 1fr;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
  }

  .timeline-year {
    font-size: clamp(0.7rem, 2.5vw, var(--text-xs));
    text-align: left;
    margin-right: 16px;
    /* Overrides: font-size, text-align, margin-right | Inherits: font-weight, color, letter-spacing, padding-top */
  }

  .timeline-content {
    padding: var(--space-4);
  }

  .timeline-description {
    font-size: clamp(0.8rem, 2vw, var(--text-sm));
  }

  .timeline-date {
    font-size: clamp(0.7rem, 2vw, var(--text-xs));
  }
}

@media (max-width: 480px) {

  /* Compress header: base nav-inner inherits gap: var(--space-6) which
     creates ~24px between each wrapped row. Reduce row-gap only. */
  .nav-inner {
    row-gap: var(--space-2);
    padding-block: var(--space-2);
  }

  /* nav-spacer forces an invisible extra row + its surrounding gaps */
  .nav-spacer {
    display: none;
  }

  .timeline-actions {
    margin-top: 0;
  }

  .timeline {
    max-width: 95%;
  }

  .timeline::before {
    left: 24px;
    border: none;
  }

  .timeline-item {
    grid-template-columns: 24px 1fr;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
    scroll-margin-top: 80px;
  }

  .timeline-year {
    font-size: clamp(0.65rem, 2vw, 0.75rem);
    margin-right: 16px;
  }

  .timeline-date {
    font-size: clamp(0.65rem, 1.5vw, 0.75rem);
  }

  .timeline-content {
    padding: var(--space-3);
  }

  .timeline-description {
    margin-bottom: var(--space-2);
    line-height: 1.5;
  }

  .timeline-wrapper {
    padding: var(--space-1);
  }
}

@media (max-width: 360px) {

  .timeline {
    max-width: 95%;
  }

  .nav-inner {
    padding-inline: var(--space-4);
    gap: var(--space-2);
  }

  .logo-link {
    font-size: 0.9rem;
  }

  .timeline-controls {
    gap: var(--space-1);
  }

  #yearJump {
    font-size: 14px;
    padding: var(--space-1) var(--space-2);
    flex: 3;
  }

  .scroll-btn {
    width: auto;
    height: 32px;
    font-size: 0.75rem;
    flex: 1;
    min-width: 32px;
  }

  .theme-toggle {
    width: 28px;
    height: 28px;
  }

  .timeline::before {
    left: 20px;
    border: none;
  }

  .timeline-item {
    grid-template-columns: 20px 1fr;
    gap: var(--space-2);
    margin-bottom: var(--space-5);
  }

  .timeline-year {
    font-size: 0.7rem;
    margin-right: 8px;
    /* Overrides: font-size, margin-right | Inherits: font-weight, color, letter-spacing, padding-top, text-align */
  }

  .timeline-content {
    padding: var(--space-2);
    border-radius: var(--radius-md);
  }

  .timeline-content h3 {
    font-size: 0.875rem;
    margin-bottom: var(--space-2);
  }

  .timeline-description {
    font-size: 0.8rem;
    margin-bottom: var(--space-2);
  }

  .timeline-wrapper {
    padding: var(--space-1);
  }
}

@media (max-width: 480px) and (orientation: portrait) {
  .timeline-item {
    grid-template-columns: 1fr;
    gap: var(--space-1);
  }

  .timeline-year {
    padding-top: 0;
    margin-right: 0;
  }
}

@media (min-width: 1200px) {
  .timeline-wrapper {
    padding: var(--space-10);
  }

  .timeline-item {
    margin-bottom: var(--space-10);
  }

  .scroll-btn {
    width: 40px;
    height: 40px;
    font-size: 1.1rem;
  }
}