:root {
  color-scheme: light dark;
  --bg: #f3f5f8;
  --surface: #fff;
  --text: #172230;
  --muted: #56677a;
  --border: #d5dee8;
  --accent: #315fca;
  --accent-text: #fff;
  --notice: #e9f0ff;
  --ok: #178046;
  --warn: #ad6500;
  --error: #bd3030;
  --shadow: 0 3px 18px #1c31400b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #111820;
    --surface: #1a2530;
    --text: #edf3fa;
    --muted: #b5c3d2;
    --border: #435466;
    --accent: #9bb9ff;
    --accent-text: #101820;
    --notice: #253650;
    --ok: #62d995;
    --warn: #ffcb72;
    --error: #ff9292;
    --shadow: none;
  }
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111820;
  --surface: #1a2530;
  --text: #edf3fa;
  --muted: #b5c3d2;
  --border: #435466;
  --accent: #9bb9ff;
  --accent-text: #101820;
  --notice: #253650;
  --ok: #62d995;
  --warn: #ffcb72;
  --error: #ff9292;
  --shadow: none;
}
html[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
header, main { max-width: 1200px; margin: auto; }
header { padding: 34px 24px 20px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
main { padding: 0 24px 60px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.5rem, 3vw, 2.15rem); line-height: 1.15; margin: .35rem 0; }
h2 { font-size: 1.22rem; margin: .3rem 0 1rem; }
h3 { font-size: 1rem; margin: 1.3rem 0 .4rem; }
p { color: var(--muted); }
.eyebrow { color: var(--accent); font-size: .7rem; font-weight: 800; letter-spacing: .13em; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; margin-bottom: 18px; box-shadow: var(--shadow); }
.login { max-width: 480px; margin: 8vh auto; }
.auth-form { max-width: 480px; }
.auth-form input { margin-bottom: 12px; }
.auth-form p { margin: 0 0 12px; font-size: .85rem; }
.section-title, .topline, .field-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.topline { margin-bottom: 14px; }
.muted, .badge { color: var(--muted); font-size: .85rem; }
.status-grid, .agent-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 10px; margin: 14px 0; }
.status-item, .agent-item { background: var(--bg); border-radius: 8px; padding: 12px; overflow-wrap: anywhere; }
.status-item { border-left: 4px solid var(--warn); }
.status-item.ok { border-color: var(--ok); }
.status-item.error { border-color: var(--error); }
.status-item small { display: block; color: var(--muted); margin-bottom: 4px; }
.status-item strong::before { content: '● '; color: var(--warn); }
.status-item.ok strong::before { color: var(--ok); }
.status-item.error strong::before { color: var(--error); }
.status-item details { margin-top: 8px; }
.agent-item h3 { margin-top: 0; }
.agent-item p { margin-bottom: 8px; }
.agent-item .actions { margin-top: 10px; }
.error-text { color: var(--error); }
.checklist { display: flex; flex-wrap: wrap; gap: 8px 22px; padding: 0; list-style: none; }
.checklist .done { color: var(--ok); }
.checklist .pending { color: var(--muted); }
.actions, .inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline input:not([type="file"]), .inline select { flex: 1; min-width: 100px; }
button, input, select { font: inherit; border-radius: 7px; }
button { border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text); padding: 8px 14px; cursor: pointer; font-weight: 600; }
button:hover { filter: brightness(.94); }
button:disabled { opacity: .5; cursor: wait; }
.secondary { background: transparent; color: var(--text); border-color: var(--border); }
.link { background: none; color: var(--accent); border: 0; padding: 0; text-decoration: underline; }
input, select { width: 100%; background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 8px 10px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
label { display: block; font-weight: 600; font-size: .86rem; margin-bottom: 6px; }
.field { padding-top: 16px; margin-top: 16px; border-top: 1px solid var(--border); }
.field:first-child { padding-top: 0; margin-top: 0; border: 0; }
.field p { font-size: .85rem; margin: 6px 0; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 14px; margin-bottom: 18px; }
.settings-grid label, .badge { overflow-wrap: anywhere; }
.notice, .secret-result { background: var(--notice); border-radius: 8px; padding: 13px; margin: 12px 0; }
.secret-result strong { display: block; margin-bottom: 8px; font-size: .85rem; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); padding: 12px; border-radius: 8px; max-height: 300px; overflow: auto; font-size: .8rem; }
code { overflow-wrap: anywhere; }
.result { margin-top: 10px; overflow-wrap: anywhere; }
.device { margin-top: 12px; }
.device p { margin-bottom: 5px; }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--text); color: var(--surface); padding: 12px 18px; border-radius: 8px; max-width: min(400px, 90vw); z-index: 10; }
.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; }
[hidden] { display: none !important; }
@media (max-width: 760px) {
  header { padding-top: 24px; }
  .card { padding: 18px; }
  .section-title, .field-head { align-items: flex-start; flex-direction: column; gap: 2px; }
  .inline input[type="file"] { width: 100%; }
}
@media (max-width: 400px) {
  header { padding: 20px 14px 16px; }
  main { padding: 0 14px 40px; }
  .card { padding: 16px; }
}

#settings-fields .help {
  display: block;
  margin-top: 0.25rem;
  color: var(--muted, inherit);
  opacity: 0.8;
}
.model-toolbar { margin-bottom: 12px; }
.model-group { margin-top: 20px; }
.model-group-heading, .model-row-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.model-group-heading h3 { margin: 0; }
.model-group-heading .actions button, .model-row .actions button { font-size: .82rem; padding: 5px 10px; }
.model-row { border-top: 1px solid var(--border); padding: 12px 0; overflow-wrap: anywhere; }
.model-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 0; }
.model-badge { border: 1px solid var(--border); border-radius: 12px; padding: 1px 8px; }
.model-toggle { display: flex; align-items: center; gap: 6px; margin: 0; white-space: nowrap; }
.model-toggle input { width: auto; accent-color: var(--accent); }
.model-row .actions { margin-top: 8px; }
.model-removed { border-top: 1px solid var(--border); padding: 12px 0; }
.model-removed summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.model-removed-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; overflow-wrap: anywhere; }
.model-removed-row button { font-size: .82rem; padding: 5px 10px; }
.model-editor, #model-add { background: var(--bg); border-radius: 8px; margin: 12px 0; padding: 14px; }
.model-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: 12px; margin: 12px 0; }
.model-fields input, .model-fields select, #model-add select { margin-top: 5px; }
.catalog-results { max-height: 240px; overflow: auto; }
.catalog-choice { display: block; width: 100%; text-align: left; background: var(--surface); color: var(--text); border-color: var(--border); border-radius: 0; overflow-wrap: anywhere; }
.model-warning { color: var(--warn); margin: 8px 0; }
.models-pending { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 9; width: min(600px, calc(100% - 24px)); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; background: var(--notice); border: 1px solid var(--border); border-radius: 10px; padding: 12px; box-shadow: var(--shadow); }

.model-summary {
  display: block;
  margin: 0.15rem 0 0.4rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 24px 12px; }
.sidebar a { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--text); text-decoration: none; border-radius: 8px; padding: 10px 12px; margin-bottom: 4px; font-weight: 600; }
.sidebar a:hover, .sidebar a[aria-current="page"] { background: var(--notice); color: var(--accent); }
.nav-indicator { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; background: var(--warn); font-size: 0; }
.checklist a { color: inherit; }
.menu-toggle { display: none; margin-bottom: 14px; }
.menu-backdrop { position: fixed; inset: 0; background: #0009; z-index: 19; }
.dashboard-content { min-width: 0; }
@media (min-width: 900px) {
  body:has(#dashboard:not([hidden])) header, body:has(#dashboard:not([hidden])) main { margin-left: 240px; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 220px; overflow-y: auto; }
}
@media (max-width: 899px) {
  .menu-toggle { display: inline-block; }
  .sidebar { display: none; position: fixed; inset: 0 auto 0 0; width: min(280px, 85vw); z-index: 20; overflow-y: auto; box-shadow: var(--shadow); }
  .sidebar.open { display: block; }
}
