/* ============================
   TIMELINE WRAPPER & CONTROLS
   ============================ */
.timeline-wrapper {
  width: 100%;
  overflow-x: auto;
  box-sizing: border-box;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  background: #fafafa;
  padding: 8px;
}

.timeline-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.timeline-controls input[type="number"] {
  width: 120px;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
}

.timeline-nav {
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 6px;
  background: #f2f2f2;
  border: 1px solid #ddd;
  transition: background 0.2s;
}
.timeline-nav:hover {
  background: #e8e8e8;
}

.timeline-year-fixed {
  position: sticky;
  top: 0;
  left: 0;
  background: rgba(255, 255, 255, 0.95);
  padding: 8px;
  z-index: 50;
  text-align: center;
  border-bottom: 1px solid #ddd;
  font-weight: 600;
  font-size: 14px;
}

/* ============================
   CHART CONTAINER & NAVIGATION
   ============================ */
.timeline-chart-container {
  position: relative;
  display: flex;
  align-items: stretch;
}

.timeline-scroll-area {
  flex: 1;
  overflow-x: auto;
  position: relative;
}

.timeline-nav-left,
.timeline-nav-right {
  position: sticky;
  top: 0;
  bottom: 0;
  width: 36px;
  background: rgba(240, 240, 240, 0.9);
  border: 1px solid #bbb;
  border-radius: 6px;
  font-size: 20px;
  cursor: pointer;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 4px;
  transition: background 0.2s;
}
.timeline-nav-left:hover,
.timeline-nav-right:hover {
  background: rgba(230, 230, 230, 0.9);
}
.timeline-nav-left { left: 0; }
.timeline-nav-right { right: 0; }

/* ============================
   GRID & ROWS
   ============================ */
.timeline-chart {
  width: max-content;
  min-width: 100%;
}

.timeline-grid {
  display: block;
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
}

.timeline-row {
  display: grid;
  grid-auto-flow: column;
  grid-template-columns: repeat(var(--columns), minmax(36px, 36px));
  align-items: center;
  font-weight: bold;
}

/* ============================
   CELLS
   ============================ */
.timeline-cell {
  height: 36px;
  box-sizing: border-box;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  background: #fff;
  border: 1px solid #eee;
  padding: 2px;
  transition: background 0.2s;
}
.timeline-cell:hover {
  background: #f9f9f9;
}

.timeline-jubilee-cell {
  background: rgba(196, 89, 17, 0.15);
  font-size: 16px;
  border: 1px solid #c45911;
  font-weight: 600;
}

.timeline-week-cell {
  background: rgba(83, 129, 53, 0.15);
  font-size: 16px;
  border: 1px solid #538135;
  font-weight: 600;
}

.timeline-year-cell {
  position: relative;
  height: 56px;
  background: rgba(31, 78, 121, 0.15);
  border: 1px solid #1f4e79;
}
.timeline-year-rot {
  padding-top: 10px;
  transform-origin: center center;
  white-space: nowrap;
  transform: rotate(-90deg);
  height: 32px;
  font-size: 12px;
  line-height: 1;
  font-weight: 500;
}

/* ============================
   PERSON ROWS
   ============================ */
.person-wrapper {
  position: relative;
  display: grid;
  grid-template-columns: repeat(49, 1fr);
  margin-top: 48px; /* extra vertical space for fixed name labels */
}

.person-row {
  position: relative;
  align-items: center;
  gap: 2px;
}

.person-name {
  position: absolute;
  left: -160px;
  width: 150px;
  text-align: right;
  font-weight: 700;
  padding-right: 8px;
  box-sizing: border-box;
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.person-year-cell {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-width: 2px;
  border-style: solid;
  border-radius: 4px;
}

.person-name-row .person-name-cell {
  font-weight: 700;
  font-size: 14px;
  background: transparent;
  border: none;
  padding: 4px 0;
  text-align: center;
}

.person-age-row {
  display: contents; /* keeps cells aligned in grid */
}

.person-age-cell {
  transform: rotate(-90deg);
  border-width: 2px;
  border-style: solid;
  font-size: 12px;
  line-height: 1;
  border-radius: 4px;
}

.person-name-label {
  position: absolute;
  top: -24px;
  font-weight: 700;
  font-size: 14px;
  pointer-events: none;
  text-align: center;
}

.person-name-label-fixed {
  background: rgba(255, 255, 255, 0.92);
  padding: 6px 10px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.08);
  white-space: nowrap;
  color: #111;
  border: 1px solid rgba(0, 0, 0, 0.06);
  pointer-events: none;
  z-index: 9999;
}

/* ============================
   EVENTS
   ============================ */
#timeline-events {
  position: relative;
  margin-top: 16px;
  width: max-content;
  min-width: 100%;
  transition: height 0.2s;
  overflow: visible;
}

.timeline-event-block {
  position: absolute;
  background: #fff;
  border: 1px solid #ddd;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  padding: 6px 8px;
  box-sizing: border-box;
  border-radius: 6px;
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 10;
  overflow: hidden;
  white-space: normal;
  font-size: 13px;
}

.timeline-event-arrow {
  font-size: 12px;
  line-height: 1;
  margin-top: -6px;
  color: #555;
}

.timeline-event-desc {
  font-size: 13px;
  line-height: 1.3;
  color: #333;
}

/* ============================
   RESPONSIVE
   ============================ */
@media (max-width: 800px) {
  .timeline-row {
    grid-template-columns: repeat(var(--columns), minmax(36px, 36px));
  }
  .timeline-cell {
    min-width: 36px;
  }
  .timeline-year-cell {
    height: 48px;
  }
  .person-name {
    left: -120px;
    width: 110px;
    font-size: 13px;
  }
}


/* Glassmorphic overlay */
.global-loading-overlay {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 180px;
  height: 180px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  flex-direction: column;
  text-align: center;
}

/* Icon */
.global-loading-overlay .loading-icon img {
  width: 64px;
  height: 64px;
}

/* Text (hidden at first) */
.global-loading-overlay .loading-text {
  margin-top: 12px;
  font-size: 14px;
  color: #1F4E79;
  font-weight: 600;
  display: none;
}