* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

:root {
  color-scheme: light;
  --page-plane:     #f9f9f7;
  --surface-1:      #fcfcfb;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --series-1:       #2a78d6;
  --series-1-wash:  rgba(42,120,214,0.10);
  --status-good:    #0ca30c;
  --status-good-wash: rgba(12,163,12,0.10);
  --status-critical: #d03b3b;
  --status-critical-wash: rgba(208,59,59,0.10);
  --success-text:   #006300;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page-plane:     #0d0d0d;
    --surface-1:      #1c1c1a;
    --text-primary:   #ffffff;
    --text-secondary: #dad9cf;
    --text-muted:     #ada99f;
    --gridline:       #3a3a32;
    --baseline:       #4c4b41;
    --border:         rgba(255,255,255,0.14);
    --series-1:       #5b9dee;
    --series-1-wash:  rgba(91,157,238,0.16);
    --status-good:    #3ecb4a;
    --status-good-wash: rgba(62,203,74,0.16);
    --status-critical: #f0817a;
    --status-critical-wash: rgba(240,129,122,0.16);
    --success-text:   #3ecb4a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page-plane:     #0d0d0d;
  --surface-1:      #1c1c1a;
  --text-primary:   #ffffff;
  --text-secondary: #dad9cf;
  --text-muted:     #ada99f;
  --gridline:       #3a3a32;
  --baseline:       #4c4b41;
  --border:         rgba(255,255,255,0.14);
  --series-1:       #5b9dee;
  --series-1-wash:  rgba(91,157,238,0.16);
  --status-good:    #3ecb4a;
  --status-good-wash: rgba(62,203,74,0.16);
  --status-critical: #f0817a;
  --status-critical-wash: rgba(240,129,122,0.16);
  --success-text:   #3ecb4a;
}

body {
  background: var(--page-plane);
  color: var(--text-primary);
  accent-color: var(--series-1);
  caret-color: var(--series-1);
}
::selection { background: var(--series-1-wash); color: var(--text-primary); }
* { scrollbar-width: thin; scrollbar-color: var(--baseline) transparent; }
a { text-underline-offset: 3px; }

/* One focus ring for every control, only for keyboard users */
:where(button, a, input, select, [tabindex]):focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
}
:where(input, select):focus-visible { outline-offset: 0; border-color: var(--series-1); }
input::placeholder { color: var(--text-muted); opacity: 1; }
:where(input, select):hover:not(:disabled):not(:focus) { border-color: var(--baseline); }

/* Secondary buttons: calm, neutral hover. Red is kept for destructive
   actions (.range-remove-btn, .user-remove-btn) so it keeps its meaning. */
:where(.auth-bar, .user-row, .date-picker-form, .date-range-row, .reset-request-banner) button {
  transition: color 120ms ease-out, border-color 120ms ease-out, background-color 120ms ease-out, filter 120ms ease-out;
}

.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 36px 20px 64px;
}
.page-header { margin-bottom: 24px; }

.page-header h1 {
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: -0.015em;
  margin: 0 0 6px;
  text-wrap: balance;
}
.subtitle {
  color: var(--text-secondary);
  margin: 0;
  font-size: 14px;
  max-width: 60ch;
}

/* Stat tiles */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 0 0 20px;
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.stat-value {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  font-variant-numeric: proportional-nums;
}
.hero-value { font-size: 34px; letter-spacing: -0.02em; }
.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}
.stat-airline {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}
.stat-airline[hidden] { display: none; }
.stat-delta {
  font-size: 13px;
  font-weight: 600;
  margin-top: 2px;
}
.stat-delta.up { color: var(--status-critical); }
.stat-delta.down { color: var(--success-text); }
.stat-delta.flat { color: var(--text-muted); }
.status-good { color: var(--status-good); }
.status-critical { color: var(--status-critical); }

/* Chart card */
.chart-card, .table-card, .date-picker-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px 20px;
  margin-bottom: 20px;
}
.date-picker-card-header h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 10px;
  color: var(--text-primary);
}
.date-picker-status {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 12px;
}
.date-range-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}
.date-range-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--page-plane);
}
.date-picker-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.date-picker-form input[type="text"],
.date-picker-form input[type="date"],
.date-picker-form input[type="password"],
.date-picker-form input[type="email"],
.date-range-row input[type="text"],
.date-range-row input[type="date"] {
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}
.date-picker-form input[type="text"],
.date-picker-form input[type="password"],
.date-picker-form input[type="email"],
.date-range-row input[type="text"] {
  width: 200px;
}
.date-picker-form input[type="email"] { width: 260px; }
.date-range-row input[type="text"] {
  width: 160px;
}
.date-picker-arrow {
  color: var(--text-muted);
}
.date-picker-form select {
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}
.date-picker-form button,
.date-range-row button {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
}
/* Every form's primary action (Track these dates, Save, Update password,
   Save email, Add user) shares one style instead of the browser default. */
.date-picker-form button[type="submit"],
.range-save-btn {
  background: var(--series-1-wash);
  color: var(--series-1);
}
.date-picker-form button[type="submit"]:hover:not(:disabled),
.range-save-btn:hover:not(:disabled) {
  filter: brightness(1.1);
  border-color: var(--series-1);
}
.range-remove-btn {
  background: transparent;
  color: var(--text-secondary);
}
.range-remove-btn:hover {
  color: var(--status-critical);
  border-color: var(--status-critical);
}
.date-picker-form button:disabled,
.date-range-row button:disabled {
  opacity: 0.6;
  cursor: default;
}
.date-picker-message,
.date-picker-max-message {
  font-size: 12px;
  color: var(--text-muted);
  margin: 8px 0 0;
  min-height: 1em;
}

/* Range tabs */
.range-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.range-tabs[hidden] {
  display: none;
}
.range-tab {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
}
.range-tab:hover {
  color: var(--text-primary);
}
.range-tab.active {
  background: var(--series-1-wash);
  color: var(--series-1);
  border-color: transparent;
}
.chart-card-header, .table-card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 12px;
}
.chart-card-header h2, .table-card-header h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}
.chart-header-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}
.chart-key {
  display: flex;
  gap: 14px;
}
.last-checked {
  font-size: 12px;
  color: var(--text-muted);
}
.last-checked.stale {
  color: var(--status-critical);
  font-weight: 600;
}
.range-checked {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.range-checked.stale {
  color: var(--status-critical);
}
.key-chip {
  font-size: 12px;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.key-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.dot-good { background: var(--status-good); }
.dot-critical { background: var(--status-critical); }

.chart-wrap {
  position: relative;
}
.chart-airline-chip-bg {
  fill: var(--surface-1);
  stroke: var(--border);
  stroke-width: 1;
}
.chart-airline-chip-text {
  fill: var(--text-secondary);
  font-size: 10px;
  font-weight: 700;
}
#chart-svg {
  width: 100%;
  height: 340px;
  display: block;
  overflow: visible;
}

.empty-state {
  padding: 48px 0;
  text-align: center;
  color: var(--text-secondary);
}
.empty-state-sub {
  font-size: 13px;
  color: var(--text-muted);
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  font-size: 12px;
  transform: translate(-50%, -110%);
  white-space: nowrap;
  z-index: 5;
}
.tooltip-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}
.tooltip-date {
  color: var(--text-secondary);
  margin-top: 2px;
}
.tooltip-meta {
  color: var(--text-muted);
  margin-top: 2px;
  max-width: 220px;
  white-space: normal;
}

.book-link {
  color: var(--series-1);
  font-weight: 600;
  text-decoration: none;
}
.book-link:hover { text-decoration: underline; }
.airline-icon {
  vertical-align: middle;
  margin-right: 6px;
  border-radius: 4px;
  object-fit: contain;
  background: var(--surface-1);
}
.airline-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-primary);
  text-decoration: none;
}
a.airline-chip:hover .airline-code {
  color: var(--series-1);
  text-decoration: underline;
}
.airline-chip .airline-icon {
  margin-right: 0;
}
.airline-code {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* Table */
.table-wrap {
  overflow: auto;
  max-height: 560px;
  overscroll-behavior: contain;
}
thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-1);
  box-shadow: inset 0 -1px 0 var(--gridline);
}
tbody tr:hover td { background: var(--series-1-wash); }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
th {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 12px;
}
td.price-cell {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
td.change-cell {
  font-variant-numeric: tabular-nums;
}
.change-up { color: var(--status-critical); }
.change-down { color: var(--success-text); }
.change-flat { color: var(--text-muted); }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 999px;
}
.badge-low {
  background: var(--status-good-wash);
  color: var(--status-good);
}
.badge-high {
  background: var(--status-critical-wash);
  color: var(--status-critical);
}
td.notes-cell {
  white-space: normal;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.4;
  min-width: 220px;
  max-width: 340px;
}

@media (max-width: 720px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .page { padding: 24px 16px 48px; }
  .page-header-top { flex-direction: column; gap: 12px; }
  .auth-bar { flex-wrap: wrap; white-space: normal; }
  .auth-bar #auth-username { flex-basis: 100%; }
  .hero-value { font-size: 30px; }
  /* The chart's SVG stretches width-only, which squashes its labels on a
     phone; give it a minimum width and let the card scroll sideways. */
  .chart-wrap { overflow-x: auto; }
  #chart-svg { min-width: 640px; }
  .chart-card, .table-card, .date-picker-card { padding: 14px 14px 16px; }
}
@media (max-width: 420px) {
  .stat-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-tile { padding: 12px; }
  .stat-value { font-size: 22px; }
  .hero-value { font-size: 26px; }
}

.app-footer {
  margin-top: 24px;
  text-align: center;
}
.app-footer a {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
}
.app-footer a:hover {
  color: var(--text-secondary);
  text-decoration: underline;
}

/* Auth bar (dashboard header) */
.page-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.auth-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.auth-bar button {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}
.auth-bar button:hover {
  color: var(--text-primary);
  border-color: var(--baseline);
}

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}
.login-card .subtitle {
  margin-bottom: 16px;
}
.login-card label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 10px;
}
.login-card input {
  font: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  margin-top: 4px;
}
.login-card button {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--series-1-wash);
  color: var(--series-1);
  cursor: pointer;
  margin-top: 16px;
}
.login-card button:hover {
  filter: brightness(1.1);
}
.login-card button:disabled {
  opacity: 0.6;
  cursor: default;
}
.login-message {
  font-size: 12px;
  color: var(--status-critical);
  margin: 10px 0 0;
  min-height: 1em;
}

.login-card .login-forgot {
  align-self: center;
  margin-top: 6px;
  padding: 4px 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 400;
  text-decoration: underline;
}
.login-card .login-forgot:hover {
  filter: none;
  color: var(--text-primary);
}
.login-message.login-message-ok {
  color: var(--success-text);
}

/* Users admin panel */
.user-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--page-plane);
}
.user-row .user-name {
  font-weight: 600;
  min-width: 100px;
}
.user-row .user-role {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 50px;
}
.user-row .user-email {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 140px;
  overflow-wrap: anywhere;
}
.user-row button {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
}
.user-row button:hover {
  color: var(--text-primary);
  border-color: var(--baseline);
}
.user-row .user-remove-btn:hover {
  color: var(--status-critical);
  border-color: var(--status-critical);
}
.user-row button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* "Forgot password?" requests, shown to the admin */
.user-row.user-row-reset-requested {
  background: var(--status-critical-wash);
}
.user-row .badge-reset {
  background: var(--status-critical-wash);
  color: var(--status-critical);
}
.reset-request-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--status-critical-wash);
  color: var(--text-primary);
  font-size: 14px;
}
/* display:flex above would otherwise override the hidden attribute */
.reset-request-banner[hidden] {
  display: none;
}
.reset-request-banner button {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
}
