:root {
  color-scheme: light dark;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  background: #0f172a;
  color: #111827;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: #e5e7eb; }
button, input, textarea, select { font: inherit; }

.connection-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  padding: 8px 14px;
  background: #92400e;
  color: white;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.connection-banner[hidden] { display: none; }

.app-shell {
  width: 100%;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
  overflow: hidden;
}

.sidebar {
  background: #111827;
  color: white;
  padding: 16px;
  overflow: auto;
}

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

.brand h1 { margin: 0; font-size: 20px; }
.brand span { color: #9ca3af; font-size: 13px; }

button {
  min-width: 0;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: #2563eb;
  color: white;
  cursor: pointer;
  white-space: nowrap;
}

button.secondary {
  background: #374151;
}

button.danger {
  background: #b91c1c;
}

button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.icon-btn {
  min-width: 58px;
  height: 42px;
  padding: 0 10px;
  display: grid;
  place-items: center;
}

.search { display: grid; gap: 6px; margin: 18px 0; font-size: 13px; color: #d1d5db; }
.search input, .config-grid input, .config-grid select, textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 10px 12px;
  background: white;
  color: #111827;
}

.job-list { display: grid; gap: 8px; }
.job-card {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 4px;
  background: #1f2937;
  color: white;
}
.job-card.active { background: #2563eb; }
.job-card small { color: #d1d5db; }

.main {
  min-width: 0;
  width: 100%;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto 1fr auto;
  max-height: 100vh;
}

.topbar,
.dashboard-grid,
.config-grid,
.inspector,
.messages,
.composer {
  min-width: 0;
  max-width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: white;
  border-bottom: 1px solid #e5e7eb;
}

.active-job { min-width: 0; flex: 1 1 auto; }
.active-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}
.active-meta { color: #6b7280; font-size: 13px; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 1px;
  background: #e5e7eb;
  border-bottom: 1px solid #e5e7eb;
}
.dashboard-grid div {
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 10px 18px;
  background: white;
}
.dashboard-grid span {
  color: #6b7280;
  font-size: 11px;
  text-transform: uppercase;
}
.dashboard-grid strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.config-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 10px;
  padding: 12px 18px;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
}
.config-grid label { display: grid; gap: 5px; font-size: 12px; color: #4b5563; }

.inspector {
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}
.inspector-actions {
  display: grid;
  grid-template-columns: auto auto auto minmax(160px, 1fr) auto;
  gap: 8px;
  padding: 10px 18px;
}
.inspector-actions input {
  min-width: 0;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 10px 12px;
  background: white;
  color: #111827;
}
.inspector-output {
  display: none;
  max-height: 220px;
  overflow: auto;
  margin: 0;
  padding: 12px 18px;
  border-top: 1px solid #e5e7eb;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.45 Consolas, "Cascadia Mono", monospace;
  background: white;
  color: #111827;
}
.inspector-output:not(:empty) {
  display: block;
}

.messages {
  padding: 18px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  position: relative;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border-radius: 8px;
  padding: 12px 14px;
  max-width: min(850px, 100%);
  line-height: 1.45;
}

.message .copy-btn,
.event-card .copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 5px 8px;
  border-radius: 6px;
  background: #111827;
  color: white;
  font-size: 11px;
}

.message.assistant,
.message.meta {
  padding-right: 62px;
}

.message code {
  padding: 1px 4px;
  border-radius: 5px;
  background: #e5e7eb;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: .92em;
}

.message .code-block {
  max-width: 100%;
  overflow: auto;
  margin: 8px 0;
  padding: 10px;
  border-radius: 8px;
  background: #111827;
  color: #e5e7eb;
  white-space: pre;
}

.message .code-block code {
  padding: 0;
  background: transparent;
  color: inherit;
}
.message.user {
  align-self: flex-end;
  background: #2563eb;
  color: white;
}
.message.assistant {
  align-self: flex-start;
  background: white;
  border: 1px solid #e5e7eb;
}
.message.meta {
  align-self: stretch;
  max-width: 100%;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  color: #374151;
  font-size: 12px;
}

.event-card {
  position: relative;
  align-self: stretch;
  max-width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #f9fafb;
  color: #374151;
  overflow: hidden;
}

.event-card summary {
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 9px 12px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  padding-right: 62px;
}

.event-card pre {
  max-height: 260px;
  overflow: auto;
  margin: 0;
  padding: 10px 12px;
  border-top: 1px solid #e5e7eb;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.45 Consolas, "Cascadia Mono", monospace;
}

.composer {
  border-top: 1px solid #e5e7eb;
  background: white;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}
.composer-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(82px, 1fr));
  gap: 10px;
}
textarea { resize: vertical; min-height: 92px; }

@media (max-width: 820px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 340px);
    z-index: 10;
    transform: translateX(-105%);
    transition: transform .18s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
  .config-grid { grid-template-columns: 1fr 1fr; }
  .inspector-actions { grid-template-columns: 1fr 1fr 1fr; }
  .inspector-actions input { grid-column: 1 / -2; }
  .topbar { gap: 10px; padding: 12px; }
  .icon-btn { min-width: 56px; }
  .composer-actions { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .message .copy-btn,
  .event-card .copy-btn { top: 6px; right: 6px; }
  .main { max-width: 100vw; max-height: 100dvh; }
}

@media (prefers-color-scheme: dark) {
  body { background: #020617; color: #e5e7eb; }
  .topbar, .composer, .message.assistant { background: #111827; border-color: #374151; color: #e5e7eb; }
  .message.meta { background: #0f172a; border-color: #374151; color: #d1d5db; }
  .message code { background: #1f2937; }
  .event-card { background: #0f172a; border-color: #374151; color: #d1d5db; }
  .event-card pre { border-color: #374151; }
  .dashboard-grid { background: #374151; border-color: #374151; }
  .dashboard-grid div { background: #111827; }
  .dashboard-grid span { color: #9ca3af; }
  .config-grid { background: #0f172a; border-color: #374151; }
  .inspector { background: #0f172a; border-color: #374151; }
  .inspector-output { background: #020617; border-color: #374151; color: #e5e7eb; }
  .config-grid label, .active-meta { color: #9ca3af; }
  .search input, .config-grid input, .config-grid select, .inspector-actions input, textarea {
    background: #020617;
    color: #e5e7eb;
    border-color: #374151;
  }
}
