/* ---- theme ---- */
:root {
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --hairline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --status-go: #0ca30c;
  --status-marginal: #fab219;
  --status-nogo: #d03b3b;
  --status-go-ink: #006300;
  --status-nogo-ink: #a02020;
  --chip-bg: #f0efec;
  --accent: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --hairline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --status-go-ink: #0ca30c;
    --status-nogo-ink: #e66767;
    --chip-bg: #2c2c2a;
    --accent: #3987e5;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%; /* stop iOS Safari's automatic font inflation */
  text-size-adjust: 100%;
}

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

/* ---- header ---- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface-1);
}
.brand { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.brand-mark { font-size: 22px; }
.brand h1 { font-size: 20px; margin: 0; }
.tagline { color: var(--text-muted); font-size: 13px; }

.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.search-wrap { position: relative; }
#location-input {
  width: 220px;
  padding: 8px 12px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
}
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 30;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  max-height: 280px;
  overflow-y: auto;
}
.search-results li {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.search-results li:hover, .search-results li.active { background: var(--chip-bg); }
.search-results .sub { color: var(--text-muted); font-size: 12px; }

.btn {
  padding: 8px 12px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { background: var(--chip-bg); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); background: var(--accent); }
.btn-ghost { border-color: transparent; color: var(--text-secondary); }
.unit-toggle { display: flex; }
.unit-toggle .btn-toggle { border-radius: 0; }
.unit-toggle .btn-toggle:first-child { border-radius: 8px 0 0 8px; }
.unit-toggle .btn-toggle:last-child { border-radius: 0 8px 8px 0; border-left: none; }
.btn-toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- layout ---- */
#app { max-width: 1060px; margin: 0 auto; padding: 16px 20px 40px; }
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card h2 { font-size: 16px; margin: 0 0 10px; }

.empty-state { text-align: center; padding: 48px 20px; }
.empty-state h2 { font-size: 20px; }
.empty-state p { color: var(--text-secondary); }
.loading-msg { color: var(--text-muted); }

/* ---- now card ---- */
.now-card { display: flex; flex-wrap: wrap; gap: 20px; justify-content: space-between; }
.now-left { min-width: 220px; }
.now-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
}
.now-badge.go { background: var(--status-go); }
.now-badge.marginal { background: var(--status-marginal); color: #3a2a00; }
.now-badge.nogo { background: var(--status-nogo); }
.badge-icon { font-size: 20px; }
.now-reasons { margin: 10px 0 0; padding: 0 0 0 4px; list-style: none; color: var(--text-secondary); font-size: 14px; }
.now-reasons li { margin: 3px 0; }
.now-right { text-align: right; flex: 1; }
.location-name { font-size: 17px; margin: 0 0 8px; }
.now-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  justify-content: flex-end;
  color: var(--text-secondary);
  font-size: 14px;
}
.now-stats .stat b { color: var(--text-primary); font-size: 16px; }

/* ---- presets ---- */
.presets-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.presets-label { color: var(--text-muted); font-size: 13px; }
.preset-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--chip-bg);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.threshold-editor { margin-top: 14px; border-top: 1px solid var(--hairline); padding-top: 14px; }
.threshold-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px 24px;
}
.threshold-row { display: grid; grid-template-columns: 1fr 110px 64px; align-items: center; gap: 10px; font-size: 14px; }
.threshold-row label { color: var(--text-secondary); }
.threshold-row input[type="range"] { width: 100%; accent-color: var(--accent); }
.threshold-row .val { text-align: right; font-variant-numeric: tabular-nums; }
.workhours-row { margin-top: 12px; font-size: 14px; color: var(--text-secondary); display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.workhours-row select {
  padding: 4px 6px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: var(--page);
  color: var(--text-primary);
}
.hint { color: var(--text-muted); font-size: 12px; }

/* ---- window grid ---- */
.window-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-secondary); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.swatch-go { background: var(--status-go); }
.swatch-marginal { background: var(--status-marginal); }
.swatch-nogo {
  background: var(--status-nogo);
  background-image: repeating-linear-gradient(45deg, rgba(0,0,0,0.22) 0 2px, transparent 2px 5px);
}

.grid-scroll { overflow-x: auto; padding-bottom: 4px; }
.window-grid { display: grid; grid-auto-rows: 30px; gap: 3px; min-width: 900px; align-items: stretch; }
.window-grid.narrow { min-width: max-content; grid-auto-rows: 34px; }
.grid-daylabel {
  grid-column: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-size: 13px;
  white-space: nowrap;
  padding-right: 10px;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface-1);
}
.grid-daylabel .dow { font-weight: 600; }
.grid-daylabel .date { color: var(--text-muted); font-size: 11px; }
.grid-daylabel .inline-summary { color: var(--text-muted); font-size: 10px; line-height: 1.2; }
.window-grid.narrow .grid-daylabel { font-size: 12px; line-height: 1.25; }
.window-grid .corner {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface-1);
}
.grid-hourlabel {
  font-size: 11px;
  color: var(--text-muted);
  text-align: left;
  align-self: end;
  padding-bottom: 2px;
}
.grid-summary {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  padding-left: 10px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.cell {
  border-radius: 4px;
  cursor: pointer;
  border: none;
  padding: 0;
  min-width: 20px;
}
.cell.go { background: var(--status-go); }
.cell.marginal { background: var(--status-marginal); }
.cell.nogo {
  background: var(--status-nogo);
  background-image: repeating-linear-gradient(45deg, rgba(0,0,0,0.22) 0 2px, transparent 2px 5px);
}
.cell.offhours { opacity: 0.25; }
.cell.past { opacity: 0.15; cursor: default; }
.cell:hover:not(.past) { outline: 2px solid var(--text-primary); outline-offset: 1px; }

/* ---- best windows ---- */
.best-windows { list-style: none; margin: 0; padding: 0; }
.best-windows li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--hairline);
  font-size: 14px;
}
.best-windows li:last-child { border-bottom: none; }
.best-windows .bw-day { font-weight: 600; min-width: 90px; }
.best-windows .bw-time { font-variant-numeric: tabular-nums; }
.best-windows .bw-dur {
  background: var(--chip-bg);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  color: var(--text-secondary);
}
.best-windows .bw-cond { color: var(--text-muted); font-size: 13px; }
.best-windows .empty { color: var(--text-muted); }

/* ---- account & saved locations ---- */
.saved-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
}
.saved-label { color: var(--text-muted); }
.saved-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.saved-chips .chip { display: inline-flex; align-items: center; gap: 6px; }
.saved-chips .chip-remove {
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}
.saved-chips .chip-remove:hover { color: var(--status-nogo); }
.save-star {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--status-marginal);
  padding: 0 2px;
  vertical-align: middle;
}
.save-star:hover { transform: scale(1.15); }

.auth-dialog {
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--surface-1);
  color: var(--text-primary);
  padding: 22px 24px;
  width: min(360px, 90vw);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.auth-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.auth-dialog h2 { margin: 0 0 4px; font-size: 17px; }
.auth-sub { margin: 0 0 14px; color: var(--text-muted); font-size: 13px; }
.auth-dialog label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}
.auth-dialog input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
}
.auth-error { color: var(--status-nogo-ink); font-size: 13px; margin: 0 0 10px; }
.auth-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.auth-forgot { margin-top: 10px; padding-left: 0; font-size: 13px; }
.digest-btn { font-size: 13px; padding: 4px 8px; }
.digest-toggle { display: flex; align-items: center; gap: 8px; }
.digest-toggle input { width: auto; margin: 0; accent-color: var(--accent); }
.auth-dialog select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
}
.digest-ok { color: var(--status-go-ink); }

/* ---- tooltip ---- */
.tooltip {
  position: fixed;
  z-index: 50;
  max-width: 260px;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  padding: 10px 12px;
  font-size: 13px;
  pointer-events: none;
}
.tooltip .tt-title { font-weight: 700; margin-bottom: 4px; }
.tooltip .tt-status { font-weight: 700; }
.tooltip .tt-status.go { color: var(--status-go-ink); }
.tooltip .tt-status.marginal { color: var(--status-marginal); }
.tooltip .tt-status.nogo { color: var(--status-nogo-ink); }
.tooltip ul { margin: 4px 0 0; padding-left: 16px; color: var(--text-secondary); }
.tooltip .tt-reasons { margin-top: 6px; color: var(--status-nogo-ink); }

.footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 12px 20px 28px;
}

@media (max-width: 700px) {
  /* compact header: brand row + full-width controls row */
  .topbar { padding: 10px 12px; gap: 8px; }
  .tagline { display: none; }
  .brand h1 { font-size: 18px; }
  .brand-mark { font-size: 18px; }
  .controls { width: 100%; }
  .search-wrap { flex: 1; min-width: 0; }
  #location-input { width: 100%; }
  .btn { padding: 8px 10px; }

  #app { padding: 10px 10px 32px; }
  .card { padding: 12px; border-radius: 10px; margin-bottom: 10px; }

  .now-card { gap: 12px; }
  /* stack verdict and conditions full-width instead of two cramped columns */
  .now-left, .now-right { flex: 1 1 100%; min-width: 0; }
  .now-badge { font-size: 18px; padding: 8px 14px; }
  .now-right { text-align: left; }
  .now-stats { justify-content: flex-start; gap: 4px 14px; font-size: 13px; }
  .location-name { font-size: 15px; }

  .threshold-row { grid-template-columns: 1fr 96px 58px; font-size: 13px; gap: 8px; }
  .legend { gap: 10px; font-size: 12px; }
  .window-header h2, .best-card h2 { font-size: 15px; }
  .best-windows li { font-size: 13px; }
  .best-windows .bw-day { min-width: 76px; }
}
