:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #18202a;
  --muted: #617084;
  --line: #d8e0e8;
  --blue: #2457d6;
  --green: #157f5b;
  --amber: #a36100;
  --red: #b42318;
  --shadow: 0 12px 32px rgba(19, 31, 46, 0.09);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101419;
    --surface: #181e25;
    --surface-2: #202933;
    --text: #edf2f7;
    --muted: #9ba9b8;
    --line: #33404d;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

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

button,
select,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 9px 12px;
  cursor: pointer;
  min-height: 38px;
}

button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.shell {
  width: min(1680px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar,
.control-strip,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.15;
}

h2 {
  font-size: 16px;
}

#healthLine {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.top-actions,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.control-strip {
  display: grid;
  grid-template-columns: minmax(150px, 0.9fr) minmax(130px, 0.75fr) minmax(220px, 1.45fr) minmax(180px, 1.05fr) minmax(130px, 0.75fr) minmax(130px, 0.75fr);
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
}

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

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 10px;
  min-height: 40px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 0.85fr) minmax(420px, 1.55fr) minmax(280px, 0.9fr);
  gap: 12px;
  margin-top: 12px;
  align-items: stretch;
}

.panel {
  min-height: 640px;
  padding: 14px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.status-pill {
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  min-width: 74px;
  text-align: center;
}

.toggles {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.toggles label {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: var(--surface-2);
  color: var(--text);
}

.toggles input {
  width: 16px;
  min-height: 16px;
}

textarea {
  min-height: 180px;
  resize: vertical;
  line-height: 1.45;
}

.button-row {
  margin-top: 10px;
}

.response-box,
.context-preview,
.bridge-state {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: auto;
}

.response-box {
  min-height: 310px;
  max-height: 56vh;
  padding: 14px;
  white-space: pre-wrap;
  line-height: 1.45;
}

.context-preview {
  min-height: 500px;
  max-height: 68vh;
  padding: 12px;
  white-space: pre-wrap;
  font-size: 12px;
}

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

.chip-list span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}

.bridge-dir {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.bridge-state {
  max-height: 68vh;
  padding: 10px;
}

.bridge-channel {
  margin-bottom: 12px;
}

.bridge-channel h3 {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--green);
}

.bridge-item {
  padding: 7px 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.warn {
  color: var(--amber);
}

.error {
  color: var(--red);
}

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

  .panel {
    min-height: auto;
  }

  .context-preview,
  .bridge-state {
    max-height: 360px;
  }

  .control-strip {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .toggles {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
}

@media (max-width: 680px) {
  .shell {
    padding: 10px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .control-strip,
  .toggles {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 20px;
  }
}
