:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e6e8eb;
  --border-soft: #eef0f2;
  --text: #1a1d21;
  --text-muted: #6b7280;
  --text-faint: #9aa1ab;

  --accent: #ea5f24;
  --accent-strong: #d94f18;
  --accent-bg: #fff1e7;
  --accent-border: #ffd9bd;

  --danger: #d92d2d;
  --danger-bg: #fdecec;
  --danger-border: #f6b9b9;

  --success: #178a4c;
  --success-bg: #e5f6ec;

  --warn: #a15c00;
  --warn-bg: #fff4de;

  --info: #2f5fd0;
  --info-bg: #eaf0fe;

  --border-hover: #d8dbe0;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 25, 0.04);
  --shadow: 0 4px 16px rgba(20, 20, 25, 0.06);
  --sidebar-w: 264px;

  --cfg-bg: #fff4c2;
  --cfg-text: #6b4b00;
  --scrollbar-thumb: #d7dade;
}

:root[data-theme="dark"] {
  --bg: #101216;
  --surface: #1a1d22;
  --border: #2c3036;
  --border-soft: #23262b;
  --border-hover: #3a3f47;
  --text: #e8eaed;
  --text-muted: #9aa1ab;
  --text-faint: #6b7280;

  --accent: #ff7a3d;
  --accent-strong: #ffab7a;
  --accent-bg: #3a2417;
  --accent-border: #6b3d1f;

  --danger: #ff8a8a;
  --danger-bg: #3a1f1f;
  --danger-border: #6b3232;

  --success: #4ade80;
  --success-bg: #16321f;

  --warn: #f0b429;
  --warn-bg: #3a2f10;

  --info: #8ab4ff;
  --info-bg: #1c2a45;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);

  --cfg-bg: #4a3f14;
  --cfg-text: #f0d878;
  --scrollbar-thumb: #3a3f47;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; color: inherit; cursor: pointer; }

.icon { display: inline-block; vertical-align: -3px; flex-shrink: 0; }
.inline-ext { vertical-align: -1px; margin-left: 2px; opacity: 0.6; }

/* ---------- Shell ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px 8px;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: #14161a;
  border: 1px solid var(--border);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-text { line-height: 1.25; }
.brand-title { font-weight: 700; font-size: 14.5px; }
.brand-sub { color: var(--text-muted); font-size: 12px; }

.nav-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  padding: 10px 10px 6px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
}
.nav-item:hover { background: var(--border-soft); }
.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent-strong);
  font-weight: 700;
}
.nav-item.active .icon { color: var(--accent-strong); }
.nav-item .icon { color: var(--text-muted); }

.sidebar-footer {
  margin-top: auto;
  padding: 10px 8px;
  font-size: 11.5px;
  color: var(--text-faint);
  border-top: 1px solid var(--border-soft);
  padding-top: 12px;
}

/* ---------- Main ---------- */
.main {
  flex: 1;
  min-width: 0;
  padding: 22px 32px 60px;
}

.searchbar {
  position: relative;
  max-width: 780px;
  margin-bottom: 22px;
}
.searchbar .icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
}
.searchbar input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  color: var(--text);
  outline: none;
}
.searchbar input:focus { border-color: var(--accent-border); box-shadow: 0 0 0 3px var(--accent-bg); }

.search-results {
  max-width: 780px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: -12px;
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.search-results-empty { padding: 16px; color: var(--text-muted); font-size: 13px; }
.search-result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.search-result-row:last-child { border-bottom: none; }
.search-result-row:hover { background: var(--bg); }
.search-result-kind {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  width: 78px;
  flex-shrink: 0;
}
.search-result-title { font-weight: 600; font-size: 13.5px; }
.search-result-sub { color: var(--text-muted); font-size: 12px; }

/* ---------- Dashboard header ---------- */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent-strong);
  margin-bottom: 10px;
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #17a34a;
  box-shadow: 0 0 0 3px #17a34a22;
}

.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.dash-title { font-size: 27px; font-weight: 800; margin: 0 0 8px; letter-spacing: -0.01em; }
.dash-subtitle { color: var(--text-muted); max-width: 640px; margin: 0; font-size: 14px; }
.dash-clock { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.dash-stats { display: flex; gap: 18px; margin-top: 8px; font-size: 12.5px; color: var(--text-muted); justify-content: flex-end; }
.dash-stats b { color: var(--text); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.triage-panel {
  border: 1px solid var(--danger-border);
  border-left: 4px solid var(--danger);
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 30px;
}
.triage-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 6px;
}
.triage-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14.5px;
  color: var(--danger);
}
.triage-panel-hint { font-size: 12px; color: var(--text-muted); }

.triage-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
@media (max-width: 980px) { .triage-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .triage-grid { grid-template-columns: 1fr; } }

.triage-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
}
.triage-card:hover { border-color: var(--danger-border); box-shadow: var(--shadow-sm); }
.triage-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--danger-bg);
  color: var(--danger);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.triage-card.severity-high .triage-icon { background: var(--warn-bg); color: var(--warn); }
.triage-card-title { font-weight: 700; font-size: 13.5px; }
.triage-card-sub { color: var(--text-muted); font-size: 12px; margin-top: 1px; }

/* ---------- Section label ---------- */
.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin: 30px 0 12px;
}

/* ---------- Category / card grid ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
@media (max-width: 1280px) { .card-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 940px) { .card-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .card-grid { grid-template-columns: 1fr; } }

.cat-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: left;
}
.cat-card:hover { box-shadow: var(--shadow); border-color: var(--border-hover); transform: translateY(-1px); }
.cat-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }

.cat-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cat-icon.indigo { background: #edeeFc; color: #5457d1; }
.cat-icon.green  { background: #e5f6ec; color: #178a4c; }
.cat-icon.red    { background: #fdecec; color: #d92d2d; }
.cat-icon.orange { background: #fff1e7; color: #d9691f; }
.cat-icon.pink   { background: #fdeef4; color: #c23577; }
.cat-icon.yellow { background: #fdf3d8; color: #a1740a; }
.cat-icon.teal   { background: #e3f6f3; color: #158577; }
.cat-icon.blue   { background: #eaf0fe; color: #2f5fd0; }

:root[data-theme="dark"] .cat-icon.indigo { background: #262a4a; color: #9ea3f5; }
:root[data-theme="dark"] .cat-icon.green  { background: #163a24; color: #4ade80; }
:root[data-theme="dark"] .cat-icon.red    { background: #3a1f1f; color: #ff8a8a; }
:root[data-theme="dark"] .cat-icon.orange { background: #3a2417; color: #ffab7a; }
:root[data-theme="dark"] .cat-icon.pink   { background: #3a1f30; color: #f082b8; }
:root[data-theme="dark"] .cat-icon.yellow { background: #3a2f10; color: #e0b23e; }
:root[data-theme="dark"] .cat-icon.teal   { background: #133a35; color: #5eead4; }
:root[data-theme="dark"] .cat-icon.blue   { background: #1c2a45; color: #8ab4ff; }

.guide-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--border-soft);
  border-radius: 20px;
  padding: 4px 9px;
}

.cat-card-title { font-weight: 700; font-size: 15px; margin: 0 0 3px; }
.cat-card-blurb { color: var(--text-muted); font-size: 12.5px; margin: 0 0 12px; }

.badge-row { display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 20px;
}
.badge.COMMON { background: var(--border-soft); color: var(--text-muted); }
.badge.MFG.CONFIRMED, .badge.mfg-confirmed { background: var(--success-bg); color: var(--success); }
.badge.CRITICAL { background: var(--danger-bg); color: var(--danger); }

/* ---------- Generic page header ---------- */
.page-head { margin-bottom: 20px; }
.page-title { font-size: 22px; font-weight: 800; margin: 0 0 4px; }
.page-sub { color: var(--text-muted); margin: 0; font-size: 13.5px; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 10px;
}
.back-link:hover { color: var(--text); }

/* ---------- Lists ---------- */
.list-grid { display: flex; flex-direction: column; gap: 10px; }
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
}
.list-row:hover { border-color: var(--border-hover); box-shadow: var(--shadow-sm); }
.list-row-title { font-weight: 700; font-size: 13.5px; }
.list-row-sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.list-row-tag {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-faint);
  background: var(--border-soft);
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ---------- Filters ---------- */
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.filter-chip {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
}
.filter-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Device detail ---------- */
.device-layout { display: grid; grid-template-columns: 1fr 260px; gap: 24px; align-items: start; }
@media (max-width: 980px) { .device-layout { grid-template-columns: 1fr; } }

.quickfacts {
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 20px;
}
.quickfacts-title { font-weight: 700; font-size: 12.5px; color: var(--accent-strong); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.quickfacts dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; }
.quickfacts dt { font-weight: 700; font-size: 12.5px; color: var(--accent-strong); }
.quickfacts dd { margin: 0; font-size: 12.5px; color: var(--text); }

.kb-section { margin-bottom: 22px; }
.kb-section h2 { font-size: 15.5px; font-weight: 700; margin: 0 0 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border-soft); }
.kb-section p, .issue-card-body p, .content-overlay-body p { margin: 0 0 10px; }
.kb-section ul, .kb-section ol, .issue-card-body ul, .issue-card-body ol, .content-overlay-body ul, .content-overlay-body ol { margin: 0 0 10px; padding-left: 22px; }
.kb-section li, .issue-card-body li, .content-overlay-body li { margin-bottom: 4px; }
.kb-section table, .issue-card-body table, .content-overlay-body table { border-collapse: collapse; width: 100%; font-size: 13px; }
.kb-section th, .kb-section td, .issue-card-body th, .issue-card-body td, .content-overlay-body th, .content-overlay-body td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
.kb-section th, .issue-card-body th, .content-overlay-body th { background: var(--border-soft); font-weight: 700; }
.md-table-wrap { overflow-x: auto; margin-bottom: 12px; }
.kb-section code, .issue-card-body code { background: var(--border-soft); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

.callout { border: 1px solid var(--border); border-left: 3px solid var(--info); border-radius: var(--radius); padding: 10px 14px; margin: 0 0 12px; background: var(--info-bg); }
.callout-title { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 12.5px; color: var(--info); margin-bottom: 4px; }
.callout-body p:last-child { margin-bottom: 0; }
.callout-warning, .callout-danger { border-left-color: var(--danger); background: var(--danger-bg); }
.callout-warning .callout-title, .callout-danger .callout-title { color: var(--danger); }
.callout-tip { border-left-color: var(--success); background: var(--success-bg); }
.callout-tip .callout-title { color: var(--success); }
.callout-summary { border-left-color: var(--accent); background: var(--accent-bg); }
.callout-summary .callout-title { color: var(--accent-strong); }
.callout-warn { border-left-color: var(--warn); background: var(--warn-bg); }
.callout-warn .callout-title { color: var(--warn); }

.issue-card { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.issue-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  font-weight: 700;
  font-size: 13.5px;
}
.issue-card-head:hover { background: var(--bg); }
.issue-card-body { padding: 0 16px 14px; }
.issue-field { margin-top: 8px; }
.issue-field-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); margin-bottom: 2px; }
.issue-field-value { font-size: 13.5px; }

.side-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; margin-bottom: 16px; }
.side-panel h3 { font-size: 12px; font-weight: 700; letter-spacing: 0.04em; color: var(--text-faint); margin: 0 0 10px; }
.side-panel ul { margin: 0; padding: 0; list-style: none; }
.side-panel li { margin-bottom: 8px; }
.side-panel a.res-link { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--info); }
.status-pill { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 20px; }
.status-pill.current { background: var(--success-bg); color: var(--success); }
.status-pill.legacy { background: var(--warn-bg); color: var(--warn); }

/* ---------- Wizard ---------- */
.wizard-box { max-width: 640px; }
.wizard-progress { display: flex; gap: 6px; margin-bottom: 16px; }
.wizard-progress span { width: 26px; height: 4px; border-radius: 4px; background: var(--border); }
.wizard-progress span.done { background: var(--accent); }
.wizard-question { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.wizard-options { display: flex; flex-direction: column; gap: 8px; }
.wizard-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
}
.wizard-option:hover { border-color: var(--accent); background: var(--accent-bg); }
.wizard-actions { margin-top: 18px; display: flex; gap: 10px; }
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.wizard-result { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; }

/* ---------- Triage detail ---------- */
.triage-detail-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.triage-detail-icon { width: 50px; height: 50px; border-radius: 12px; background: var(--danger-bg); color: var(--danger); display: flex; align-items: center; justify-content: center; }
.severity-tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 20px; background: var(--danger-bg); color: var(--danger); margin-bottom: 6px; }
.severity-tag.high { background: var(--warn-bg); color: var(--warn); }

.script-step { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; margin-bottom: 12px; }
.script-step h3 { font-size: 13.5px; margin: 0 0 8px; }
.script-step p { margin: 0 0 8px; font-size: 13.5px; }
.script-step p:last-child { margin-bottom: 0; }

.donot-box { background: var(--danger-bg); border: 1px solid var(--danger-border); border-radius: var(--radius-lg); padding: 16px 18px; margin-top: 6px; }
.donot-box h3 { color: var(--danger); font-size: 13px; margin: 0 0 8px; display: flex; align-items: center; gap: 6px; }
.donot-box ul { margin: 0; padding-left: 18px; }
.donot-box li { margin-bottom: 5px; font-size: 13px; }

/* ---------- Call scripts ---------- */
.script-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; margin-bottom: 12px; }
.script-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.script-card-group { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent-strong); background: var(--accent-bg); padding: 3px 8px; border-radius: 20px; }
.script-card h3 { font-size: 14.5px; margin: 0; }
.script-line { background: var(--bg); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 8px; font-size: 13.5px; }
.script-tips { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.script-tips-label { font-size: 11px; font-weight: 700; color: var(--text-faint); margin-bottom: 5px; }
.script-tips ul { margin: 0; padding-left: 18px; }
.copy-btn { font-size: 11px; }

/* ---------- Config placeholder highlight ---------- */
.cfg { background: var(--cfg-bg); color: var(--cfg-text); padding: 1px 4px; border-radius: 4px; font-weight: 600; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Nav spacer (pushes Settings toward the bottom) ---------- */
.nav-spacer { flex: 1; min-height: 8px; }

/* ---------- Settings ---------- */
.settings-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; margin-bottom: 16px; max-width: 560px; }
.settings-section h2 { font-size: 14.5px; font-weight: 700; margin: 0 0 4px; display: flex; align-items: center; gap: 7px; }
.settings-hint { color: var(--text-muted); font-size: 12.5px; margin: 0 0 14px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 6px 0; }
.settings-row-title { font-weight: 600; font-size: 13.5px; }
.settings-row-sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.field-label { display: block; font-size: 11.5px; font-weight: 700; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.03em; margin: 14px 0 6px; }
.field-label:first-of-type { margin-top: 4px; }
.tts-provider-toggle { display: flex; gap: 6px; }
.key-input-group { display: flex; gap: 8px; align-items: center; }
.key-input-group input,
.key-input-group select {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.key-input-group select { cursor: pointer; }
.key-input-group input:focus,
.key-input-group select:focus { border-color: var(--accent-border); box-shadow: 0 0 0 3px var(--accent-bg); }
.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 8px 9px;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg); }
.settings-status { font-size: 12px; color: var(--text-muted); margin-top: 6px; min-height: 15px; }
.settings-note {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 560px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--border-soft);
  border-radius: var(--radius);
  padding: 10px 14px;
}

.toggle-switch {
  width: 40px;
  height: 23px;
  border-radius: 20px;
  background: var(--border);
  border: none;
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s;
}
.toggle-switch .toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
  box-shadow: var(--shadow-sm);
}
.toggle-switch.on { background: var(--accent); }
.toggle-switch.on .toggle-thumb { transform: translateX(17px); }
.toggle-switch.disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Chat assistant ---------- */
.chat-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  z-index: 40;
}
.chat-launcher:hover { background: var(--accent-strong); }

.chat-panel {
  position: fixed;
  right: 24px;
  bottom: 88px;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 560px;
  max-height: calc(100vh - 130px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 40;
}
.chat-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.chat-panel-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13.5px; }
.chat-panel-actions { display: flex; align-items: center; gap: 4px; }
.chat-panel-actions button {
  border: none;
  background: transparent;
  color: var(--text-faint);
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
}
.chat-panel-actions button:hover { background: var(--border-soft); color: var(--text); }

.chat-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.chat-empty-hint { color: var(--text-muted); font-size: 12.5px; text-align: center; padding: 20px 10px; }
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg-bubble { max-width: 88%; padding: 9px 12px; border-radius: var(--radius); font-size: 13px; line-height: 1.5; }
.chat-msg.user .chat-msg-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.chat-msg.assistant .chat-msg-bubble { background: var(--bg); border: 1px solid var(--border-soft); border-bottom-left-radius: 3px; }
.chat-msg-bubble p { margin: 0 0 8px; }
.chat-msg-bubble p:last-child { margin-bottom: 0; }
.chat-msg-bubble ul, .chat-msg-bubble ol { margin: 0 0 8px; padding-left: 20px; }
.chat-msg-bubble a.wikilink { color: var(--accent-strong); font-weight: 600; text-decoration: underline; }
.chat-msg.user .chat-msg-bubble a.wikilink { color: #fff; }
.chat-typing { display: flex; gap: 4px; padding: 4px 2px; }
.chat-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); animation: chatTypingBounce 1.1s infinite ease-in-out; }
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatTypingBounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }

.chat-setup-hint { margin: 14px; padding: 12px 14px; background: var(--accent-bg); border: 1px solid var(--accent-border); border-radius: var(--radius); font-size: 12.5px; color: var(--accent-strong); }
.chat-setup-hint a { text-decoration: underline; font-weight: 700; }

.chat-input-row { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border-soft); flex-shrink: 0; }
.chat-input-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  max-height: 90px;
}
.chat-input-row textarea:focus { border-color: var(--accent-border); box-shadow: 0 0 0 3px var(--accent-bg); }
.chat-send-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  width: 38px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-send-btn:hover { background: var(--accent-strong); }
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Model picker ---------- */
.model-picker-wrap { position: relative; max-width: 560px; }
.model-picker-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  text-align: left;
}
.model-picker-trigger:hover { border-color: var(--border-hover); }
.model-picker-trigger .icon { color: var(--text-faint); flex-shrink: 0; }

.model-picker-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 30;
  padding: 10px;
}
.model-picker-search-row { display: flex; gap: 8px; margin-bottom: 8px; }
.model-picker-search {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 12.5px;
  outline: none;
}
.model-picker-search:focus { border-color: var(--accent-border); box-shadow: 0 0 0 3px var(--accent-bg); }
.model-picker-filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.model-picker-filters .filter-chip { padding: 4px 9px; font-size: 11px; }
.filter-chip-count { opacity: 0.65; font-weight: 500; }

.model-picker-list { max-height: 280px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.model-picker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  border: none;
  background: transparent;
  padding: 8px 8px;
  border-radius: var(--radius-sm);
  text-align: left;
}
.model-picker-row:hover { background: var(--bg); }
.model-picker-row-main { min-width: 0; }
.model-picker-row-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-picker-row-id { font-size: 11px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-picker-row-meta { flex-shrink: 0; text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.model-badges { display: flex; gap: 4px; }
.model-badge { color: var(--text-faint); display: flex; }
.model-price { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.model-picker-empty { color: var(--text-muted); font-size: 12px; text-align: center; padding: 14px 8px; }

/* ---------- Chat image attach ---------- */
.chat-attach-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  width: 38px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-attach-btn:hover { background: var(--bg); }
.chat-vision-hint { font-size: 11px; color: var(--warn); padding: 0 12px 8px; }
.chat-image-preview { display: flex; align-items: center; gap: 8px; padding: 8px 12px 0; }
.chat-image-preview img { width: 44px; height: 44px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.chat-image-preview-remove {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-image-preview-remove:hover { background: var(--bg); color: var(--danger); }
.chat-msg-bubble img.chat-msg-image { max-width: 100%; border-radius: var(--radius-sm); margin-bottom: 8px; display: block; }

/* ---------- Device gallery + lightbox ---------- */
.device-gallery { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.device-gallery img {
  height: 140px;
  width: 140px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}
.device-gallery img:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 11, 13, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 40px;
}
.lightbox-overlay img { max-width: 100%; max-height: 100%; border-radius: var(--radius); box-shadow: var(--shadow); }
.lightbox-close {
  position: absolute;
  top: 20px;
  right: 24px;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.22); }

/* ---------- Device doc buttons + content overlay ---------- */
.device-doc-buttons { display: flex; gap: 8px; margin-top: 12px; }

.content-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 11, 13, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 32px;
}
.content-overlay-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 860px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.content-overlay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.content-overlay-title { font-weight: 700; font-size: 15px; }
.content-overlay-body { padding: 20px 24px; overflow-y: auto; }
.content-overlay-loading { color: var(--text-muted); font-size: 13.5px; padding: 20px 0; text-align: center; }
