/* ============================================================
   CSS Custom Properties — Dark Theme (default)
   ============================================================ */
:root {
  /* Colors */
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-surface-2: #273549;
  --color-border: #334155;
  --color-text: #e2e8f0;
  --color-text-muted: #94a3b8;
  --color-text-dim: #64748b;

  /* Status colors */
  --color-yes: #22c55e;
  --color-no: #ef4444;
  --color-maybe: #f59e0b;
  --color-current: #3b82f6;
  --color-current-bg: #1d3461;
  --color-featured-bg: #1a2f4a;
  --color-featured-intersection: #1a3060;

  /* Status cell backgrounds */
  --cell-yes-bg: rgba(34, 197, 94, 0.18);
  --cell-no-bg: rgba(239, 68, 68, 0.25);
  --cell-maybe-bg: rgba(245, 158, 11, 0.2);

  /* Accent */
  --color-accent: #38bdf8;
  --color-accent-hover: #7dd3fc;

  /* Layout */
  --header-height: 52px;
  --section-gap: 20px;
  --col-group-width: 60px;
  /* sticky group-name column */
  --cell-height: 32px;
  /* table row height */
  --timeline-bar-width: 5px;

  /* Typography */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-xs: 0.675rem;
  --font-size-sm: 0.75rem;
  --font-size-base: 0.875rem;
  --font-size-lg: 1rem;
  --font-size-xl: 1.125rem;

  /* Borders */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

/* ============================================================
   Light Theme
   ============================================================ */
[data-theme="light"] {
  --color-bg: #f1f5f9;
  --color-surface: #ffffff;
  --color-surface-2: #f1f5f9;
  --color-border: #cbd5e1;
  --color-text: #0f172a;
  --color-text-muted: #475569;
  --color-text-dim: #94a3b8;

  --color-current: #2563eb;
  --color-current-bg: #dbeafe;
  --color-featured-bg: #e0f2fe;
  --color-featured-intersection: #bfdbfe;

  --cell-yes-bg: rgba(34, 197, 94, 0.13);
  --cell-no-bg: rgba(239, 68, 68, 0.13);
  --cell-maybe-bg: rgba(245, 158, 11, 0.13);

  --color-accent: #0284c7;
  --color-accent-hover: #0369a1;
}

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

html {
  scroll-behavior: smooth;
}

body {
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: 1.5;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s, color 0.2s, border-color 0.6s;
  border: 5px solid transparent;
}

body[data-monitor-status="up"]    { border-color: var(--color-yes); }
body[data-monitor-status="down"]  { border-color: var(--color-no); }
body[data-monitor-status="grace"] { border-color: var(--color-maybe); }

a {
  color: var(--color-accent);
  text-decoration: none;
}

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

ul {
  list-style: none;
}

button {
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
}

body.loading .main-layout {
  opacity: 0.4;
  pointer-events: none;
}

/* ============================================================
   Header / Meta Bar
   ============================================================ */
.meta-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  height: var(--header-height);
  display: flex;
  align-items: center;
  transition: background-color 0.2s, border-color 0.2s;
}

.meta-bar__inner {
  width: 100%;
  max-width: 1700px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.meta-bar__title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  flex-shrink: 0;
}

.meta-bar__icon {
  font-size: 1.1rem;
}

.meta-bar__region {
  color: var(--color-text-muted);
  font-weight: 400;
}

.meta-bar__info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.meta-bar__updated,
.meta-bar__countdown {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
}

#countdown-display {
  color: var(--color-accent);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Theme Button
   ============================================================ */
.theme-btn {
  padding: 3px 7px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  transition: background 0.15s;
  line-height: 1;
}

.theme-btn:hover {
  background: var(--color-border);
}

/* ============================================================
   Language Switcher
   ============================================================ */
.lang-switcher {
  display: flex;
  gap: 3px;
}

.lang-btn {
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  transition: background 0.15s, color 0.15s;
}

.lang-btn:hover {
  color: var(--color-text);
  background: var(--color-border);
}

.lang-btn--active {
  color: var(--color-accent);
  background: var(--color-current-bg);
  border-color: var(--color-current);
}

/* ============================================================
   Error Banner
   ============================================================ */
.error-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #7f1d1d;
  color: #fca5a5;
  padding: 7px 16px;
  font-size: var(--font-size-sm);
  border-bottom: 1px solid #991b1b;
}

.error-banner[hidden] {
  display: none;
}

[data-theme="light"] .error-banner {
  background: #fee2e2;
  color: #991b1b;
  border-bottom-color: #fca5a5;
}

/* ============================================================
   Main Layout — CSS Grid on desktop, flex column on mobile
   Columns: [220px sidebar] [1fr content]
   Rows:    [auto monitor ] [1fr  overview]
   ============================================================ */
.main-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "sidebar monitor"
    "sidebar overview";
  gap: var(--section-gap);
  flex: 1;
  max-width: 1700px;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
  transition: opacity 0.2s;
}

/* ============================================================
   Sections
   ============================================================ */
.group-section,
.monitor-section,
.overview-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: background-color 0.2s, border-color 0.2s;
}

/* Sticky sidebar — spans both grid rows */
.group-section {
  grid-area: sidebar;
  align-self: start;
  min-width: 0;
  position: sticky;
  top: calc(var(--header-height) + 16px);
  max-height: calc(100dvh - var(--header-height) - 32px);
  overflow-y: auto;
}

.monitor-section {
  grid-area: monitor;
}

.overview-section {
  grid-area: overview;
  min-width: 0;
  overflow: hidden;
}

.section-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.section-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--color-text);
}

/* ============================================================
   Tab Row & Groups
   ============================================================ */
.tab-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.tab-group {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--color-text);
  background: var(--color-border);
}

.tab-btn--active {
  color: var(--color-accent);
  background: var(--color-current-bg);
  border-color: var(--color-current);
}

.tab-btn--tomorrow[hidden],
.tab-btn[hidden] {
  display: none;
}

/* ============================================================
   Timeline (Group Section)
   ============================================================ */
.timeline {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.timeline__item {
  display: grid;
  grid-template-columns: 46px var(--timeline-bar-width) 1fr;
  align-items: center;
  gap: 7px;
  padding: 4px 6px;
  border-bottom: 1px solid var(--color-border);
}

.timeline__item:last-child {
  border-bottom: none;
}

.timeline__item--current {
  background: var(--color-current-bg);
  box-shadow: inset 3px 0 0 var(--color-current);
}

.timeline__time {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.timeline__item--current .timeline__time {
  color: var(--color-accent);
  font-weight: 600;
}

.timeline__bar {
  width: var(--timeline-bar-width);
  height: 22px;
  border-radius: 3px;
  flex-shrink: 0;
}

.timeline__bar--split {
  display: flex;
  flex-direction: column;
}

.timeline__bar--split .bar-half {
  flex: 1;
}

.timeline__bar--split .bar-half:first-child {
  border-radius: 3px 3px 0 0;
}

.timeline__bar--split .bar-half:last-child {
  border-radius: 0 0 3px 3px;
}

.timeline__label {
  font-size: var(--font-size-xs);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar--yes {
  background: var(--color-yes);
}

.bar--no {
  background: var(--color-no);
}

.bar--maybe {
  background: var(--color-maybe);
}

.status--yes {
  color: var(--color-yes);
}

.status--no {
  color: var(--color-no);
}

.status--maybe {
  color: var(--color-maybe);
}

/* ============================================================
   Overview Table — rows=groups, cols=hours
   Key: table-layout:fixed fills available width on large screens
        (no horizontal scroll). On small screens min-width forces scroll.
   ============================================================ */
.overview-table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  /* Right-edge scroll hint */
  background:
    linear-gradient(to right, var(--color-surface) 30%, transparent),
    linear-gradient(to left, var(--color-surface) 30%, transparent) right,
    radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, .2), transparent),
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .2), transparent) right;
  background-repeat: no-repeat;
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}

.overview-table-wrapper:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.overview-table {
  /* Fixed layout: columns share available width — no horizontal scroll on desktop */
  table-layout: fixed;
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-xs);
}

/* On stacked/mobile layouts, rotate hour headers vertically so
   narrow cells can fit without forcing horizontal scroll.
   table-layout:fixed distributes width; height absorbs text length. */
@media (max-width: 899px) {
  .overview-table thead th:not(.col-group) {
    writing-mode: vertical-lr;
    white-space: nowrap;
    height: 58px;
    padding: 4px 1px;
    vertical-align: bottom;
    font-size: 0.65rem;
  }
}

/* ── Header ──────────────────────────────────────────────── */
.overview-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

.overview-table th {
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-weight: 600;
  text-align: center;
  padding: 6px 2px;
  border-bottom: 2px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  white-space: nowrap;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}

/* Sticky group-name column */
.overview-table th.col-group {
  position: sticky;
  left: 0;
  z-index: 20;
  width: var(--col-group-width);
  /* <-- drives fixed-layout column width */
  text-align: left;
  padding: 6px 8px;
  background: var(--color-surface-2);
  border-right: 2px solid var(--color-border);
}

.overview-table td.col-group {
  position: sticky;
  left: 0;
  z-index: 5;
  background: var(--color-surface);
  font-weight: 700;
  font-size: var(--font-size-xs);
  color: var(--color-text);
  padding: 0 8px;
  border-right: 2px solid var(--color-border);
  white-space: nowrap;
  transition: background-color 0.2s;
}

/* ── Current hour column ─────────────────────────────────── */
.overview-table th.col-current {
  color: var(--color-accent);
  background: var(--color-current-bg) !important;
  border-top: 3px solid var(--color-current);
  border-bottom-color: var(--color-current);
}

/* With vertical text the accent border should be on the left (inline-start) */
@media (max-width: 899px) {
  .overview-table th.col-current {
    border-top: none;
    border-left: 3px solid var(--color-current);
    border-bottom-color: var(--color-border);
  }
}

.overview-table td.col-current {
  background: var(--color-current-bg);
}

/* ── Featured row (GPV 3.2) ─────────────────────────────── */
.overview-table tr.row--featured td {
  background: var(--color-featured-bg);
}

.overview-table tr.row--featured td.col-group {
  color: var(--color-accent);
  background: var(--color-featured-bg);
}

.overview-table tr.row--featured td.col-current {
  background: var(--color-featured-intersection);
}

/* ── Data cells ──────────────────────────────────────────── */
.overview-table td {
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  height: var(--cell-height);
  padding: 0;
  text-align: center;
  vertical-align: middle;
}

/* ============================================================
   Cell content
   ============================================================ */
.cell-full {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell-split {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: row;
}

.cell-half {
  flex: 1;
  height: 100%;
}

.bg--yes {
  background-color: var(--cell-yes-bg);
}

.bg--no {
  background-color: var(--cell-no-bg);
}

.bg--maybe {
  background-color: var(--cell-maybe-bg);
}

.cell-full.bg--yes::after {
  content: '';
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-yes);
}

.cell-full.bg--no::after {
  content: '';
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-no);
}

.cell-full.bg--maybe::after {
  content: '';
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-maybe);
}

.cell-half.bg--yes {
  background-color: var(--cell-yes-bg);
}

.cell-half.bg--no {
  background-color: var(--cell-no-bg);
}

.cell-half.bg--maybe {
  background-color: var(--cell-maybe-bg);
}

/* ============================================================
   Monitor Section
   ============================================================ */
.monitor-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.monitor-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  min-width: 120px;
  gap: 2px;
}

.monitor-card__name {
  font-weight: 600;
  font-size: 0.9rem;
}

.monitor-card__status {
  font-size: var(--font-size-xs);
  opacity: 0.85;
}

/* Status colors — reuse existing palette */
.monitor-card--up      { background: rgba(34, 197, 94, 0.18);  color: var(--color-yes); border: 1px solid var(--color-yes); }
.monitor-card--down    { background: rgba(239, 68, 68, 0.18);  color: var(--color-no);  border: 1px solid var(--color-no); }
.monitor-card--grace   { background: rgba(245, 158, 11, 0.18); color: var(--color-maybe); border: 1px solid var(--color-maybe); }
.monitor-card--unknown { background: var(--color-surface);     color: var(--color-text-muted); border: 1px solid var(--color-border); }

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  text-align: center;
  padding: 12px 16px;
  color: var(--color-text-dim);
  font-size: var(--font-size-xs);
  border-top: 1px solid var(--color-border);
  margin-top: auto;
}

/* ============================================================
   Scrollbar
   ============================================================ */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: var(--color-surface);
}

::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-dim);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* ── Tablet landscape / small desktop  (900px – 1199px)
      Stack sections vertically; overview fills full width.
      Table is still fixed-layout so it fills the wider stacked column.
   ── */
@media (max-width: 1199px) {
  .main-layout {
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 14px;
  }

  /* Monitor floats to top on stacked layout */
  .monitor-section { order: -1; }

  .group-section {
    order: 0;
    width: 100%;
    position: static;
    max-height: none;
    overflow-y: visible;
  }

  /* Two-column timeline: hours 1–12 left, 13–24 right */
  .timeline {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-auto-flow: column;
    grid-template-rows: repeat(12, auto);
  }
  /* Divider between the two columns */
  .timeline__item:nth-child(-n+12) {
    border-right: 1px solid var(--color-border);
  }
  /* Item 12 is the last row of column 1 — no bottom border */
  .timeline__item:nth-child(12) {
    border-bottom: none;
  }

  .overview-section {
    width: 100%;
  }
}

/* ── Tablet portrait (600px – 899px) ── */
@media (max-width: 899px) {
  /* Narrower group-name column — values are max 3 chars ("6.2") */
  :root { --col-group-width: 42px; }
  .overview-table th.col-group,
  .overview-table td.col-group { padding-left: 4px; padding-right: 4px; }

  .meta-bar {
    height: auto;
    padding: 6px 0;
  }

  .meta-bar__inner {
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 12px;
  }

  :root {
    --header-height: 0px;
  }

  /* not sticky on tablet — saves room */

  .main-layout {
    padding: 10px;
    gap: 12px;
  }

  .group-section,
  .overview-section {
    padding: 12px;
  }

  .section-title {
    font-size: var(--font-size-base);
  }
}

/* ── Mobile (≤ 599px) ── */
@media (max-width: 599px) {
  .meta-bar__inner {
    padding: 6px 10px;
  }

  .meta-bar__updated {
    display: none;
  }

  .meta-bar__title {
    font-size: var(--font-size-sm);
  }

  .main-layout {
    padding: 8px;
    gap: 10px;
  }

  .group-section,
  .overview-section {
    padding: 10px;
    border-radius: var(--radius-md);
    gap: 8px;
  }

  .section-title {
    font-size: var(--font-size-sm);
  }

  .tab-btn {
    padding: 3px 7px;
    font-size: 0.65rem;
  }

  :root {
    --cell-height: 30px;
  }

  .overview-table thead th:not(.col-group) {
    line-height: 100%;
  }
}

/* ── Very small mobile (≤ 374px) ── */
@media (max-width: 374px) {
  .meta-bar__countdown {
    display: none;
  }

  .lang-btn {
    padding: 2px 6px;
  }

  .tab-btn {
    padding: 2px 5px;
    font-size: 0.6rem;
  }
}
