:root {
  --ink: #171717;
  --muted: #61656f;
  --line: #d9dde5;
  --panel: #ffffff;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow: 0 18px 60px rgba(25, 31, 42, .14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  background: var(--page-bg, #faf8f4);
}

.shell {
  min-height: 100vh;
}

.layout-split-left {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
}

.layout-split-right {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 440px);
}

.layout-stack-top {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: 1fr;
}

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: var(--stage-pad, 28px);
  background: var(--stage-bg);
  border: var(--stage-border, none);
}

.layout-split-left .stage { justify-content: flex-end; border-right: 1px solid var(--line); }
.layout-split-right .stage { justify-content: flex-end; border-left: 1px solid var(--line); order: 2; }
.layout-split-right .workspace { order: 1; }
.layout-stack-top .stage {
  justify-content: center;
  min-height: var(--stage-min-h, 42vh);
  border-bottom: 1px solid var(--line);
}

.brand {
  position: absolute;
  top: 24px;
  left: 28px;
  right: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 2;
}

.mark { display: flex; align-items: center; gap: 10px; font-weight: 760; }
.mark-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 13px 0 0 var(--secondary), 26px 0 0 var(--tertiary);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}

.webrtc-note {
  margin: 0;
  padding: 8px 14px 0;
  text-align: center;
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted, #61656f);
}

.webrtc-note:empty {
  display: none;
}

.pulse {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #bbb;
  box-shadow: 0 0 0 5px rgba(0,0,0,.06);
  transition: background .3s;
}

.pulse.live {
  background: var(--primary);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--primary) 18%, transparent);
}

.portrait-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  padding-top: var(--portrait-pad-top, 70px);
}

.layout-stack-top .portrait-wrap {
  padding-top: 56px;
  max-width: 920px;
  margin: 0 auto;
}

.portrait {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: var(--portrait-filter, drop-shadow(0 32px 42px rgba(35,45,55,.25)));
  transition: opacity .4s;
}

.portrait.hidden { opacity: 0; pointer-events: none; position: absolute; inset: 0; }

.did-target {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-lg);
  overflow: hidden;
  opacity: 0;
  transition: opacity .5s;
}

.did-target.visible { opacity: 1; }
.did-target :is(video, iframe) {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  border: 0;
  border-radius: var(--radius-lg);
}

.avatar-frame {
  width: 100%;
  margin: 0 auto;
  background: var(--frame-bg, #0d0d1a);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  border: var(--frame-border, none);
}

.did-start-btn {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 20px;
  border: 0;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(8, 12, 24, .55), rgba(8, 12, 24, .82));
  color: #fff;
  cursor: pointer;
  text-align: center;
  font: inherit;
  transition: background .2s ease;
}

.did-start-btn:hover {
  background: linear-gradient(180deg, rgba(8, 12, 24, .45), rgba(8, 12, 24, .72));
}

.did-start-btn[hidden] { display: none !important; }

.did-start-label {
  font-size: clamp(16px, 2.4cqi, 20px);
  font-weight: 700;
}

.did-start-hint {
  font-size: 12px;
  opacity: .78;
  max-width: 16rem;
}

.avatar-frame.format-square { aspect-ratio: 1 / 1; max-width: 480px; }
.avatar-frame.format-vertical { aspect-ratio: 9 / 16; max-height: 72vh; max-width: 420px; }
.avatar-frame.format-landscape { aspect-ratio: 16 / 9; width: 100%; max-width: 100%; }

.layout-stack-top .avatar-frame.format-square { max-width: 320px; }
.layout-stack-top .avatar-frame.format-vertical { max-height: 50vh; max-width: 280px; }
.layout-stack-top .avatar-frame.format-landscape { max-width: 720px; }

.stage.format-landscape-heavy { justify-content: center; }
.stage.format-landscape-heavy .caption {
  position: absolute;
  bottom: 28px;
  left: 28px;
  right: 28px;
  z-index: 3;
  background: var(--caption-bg, rgba(255,255,255,.82));
  backdrop-filter: blur(8px);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.caption h1 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: clamp(32px, 6vw, 64px);
  line-height: .95;
  letter-spacing: var(--heading-track, 0);
}

.caption p {
  margin: 12px 0 0;
  max-width: 32rem;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.layout-stack-top .caption {
  text-align: center;
  margin-top: 20px;
}

.layout-stack-top .caption p { margin-left: auto; margin-right: auto; }

.workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 100vh;
  padding: var(--workspace-pad, 24px);
  gap: 16px;
  background: var(--workspace-bg, transparent);
}

.layout-stack-top .workspace {
  min-height: 0;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar h2 {
  margin: 0;
  font-size: 21px;
  font-family: var(--font-heading);
  font-weight: var(--topbar-weight, 700);
}

.vertical-pill {
  display: inline-block;
  margin-bottom: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.format-nav { display: flex; gap: 6px; flex-wrap: wrap; }

.format-nav a {
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 34px;
  border-radius: var(--radius-pill, 999px);
  padding: 0 12px;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
}

.format-nav a.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text, #fff);
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 40px;
  border-radius: var(--radius-sm);
  padding: 0 13px;
  font: inherit;
  font-weight: 720;
  cursor: pointer;
}

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

.lead-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--card-bg, rgba(255,255,255,.88));
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 14px;
  align-items: center;
  transition: border-color .4s;
}

.lead-card.complete { border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); }
.lead-card h3 { margin: 0 0 6px; font-size: 17px; }
.lead-card p { margin: 0 0 12px; color: var(--muted); font-size: 13px; line-height: 1.45; }

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

.detail-item {
  border: 1px solid var(--detail-border, #e0e5eb);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  background: var(--detail-bg, #f8faf9);
  min-width: 0;
}

.detail-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  margin-bottom: 3px;
}

.detail-item strong { display: block; font-size: 13px; overflow-wrap: anywhere; }
.detail-item.captured strong { color: var(--primary); animation: fadeIn .5s ease; }

.signal {
  width: 52px;
  height: 52px;
  border-radius: var(--signal-radius, 50%);
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--signal-bg, linear-gradient(135deg, var(--primary), var(--tertiary)));
  font-weight: 850;
}

.chat { min-height: 0; overflow: auto; padding: 4px; }

.message {
  display: grid;
  grid-template-columns: 42px minmax(0,720px);
  gap: 12px;
  margin: 0 0 16px;
}

.message.user { grid-template-columns: minmax(0,720px) 42px; justify-content: end; }

.avatar-chip {
  width: 42px;
  height: 42px;
  border-radius: var(--chip-radius, 8px);
  display: grid;
  place-items: center;
  font-weight: 800;
  background: color-mix(in srgb, var(--primary) 12%, #fff);
  color: var(--primary);
  border: 1px solid color-mix(in srgb, var(--primary) 22%, #fff);
}

.message.user .avatar-chip {
  grid-column: 2;
  background: var(--user-chip-bg, #e8ecf8);
  color: var(--tertiary);
}

.bubble {
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: var(--bubble-bg, rgba(255,255,255,.88));
  border-radius: var(--bubble-radius, 8px);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  background: var(--user-bubble-bg, #f0f3fb);
  grid-column: 1;
}

.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.source {
  font-size: 12px;
  background: var(--source-bg, #eef2f1);
  border: 1px solid var(--source-border, #d7dfdc);
  border-radius: 999px;
  padding: 4px 8px;
}

.composer {
  border: 1px solid var(--line);
  background: var(--composer-bg, rgba(255,255,255,.84));
  border-radius: var(--radius-md);
  padding: 12px;
  box-shadow: var(--shadow);
}

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.suggestions button { min-height: 32px; font-size: 13px; font-weight: 650; }

.chat-form {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 10px;
  align-items: end;
}

textarea {
  width: 100%;
  min-height: 54px;
  max-height: 150px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font: inherit;
  background: var(--input-bg, #fff);
  color: var(--ink);
}

.meta {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  gap: 12px;
  flex-wrap: wrap;
}

@keyframes fadeIn {
  from { opacity: .2; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
  .layout-split-left,
  .layout-split-right,
  .layout-stack-top {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .layout-split-right .stage,
  .layout-split-right .workspace { order: unset; }

  .layout-split-left .stage,
  .layout-split-right .stage,
  .layout-stack-top .stage {
    min-height: 44vh;
    border-right: 0;
    border-left: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace { min-height: 56vh; }
  .detail-grid { grid-template-columns: 1fr; }
  .chat-form { grid-template-columns: 1fr; }
}