:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #0ca30c;
  --critical: #d03b3b;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good: #0ca30c;
    --critical: #e66767;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: 24px;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

h1 {
  font-size: 1.4rem;
  margin: 0;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 4px;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.countdown-banner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 20px;
}

.countdown-ring {
  position: relative;
  width: 48px;
  height: 48px;
  flex: none;
}

.countdown-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.countdown-ring-bg {
  fill: none;
  stroke: var(--gridline);
  stroke-width: 3;
}

.countdown-ring-fg {
  fill: none;
  stroke: var(--series-1);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 100.53;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear;
}

.countdown-ring span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.countdown-label {
  color: var(--text-secondary);
  font-size: 0.85rem;
  flex: 1;
}

.run-now-btn {
  background: transparent;
  color: var(--series-1);
  border: 1px solid var(--series-1);
  padding: 8px 16px;
  font-size: 0.85rem;
  border-radius: 999px;
}

.run-now-btn:hover {
  filter: none;
  background: var(--series-1);
  color: white;
}

.run-now-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

#run-now-status {
  font-size: 0.78rem;
  color: var(--text-muted);
  width: 100%;
}

#run-now-status:empty {
  display: none;
}

form.search-form {
  display: grid;
  grid-template-columns: repeat(4, 1fr) auto;
  gap: 12px;
  align-items: end;
}

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

.field label {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.field input {
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text-primary);
  font-size: 0.95rem;
}

button {
  background: var(--series-1);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.95rem;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

.range-filter {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.range-filter button {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 6px 14px;
  font-size: 0.85rem;
  border-radius: 999px;
}

.range-filter button:hover {
  filter: none;
  background: var(--gridline);
}

.range-filter button.active {
  background: var(--series-1);
  color: white;
  border-color: var(--series-1);
}

.day-picker {
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  color: var(--text-primary);
  font-size: 0.85rem;
}

#form-status {
  font-size: 0.85rem;
  margin-top: 8px;
  color: var(--text-secondary);
}

#form-status.error {
  color: var(--critical);
}

#form-status.success {
  color: var(--good);
}

.latest-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.latest-card h3 {
  margin: 0 0 8px 0;
  font-size: 1rem;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  white-space: nowrap;
}

th,
td {
  text-align: left;
  padding: 6px 4px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}

th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.empty {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.chart-title {
  font-size: 1rem;
  margin: 0;
}

.reset-zoom-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 5px 12px;
  font-size: 0.78rem;
  border-radius: 999px;
  flex: none;
}

.reset-zoom-btn:hover {
  filter: none;
  background: var(--gridline);
}

.zoom-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.chart-wrap {
  position: relative;
  height: 320px;
  overflow-x: auto;
  overflow-y: hidden;
}

.chart-inner {
  position: relative;
  height: 100%;
  min-width: 100%;
}

.chart-inner canvas {
  touch-action: none;
}

@media (max-width: 700px) {
  body {
    padding: 14px;
  }

  .container {
    gap: 16px;
  }

  h1 {
    font-size: 1.2rem;
  }

  .subtitle {
    font-size: 0.82rem;
  }

  .card {
    padding: 14px;
    border-radius: 10px;
  }

  form.search-form {
    grid-template-columns: 1fr 1fr;
  }

  form.search-form button {
    grid-column: 1 / -1;
    padding: 12px 18px;
  }

  .field input {
    font-size: 16px;
    padding: 10px;
  }

  .range-filter {
    justify-content: space-between;
  }

  .range-filter button {
    flex: 1 1 auto;
    text-align: center;
    padding: 9px 8px;
  }

  .latest-grid {
    grid-template-columns: 1fr;
  }

  .chart-wrap {
    height: 240px;
  }

  table {
    font-size: 0.8rem;
  }
}

@media (max-width: 420px) {
  form.search-form {
    grid-template-columns: 1fr;
  }
}
