:root {
  color-scheme: light;
  --page: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef3f4;
  --surface-3: #18202a;
  --ink: #18202a;
  --muted: #637282;
  --line: #d9e0e6;
  --line-strong: #bdc8d2;
  --accent: #0f766e;
  --accent-soft: #dff4ef;
  --violet: #5b5fc7;
  --danger: #b42318;
  --warning: #b35c00;
  --shadow: 0 14px 40px rgba(24, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

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

button,
select,
input,
textarea {
  border-radius: 8px;
}

button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  padding: 0 13px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  border-color: #8ea0ad;
  background: #f8fafb;
}

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

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

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

input,
select {
  min-height: 40px;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.13);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.6rem;
  line-height: 1.15;
}

h2,
legend {
  font-size: 0.96rem;
  font-weight: 760;
  line-height: 1.25;
}

label span,
.eyebrow,
.form-message,
.topbar span,
.panel-heading span,
.message small {
  color: var(--muted);
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 24px;
  box-shadow: var(--shadow);
}

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

.brand-row.compact strong {
  display: block;
  line-height: 1.2;
}

.brand-row.compact span {
  display: block;
  max-width: 52vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.86rem;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-3);
  color: #ffffff;
  font-weight: 800;
}

.segmented,
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.segmented {
  margin: 22px 0;
}

.segmented button,
.tabs button {
  flex: 1;
  border-color: transparent;
  background: transparent;
  min-width: 0;
}

.segmented button.active,
.tabs button.active {
  border-color: var(--line);
  background: var(--surface);
  color: var(--accent);
  font-weight: 760;
}

.stack-form {
  display: grid;
  gap: 14px;
}

label,
fieldset {
  display: grid;
  gap: 7px;
  min-width: 0;
}

fieldset {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
}

legend {
  padding: 0 7px;
}

.full,
fieldset .full {
  grid-column: 1 / -1;
}

.wide-field {
  margin: 14px 0;
}

.form-message {
  min-height: 20px;
  font-size: 0.9rem;
}

.form-message.error {
  color: var(--danger);
}

.form-message.success {
  color: var(--accent);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 68px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#userBadge {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 370px;
  gap: 16px;
  height: calc(100vh - 68px);
  padding: 16px;
}

.sidebar,
.builder,
.voice-console {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.sidebar,
.voice-console {
  overflow: auto;
}

.sidebar {
  padding: 14px;
}

.sidebar-head,
.builder-head,
.builder-actions,
.section-head,
.panel-heading,
.voice-controls,
.tool-grid {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-head,
.builder-head,
.section-head,
.panel-heading {
  justify-content: space-between;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 1.35rem;
  line-height: 1;
}

.agent-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.agent-item {
  display: grid;
  gap: 5px;
  width: 100%;
  min-height: 62px;
  justify-items: start;
  white-space: normal;
  text-align: left;
}

.agent-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.agent-item strong {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  background: #edf0f2;
  color: var(--muted);
  padding: 2px 8px;
  font-size: 0.78rem;
}

.status-pill.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.status-pill.paused {
  background: #fff1da;
  color: var(--warning);
}

.builder {
  overflow: auto;
  padding: 18px;
}

.builder-head {
  align-items: start;
}

.builder-head > div:first-child {
  min-width: min(460px, 100%);
}

.builder-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.title-input {
  min-height: 48px;
  margin-top: 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 6px 0;
  font-size: 1.7rem;
  font-weight: 780;
}

.title-input:focus {
  border-color: var(--accent);
  box-shadow: none;
}

.tabs {
  position: sticky;
  top: -18px;
  z-index: 2;
  margin: 14px 0 16px;
}

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

.panel-grid.active {
  display: grid;
}

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

.row-card {
  display: grid;
  grid-template-columns: auto minmax(120px, 0.8fr) minmax(180px, 1.2fr) minmax(140px, 0.9fr) auto;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 12px;
}

.row-card.two-col {
  grid-template-columns: minmax(140px, 0.7fr) minmax(220px, 1.4fr) auto;
}

.row-card.handoff {
  grid-template-columns: minmax(130px, 0.6fr) minmax(120px, 0.5fr) minmax(220px, 1.4fr) auto;
}

.row-card button {
  width: 38px;
  padding: 0;
}

.check-line {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
}

.check-line input {
  width: 18px;
  height: 18px;
  min-height: 18px;
  flex: 0 0 18px;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.voice-console {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 14px;
}

.panel-heading.thin {
  margin-top: 4px;
}

.dot {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 50%;
  background: #a9b4bd;
}

.dot.connected {
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(15, 118, 110, 0.14);
}

#waveform {
  display: block;
  width: 100%;
  height: 160px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101820;
}

.voice-controls,
.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.transcript {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 160px;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 10px;
}

.message {
  border-left: 3px solid var(--violet);
  background: #ffffff;
  padding: 8px 9px;
}

.message small {
  display: block;
  margin-bottom: 4px;
  font-size: 0.78rem;
}

pre {
  min-height: 92px;
  max-height: 220px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101820;
  color: #dbe7ee;
  padding: 11px;
  white-space: pre-wrap;
  word-break: break-word;
}

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

  .voice-console {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .topbar,
  .builder-head,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .builder-actions {
    justify-content: space-between;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .panel-grid,
  fieldset,
  .check-grid {
    grid-template-columns: 1fr;
  }

  .tabs {
    overflow: auto;
  }

  .tabs button {
    flex: 0 0 auto;
  }

  .row-card,
  .row-card.two-col,
  .row-card.handoff {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .auth-screen {
    padding: 12px;
  }

  .auth-panel,
  .builder,
  .sidebar,
  .voice-console {
    padding: 12px;
  }

  .topbar {
    height: auto;
    padding: 12px;
  }

  .voice-controls,
  .tool-grid {
    grid-template-columns: 1fr;
  }

  .title-input {
    font-size: 1.35rem;
  }
}
