:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-strong: #eef2f8;
  --line: #d7dde8;
  --text: #172033;
  --muted: #667085;
  --blue: #2563eb;
  --green: #067647;
  --amber: #b54708;
  --red: #c2410c;
  --shadow: 0 10px 28px rgba(31, 41, 55, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

button {
  min-height: 38px;
  border: 1px solid var(--blue);
  border-radius: 6px;
  background: var(--blue);
  color: #ffffff;
  padding: 0 14px;
  font-weight: 650;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button.secondary {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line);
}

button.danger {
  background: var(--red);
  border-color: var(--red);
}

button.icon-button {
  min-height: 30px;
  padding: 0 10px;
  background: #ffffff;
  color: var(--muted);
  border-color: var(--line);
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 86px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  background: var(--text);
  color: #ffffff;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

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

h2 {
  font-size: 14px;
  line-height: 1.2;
}

.brand p,
.session-title p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill,
.metric {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-muted {
  background: var(--surface-strong);
  color: var(--muted);
}

.status-ok {
  background: #dcfce7;
  color: var(--green);
}

.status-warn {
  background: #fef3c7;
  color: var(--amber);
}

.status-bad {
  background: #ffedd5;
  color: var(--red);
}

.metric {
  background: #e0ecff;
  color: #1d4ed8;
}

.connection-band {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) minmax(150px, 1fr) minmax(160px, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.connection-actions,
.composer-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 310px;
  gap: 14px;
  padding: 14px 20px 20px;
}

.session-rail,
.main-pane,
.event-rail,
.composer,
.session-title {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.session-rail,
.event-rail {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.rail-head span {
  min-width: 28px;
  text-align: center;
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-weight: 800;
  font-size: 12px;
}

.session-list,
.event-log {
  min-height: 0;
  overflow: auto;
  padding: 10px;
}

.session-item {
  width: 100%;
  display: grid;
  gap: 5px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  padding: 10px;
  text-align: left;
}

.session-item.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.session-item strong,
.event-row strong {
  overflow-wrap: anywhere;
}

.session-item small,
.event-row small {
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.main-pane {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto minmax(220px, 1fr);
  overflow: hidden;
}

.composer {
  margin: 12px;
  padding: 12px;
  box-shadow: none;
}

.composer-grid {
  display: grid;
  grid-template-columns: minmax(160px, 0.7fr) minmax(0, 1.35fr) 130px minmax(145px, 0.65fr);
  gap: 10px;
  margin-bottom: 10px;
}

.field-status {
  min-height: 16px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.composer-actions {
  margin-top: 10px;
}

.session-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 12px 12px;
  padding: 12px;
  box-shadow: none;
}

.session-title div {
  min-width: 0;
}

.session-title h2,
.session-title p {
  overflow-wrap: anywhere;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  padding: 0 12px 12px;
}

.tab {
  min-height: 34px;
  background: #ffffff;
  color: var(--muted);
  border-color: var(--line);
  padding: 0 8px;
}

.tab.active {
  background: var(--text);
  color: #ffffff;
  border-color: var(--text);
}

.tab-panel {
  min-height: 0;
  display: none;
  overflow: auto;
  padding: 0 12px 12px;
}

.tab-panel.active {
  display: block;
}

.message-stream,
.approval-list,
.pairing-list,
.security-list,
.status-grid {
  display: grid;
  gap: 8px;
}

.message-row,
.approval-row,
.pairing-row,
.security-row,
.status-row,
.event-row {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  padding: 10px;
}

.message-row {
  display: grid;
  gap: 4px;
}

.message-row .role {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.message-row .text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.code-view {
  min-height: 220px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101828;
  color: #f8fafc;
  padding: 12px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 12px;
  line-height: 1.45;
}

.approval-row {
  display: grid;
  gap: 8px;
}

.approval-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.history-gap-banner {
  margin-bottom: 10px;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  background: #fffbeb;
  color: #92400e;
  padding: 10px;
  font-size: 13px;
  font-weight: 700;
}

.pairing-panel {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.pairing-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

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

.pairing-row small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.pairing-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

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

.security-row small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.security-row button {
  min-width: 92px;
}

.status-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

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

.status-row small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.status-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 800;
  text-align: right;
  overflow-wrap: anywhere;
}

.approval-section {
  display: grid;
  gap: 8px;
}

.approval-section + .approval-section {
  margin-top: 14px;
}

.approval-section-head,
.approval-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.approval-section-head h3 {
  margin: 0;
  font-size: 13px;
}

.approval-section-head span,
.approval-state {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.approval-section-head span,
.approval-state-muted {
  background: var(--surface-strong);
  color: var(--muted);
}

.approval-state-ok {
  background: #dcfce7;
  color: var(--green);
}

.approval-state-warn {
  background: #fef3c7;
  color: var(--amber);
}

.approval-state-bad {
  background: #ffedd5;
  color: var(--red);
}

.approval-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.approval-warning {
  color: var(--amber);
  font-weight: 700;
}

.event-row {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
}

.empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #ffffff;
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .event-rail {
    grid-column: 1 / -1;
    min-height: 240px;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-strip {
    justify-content: flex-start;
  }

  .connection-band,
  .workspace,
  .composer-grid {
    grid-template-columns: 1fr;
  }

  .workspace {
    padding: 10px;
  }

  .session-rail,
  .event-rail {
    min-height: 220px;
  }

  .tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .connection-actions button,
  .composer-actions button,
  .pairing-actions button {
    flex: 1 1 130px;
  }
}
