:root {
  color-scheme: light;
  --ink: #18201e;
  --muted: #64706c;
  --line: #d9dfdc;
  --soft: #f3f6f4;
  --paper: #ffffff;
  --accent: #147d64;
  --accent-dark: #0f5e4c;
  --amber: #a75d12;
  --danger: #b33a35;
  --shadow: 0 18px 50px rgba(20, 35, 30, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-size: 14px;
  line-height: 1.5;
}

button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

.topbar {
  height: 72px;
  padding: 0 max(24px, calc((100vw - 1180px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.brand-block { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: #fff;
  background: var(--ink);
  font-weight: 800;
}
.brand-block h1 { margin: 0; font-size: 15px; line-height: 1.25; }
.brand-block p { margin: 2px 0 0; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.header-actions { display: flex; align-items: center; gap: 16px; }
.service-state { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.service-state i { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.service-state.ready i { background: var(--accent); }

main { min-height: calc(100vh - 72px); }
.login-view { min-height: calc(100vh - 72px); display: grid; place-items: center; padding: 32px 20px; background: var(--soft); }
.login-form { width: min(390px, 100%); padding: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); box-shadow: var(--shadow); }
.login-form .button { width: 100%; margin-top: 20px; }

.workspace { width: min(1180px, 100%); margin: 0 auto; }
.tabs { height: 56px; display: flex; align-items: end; gap: 24px; padding: 0 24px; border-bottom: 1px solid var(--line); }
.tab { height: 56px; padding: 0 2px; border: 0; border-bottom: 2px solid transparent; color: var(--muted); background: transparent; font-weight: 650; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }

.status-strip { display: grid; grid-template-columns: repeat(3, 1fr) auto; border-bottom: 1px solid var(--line); }
.status-metric, .status-action { min-height: 88px; padding: 20px 24px; display: flex; flex-direction: column; justify-content: center; }
.status-metric + .status-metric, .status-action { border-left: 1px solid var(--line); }
.status-metric span { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.status-metric strong { margin-top: 5px; font-size: 14px; overflow-wrap: anywhere; }
.status-action { min-width: 150px; }

.section-band { padding: 36px 24px 42px; border-bottom: 1px solid var(--line); }
.section-band.subdued { background: var(--soft); }
.first-band { border-top: 0; }
.section-heading { margin-bottom: 24px; }
.section-heading h2 { margin: 2px 0 0; font-size: 20px; line-height: 1.25; }
.eyebrow { margin: 0; color: var(--accent); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.split-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; }

.auth-options { display: grid; grid-template-columns: minmax(240px, 0.8fr) minmax(360px, 1.2fr); gap: 44px; }
.auth-option { min-width: 0; }
.auth-option + .auth-option { padding-left: 44px; border-left: 1px solid var(--line); }
.auth-option h3 { margin: 0 0 18px; font-size: 14px; }
.oauth-buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.inline-fields { display: flex; gap: 10px; margin-bottom: 12px; }
.grow { flex: 1; min-width: 0; }
.align-end { align-self: end; }

label { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
label > span, .field-note { color: var(--muted); font-size: 12px; }
input, textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid #c7d0cc;
  border-radius: 6px;
  color: var(--ink);
  background: var(--paper);
  outline: none;
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(20, 125, 100, 0.12); }
.credential-form { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.wide { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.form-error { min-height: 21px; margin: 10px 0 0; color: var(--danger); font-size: 12px; }

.button {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  white-space: nowrap;
  font-weight: 700;
}
.button.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.button.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.button.secondary { color: var(--ink); background: var(--paper); border-color: #bcc7c2; }
.button.secondary:hover, .button.ghost:hover { background: var(--soft); }
.button.ghost { min-height: 32px; padding: 5px 9px; color: var(--muted); background: transparent; border-color: transparent; }
.button.danger { color: var(--danger); }

.key-create { display: flex; gap: 8px; width: min(440px, 100%); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 10px; text-transform: uppercase; }
td:last-child, th:last-child { text-align: right; }
.empty-state { padding: 24px 10px; color: var(--muted); text-align: center; }

code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.92em; overflow-wrap: anywhere; }
.config-list { margin: 0; border-top: 1px solid var(--line); }
.config-list > div { display: grid; grid-template-columns: 160px 1fr; min-height: 58px; align-items: center; border-bottom: 1px solid var(--line); }
.config-list dt { color: var(--muted); }
.config-list dd { margin: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; }
.copy-button { padding: 5px 8px; border: 0; color: var(--accent); background: transparent; font-weight: 700; }
.model-list { display: flex; flex-wrap: wrap; gap: 8px; }
.model-list code { padding: 7px 10px; border: 1px solid var(--line); border-radius: 5px; background: var(--paper); }

dialog { width: min(560px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 8px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(13, 22, 19, 0.58); }
.dialog-shell { padding: 28px; }
.secret-output { padding: 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--soft); overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: end; gap: 8px; margin-top: 20px; }
.oauth-callback-form { display: grid; gap: 16px; }
.oauth-callback-form .section-heading, .oauth-callback-form .dialog-actions { margin: 0; }
.oauth-callback-form textarea { min-height: 108px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.oauth-waiting { display: flex; align-items: center; gap: 9px; padding: 10px 0; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.oauth-waiting i { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: #d49a24; box-shadow: 0 0 0 3px rgba(212, 154, 36, 0.14); }

.toast { position: fixed; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 40px)); padding: 11px 14px; border-radius: 6px; color: #fff; background: var(--ink); box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); pointer-events: none; transition: 160ms ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

@media (max-width: 760px) {
  .topbar { height: 64px; padding: 0 16px; }
  main { min-height: calc(100vh - 64px); }
  .brand-block p { display: none; }
  .workspace { width: 100%; }
  .tabs { padding: 0 16px; gap: 20px; }
  .status-strip { grid-template-columns: 1fr; }
  .status-metric, .status-action { min-height: 68px; padding: 14px 16px; }
  .status-metric + .status-metric, .status-action { border-left: 0; border-top: 1px solid var(--line); }
  .section-band { padding: 28px 16px 34px; }
  .auth-options { grid-template-columns: 1fr; gap: 30px; }
  .auth-option + .auth-option { padding: 30px 0 0; border-left: 0; border-top: 1px solid var(--line); }
  .credential-form { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .split-heading { align-items: stretch; flex-direction: column; }
  .key-create { flex-direction: column; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .config-list > div { grid-template-columns: 1fr; gap: 4px; padding: 12px 0; }
  .config-list dd { align-items: start; }
  .header-actions { gap: 4px; }
  .service-state { max-width: 140px; }
  .service-state span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
