:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #dfe4ea;
  --text: #17212b;
  --muted: #5b6876;
  --navy: #17324d;
  --navy-2: #22476b;
  --accent: #1f6f8b;
  --accent-ink: #ffffff;
  --ok: #18794e;
  --ok-bg: #e6f4ec;
  --warn: #9a5b00;
  --warn-bg: #fdf1dc;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --idle: #5b6876;
  --idle-bg: #edf0f3;
  --focus: #2f80ed;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151c;
    --surface: #161e27;
    --surface-2: #1b2531;
    --border: #2a3644;
    --text: #e6edf3;
    --muted: #9aa8b6;
    --navy: #0b1622;
    --navy-2: #13263a;
    --accent: #3a9bbd;
    --ok: #4cc38a;
    --ok-bg: #12301f;
    --warn: #f0b350;
    --warn-bg: #33270f;
    --bad: #ff7a6b;
    --bad-bg: #3a1714;
    --idle: #9aa8b6;
    --idle-bg: #222d39;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
[hidden] { display: none !important; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.fine { color: var(--muted); font-size: 12px; margin: 12px 0 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Buttons & inputs */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 7px 14px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
label { display: block; font-weight: 600; margin: 0 0 6px; }
input[type=text], input[type=password], input[type=url] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
input::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
.form-error { color: var(--bad); margin: 8px 0 0; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.login-card h1 { font-size: 20px; margin: 18px 0 4px; }
.login-card input { margin-bottom: 14px; }
.login-card .btn { width: 100%; margin-top: 4px; }
.login-card .field-help { margin: -8px 0 12px; }
.btn.full { width: 100%; margin-top: 8px; }
.info-box { margin-top: 16px; padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--border)); background: var(--warn-bg); border-radius: 8px; font-size: 13px; }
.info-box p { margin: 4px 0; }
.info-label { font-weight: 600; margin-top: 10px !important; }
.cmd { display: block; padding: 6px 8px; margin: 4px 0; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); overflow-x: auto; white-space: nowrap; }
.fine-inline { color: var(--muted); font-size: 12px; }
input[type=email], select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
/* minmax(0, 1fr): wide tables scroll inside .table-wrap instead of stretching the page. */
.page { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.span-2 { grid-column: 1 / -1; }
.section-h { font-size: 14px; margin: 0; }
.small { font-size: 12.5px; margin: 2px 0 0; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check input { width: 16px; height: 16px; }
.pad { padding: 14px 18px; margin: 0; }
.table input[type=text] { min-width: 160px; padding: 5px 8px; }
.card-head h2 { font-size: 15px; }
.table-wrap { overflow-x: auto; position: relative; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 10px 18px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.table tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; }

/* Shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: #dbe6f0; padding: 18px 12px; }
.sidebar .brand { color: #fff; padding: 0 8px 18px; }
.nav-item { display: block; color: #c4d3e0; text-decoration: none; padding: 8px 10px; border-radius: 7px; margin-bottom: 2px; }
.nav-item:hover { background: var(--navy-2); color: #fff; }
.nav-item.active { background: var(--navy-2); color: #fff; font-weight: 600; }
.main { padding: 22px 28px 48px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.topbar h1 { font-size: 22px; }
.topbar p { margin: 4px 0 0; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--idle-bg); color: var(--idle); text-transform: capitalize; }
.badge.production { background: var(--bad-bg); color: var(--bad); }
.badge.staging { background: var(--warn-bg); color: var(--warn); }
.notice { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; border: 1px solid var(--border); background: var(--surface); }
.notice.ok { border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); background: var(--ok-bg); }
.notice.bad { border-color: color-mix(in srgb, var(--bad) 35%, var(--border)); background: var(--bad-bg); }

/* Summary */
.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; }

/* Provider cards */
.providers { display: grid; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.card-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card-title h2 { font-size: 16px; }
.card-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.tag { font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); padding: 1px 8px; border-radius: 999px; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.idle { background: var(--idle-bg); color: var(--idle); }
.card-body { padding: 16px 18px; display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 22px; }
.fields { display: grid; gap: 14px; }
.field-row { display: flex; gap: 8px; }
.field-row input { flex: 1; }
.field-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.field-meta .stored { color: var(--ok); font-weight: 600; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.result { font-size: 13px; }
.result.ok { color: var(--ok); }
.result.bad { color: var(--bad); }
.side h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.models { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.models li { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-2); }
.empty { color: var(--muted); font-size: 13px; }

.dialog { border: 1px solid var(--border); border-radius: 14px; padding: 22px; max-width: 440px; width: calc(100% - 32px); background: var(--surface); color: var(--text); }
.dialog::backdrop { background: rgba(10, 20, 30, .45); }
.dialog h2 { font-size: 17px; margin-bottom: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dialog.wide { max-width: 760px; }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.dialog .kv { margin-bottom: 14px; }
.dialog h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 8px; }
.dialog .table th, .dialog .table td { padding: 7px 10px; }

.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px 14px; padding: 16px 18px; border-bottom: 1px solid var(--border); align-items: end; }
.filters label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.filters input, .filters select { width: 100%; box-sizing: border-box; }
.filter-actions { display: flex; gap: 8px; }
.table.clickable tbody tr { cursor: pointer; }
.table.clickable tbody tr:hover td, .table.clickable tbody tr:focus-visible td { background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
pre.json { margin: 6px 0 0; padding: 8px 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px; font-size: 12px; max-height: 260px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
details summary { cursor: pointer; color: var(--accent); font-size: 12.5px; }
.settle { margin-top: 16px; padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--warn) 35%, var(--border)); background: var(--warn-bg); border-radius: var(--radius); }
.settle h3 { margin-top: 0; }
.settle-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; align-items: start; margin-top: 10px; }
.settle-grid .span-3 { grid-column: 1 / -1; }
.settle-grid label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.settle-actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }
.stat.link .btn { margin-top: 6px; }
@media (max-width: 640px) { .settle-grid { grid-template-columns: 1fr; } }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; overflow-x: auto; }
  .sidebar .brand { padding: 0; white-space: nowrap; flex: none; }
  .sidebar nav { display: flex; gap: 4px; }
  .nav-item { white-space: nowrap; margin-bottom: 0; }
  .main { padding: 16px; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-body, .form-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
  .topbar-right { justify-content: flex-start; }
}
