:root {
  color-scheme: light dark;
  --page: #f4f6f7;
  --surface: #ffffff;
  --surface-muted: #eef1f2;
  --text: #181b1d;
  --muted: #596168;
  --faint: #7b858d;
  --border: #d5dbde;
  --border-strong: #aeb8bd;
  --grid: rgba(27, 35, 39, 0.075);
  --accent: #087b70;
  --accent-hover: #05645c;
  --accent-text: #ffffff;
  --ok: #087a50;
  --ok-bg: #e7f6ef;
  --multiplier: #166534;
  --multiplier-bg: #dcfce7;
  --multiplier-border: #86d8a6;
  --warn: #9a5d00;
  --warn-bg: #fff3d6;
  --error: #b62f39;
  --error-bg: #fdebed;
  --maintenance: #365f9d;
  --maintenance-bg: #eaf0fb;
  --unknown: #667078;
  --unknown-bg: #edf0f2;
  --history-ok: #00a66a;
  --history-warn: #c17800;
  --history-error: #d13b48;
  --shadow: 0 12px 30px rgba(30, 38, 42, 0.07);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #111516;
    --surface: #1a1f21;
    --surface-muted: #22282a;
    --text: #eef1f2;
    --muted: #b0b8bc;
    --faint: #8e999e;
    --border: #343c3f;
    --border-strong: #536064;
    --grid: rgba(228, 237, 240, 0.075);
    --accent: #58c8b8;
    --accent-hover: #73d7c9;
    --accent-text: #102220;
    --ok: #66d19e;
    --ok-bg: #17372b;
    --multiplier: #9aefb7;
    --multiplier-bg: #183d27;
    --multiplier-border: #2c6b43;
    --warn: #f2bd5b;
    --warn-bg: #3b301b;
    --error: #f0838b;
    --error-bg: #3d2227;
    --maintenance: #91b5ed;
    --maintenance-bg: #24334a;
    --unknown: #bdc5c8;
    --unknown-bg: #2b3133;
    --history-ok: #3bc68c;
    --history-warn: #e6aa32;
    --history-error: #e46470;
    --shadow: 0 14px 36px rgba(0, 0, 0, 0.24);
  }
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background-color: var(--page);
  background-image:
    linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-position: -1px -1px;
  background-size: 40px 40px;
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

img {
  display: block;
  max-width: 100%;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.corner-mark {
  position: fixed;
  z-index: 0;
  width: 24px;
  height: 24px;
  color: var(--border-strong);
  pointer-events: none;
}

.corner-mark::before,
.corner-mark::after {
  content: "";
  position: absolute;
  background: currentColor;
}

.corner-mark::before {
  top: 11px;
  left: 0;
  width: 24px;
  height: 1px;
}

.corner-mark::after {
  top: 0;
  left: 11px;
  width: 1px;
  height: 24px;
}

.corner-mark--tl { top: 24px; left: 24px; }
.corner-mark--tr { top: 24px; right: 24px; }
.corner-mark--bl { bottom: 24px; left: 24px; }
.corner-mark--br { right: 24px; bottom: 24px; }

.site-frame {
  position: relative;
  z-index: 1;
  width: min(1480px, calc(100% - 64px));
  margin: 0 auto;
  padding: 42px 0 28px;
}

.public-header,
.page-heading,
.admin-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.public-header {
  min-height: 58px;
  margin-bottom: 28px;
}

.public-header__primary {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 18px;
}

.home-link {
  flex: 0 0 auto;
  gap: 7px;
  white-space: nowrap;
}

.home-link[hidden] {
  display: none;
}

.home-link__arrow {
  font-size: 1.12rem;
  line-height: 1;
}

.site-brand,
.admin-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--text);
  text-decoration: none;
}

.site-brand__logo {
  display: grid;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface) url("/static/providers/openai.svg") center / 38px 38px no-repeat;
  box-shadow: var(--shadow);
}

.site-brand__logo img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  background: var(--surface);
}

.site-brand__name {
  overflow-wrap: anywhere;
  font-size: 1.24rem;
  font-weight: 750;
  line-height: 1.25;
}

.public-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}

.update-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 680;
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
  transition: background-color 180ms ease-out, border-color 180ms ease-out, color 180ms ease-out, box-shadow 180ms ease-out;
}

.button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.button--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.button--primary:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.button--secondary,
.button--quiet {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.button--secondary:hover:not(:disabled),
.button--quiet:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.button--danger {
  border-color: color-mix(in srgb, var(--error) 38%, var(--border));
  background: var(--surface);
  color: var(--error);
}

.button--danger:hover:not(:disabled) {
  background: var(--error-bg);
}

.button--small {
  min-height: 36px;
  padding: 7px 10px;
  font-size: 0.83rem;
}

.button--block {
  width: 100%;
}

.notice {
  min-height: 22px;
  margin: -14px 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}

.notice.is-error {
  color: var(--error);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}

.status-card {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 330px;
  flex-direction: column;
  padding: 22px;
  border: 1px solid var(--border);
  border-top: 3px solid var(--unknown);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.status-card.is-ok { border-top-color: var(--ok); }
.status-card.is-degraded { border-top-color: var(--warn); }
.status-card.is-error { border-top-color: var(--error); }
.status-card.is-maintenance { border-top-color: var(--maintenance); }

.status-card__header {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
}

.provider-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.provider-mark img {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.status-card__identity {
  min-width: 0;
}

.status-card__identity h2 {
  display: -webkit-box;
  min-height: 2.5em;
  margin: 0;
  overflow-wrap: anywhere;
  overflow: hidden;
  font-size: 1.25rem;
  font-weight: 780;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.25;
}

.status-card__identity p {
  margin: 3px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.76rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-card__badges {
  display: flex;
  min-width: 94px;
  flex-direction: column;
  align-items: flex-end;
  gap: 7px;
}

.multiplier-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border: 1px solid var(--multiplier-border);
  border-radius: 999px;
  background: var(--multiplier-bg);
  color: var(--multiplier);
  font-size: 0.78rem;
  font-weight: 780;
  white-space: nowrap;
}

.status-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  gap: 7px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--unknown-bg);
  color: var(--unknown);
  font-size: 0.75rem;
  font-weight: 720;
  white-space: nowrap;
}

.status-badge > span:first-child {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge.is-ok,
.is-ok .status-badge { background: var(--ok-bg); color: var(--ok); }
.status-badge.is-degraded,
.is-degraded .status-badge { background: var(--warn-bg); color: var(--warn); }
.status-badge.is-error,
.is-error .status-badge { background: var(--error-bg); color: var(--error); }
.status-badge.is-maintenance,
.is-maintenance .status-badge { background: var(--maintenance-bg); color: var(--maintenance); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 24px 0 0;
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}

.metric-grid > div {
  min-width: 0;
  padding: 14px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.metric-grid__wide {
  grid-column: 1 / -1;
}

.status-card .metric-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 18px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-muted);
}

.status-card .metric-grid__wide {
  grid-column: auto;
}

.status-card .metric-grid > div {
  padding: 14px 13px;
  border: 0;
  border-right: 1px solid var(--border);
}

.status-card .metric-grid > div:last-child {
  border-right: 0;
}

.status-card .metric-grid dt {
  font-size: 0.75rem;
}

.status-card .metric-grid dd {
  margin-top: 6px;
  font-size: 1.08rem;
  font-weight: 760;
}

.metric-grid dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
}

.metric-grid dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 1rem;
  font-weight: 730;
}

.history-block {
  position: relative;
  margin-top: auto;
  padding-top: 22px;
}

.history-block__label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 620;
}

.history-strip {
  position: relative;
  display: grid;
  min-height: 28px;
  grid-template-columns: repeat(60, minmax(2px, 1fr));
  align-items: stretch;
  gap: 2px;
  border-radius: 3px;
}

.history-segment {
  position: relative;
  min-width: 2px;
  border-radius: 2px;
  background: var(--unknown-bg);
  cursor: pointer;
  transition: filter 160ms ease-out, box-shadow 160ms ease-out, opacity 160ms ease-out;
}

.history-segment.segment-ok { background: var(--history-ok); }
.history-segment.segment-degraded { background: var(--history-warn); }
.history-segment.segment-error { background: var(--history-error); }

.history-segment:hover,
.history-segment.is-active {
  z-index: 1;
  filter: brightness(1.08) saturate(1.08);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
}

.history-strip:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 4px;
}

.history-tooltip {
  --history-tooltip-x: 50%;
  position: absolute;
  z-index: 20;
  left: var(--history-tooltip-x);
  bottom: 38px;
  visibility: hidden;
  width: min(300px, calc(100% - 8px));
  padding: 12px 13px;
  border: 1px solid #455156;
  border-radius: 6px;
  background: #172023;
  box-shadow: 0 12px 28px rgba(7, 12, 14, 0.28);
  color: #f6f8f9;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 6px);
  transition: opacity 160ms ease-out, transform 160ms ease-out, visibility 160ms ease-out;
}

.history-tooltip.is-visible {
  visibility: visible;
  opacity: 1;
  transform: translate(-50%, 0);
}

.history-tooltip > time {
  display: block;
  overflow-wrap: anywhere;
  color: #ffffff;
  font-size: 0.76rem;
  font-weight: 720;
}

.history-tooltip dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 9px 0 0;
}

.history-tooltip dl > div {
  min-width: 0;
}

.history-tooltip dt {
  color: #b8c2c6;
  font-size: 0.66rem;
}

.history-tooltip dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 700;
}

.history-empty {
  grid-column: 1 / -1;
  align-self: center;
  color: var(--faint);
  font-size: 0.72rem;
}

.empty-state {
  grid-column: 1 / -1;
  min-height: 280px;
  align-content: center;
  padding: 48px 20px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.empty-state h2 {
  margin: 0;
  font-size: 1.05rem;
}

.empty-state p {
  margin: 8px 0 0;
  color: var(--muted);
}

.public-footer {
  margin-top: 28px;
  color: var(--faint);
  font-size: 0.75rem;
  text-align: center;
}

.admin-page {
  background-color: var(--page);
}

.admin-header {
  position: relative;
  z-index: 2;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
}

.admin-header__inner,
.admin-main {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
}

.admin-header__inner {
  min-height: 64px;
}

.admin-brand {
  font-weight: 760;
}

.admin-brand img,
.login-panel > img {
  flex: 0 0 auto;
  object-fit: contain;
}

.admin-brand img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.login-panel > img {
  width: 42px;
  height: 42px;
  border-radius: 8px;
}

.admin-nav,
.row-actions,
.form-actions,
.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-nav > a {
  min-height: 44px;
  padding: 10px 8px;
  color: var(--muted);
  font-weight: 650;
  text-decoration: none;
}

.admin-nav > a:hover {
  color: var(--text);
}

.admin-nav form,
.row-actions form {
  margin: 0;
}

.admin-main {
  position: relative;
  z-index: 1;
  padding: 38px 0 56px;
}

.admin-main--narrow {
  width: min(820px, calc(100% - 48px));
}

.page-heading {
  margin-bottom: 24px;
}

.page-heading h1 {
  margin: 2px 0 0;
  font-size: 1.55rem;
  line-height: 1.25;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.7rem;
  font-weight: 760;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.data-table {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
  text-align: left;
}

.data-table th,
.data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 760;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover {
  background: color-mix(in srgb, var(--surface-muted) 52%, transparent);
}

.cell-subtext {
  display: block;
  max-width: 240px;
  overflow: hidden;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.75rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions-heading {
  min-width: 285px;
}

.row-actions {
  flex-wrap: wrap;
}

.inline-result {
  display: block;
  min-height: 20px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.74rem;
}

.inline-result.is-error {
  color: var(--error);
}

.settings-form,
.login-panel,
.result-panel {
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.field {
  min-width: 0;
}

.field--wide {
  grid-column: 1 / -1;
}

.field label,
.stack-form label {
  display: block;
  margin-bottom: 7px;
  font-size: 0.82rem;
  font-weight: 720;
}

.field input,
.field select,
.stack-form input {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.field input:focus,
.field select:focus,
.stack-form input:focus {
  border-color: var(--accent);
}

.field-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.check-field {
  display: flex;
  min-height: 56px;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.check-field input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.check-field span,
.check-field strong,
.check-field small {
  display: block;
}

.check-field small {
  margin-top: 2px;
  color: var(--muted);
}

.form-actions {
  justify-content: flex-end;
  margin-top: 24px;
}

.form-message {
  margin: 0 0 18px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.form-message--error {
  border-color: color-mix(in srgb, var(--error) 45%, var(--border));
  background: var(--error-bg);
  color: var(--error);
}

.form-message--success {
  border-color: color-mix(in srgb, var(--ok) 45%, var(--border));
  background: var(--ok-bg);
  color: var(--ok);
}

.admin-empty {
  min-height: 240px;
}

.pagination {
  justify-content: center;
  margin-top: 20px;
  color: var(--muted);
}

.login-page {
  display: grid;
  place-items: center;
}

.login-shell {
  position: relative;
  z-index: 1;
  width: min(420px, calc(100% - 40px));
  padding: 40px 0;
}

.login-panel h1 {
  margin: 18px 0 22px;
  font-size: 1.45rem;
}

.stack-form {
  display: grid;
  gap: 10px;
}

.stack-form .button {
  margin-top: 10px;
}

.result-panel .metric-grid {
  margin-bottom: 0;
}

code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.82em;
}

@media (max-width: 1120px) {
  .status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .corner-mark--tl { top: 12px; left: 12px; }
  .corner-mark--tr { top: 12px; right: 12px; }
  .corner-mark--bl { bottom: 12px; left: 12px; }
  .corner-mark--br { right: 12px; bottom: 12px; }
  .site-frame { width: min(100% - 28px, 1480px); padding-top: 28px; }
  .public-header,
  .page-heading { align-items: flex-start; flex-direction: column; }
  .public-header__primary { width: 100%; }
  .public-actions { width: 100%; align-items: flex-start; justify-content: space-between; }
  .status-grid { grid-template-columns: minmax(0, 1fr); }
  .status-card { min-height: 320px; padding: 18px; }
  .admin-header__inner,
  .admin-main,
  .admin-main--narrow { width: min(100% - 28px, 1180px); }
  .admin-header__inner { min-height: 72px; align-items: flex-start; flex-direction: column; gap: 4px; padding: 12px 0; }
  .admin-nav { width: 100%; justify-content: space-between; }
  .admin-nav > a { padding-left: 0; }
  .admin-main { padding-top: 28px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .field--wide { grid-column: auto; }
  .settings-form,
  .login-panel,
  .result-panel { padding: 20px; }
}

@media (max-width: 430px) {
  .public-header__primary { align-items: flex-start; flex-direction: column; gap: 12px; }
  .site-brand__name { font-size: 1.05rem; }
  .public-actions { flex-direction: column; }
  .public-actions .button { width: 100%; }
  .status-card__header { grid-template-columns: 40px minmax(0, 1fr); gap: 12px; }
  .provider-mark { width: 40px; height: 40px; }
  .status-card__badges { grid-column: 1 / -1; min-width: 0; flex-direction: row; align-items: center; justify-content: flex-start; }
  .status-card .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-card .metric-grid > div:nth-child(2) { border-right: 0; }
  .status-card .metric-grid__wide { grid-column: 1 / -1; border-top: 1px solid var(--border); }
  .metric-grid > div { padding: 12px; }
  .history-strip { gap: 1px; }
  .history-tooltip { width: calc(100% - 4px); padding: 10px 11px; }
  .form-actions { align-items: stretch; flex-direction: column-reverse; }
  .form-actions .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
