:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --line: #e3e3e3;
  --text: #0d0d0d;
  --muted: #676767;
  --soft: #f4f4f4;
  --accent: #0d0d0d;
  --green: #10a37f;
  --blue: #2563eb;
  --amber: #9a6700;
  --danger: #c84747;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: #ffffff;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  height: 42px;
  border: 1px solid transparent;
  background: #f7f7f7;
  color: var(--text);
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 14px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
}

button:hover:not(:disabled),
.navButton:hover {
  border-color: transparent;
  background: #ececec;
  transform: translateY(-1px);
}

button:disabled {
  color: #a9a9a9;
  cursor: not-allowed;
  background: #f5f5f5;
}

button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.navButton {
  min-height: 42px;
  border: 1px solid transparent;
  background: #f7f7f7;
  color: var(--text);
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
}

.app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  background: #ffffff;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #f9f9f9;
  padding: 20px;
  display: grid;
  align-content: start;
  gap: 14px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 2px 0 18px;
  border-bottom: 1px solid var(--line);
}

.brand strong { display: block; font-size: 15px; letter-spacing: 0; font-weight: 650; }
.brand span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }

.mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: #0d0d0d;
  position: relative;
}

.mark::before,
.mark::after {
  content: "";
  position: absolute;
  inset: 9px 7px;
  border: 2px solid #fff;
  border-radius: 999px;
}

.mark::after {
  transform: rotate(90deg);
}

.controlStack {
  display: grid;
  gap: 10px;
}

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

.controlGrid button {
  width: 100%;
  font-size: 13px;
}

.sidebarNav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.statusPanel {
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
}

.statusPanel span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.statusPanel strong { font-size: 14px; }
.statusPanel strong.ok { color: var(--green); }
.statusPanel strong.warn { color: #9a6a00; }
.statusPanel strong.error { color: var(--danger); }

.statusPanel small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.micPanel strong.ok { color: var(--green); }
.micPanel strong.active { color: var(--blue); }
.micPanel strong.warn { color: #9a6a00; }
.micPanel strong.error { color: var(--danger); }

.accessPanel strong.ok { color: var(--green); }
.accessPanel strong.warn { color: #9a6a00; }
.accessPanel strong.error { color: var(--danger); }

.speakerPanel strong.ok { color: var(--green); }
.speakerPanel strong.warn { color: #9a6a00; }
.speakerPanel strong.error { color: var(--danger); }

.stage {
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto auto auto;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  overflow: hidden;
  background: #ffffff;
}

.topbar {
  min-height: 86px;
  padding: 22px 36px 10px;
  border-bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  background: #ffffff;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
  font-weight: 650;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
}

.topbar .eyebrow {
  color: var(--muted);
  letter-spacing: 0;
  text-transform: none;
}

.voiceMode {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 28px;
  padding: 20px 36px 10px;
  min-height: 0;
  overflow: hidden;
}

.voiceOrbShell {
  --voice-level: 0;
  --voice-ring-opacity: 0.32;
  --voice-ring-2-opacity: 0.18;
  --voice-ring-border-opacity: 0.06;
  width: min(48vh, 360px);
  height: min(48vh, 360px);
  min-width: 220px;
  min-height: 220px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fafafa;
  border: 1px solid #eeeeee;
  position: relative;
  overflow: hidden;
  transition: background 180ms ease, border-color 180ms ease;
}

.voiceOrbShell::before,
.voiceOrbShell::after {
  content: "";
  position: absolute;
  inset: calc(18% - var(--voice-level) * 7%);
  border-radius: 50%;
  border: 1px solid rgba(13, 13, 13, var(--voice-ring-border-opacity));
  transform: scale(calc(0.9 + var(--voice-level) * 0.36));
  opacity: var(--voice-ring-opacity);
  pointer-events: none;
  transition: inset 90ms linear, transform 90ms linear, opacity 90ms linear;
}

.voiceOrbShell::after {
  inset: calc(30% - var(--voice-level) * 9%);
  opacity: var(--voice-ring-2-opacity);
  transform: scale(calc(1 + var(--voice-level) * 0.5));
}

.voiceOrbShell.is-hearing {
  background: #f6f6f6;
  border-color: #d4d4d4;
}

.voiceOrbShell.is-speaking {
  background: #f8fbff;
  border-color: #dfe7f5;
}

.voiceOrbShell.is-speaking::before,
.voiceOrbShell.is-speaking::after {
  border-color: rgba(37, 99, 235, var(--voice-ring-border-opacity));
}

.voiceOrbShell.is-voicing {
  background: #f3f7ff;
  border-color: #bfd0f5;
}

.orb {
  --voice-level: 0;
  --voice-scale: 1;
  --voice-opacity: 0.18;
  --voice-dot-opacity: 0.34;
  --voice-accent: 13, 13, 13;
  width: 168px;
  height: 168px;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: none;
  transition: border-color 120ms ease, transform 120ms ease;
  position: relative;
}

.orb::before,
.orb::after {
  content: "";
  position: absolute;
  border-radius: 999px;
}

.orb::before {
  inset: 22px;
  border: 2px solid rgba(var(--voice-accent), var(--voice-opacity));
  transform: scale(var(--voice-scale));
  transition: transform 80ms linear, border-color 80ms linear;
}

.orb::after {
  width: 28px;
  height: 28px;
  left: 50%;
  top: 50%;
  background: rgba(var(--voice-accent), var(--voice-dot-opacity));
  transform: translate(-50%, -50%) scale(calc(1 + var(--voice-level) * 1.8));
  transition: transform 80ms linear, background 80ms linear;
}

.orb.listening {
  border-color: #bdbdbd;
}

.orb.hearing {
  border-color: #0d0d0d;
}

.orb.speaking {
  --voice-accent: 37, 99, 235;
  animation: pulse 900ms ease-in-out infinite;
}
.orb.voicing {
  border-color: #2563eb;
}
.orb.idle { opacity: 0.72; }

@keyframes pulse {
  0%, 100% { transform: scale(1); border-color: var(--line); }
  50% { transform: scale(1.025); border-color: #2563eb; }
}

.voiceState {
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
}

.voiceState strong {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: 0;
  transition: transform 140ms ease;
}

.voiceState span {
  color: var(--muted);
  font-size: 14px;
  max-width: 520px;
  overflow-wrap: anywhere;
}

.voiceState.is-active strong {
  transform: translateY(-1px);
}

.messages {
  padding: 6px 36px 20px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #ffffff;
  max-width: 900px;
  width: 100%;
  justify-self: center;
  min-height: 0;
  max-height: clamp(96px, 22vh, 210px);
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.messages:empty::before {
  content: "";
  display: none;
  align-self: center;
  margin: auto;
  max-width: 360px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f9f9f9;
}

.pipeline {
  border-top: 1px solid var(--line);
  background: #ffffff;
  padding: 0 24px;
}

.pipelineHeader {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0;
  padding: 13px 0;
  cursor: pointer;
  list-style: none;
}

.pipelineHeader::-webkit-details-marker {
  display: none;
}

.pipeline h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0;
}

.pipelineBody {
  padding-bottom: 14px;
}

#pipelineSummary {
  color: var(--muted);
  font-size: 12px;
}

.stageGrid {
  display: grid;
  grid-template-columns: repeat(5, minmax(116px, 1fr));
  gap: 8px;
}

.stageCard {
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  padding: 10px;
  display: grid;
  gap: 4px;
  align-content: start;
}

.stageCard span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stageCard strong {
  font-size: 14px;
}

.stageCard small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stageCard.active {
  border-color: #bdbdbd;
  background: #f7f7f7;
  box-shadow: none;
}

.stageCard.done {
  background: #fafafa;
}

.stageCard.error,
.stageCard.cancelled {
  border-color: rgba(216, 74, 74, 0.5);
  background: #fff6f6;
}

.eventLog {
  margin-top: 10px;
  max-height: 72px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafafa;
  padding: 8px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: #4c4b45;
}

.eventLine {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 2px 0;
}

.message {
  max-width: 820px;
  line-height: 1.58;
  font-size: 16px;
  min-width: 0;
  flex: 0 0 auto;
  animation: messageIn 180ms ease-out;
}

.message .role {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.message.user {
  align-self: flex-end;
  background: #f4f4f4;
  color: var(--text);
  border: 1px solid #eeeeee;
  padding: 12px 14px;
  border-radius: 18px;
  max-width: min(820px, 78%);
}

.message.user .role { color: var(--muted); }

.message .content {
  overflow-wrap: anywhere;
}

.message.assistant {
  align-self: flex-start;
  max-width: min(820px, 82%);
  padding: 14px 16px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.message.tool {
  align-self: flex-start;
  max-width: min(820px, 82%);
  padding: 8px 12px;
  border-radius: 10px;
  background: #f7f7f4;
  border: 1px solid #ececea;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.message.tool .role {
  font-size: 10px;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.message.tool-call { border-left: 3px solid var(--blue); }
.message.tool-result { border-left: 3px solid var(--green); }
.message.tool .content { white-space: pre-wrap; word-break: break-word; }

@keyframes messageIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.composer {
  border-top: 1px solid var(--line);
  background: #ffffff;
  padding: 14px 36px 22px;
}

#meter {
  width: 100%;
  height: 24px;
  display: block;
  max-width: 900px;
  margin: 0 auto;
}

.composerRow {
  margin: 12px auto 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  max-width: 900px;
}

#liveTranscript {
  min-height: 42px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 14px;
  padding: 0 14px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.voiceControls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.voiceControls button {
  height: 42px;
  min-width: 78px;
}

#talkBtn {
  min-width: 92px;
  border-radius: 999px;
}

#talkBtn.active {
  background: #0d0d0d;
  border-color: #0d0d0d;
  color: white;
}

@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }
  .sidebar {
    grid-template-columns: 1fr;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .stage {
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    grid-template-rows: auto auto auto auto auto;
  }
  .topbar { padding: 20px; }
  .voiceMode { padding: 18px 20px; }
  .voiceOrbShell {
    width: min(68vw, 300px);
    height: min(68vw, 300px);
    min-width: 210px;
    min-height: 210px;
  }
  .orb {
    width: 138px;
    height: 138px;
  }
  .messages {
    padding: 20px;
    max-height: 34vh;
  }
  .stageGrid { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .message.user,
  .message.assistant { max-width: 100%; }
  .composer { padding: 14px 20px 20px; }
  .composerRow { grid-template-columns: 1fr; }
  .voiceControls { justify-content: center; flex-wrap: wrap; }
}

/* ==========  SETTINGS SCREEN ========== */

.settingsApp { background: var(--bg); }

.settingsSidebar {
  padding: 20px 18px;
  gap: 12px;
  min-height: 0;
  overflow-y: auto;
}

.moduleNav {
  display: grid;
  gap: 4px;
  margin: 4px 0 6px;
}

.moduleNavItem {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  height: auto;
  padding: 10px 10px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.moduleNavItem:hover { background: #f1f1ec; }

.moduleNavItem.active {
  background: var(--panel);
  border-color: var(--line);
  box-shadow: 0 8px 18px rgba(25, 25, 25, 0.05);
}

.moduleNavIcon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #111, #4b4b4b);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.04em;
}

.moduleNavItem.active .moduleNavIcon {
  background: linear-gradient(135deg, #10a37f, #0b6b55);
}

.moduleNavLabel {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.moduleNavLabel strong { font-size: 13px; }

.moduleNavLabel small {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settingsStage {
  grid-template-rows: auto 1fr;
  background: var(--bg);
  min-width: 0;
  min-height: 0;
  height: 100vh;
  overflow: hidden;
}

.settingsTopbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(247, 247, 244, 0.94);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 32px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  display: block;
  margin-bottom: 6px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.settingsTopbar h1 { font-size: 24px; }
.settingsTopbar p { margin-top: 4px; font-size: 13px; }

.topbarActions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.topbarActions button {
  height: 38px;
  padding: 0 14px;
  font-size: 13px;
}

.settingsScreens {
  padding: 28px 32px 80px;
  display: block;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.moduleScreen {
  display: none;
  flex-direction: column;
  gap: 18px;
  max-width: 1080px;
  margin: 0 auto;
}

.moduleScreen.active { display: flex; }

.moduleHero {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(220px, 1fr);
  gap: 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #fff 0%, #fbfbf8 100%);
  padding: 24px 26px;
  box-shadow: 0 18px 44px rgba(25, 25, 25, 0.05);
}

.moduleHero h2 { margin: 8px 0 6px; font-size: 22px; line-height: 1.2; }
.moduleHero p { margin: 0; font-size: 14px; line-height: 1.55; max-width: 56ch; }

.moduleStats {
  display: grid;
  gap: 10px;
  align-content: start;
  margin: 0;
}

.moduleStats div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
}

.moduleStats dt {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.moduleStats dd {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  text-align: right;
  overflow-wrap: anywhere;
  max-width: 60%;
}

.chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(16, 163, 127, 0.28);
  border-radius: 999px;
  background: #f4fbf8;
  color: #0b6b55;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chip-blue   { color: #20488f; background: #eef3ff; border-color: rgba(47, 111, 235, 0.28); }
.chip-amber  { color: #8a5a00; background: #fff6e2; border-color: rgba(196, 134, 0, 0.28); }
.chip-violet { color: #5b3aa6; background: #f2edff; border-color: rgba(116, 78, 196, 0.28); }
.chip-slate  { color: #444c58; background: #eef0f3; border-color: rgba(80, 92, 110, 0.28); }

.moduleCard {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 18px 20px 20px;
  box-shadow: 0 10px 26px rgba(25, 25, 25, 0.03);
}

.moduleCard header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--soft);
}

.moduleCard header h3 { margin: 0; font-size: 15px; }
.moduleCard header small { color: var(--muted); font-size: 12px; }

.moduleCard.dimmed {
  opacity: 0.55;
  filter: saturate(0.85);
}

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

.formGrid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  min-width: 0;
}

.formGrid label.wide { grid-column: 1 / -1; }

.formGrid input,
.formGrid select,
.formGrid textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 12px;
  color: var(--text);
  background: #fdfdfb;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
}

.formGrid textarea {
  resize: vertical;
  line-height: 1.5;
  min-height: 120px;
}

.formGrid input:focus,
.formGrid select:focus,
.formGrid textarea:focus {
  outline: 0;
  border-color: rgba(16, 163, 127, 0.65);
  box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.14);
  background: #fff;
}

.formGrid .hint {
  font-weight: 500;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.formHint {
  border: 1px dashed var(--line);
  border-radius: 9px;
  padding: 9px 12px;
  background: #fbfbf8;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.formHint.ok    { color: var(--green); border-color: rgba(16, 163, 127, 0.32); background: #f4fbf8; }
.formHint.active{ color: var(--blue);  border-color: rgba(47, 111, 235, 0.32); background: #eef3ff; }
.formHint.error { color: var(--danger);border-color: rgba(216, 74, 74, 0.34);  background: #fff6f6; }

.inputWithButton {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
  min-width: 0;
}

.inputWithButton button {
  height: auto;
  min-height: 42px;
  padding: 0 14px;
  font-size: 13px;
}

.checkRow {
  grid-template-columns: 22px 1fr !important;
  align-items: start !important;
  gap: 10px !important;
}

.checkRow input { min-height: auto; width: 18px; height: 18px; margin-top: 4px; }

.checkRow strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 4px;
}

.formFooter {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.dirtyIndicator {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--soft);
}

.dirtyIndicator.dirty {
  color: #8a5a00;
  background: #fff6e2;
}

.dirtyIndicator.saved {
  color: var(--green);
  background: #ecf8f3;
}

#applyBtn[disabled] {
  background: #d6d5cf;
  border-color: #d6d5cf;
  color: #6b6b63;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  min-width: 240px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #1c1c1a;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 30;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok      { background: #0b6b55; }
.toast.error   { background: #a83434; }

@media (max-width: 980px) {
  .moduleHero { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .settingsApp.app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }
  .settingsSidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .settingsStage {
    height: auto;
    overflow: visible;
    grid-template-rows: auto auto;
  }
  .settingsTopbar { padding: 16px 20px; flex-direction: column; align-items: stretch; }
  .topbarActions { flex-wrap: wrap; }
  .settingsScreens {
    padding: 20px;
    overflow: visible;
  }
  .formGrid { grid-template-columns: 1fr; }
  .moduleHero { padding: 20px; }
  .moduleCard { padding: 16px; }
  .inputWithButton { grid-template-columns: 1fr; }
}

/* ========== AGENTS SCREEN ========== */

.agentsApp { background: var(--bg); }
.agentsSidebar { padding: 20px 18px; gap: 12px; overflow-y: auto; }
.agentsStage { grid-template-rows: auto 1fr; min-width: 0; background: var(--bg); }

.agentsTopbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(247, 247, 244, 0.94);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 32px;
  border-bottom: 1px solid var(--line);
}

.agentsTopbar h1 { font-size: 24px; }
.agentsTopbar p { margin-top: 4px; font-size: 13px; }

.agentsBody {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
  grid-template-rows: auto auto;
  gap: 18px;
  padding: 24px 32px 80px;
  align-items: start;
}

.agentGrid {
  grid-row: 1;
  grid-column: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.agentEmpty,
.taskEmpty {
  padding: 30px 18px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  grid-column: 1 / -1;
}

.agentCard {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 16px;
  display: grid;
  gap: 10px;
  align-content: start;
  box-shadow: 0 10px 24px rgba(25, 25, 25, 0.04);
  transition: border-color 160ms ease, transform 160ms ease;
}

.agentCard:hover { transform: translateY(-1px); }
.agentCard-ok { border-color: rgba(16, 163, 127, 0.45); }
.agentCard-http_error { border-color: rgba(154, 106, 0, 0.45); }
.agentCard-error { border-color: rgba(216, 74, 74, 0.45); }

.agentCard header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 10px;
}

.agentCard h3 { margin: 0; font-size: 16px; }
.agentCard header small { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.agentCard p { margin: 0; font-size: 13px; line-height: 1.5; color: var(--muted); }

.agentMeta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.agentStats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--soft);
  border-radius: 9px;
  background: #fbfbf8;
  font-size: 11px;
}
.agentStats div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.agentStats dt { color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
.agentStats dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; max-width: 60%; text-align: right; }

.agentHttp {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.agentError {
  display: block;
  font-size: 11px;
  color: var(--danger);
  overflow-wrap: anywhere;
  background: #fff6f6;
  border: 1px solid rgba(216, 74, 74, 0.25);
  border-radius: 8px;
  padding: 6px 8px;
}

.agentActions {
  display: flex;
  justify-content: flex-end;
}

.agentActions button {
  height: 34px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 700;
}

.pill {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid;
  white-space: nowrap;
}
.pill-ok    { color: #0b6b55; background: #ecf8f3; border-color: rgba(16, 163, 127, 0.32); }
.pill-active { color: #1d4f91; background: #eef5ff; border-color: rgba(37, 99, 235, 0.28); }
.pill-warn  { color: #8a5a00; background: #fff6e2; border-color: rgba(196, 134, 0, 0.32); }
.pill-error { color: #a83434; background: #fff0f0; border-color: rgba(216, 74, 74, 0.32); }
.pill-idle  { color: var(--muted); background: var(--soft); border-color: var(--line); }

.tag {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: #f2f1ec;
  color: #4c4b45;
  border: 1px solid var(--line);
}
.tag-blue { color: #20488f; background: #eef3ff; border-color: rgba(47, 111, 235, 0.28); }

.dispatchPanel {
  grid-row: 1;
  grid-column: 2;
  position: sticky;
  top: 96px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 18px 18px 20px;
  box-shadow: 0 10px 26px rgba(25, 25, 25, 0.05);
  display: grid;
  gap: 12px;
}

.dispatchPanel header h2 { margin: 0; font-size: 16px; }
.dispatchPanel header small { color: var(--muted); font-size: 12px; }
.dispatchPanel .formGrid { gap: 10px; }
.dispatchPanel textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

.formActions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.dispatchHint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.tasksPanel {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 18px 18px 22px;
  box-shadow: 0 10px 26px rgba(25, 25, 25, 0.04);
}

.tasksPanel header { margin-bottom: 12px; }
.tasksPanel header h2 { margin: 0; font-size: 16px; }
.tasksPanel header small { color: var(--muted); font-size: 12px; }

.taskList {
  display: grid;
  gap: 8px;
}

.taskCard {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfbf8;
  padding: 10px 12px;
}
.taskCard-ok { border-left: 3px solid var(--green); }
.taskCard-error,
.taskCard-http_error { border-left: 3px solid var(--danger); }
.taskCard-running { border-left: 3px solid var(--blue); }

.taskCard header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.taskCard header strong { font-size: 13px; }
.taskCard header small { color: var(--muted); font-size: 11px; }
.taskMeta { display: flex; align-items: center; gap: 8px; }

.taskCard summary {
  margin-top: 8px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
}

.taskBody,
.taskContext,
.taskResponse {
  margin: 6px 0 0;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow: auto;
}

.taskContext { background: #fafaf6; }
.taskResponse { background: #f4fbf8; }

.taskError {
  margin-top: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #fff0f0;
  border: 1px solid rgba(216, 74, 74, 0.32);
  color: var(--danger);
  font-size: 11px;
  font-weight: 700;
}

/* ========== Diagnostics ========== */

.diagApp .agentsSidebar {
  grid-auto-rows: max-content;
}

.diagApp .agentsStage {
  grid-template-rows: auto auto 1fr;
}

.diagSummary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
  padding: 18px 32px 0;
  min-width: 0;
}

.diagNode {
  position: relative;
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfbf8 100%);
  padding: 14px 14px 12px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  box-shadow: 0 10px 26px rgba(25, 25, 25, 0.035);
  overflow: hidden;
}

.diagNode::before {
  content: "";
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #b8b8b8;
  box-shadow: 0 0 0 5px rgba(184, 184, 184, 0.12);
}

.diagNode:not(:last-child)::after {
  content: none;
}

.diagNode span {
  position: absolute;
  top: 13px;
  right: 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.diagNode strong {
  margin-top: 16px;
  font-size: 17px;
  line-height: 1.1;
}

.diagNode small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.diagNode[data-state="ok"] {
  border-color: rgba(16, 163, 127, 0.28);
  background: linear-gradient(180deg, #ffffff 0%, #f3fbf7 100%);
}

.diagNode[data-state="ok"]::before {
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(16, 163, 127, 0.12);
}

.diagNode[data-state="warn"] {
  border-color: rgba(154, 103, 0, 0.28);
  background: linear-gradient(180deg, #ffffff 0%, #fff8e8 100%);
}

.diagNode[data-state="warn"]::before {
  background: var(--amber);
  box-shadow: 0 0 0 5px rgba(154, 103, 0, 0.12);
}

.diagNode[data-state="active"] {
  border-color: rgba(37, 99, 235, 0.26);
  background: linear-gradient(180deg, #ffffff 0%, #f2f7ff 100%);
}

.diagNode[data-state="active"]::before {
  background: var(--blue);
  box-shadow: 0 0 0 5px rgba(37, 99, 235, 0.12);
}

.diagNode[data-state="error"] {
  border-color: rgba(200, 71, 71, 0.28);
  background: linear-gradient(180deg, #ffffff 0%, #fff4f4 100%);
}

.diagNode[data-state="error"]::before {
  background: var(--danger);
  box-shadow: 0 0 0 5px rgba(200, 71, 71, 0.12);
}

.diagBody {
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-rows: minmax(0, 1fr);
  align-items: start;
}

.moduleGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 14px;
  min-width: 0;
}

.moduleCard.wide {
  grid-column: 1 / -1;
}

.moduleHint,
.moduleDetail {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.moduleMeter {
  display: grid;
  gap: 8px;
}

.moduleMeter canvas {
  width: 100%;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fafafa;
}

.meterLegend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.meterLegend strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.moduleActions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 10px;
}

.moduleActions button {
  height: 36px;
  font-size: 12px;
  padding: 0 12px;
}

.moduleField {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.moduleField input {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  color: var(--text);
  background: #fdfdfb;
  font: inherit;
  font-size: 13px;
}

.modulePre {
  min-height: 64px;
  max-height: 180px;
  overflow: auto;
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfbf8;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.moduleList {
  list-style: none;
  margin: 10px 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.moduleList li {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfbf8;
  padding: 8px 10px;
}

.moduleList strong { font-size: 12px; }
.moduleList span { color: var(--muted); font-size: 11px; line-height: 1.35; overflow-wrap: anywhere; }

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

.flowStep {
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfbf8;
  padding: 10px;
  display: grid;
  align-content: space-between;
  gap: 8px;
}

.flowStep strong {
  font-size: 12px;
}

.flowStep span {
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.flowStep[data-status="ok"] {
  border-color: rgba(16, 163, 127, 0.36);
  background: #f4fbf8;
}

.flowStep[data-status="active"],
.flowStep[data-status="running"] {
  border-color: rgba(37, 99, 235, 0.32);
  background: #f2f6ff;
}

.flowStep[data-status="error"] {
  border-color: rgba(216, 74, 74, 0.36);
  background: #fff6f6;
}

.diagLogPanel {
  position: sticky;
  top: 96px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 16px;
  box-shadow: 0 10px 26px rgba(25, 25, 25, 0.04);
  min-width: 0;
}

.diagLogPanel header {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
}

.diagLogPanel h2 {
  margin: 0;
  font-size: 16px;
}

.diagLogPanel small {
  color: var(--muted);
  font-size: 12px;
}

.diagLog {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 210px);
  overflow: auto;
}

.diagLine {
  display: grid;
  grid-template-columns: 68px 70px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfbf8;
  padding: 8px 9px;
  font-size: 11px;
}

.diagStamp,
.diagModule {
  color: var(--muted);
  font-weight: 800;
}

.diagMsg {
  overflow-wrap: anywhere;
}

.diagLine-ok { border-left: 3px solid var(--green); }
.diagLine-warn { border-left: 3px solid #c48600; }
.diagLine-error { border-left: 3px solid var(--danger); }
.diagLine-info { border-left: 3px solid var(--blue); }

.bargeMeter canvas {
  height: 48px;
  background: #fcfcfa;
}

.moduleCard.bargeHot {
  border-color: rgba(16, 163, 127, 0.45);
  background: linear-gradient(180deg, #ffffff 0%, #f1faf6 100%);
}

.thresholdRow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px;
  gap: 10px;
  align-items: center;
}

.thresholdRow input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.thresholdRow input[type="number"] {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
  text-align: right;
  background: #fdfdfb;
}

.moduleFieldHint {
  display: block;
  font-weight: 500;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  margin-top: 2px;
}

/* ========== CHAT HISTORY SCREEN ========== */

.historyApp .agentsStage { grid-template-rows: auto 1fr; }
.historyStage { min-height: 0; }

.historyApp .topbarActions { display: flex; gap: 8px; align-items: center; }
.historyApp #historySearch {
  min-width: 220px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 12px;
  background: #fdfdfb;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.historyBody {
  display: grid;
  grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
  gap: 18px;
  padding: 24px 32px 40px;
  height: calc(100vh - 96px);
  min-height: 0;
}

.historyList {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  box-shadow: 0 10px 26px rgba(25, 25, 25, 0.04);
}

.historyList header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.historyList header h2 { margin: 0; font-size: 15px; }
.historyList header small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

.sessionList {
  overflow-y: auto;
  padding: 8px;
  display: grid;
  gap: 6px;
  align-content: start;
}

.sessionItem {
  text-align: left;
  width: 100%;
  border: 1px solid transparent;
  background: #fbfbf8;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  display: grid;
  gap: 4px;
  font: inherit;
  color: var(--text);
  transition: background 120ms ease, border-color 120ms ease;
}

.sessionItem:hover { background: #f1f1ec; }

.sessionItem.active {
  background: #eef3ff;
  border-color: rgba(37, 99, 235, 0.32);
}

.sessionRow {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.sessionRow strong {
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
  word-break: break-all;
  line-height: 1.3;
}

.sessionCount {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  white-space: nowrap;
}

.sessionMeta {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.35;
}

.historyChat {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
  box-shadow: 0 10px 26px rgba(25, 25, 25, 0.04);
}

.historyChatHeader {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.historyChatHeader h2 { margin: 0; font-size: 16px; overflow-wrap: anywhere; word-break: break-all; }
.historyChatHeader small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }

.historyChatActions { display: flex; gap: 8px; }

.historyChatActions button.danger {
  background: #fff4f4;
  color: var(--danger);
  border-color: rgba(216, 74, 74, 0.32);
}

.historyChatActions button.danger:hover:not(:disabled) {
  background: #ffeaea;
}

.historyMessages {
  overflow-y: auto;
  padding: 20px 24px 28px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.historyTurn {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  background: #fdfdfb;
}

.historyTurnHeader {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.historyTurnIndex {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.historyMessage {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.historyMessageRole {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding-top: 2px;
}

.historyMessage.user .historyMessageRole { color: #0d0d0d; }
.historyMessage.assistant .historyMessageRole { color: var(--green); }

.historyMessageBody {
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.historyEmpty {
  padding: 28px 18px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

@media (max-width: 1100px) {
  .historyBody {
    grid-template-columns: 1fr;
    height: auto;
    padding-bottom: 80px;
  }
  .historyList { max-height: 320px; }
}

@media (max-width: 1100px) {
  .agentsBody { grid-template-columns: 1fr; }
  .dispatchPanel { position: static; grid-row: auto; grid-column: 1; }
  .diagSummary { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .diagNode:not(:last-child)::after { display: none; }
  .diagBody { grid-template-columns: 1fr; }
  .diagLogPanel { position: static; }
  .pipelineFlow { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .diagSummary { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 14px 16px 0; }
  .moduleGrid { grid-template-columns: 1fr; }
  .pipelineFlow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .diagLine { grid-template-columns: 1fr; }
}

/* ========== MCP / AGENTS server-list editor (used inside Settings) ========== */

.serverList {
  display: grid;
  gap: 10px;
}

.serverEditorRow {
  border: 1px solid var(--line);
  background: #fbfbf8;
  border-radius: 10px;
  padding: 12px 14px;
  display: grid;
  gap: 8px;
}

.serverEditorRow header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.serverEditorRow header strong {
  font-size: 13px;
}

.serverEditorRow header button {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
  border-color: rgba(216, 74, 74, 0.5);
  color: var(--danger);
  background: #fff6f6;
}

.serverEditorRow .gridRow {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
}

.serverEditorRow input,
.serverEditorRow select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 12px;
  background: #fff;
}

.serverAddRow {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.serverAddRow button {
  height: 34px;
  padding: 0 12px;
  font-size: 12px;
}
