:root {
  --bg: #fff8ef;
  --card: #ffffff;
  --ink: #1d1a24;
  --muted: #6f6878;
  --line: #ece3d6;
  --accent: #ff5a36;
  --accent-ink: #ffffff;
  --accent-soft: #ffe6dc;
  --good: #1f9d63;
  --bad: #d43b3b;
  --agent: #f2ecff;
  --user: #eef6ee;
  --radius: 16px;

  /* Spacing scale: every gap, margin and padding comes from here. */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --gutter: 16px;
  --card-pad: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15131a;
    --card: #1f1c26;
    --ink: #f3eff8;
    --muted: #a39cad;
    --line: #322d3b;
    --accent: #ff6a48;
    --accent-soft: #3a2420;
    --agent: #2a2440;
    --user: #1f3226;
    color-scheme: dark;
  }
}
@media (min-width: 640px) {
  :root { --gutter: 24px; --card-pad: 24px; }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 "Bricolage Grotesque", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
p { margin: 0; }

.logo { font-weight: 800; letter-spacing: -0.03em; margin: 0; font-size: 26px; line-height: 1; }
.logo span { color: var(--accent); }

/* ---------- sign in ---------- */
.login { max-width: 400px; margin: 0 auto; padding: 12vh var(--gutter) var(--s6); text-align: center; }
.login .logo { font-size: 52px; }
.tag { color: var(--muted); margin: var(--s3) auto var(--s5); max-width: 30ch; }
.login .card { text-align: left; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--s3) var(--s4);
  max-width: 880px; margin: 0 auto; padding: var(--s4) var(--gutter) var(--s3);
}
.top nav { display: flex; gap: var(--s1); flex: 1; }
.top nav button {
  background: none; border: 0; padding: var(--s2) 14px; border-radius: 999px;
  font-weight: 600; color: var(--muted); white-space: nowrap;
}
.top nav button.active { background: var(--ink); color: var(--bg); }
@media (max-width: 599px) {
  .top { justify-content: space-between; }
  /* Nav gets its own full-width row on phones, scrolling sideways if it ever overflows. */
  .top nav { order: 3; flex-basis: 100%; overflow-x: auto; scrollbar-width: none; }
  .top nav::-webkit-scrollbar { display: none; }
  .top nav button { flex: 1; padding: var(--s2) 10px; }
}

.banner {
  max-width: calc(880px - 2 * var(--gutter)); margin: 0 auto var(--s4); padding: var(--s3) var(--s4);
  border-radius: 12px; background: var(--accent-soft); font-size: 14px;
}
@media (max-width: 879px) { .banner { margin: 0 var(--gutter) var(--s4); } }

/* ---------- layout ---------- */
.panel { max-width: 880px; margin: 0 auto; padding: 0 var(--gutter) var(--s6); display: grid; gap: var(--s4); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--card-pad); min-width: 0; }
.card h2 { margin: 0 0 var(--s4); font-size: 20px; line-height: 1.2; }
.stack { display: grid; gap: var(--s4); }
.stack > h2 { margin-bottom: 0; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: var(--s4); align-items: start; }

/* ---------- fields ---------- */
label, .field { display: grid; gap: 6px; min-width: 0; }
label, .field-label { font-weight: 600; font-size: 14px; }
.optional { font-weight: 400; color: var(--muted); }
.narrow { max-width: 360px; }
input, select, textarea {
  font: inherit; font-size: 16px; font-weight: 400; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; min-width: 0;
}
select { appearance: none; padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.hint, .muted { color: var(--muted); font-size: 13px; font-weight: 400; }

.field-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: 14px; font-weight: 600; }
button.link:hover { text-decoration: underline; }
.pick-empty {
  display: grid; gap: 2px; text-align: left; width: 100%; padding: var(--s3) var(--s4);
  border: 1.5px dashed var(--accent); border-radius: 10px; background: var(--accent-soft); color: var(--ink);
}
.pick-empty strong { color: var(--accent); }
.pick-empty span { font-weight: 400; font-size: 14px; color: var(--muted); }

.checks { display: grid; gap: var(--s3); padding: var(--s4); border-radius: 12px; background: var(--bg); }
label.check { display: flex; align-items: flex-start; gap: var(--s3); font-weight: 400; font-size: 15px; line-height: 1.4; cursor: pointer; }
label.check input { width: 20px; height: 20px; flex: none; margin: 0; padding: 0; accent-color: var(--accent); }

/* ---------- buttons ---------- */
button {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 999px; padding: 11px 20px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink); line-height: 1.2;
}
button:disabled { opacity: 0.55; cursor: progress; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
button.ghost { background: transparent; }
button.small { padding: 7px 14px; font-size: 14px; }
button.big { padding: 14px 28px; font-size: 17px; }
button.block { width: 100%; }
/* Buttons in a form sit at their natural width instead of stretching across the card. */
.stack > button { justify-self: start; }
.stack > button.block { justify-self: stretch; }

.actions { display: flex; gap: var(--s3); justify-content: flex-end; flex-wrap: wrap; padding-top: var(--s4); border-top: 1px solid var(--line); }
@media (max-width: 519px) {
  /* Thumb-friendly: full-width, primary action first. */
  .actions { flex-direction: column-reverse; }
  .actions button { width: 100%; }
  .stack > button { justify-self: stretch; }
}

.error { color: var(--bad); font-size: 14px; }
.error:empty { display: none; }

/* ---------- chips ---------- */
.scenarios, .presets { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  border-radius: 999px; padding: var(--s2) 14px; font-weight: 600; font-size: 14px;
  background: var(--bg); border: 1px solid var(--line);
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }

/* ---------- voice previews ---------- */
.previews { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: var(--s3); }
.preview { border: 2px solid var(--line); border-radius: 12px; padding: var(--s3); display: grid; gap: var(--s2); cursor: pointer; }
.preview.active { border-color: var(--accent); background: var(--accent-soft); }
.preview audio { width: 100%; }
.preview button { justify-self: start; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.list > li {
  display: flex; gap: var(--s3); align-items: center; justify-content: space-between;
  padding: var(--s3) var(--s4); border: 1px solid var(--line); border-radius: 12px;
}
.list > li > div { min-width: 0; }
@media (max-width: 519px) {
  /* Row buttons drop under the text instead of squeezing it. */
  .list > li:not(.history-item):not(.empty) { flex-wrap: wrap; }
  .list > li:not(.history-item):not(.empty) > div:first-child { flex: 1 1 100%; }
}
.list .name { font-weight: 700; }
.list .sub { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; margin-top: 2px; }
.list .btns { display: flex; gap: var(--s2); flex-shrink: 0; }
.list > li.empty { color: var(--muted); border-style: dashed; justify-content: center; padding: var(--s4); }

/* ---------- live call ---------- */
.live-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.live-head > div { min-width: 0; }
#live-who { margin-top: var(--s1); overflow-wrap: anywhere; }
.status { font-size: 22px; font-weight: 800; line-height: 1.2; }
.status::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); margin-right: var(--s2); vertical-align: middle; }
.status.active::before { background: var(--good); animation: pulse 1.2s infinite; }
.status.dialing::before { background: var(--accent); animation: pulse 0.8s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
#live-body:not(:empty) { margin-top: var(--s4); }
.live #new-call { margin-top: var(--s4); }

/* ---------- transcript, summary, recording ---------- */
.transcript { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s2); }
.transcript li { padding: 10px 14px; border-radius: 14px; max-width: min(85%, 560px); overflow-wrap: anywhere; }
.transcript li.agent { background: var(--agent); border-bottom-left-radius: 4px; }
.transcript li.user { background: var(--user); justify-self: end; border-bottom-right-radius: 4px; }
.transcript li small { display: block; color: var(--muted); font-size: 12px; font-weight: 600; margin-bottom: 2px; }
.transcript + .summary, .transcript + .recording, .transcript + .muted { margin-top: var(--s4); }
.summary { background: var(--bg); border-radius: 12px; padding: var(--s3) var(--s4); }
.summary + .recording, .summary + .muted { margin-top: var(--s4); }
.recording { display: grid; gap: var(--s2); }
.recording audio { width: 100%; }
.small-link { color: var(--accent); font-size: 14px; font-weight: 600; justify-self: start; }

/* ---------- history ---------- */
.list > li.history-item { display: block; }
.history-head { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; justify-content: space-between; }
.history-head > div:first-child { flex: 1 1 260px; min-width: 0; }
.history-detail { margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--line); }
@media (max-width: 519px) {
  .history-head .btns, .history-head .btns button { width: 100%; }
  .transcript li { max-width: 92%; }
}
