:root {
  --bg: #f5f6f8;
  --bg-elevated: #ffffff;
  --bg-sunken: #eceef2;
  --text: #1b1f24;
  --text-muted: #5b6470;
  --text-faint: #8790a0;
  --border: #dde1e7;
  --accent: #2563eb;
  --accent-soft: #e6edfe;
  --accent-contrast: #ffffff;
  --danger: #d1453b;
  --danger-soft: #fbe6e4;
  --warn: #b8791a;
  --warn-soft: #fbedd6;
  --ok: #1f8a52;
  --ok-soft: #e2f5ea;
  --heat-0: #eef0f4;
  --heat-1: #cfe3ff;
  --heat-2: #93c0ff;
  --heat-3: #4f92ff;
  --heat-4: #1d5fd6;
  --heat-5: #123c93;
  --shadow: 0 1px 2px rgba(20, 24, 30, 0.06), 0 4px 12px rgba(20, 24, 30, 0.06);
  --radius: 10px;
  --radius-sm: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --bg-elevated: #1c1f25;
    --bg-sunken: #21252c;
    --text: #e9ebef;
    --text-muted: #a2aab6;
    --text-faint: #6d7580;
    --border: #2c3038;
    --accent: #5b8def;
    --accent-soft: #1e2a44;
    --accent-contrast: #0d1117;
    --danger: #f0685f;
    --danger-soft: #3a2020;
    --warn: #e0ab5b;
    --warn-soft: #3a2f18;
    --ok: #4cbd83;
    --ok-soft: #17301f;
    /* Sequential ramp from "blends into the background" (0/no data) up to
       the most saturated/prominent color (5/highest). --heat-5 used to be
       #a9c9ff — at ~83% lightness it's so close to white that it reads as
       *paler* than the punchier mid-range blues below it, i.e. "highest
       count" visually looked weakest. Cap the top bucket's lightness so it
       stays a vivid, saturated blue instead of washing out to pastel. */
    --heat-0: #1e2128;
    --heat-1: #1c3157;
    --heat-2: #204a8f;
    --heat-3: #2c66c4;
    --heat-4: #4f8bef;
    --heat-5: #5b9dff;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

/* Class-based `display` rules below (flex/inline-block/grid/...) would
   otherwise win over the UA stylesheet's `[hidden] { display: none }`
   since both are author-level specificity — force hidden to always win. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

#app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 12px 48px;
}

a {
  color: var(--accent);
}

.app-header {
  padding: 16px 4px 8px;
}

.app-header h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.app-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 12.5px;
}

.auth-banner {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  background: var(--bg);
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.tab-btn[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-contrast);
}

.filter-bar {
  position: sticky;
  top: 45px;
  z-index: 19;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.filter-row-chips {
  align-items: center;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.filter-group-grow {
  flex: 1 1 220px;
}

.filter-label {
  font-size: 11.5px;
  color: var(--text-faint);
  font-weight: 600;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.text-input {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  font-size: 13.5px;
  min-width: 0;
}

.range-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
}

.range-sep {
  color: var(--text-faint);
  font-size: 12px;
}

.switch-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.switch {
  display: inline-block;
}
.switch input { display: none; }
.switch-track {
  display: inline-block;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  position: relative;
  cursor: pointer;
}
.switch-thumb {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: left .15s ease;
}
.switch input:checked + .switch-track {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.switch input:checked + .switch-track .switch-thumb {
  left: 17px;
  background: var(--accent);
}

.btn-ghost {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-faint); }
.btn-small { padding: 4px 9px; font-size: 12px; }

.active-slot-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}

#panels {
  min-height: 40vh;
}

.panel {
  padding: 4px 2px 32px;
}

.panel-section {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.panel-section h2 {
  font-size: 14.5px;
  margin: 0 0 10px;
}

.panel-section h3 {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0 0 8px;
}

.state-msg {
  padding: 24px 8px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

.state-msg.is-error {
  color: var(--danger);
}

.when-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

@media (min-width: 860px) {
  .when-layout {
    grid-template-columns: minmax(0, 2.1fr) minmax(0, 1fr);
  }
}

.bucket-toggle {
  display: inline-flex;
  gap: 4px;
  margin-bottom: 10px;
}

.heatmap-scroll {
  overflow-x: auto;
}

.heatmap-grid {
  display: grid;
  gap: 2px;
  font-size: 10.5px;
  min-width: 520px;
}

.heat-cell {
  aspect-ratio: 1 / 1;
  min-height: 20px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  border: 1px solid rgba(0,0,0,0.03);
}
.heat-cell:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
.heat-cell.is-active { outline: 2px solid var(--accent); outline-offset: -2px; }
.heat-cell.heat-0 { background: var(--heat-0); color: var(--text-faint); }
.heat-cell.heat-1 { background: var(--heat-1); }
.heat-cell.heat-2 { background: var(--heat-2); }
.heat-cell.heat-3 { background: var(--heat-3); color: var(--accent-contrast); }
.heat-cell.heat-4 { background: var(--heat-4); color: var(--accent-contrast); }
.heat-cell.heat-5 { background: var(--heat-5); color: var(--accent-contrast); }

.heat-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 2px 0;
  font-size: 10.5px;
  color: var(--text-faint);
}
.heat-legend-label { white-space: nowrap; }
.heat-legend-swatch {
  width: 16px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.05);
}
.heat-legend-swatch.heat-0 { background: var(--heat-0); }
.heat-legend-swatch.heat-1 { background: var(--heat-1); }
.heat-legend-swatch.heat-2 { background: var(--heat-2); }
.heat-legend-swatch.heat-3 { background: var(--heat-3); }
.heat-legend-swatch.heat-4 { background: var(--heat-4); }
.heat-legend-swatch.heat-5 { background: var(--heat-5); }

.heat-axis-label {
  font-size: 10px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
}

.heat-total-label {
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.top-slots-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.top-slots-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  cursor: pointer;
  font-size: 12.5px;
}
.top-slots-list li:hover { background: var(--accent-soft); }
.top-slots-list .rank {
  color: var(--text-faint);
  margin-right: 6px;
}
.top-slots-list .count {
  font-weight: 700;
  color: var(--accent);
}

.histogram-wrap {
  /* keeps the y-max label fixed while .histogram-scroll scrolls horizontally */
}

.hist-ymax-label {
  text-align: right;
  font-size: 10.5px;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.histogram-scroll {
  overflow-x: auto;
}

/* Bars, reference lines AND axis ticks are all positioned as `left: X%` of
   this single 0..domainMax scale, so a given lead_days value always lines
   up the same way across all three — see views/leadtime.js. */
.histogram {
  position: relative;
  height: 200px;
  min-width: 100%;
}

.hist-bar {
  position: absolute;
  bottom: 0;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  min-width: 2px;
}

.hist-refline {
  position: absolute;
  bottom: 0;
  top: 0;
  border-left: 1px dashed var(--danger);
}
.hist-refline .hist-refline-label {
  position: absolute;
  top: -2px;
  left: 3px;
  font-size: 10px;
  color: var(--danger);
  white-space: nowrap;
}
.hist-refline.is-secondary { border-left-color: var(--warn); }
.hist-refline.is-secondary .hist-refline-label { color: var(--warn); }

.hist-axis {
  position: relative;
  height: 16px;
  min-width: 100%;
}

.hist-axis-tick {
  position: absolute;
  top: 0;
  font-size: 10px;
  color: var(--text-faint);
  white-space: nowrap;
}

.table-wrap {
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.data-table th, .data-table td {
  padding: 8px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  color: var(--text-faint);
  font-weight: 600;
  cursor: pointer;
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
}
.data-table th.is-sorted { color: var(--accent); }

.fav-star {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  color: var(--text-faint);
  line-height: 1;
  padding: 2px;
}
.fav-star.is-fav { color: #e3a521; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
}
.badge-open { background: var(--ok-soft); color: var(--ok); }
.badge-cancelfee { background: var(--warn-soft); color: var(--warn); }

.hour-chip {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: 10.5px;
  margin-right: 3px;
}

.sparkline {
  display: block;
}

.room-row {
  cursor: pointer;
}
.room-row:hover td { background: var(--bg-sunken); }

.room-detail-row td {
  background: var(--bg-sunken);
  white-space: normal;
}

.calendar-month-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12.5px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  max-width: 420px;
}

.calendar-cell {
  aspect-ratio: 1/1;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text);
}
.calendar-cell.is-empty { visibility: hidden; }
.calendar-cell .cal-day { font-weight: 600; }
.calendar-cell .cal-count { font-size: 9px; opacity: 0.85; }

.timeline-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.timeline-item {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  align-items: baseline;
}

.timeline-time {
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
  min-width: 108px;
}

.timeline-room {
  font-weight: 600;
  flex: 1 1 200px;
  min-width: 0;
}

.timeline-meta {
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.load-more-sentinel {
  height: 1px;
}

.insights-body {
  font-size: 13.5px;
  line-height: 1.7;
}
.insights-body h1, .insights-body h2, .insights-body h3 {
  margin: 16px 0 8px;
}
.insights-body ul, .insights-body ol {
  padding-left: 20px;
}
.insights-body code {
  background: var(--bg-sunken);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 90%;
}
.insights-meta {
  color: var(--text-faint);
  font-size: 12px;
  margin-bottom: 10px;
}

.mock-badge {
  display: inline-block;
  margin: 18px auto 0;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 11.5px;
  text-align: center;
}

.app-footer {
  text-align: center;
  padding: 12px 0;
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--border) 37%, var(--bg-sunken) 63%);
  background-size: 400% 100%;
  animation: skeleton-loading 1.4s ease infinite;
  border-radius: 4px;
}
@keyframes skeleton-loading {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

@media (max-width: 599px) {
  .app-header h1 { font-size: 17px; }
  .filter-bar { top: 41px; padding: 8px 10px; }
  .data-table th, .data-table td { padding: 6px 6px; }
  .timeline-time { min-width: 88px; }
}
