:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #fbfcfb;
  --surface-3: #f1f4f1;
  --ink: #17211d;
  --ink-2: #2c3631;
  --muted: #68716d;
  --muted-2: #8a938e;
  --line: #e4e8e3;
  --line-2: #dce2dd;
  --accent: #0f7b68;
  --accent-strong: #09584b;
  --accent-soft: #e6f4ef;
  --accent-tint: rgba(15, 123, 104, 0.08);
  --warn: #a15c07;
  --warn-soft: #fff6df;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --amber: #d89b24;
  --amber-soft: #fff3d8;
  --shadow-sm: 0 1px 2px rgba(15, 23, 19, 0.04), 0 1px 1px rgba(15, 23, 19, 0.03);
  --shadow-md: 0 4px 12px rgba(15, 23, 19, 0.06), 0 1px 2px rgba(15, 23, 19, 0.04);
  --shadow-card: 0 1px 0 rgba(15, 23, 19, 0.02), 0 8px 24px -12px rgba(15, 23, 19, 0.08);
  --r-card: 12px;
  --r-input: 8px;
  --r-pill: 999px;
  --rail-w: 64px;
  --topbar-h: 56px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

a {
  color: inherit;
  text-decoration: none;
}

::selection {
  background: var(--accent-tint);
  color: var(--accent-strong);
}

/* ---------- Shell ---------- */
.shell {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  min-height: 100vh;
}

/* ---------- Side rail ---------- */
.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  background: var(--bg);
  border-right: 1px solid var(--line);
}

.rail-brand {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-bottom: 16px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 160ms ease;
}

.rail-brand:hover {
  transform: translateY(-1px);
}

.rail-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 0 8px;
}

.rail-item {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border-radius: 8px;
  transition:
    color 160ms ease,
    background 160ms ease,
    transform 120ms ease;
}

.rail-item svg {
  width: 18px;
  height: 18px;
}

.rail-item:hover {
  color: var(--ink);
  background: rgba(15, 23, 19, 0.04);
}

.rail-item:active {
  transform: scale(0.96);
}

.rail-item.is-active {
  color: var(--accent);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.rail-foot {
  margin-top: auto;
  padding: 8px;
}

.rail-pro {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #fff5d8 0%, #ffe49a 100%);
  color: #8b5a00;
  box-shadow: var(--shadow-sm);
  transition: transform 160ms ease;
}

.rail-pro:hover {
  transform: translateY(-1px);
}

.rail-pro svg {
  width: 18px;
  height: 18px;
}

/* ---------- Frame & topbar ---------- */
.frame {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.78);
  border-bottom: 1px solid var(--line);
  backdrop-filter: saturate(150%) blur(8px);
  -webkit-backdrop-filter: saturate(150%) blur(8px);
}

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

.brand {
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent-strong);
  font-size: 16px;
}

.brand-sep {
  width: 1px;
  height: 16px;
  background: var(--line);
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  min-width: 0;
}

.crumbs a {
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 140ms ease, color 140ms ease;
  white-space: nowrap;
}

.crumbs a:hover {
  background: rgba(15, 23, 19, 0.04);
  color: var(--ink);
}

.crumb-sep {
  color: var(--muted-2);
}

.crumb-current {
  color: var(--ink);
  font-weight: 600;
  padding: 4px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ws-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}

.ws-switch:hover {
  border-color: var(--line-2);
  background: var(--surface-3);
}

.ws-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.top-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  transition: background 140ms ease, color 140ms ease;
}

.top-link:hover {
  background: rgba(15, 23, 19, 0.04);
  color: var(--ink);
}

.top-news {
  position: relative;
  padding-left: 18px;
}

.news-dot {
  position: absolute;
  left: 8px;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 3px rgba(216, 155, 36, 0.18);
}

.divider-v {
  width: 1px;
  height: 18px;
  background: var(--line);
  margin: 0 4px;
}

.avatar {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.avatar:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* ---------- Canvas ---------- */
.canvas {
  flex: 1;
  padding: 20px;
  overflow: auto;
}

.grid {
  display: grid;
  grid-template-columns: minmax(380px, 5fr) minmax(0, 7fr);
  gap: 16px;
  width: min(1600px, 100%);
  margin: 0 auto;
  align-items: stretch;
  min-height: calc(100vh - var(--topbar-h) - 40px);
}

/* ---------- Panel base ---------- */
.panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(246, 247, 244, 0.6));
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.panel-head h1,
.panel-head h2 {
  margin: 0;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.panel-head h1 {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  max-width: 36ch;
}

.panel-head h2.call-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}

/* ---------- Status pills ---------- */
.status-badge,
.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-badge::before,
.status-dot::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}

.status-badge.ok,
.status-dot.live {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-dot.live::before {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(15, 123, 104, 0.18);
  animation: pulse 1.6s ease-out infinite;
}

.status-badge.warn,
.status-dot.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(15, 123, 104, 0.36);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(15, 123, 104, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(15, 123, 104, 0);
  }
}

/* ---------- Setup panel ---------- */
.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  margin: 0;
  list-style: none;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  overflow-x: auto;
  scrollbar-width: none;
}

.stepper::-webkit-scrollbar {
  display: none;
}

.step {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.step-num {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.step.is-active {
  color: var(--accent);
}

.step.is-active .step-num {
  background: var(--accent-tint);
  color: var(--accent);
}

.step-sep {
  flex: 0 0 14px;
  height: 1px;
  background: var(--line-2);
}

.panel-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 20px 12px;
  flex: 1;
  min-height: 0;
}

.field {
  display: grid;
  gap: 6px;
}

.field-label,
.field-label-row .field-label {
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
}

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

.field-help {
  color: var(--muted-2);
  font-size: 12px;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: color 140ms ease;
}

.link-btn:hover {
  color: var(--accent-strong);
}

textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  background: var(--surface-2);
  color: var(--ink);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

textarea {
  resize: vertical;
  min-height: 72px;
  padding: 10px 12px;
  line-height: 1.5;
  font-size: 13.5px;
}

.select-wrap {
  position: relative;
}

select {
  appearance: none;
  -webkit-appearance: none;
  height: 38px;
  padding: 0 32px 0 12px;
  font-size: 13px;
  cursor: pointer;
}

.select-caret {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

textarea:hover,
select:hover {
  border-color: var(--line-2);
}

textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 123, 104, 0.14);
  background: #fff;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

.field.compact {
  gap: 6px;
}

.panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  flex-wrap: wrap;
}

.foot-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Buttons ---------- */
.btn,
button.primary,
button.danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    box-shadow 140ms ease,
    transform 80ms ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--line-2);
  background: var(--surface-3);
}

.btn:active:not(:disabled) {
  transform: translateY(0.5px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 1px 0 rgba(9, 88, 75, 0.16);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn-secondary {
  background: var(--surface);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: transparent;
  color: var(--ink);
}

.btn-danger {
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-mini {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 6px;
  background: var(--surface);
}

.btn:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Call panel ---------- */
.call-panel {
  min-height: 720px;
}

.call-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.signal {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}

.signal i {
  width: 3px;
  border-radius: 1px;
  background: var(--line-2);
}

.signal i:nth-child(1) { height: 4px; }
.signal i:nth-child(2) { height: 7px; }
.signal i:nth-child(3) { height: 10px; }
.signal i:nth-child(4) { height: 13px; }

.meter-wrap {
  height: 6px;
  margin: 0 20px;
  margin-top: 14px;
  overflow: hidden;
  border-radius: var(--r-pill);
  background: var(--surface-3);
}

.meter {
  width: 2%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0f7b68 0%, #2fa68e 50%, #d89b24 100%);
  transition: width 80ms linear;
}

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

.tab {
  position: relative;
  height: 34px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 140ms ease, border-color 140ms ease;
}

.tab:hover {
  color: var(--ink);
}

.tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------- Transcript ---------- */
.transcript-wrap {
  position: relative;
  flex: 1;
  min-height: 240px;
  margin: 14px 20px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  overflow: hidden;
}

.transcript {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 14px;
  z-index: 2;
}

.transcript:empty + .empty-state {
  opacity: 1;
  pointer-events: auto;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 32px;
  opacity: 0;
  pointer-events: none;
  z-index: 1;
  transition: opacity 200ms ease;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
}

.empty-title {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  max-width: 32ch;
}

.empty-chips {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.chip {
  height: 28px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  border-radius: var(--r-pill);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.chip-soft {
  background: var(--accent-tint);
  color: var(--accent);
  border-color: transparent;
}

.message {
  margin-bottom: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  animation: msg-in 200ms ease-out both;
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message .role {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.message .content {
  display: block;
  color: var(--ink);
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.user {
  border-left: 3px solid var(--amber);
}

.message.user .role {
  background: var(--amber-soft);
  color: #8b5a00;
}

.message.agent {
  border-left: 3px solid var(--accent);
}

.message.agent .role {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.message.system {
  background: var(--surface-2);
  border-style: dashed;
  border-left: 3px solid var(--line-2);
}

.message.system .role {
  background: transparent;
  color: var(--muted-2);
  padding: 0;
}

/* ---------- Brief ---------- */
.brief {
  display: grid;
  grid-template-rows: auto 1fr;
  margin: 14px 20px 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
  min-height: 200px;
  max-height: 32vh;
}

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

.brief-head strong {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.005em;
}

.brief-actions {
  display: inline-flex;
  gap: 6px;
}

pre {
  margin: 0;
  overflow: auto;
  padding: 14px;
  white-space: pre-wrap;
  color: var(--ink-2);
  font:
    13px/1.55 ui-monospace, "JetBrains Mono", SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", monospace;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .call-panel {
    min-height: 640px;
  }
}

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

  .rail {
    position: static;
    flex-direction: row;
    height: auto;
    width: 100%;
    padding: 8px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .rail-brand {
    margin-bottom: 0;
    margin-right: 8px;
  }

  .rail-nav {
    flex-direction: row;
    padding: 0;
    width: auto;
  }

  .rail-foot {
    margin: 0 0 0 auto;
    padding: 0;
  }

  .topbar {
    padding: 0 14px;
  }

  .crumbs {
    font-size: 12px;
  }

  .crumb-current {
    max-width: 14ch;
  }

  .ws-switch {
    display: none;
  }

  .canvas {
    padding: 14px;
  }

  .panel-head h1 {
    font-size: 17px;
  }
}

@media (max-width: 540px) {
  .top-link {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
