:root {
  color-scheme: light dark;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #66665f;
  --line: #e2e1dc;
  --accent: #dc2626;
  --accent-hover: #b91c1c;
  --on-accent: #ffffff;
  --error: #b91c1c;
  --error-bg: #fdecec;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #20201e;
    --text: #efefea;
    --muted: #a3a39b;
    --line: #353532;
    --accent: #dc2626;
    --accent-hover: #ef4444;
    --error: #fca5a5;
    --error-bg: #3a1b1b;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 32px 16px 64px;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

h1 { margin: 0; font-size: 20px; line-height: 1.2; }
header p { margin: 0; color: var(--muted); }
h2 { margin: 0 0 14px; font-size: 16px; }

form, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
}

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

label span { display: block; margin-bottom: 5px; font-weight: 600; }
small { margin-left: 4px; color: var(--muted); font-size: 12px; font-weight: 400; }

input {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  font: 14px ui-monospace, Consolas, monospace;
}

input:focus-visible, button:focus-visible, a:focus-visible, .table-wrap:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.actions p { margin: 0 0 0 6px; color: var(--muted); font-size: 13px; }

button {
  height: 38px;
  padding: 0 16px;
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid transparent;
  border-radius: 7px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.65; cursor: progress; }
button.secondary { background: transparent; color: var(--text); border-color: var(--line); }
button.secondary:hover { background: var(--bg); }

#message {
  margin: 14px 0 0;
  padding: 10px 12px;
  background: var(--error-bg);
  color: var(--error);
  border-radius: 7px;
}

#results { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; margin-top: 18px; }
.org { margin: 0; color: var(--muted); }
.org strong { color: var(--text); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.stats span { display: block; color: var(--muted); font-size: 13px; }
.stats strong { font-size: 22px; font-variant-numeric: tabular-nums; }

meter { display: block; width: 100%; height: 10px; margin-bottom: 10px; }

.note { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.note:last-child { margin-bottom: 0; }
.note.error { color: var(--error); }
a { color: inherit; text-underline-offset: 2px; }

.table-wrap { overflow-x: auto; margin-top: 4px; }
table { width: 100%; border-collapse: collapse; }

th, td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

tbody tr:last-child td { border-bottom: 0; }
th { color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }

.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.cap { text-transform: capitalize; }
.supports { min-width: 220px; color: var(--muted); font-size: 13px; }

td code {
  display: block;
  color: var(--muted);
  font: 12px ui-monospace, Consolas, monospace;
  white-space: nowrap;
}

.badge {
  margin-left: 6px;
  padding: 1px 6px;
  background: var(--error-bg);
  color: var(--error);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.grow { flex: 1; min-width: 0; }

nav {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab {
  flex: none;
  height: 38px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
}

.tab:hover { background: transparent; color: var(--text); }
.tab[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }

.tab-panel { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

form.narrow { width: min(380px, 100%); margin: 48px auto 0; grid-template-columns: minmax(0, 1fr); }

.panel-form h2, .panel-form fieldset, .panel-form .full, .panel-form .form-error, form.narrow .form-error { grid-column: 1 / -1; }
.panel-form h2 { margin-bottom: 0; }

.form-error { margin: 0; color: var(--error); font-size: 14px; }

fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
legend { margin-bottom: 5px; padding: 0; font-weight: 600; }

label.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
label.check span { margin: 0; font-weight: 400; }
label.check input { flex: none; width: 16px; height: 16px; padding: 0; accent-color: var(--accent); }

.model-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 6px 12px;
  margin-top: 8px;
}

.banner {
  margin: 0;
  padding: 10px 12px;
  background: var(--error-bg);
  color: var(--error);
  border-radius: 7px;
}

button.link {
  height: auto;
  padding: 0;
  background: transparent;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

button.link:hover { background: transparent; }

button.small { height: 30px; padding: 0 10px; font-size: 13px; }
button.danger { background: transparent; color: var(--error); border-color: var(--line); }
button.danger:hover { background: var(--error-bg); }

.secret { border-color: var(--accent); }
.copy-row { display: flex; gap: 8px; align-items: stretch; margin-bottom: 12px; }

.copy-row code {
  flex: 1;
  min-width: 0;
  padding: 9px 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  font: 13px ui-monospace, Consolas, monospace;
  overflow-wrap: anywhere;
  user-select: all;
}

pre {
  margin: 0 0 12px;
  padding: 11px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow-x: auto;
  font: 13px/1.6 ui-monospace, Consolas, monospace;
}

pre:last-child { margin-bottom: 0; }
pre code { font: inherit; }

.note.fine { margin-top: 12px; font-size: 13px; }
.usage { min-width: 130px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.usage meter { margin: 5px 0 0; height: 7px; }
.models { min-width: 110px; max-width: 220px; color: var(--muted); font-size: 13px; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions button + button { margin-left: 6px; }
tr.inactive td { color: var(--muted); }
tr.inactive strong { font-weight: 500; }

@media (max-width: 640px) {
  form { grid-template-columns: minmax(0, 1fr); }
  .actions p { flex-basis: 100%; margin-left: 0; }
  .stats { grid-template-columns: minmax(0, 1fr); }
}
