:root {
  color-scheme: light;
  font-family: "DM Sans", sans-serif;
  color: #17333b;
  background: #e3eef1;
  font-synthesis: none;
  --ink: #17333b;
  --muted: #6a8086;
  --faint: #96a9ad;
  --canvas: #e3eef1;
  --surface: #f7f8f8;
  --surface-blue: #edf5f7;
  --primary: #227f9d;
  --primary-deep: #126580;
  --primary-light: #79b7c8;
  --line: rgba(31, 112, 137, .13);
  --shadow: rgba(21, 84, 103, .13);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 10%, rgba(255,255,255,.9), transparent 28rem),
    linear-gradient(145deg, #edf5f7, #ccdde2);
}

button { font: inherit; }

.app-shell {
  width: min(980px, 100%);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  overflow: hidden;
  background: rgba(248, 250, 250, .88);
  box-shadow: 0 0 80px var(--shadow);
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  backdrop-filter: blur(20px);
}

.topbar {
  padding: 24px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.identity { display: flex; align-items: center; gap: 13px; }
.logo {
  width: 48px;
  height: 48px;
  display: block;
  object-fit: contain;
  background: transparent;
}

h1 { margin: 0; font: 600 22px/1 "Fraunces", serif; }
.identity p { margin: 5px 0 0; font-size: 12px; color: var(--muted); }
.online-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--primary-light); margin-right: 4px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.text-button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 8px; font-size: 13px; }
.text-button:hover { color: var(--primary-deep); }
.resource-button {
  padding: 7px 11px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, .56);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.resource-button:hover { background: rgba(255, 255, 255, .9); }
.credit-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--primary-light); box-shadow: 0 0 0 3px rgba(121,183,200,.16); }

.provider-tabs {
  padding: 12px 28px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--line);
}
.provider-tab {
  position: relative;
  padding: 11px 14px 13px;
  border: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.provider-tab::after {
  content: "";
  position: absolute;
  right: 10px;
  bottom: -1px;
  left: 10px;
  height: 2px;
  border-radius: 2px;
  background: transparent;
}
.provider-tab.active { color: var(--ink); }
.provider-tab.active::after { background: var(--primary-deep); }
.provider-tab[data-provider="retell"].active::after { background: var(--primary-light); }
.tab-mark { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; }
.eva-mark { background: var(--primary-deep); }
.retell-mark { background: var(--primary-light); }
.stt-selector {
  margin: 0;
  padding: 3px;
  display: flex;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, .55);
}
.stt-option {
  padding: 6px 9px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
}
.stt-option.active { color: #fff; background: var(--primary-deep); box-shadow: 0 3px 9px rgba(18, 101, 128, .2); }
.stt-option[data-stt="google"].active { background: var(--primary); box-shadow: 0 3px 9px rgba(34, 127, 157, .2); }
.stt-option[data-stt="speechmatics"].active { background: #559caf; box-shadow: 0 3px 9px rgba(85, 156, 175, .2); }
.stt-option:disabled { cursor: default; opacity: .55; }
[hidden] { display: none !important; }

.model-toolbar {
  min-width: 0;
  padding: 12px 20px;
  display: grid;
  grid-template-columns: minmax(245px, .9fr) minmax(290px, 1.1fr) minmax(290px, 1.1fr);
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(237, 245, 247, .5);
}
.control-card {
  min-width: 0;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .7);
  box-shadow: 0 6px 18px rgba(21, 84, 103, .045);
}
.control-card-heading { display: flex; align-items: center; gap: 8px; min-width: 0; }
.control-card-heading > span:last-child { min-width: 0; display: flex; align-items: baseline; gap: 6px; }
.control-card-heading strong { color: var(--ink); font-size: 12px; line-height: 1; }
.control-card-heading small { overflow: hidden; color: var(--faint); font-size: 9px; line-height: 1; text-overflow: ellipsis; white-space: nowrap; }
.control-step { width: 20px; height: 20px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--primary-deep); font-size: 9px; font-weight: 600; }
.control-card-tts .control-step { background: var(--primary); }
.control-card-body { min-width: 0; display: flex; align-items: center; gap: 7px; }
.control-card-stt .stt-selector { width: 100%; }
.control-card-stt .stt-option { min-width: 0; flex: 1 1 auto; padding-inline: 5px; }
.model-label { color: var(--faint); font-size: 10px; font-weight: 600; letter-spacing: .08em; }
.llm-provider-switch { flex: 0 0 auto; padding: 3px; display: flex; gap: 2px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, .65); }
.llm-provider { padding: 6px 7px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; cursor: pointer; font-size: 10px; font-weight: 600; }
.llm-provider.active { color: #fff; background: var(--primary-deep); box-shadow: 0 3px 9px rgba(18, 101, 128, .2); }
.llm-provider[data-llm-provider="openrouter"].active { background: #315d6a; box-shadow: 0 3px 9px rgba(49, 93, 106, .2); }
.llm-provider:disabled { cursor: default; opacity: .55; }
.model-select-wrap { min-width: 0; flex: 1 1 auto; display: block; color: var(--faint); font-size: 10px; font-weight: 600; letter-spacing: .06em; }
.model-select-wrap > span, .voice-select-wrap > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.model-select-wrap select { min-width: 0; width: 100%; height: 34px; padding: 0 30px 0 10px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: rgba(255, 255, 255, .82); font: 500 11px "DM Sans", sans-serif; cursor: pointer; }
.model-select-wrap select:disabled { cursor: wait; opacity: .6; }
.tts-selector { flex: 0 0 auto; padding: 3px; display: flex; align-items: center; gap: 2px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, .65); }
.tts-selector .model-label { padding: 0 5px; }
.tts-option { padding: 6px 9px; border: 0; border-radius: 7px; color: var(--muted); background: transparent; cursor: pointer; font-size: 11px; font-weight: 600; }
.tts-option.active { color: #fff; background: var(--primary); box-shadow: 0 3px 9px rgba(34, 127, 157, .2); }
.tts-option[data-tts="google"].active { background: #559caf; box-shadow: 0 3px 9px rgba(85, 156, 175, .2); }
.tts-option:disabled { cursor: default; opacity: .55; }
.voice-select-wrap { min-width: 0; flex: 1 1 auto; display: block; color: var(--faint); font-size: 10px; font-weight: 600; letter-spacing: .06em; }
.voice-select-wrap select { min-width: 0; width: 100%; height: 34px; padding: 0 30px 0 10px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: rgba(255, 255, 255, .82); font: 500 11px "DM Sans", sans-serif; cursor: pointer; }
.voice-select-wrap select:disabled { cursor: wait; opacity: .6; }

.conversation {
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.empty-state { margin: auto; text-align: center; padding: 48px 20px; }
.empty-state h2 { margin: 24px 0 8px; font: 600 32px/1.15 "Fraunces", serif; }
.empty-state p { margin: 0; color: var(--muted); }
.empty-state small { display: block; margin-top: 12px; color: var(--faint); }
.orb {
  width: 104px;
  height: 104px;
  margin: 0 auto;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: linear-gradient(145deg, var(--primary-light), var(--primary-deep));
  box-shadow: 0 18px 45px rgba(18, 101, 128, .25), inset 0 1px rgba(255,255,255,.4);
}
.orb span { width: 4px; height: 22px; border-radius: 4px; background: rgba(255,255,255,.85); animation: wave 1.2s ease-in-out infinite; }
.orb span:nth-child(2) { height: 34px; animation-delay: -.25s; }
.orb span:nth-child(3) { animation-delay: -.5s; }
.retell-orb { background: linear-gradient(145deg, #a4cfda, #4d96ad); box-shadow: 0 18px 45px rgba(77, 150, 173, .22), inset 0 1px rgba(255,255,255,.4); }
@keyframes wave { 0%, 100% { transform: scaleY(.55); } 50% { transform: scaleY(1); } }

.message { display: flex; flex-direction: column; max-width: 78%; animation: arrive .25s ease-out; }
.message.user { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; }
.bubble { margin: 0; padding: 13px 16px; line-height: 1.5; font-size: 15px; border-radius: 18px; }
.user .bubble { color: white; background: var(--primary-deep); border-bottom-right-radius: 5px; }
.assistant .bubble { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 5px; box-shadow: 0 8px 24px rgba(21, 84, 103, .07); }
.speaker { margin: 6px 5px 0; color: var(--faint); font-size: 11px; }
@keyframes arrive { from { opacity: 0; transform: translateY(7px); } }

.controls {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  padding: 18px 28px 26px;
  text-align: center;
  border-top: 1px solid var(--line);
  background: rgba(247, 250, 250, .92);
}
.status { height: 22px; margin-bottom: 10px; color: #48646b; font-size: 14px; font-weight: 500; }
.talk-button {
  width: 76px;
  height: 76px;
  border: 0;
  border-radius: 50%;
  color: white;
  background: var(--primary-deep);
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(18, 101, 128, .3), inset 0 1px rgba(255,255,255,.35);
  transition: transform .15s, box-shadow .15s, background .15s;
}
.talk-button:hover { transform: translateY(-2px); box-shadow: 0 16px 34px rgba(18, 101, 128, .34); }
.talk-button:disabled { cursor: wait; opacity: .55; transform: none; }
.talk-button svg { width: 29px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.stop-icon { display: none; fill: currentColor !important; stroke: none !important; }
.talk-button.recording { background: #244c58; animation: pulse 1.5s infinite; }
.talk-button.recording .mic-icon { display: none; }
.talk-button.recording .stop-icon { display: inline; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(18,101,128,.22); } 50% { box-shadow: 0 0 0 12px rgba(18,101,128,0); } }
.hint { margin: 10px 0 0; color: var(--faint); font-size: 11px; }

.panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(15, 62, 75, .24);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity .22s ease;
}
.panel-backdrop.open { opacity: 1; }
.resources-panel {
  position: fixed;
  z-index: 21;
  top: 0;
  right: 0;
  width: min(390px, 92vw);
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  color: var(--ink);
  background: #f1f7f8;
  box-shadow: -24px 0 70px rgba(21, 84, 103, .2);
  transform: translateX(105%);
  transition: transform .26s cubic-bezier(.2,.8,.2,1);
}
.resources-panel.open { transform: translateX(0); }
.panel-header {
  padding: 26px 24px 19px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.panel-kicker { margin: 0 0 7px; color: var(--primary-deep); font-size: 9px; font-weight: 600; letter-spacing: .14em; }
.panel-header h2 { margin: 0; font: 600 25px/1.1 "Fraunces", serif; }
.panel-close { width: 34px; height: 34px; border: 0; border-radius: 50%; color: var(--muted); background: #deecef; cursor: pointer; font-size: 24px; line-height: 1; }
.resources-list { min-height: 0; padding: 18px 20px; overflow-y: auto; }
.resource-loading { padding: 44px 10px; color: var(--muted); text-align: center; font-size: 13px; }
.resource-card {
  margin-bottom: 10px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 255, 255, .72);
  box-shadow: 0 7px 20px rgba(21, 84, 103, .045);
}
.resource-card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.resource-name { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 600; }
.resource-state { width: 8px; height: 8px; border-radius: 50%; background: var(--primary-light); }
.resource-card.warning .resource-state { background: #d39549; }
.resource-card.missing .resource-state { background: #b7afa5; }
.resource-metric { margin-top: 11px; font: 600 24px/1.1 "Fraunces", serif; }
.resource-detail { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.resource-link { color: var(--primary-deep); text-decoration: none; font-size: 11px; font-weight: 600; white-space: nowrap; }
.resource-link:hover { text-decoration: underline; }
.panel-footer {
  padding: 14px 20px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 10px;
}
.panel-footer button { padding: 7px 11px; border: 0; border-radius: 9px; color: #fff; background: var(--primary-deep); cursor: pointer; font-size: 11px; }
.panel-footer button:disabled { opacity: .5; cursor: wait; }
body.panel-open { overflow: hidden; }

@media (max-width: 860px) {
  .model-toolbar {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  .control-card { width: min(300px, calc(100vw - 42px)); flex: 0 0 min(300px, calc(100vw - 42px)); scroll-snap-align: start; }
}

@media (max-width: 600px) {
  body { overflow: hidden; }
  .app-shell {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    box-shadow: none;
  }
  .topbar {
    min-width: 0;
    padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
    gap: 10px;
  }
  .identity { min-width: 0; gap: 9px; }
  .logo { width: 39px; height: 39px; flex: 0 0 auto; border-radius: 12px; }
  h1 { overflow: hidden; font-size: 18px; line-height: 1.05; text-overflow: ellipsis; white-space: nowrap; }
  .identity p, .text-button { display: none; }
  .topbar-actions { flex: 0 0 auto; }
  .resource-button { min-height: 36px; padding: 7px 9px; font-size: 11px; }
  .provider-tabs { min-height: 49px; padding: 5px 14px 0; overflow-x: auto; scrollbar-width: none; }
  .provider-tabs::-webkit-scrollbar, .model-toolbar::-webkit-scrollbar { display: none; }
  .provider-tab { min-height: 43px; padding: 9px 9px 11px; white-space: nowrap; }
  .stt-selector { flex: 0 0 auto; width: auto; justify-content: flex-start; }
  .stt-label { display: inline; }
  .model-toolbar {
    min-height: 0;
    padding: 8px 12px 9px;
    gap: 9px;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }
  .control-card { width: calc(100vw - 42px); flex-basis: calc(100vw - 42px); padding: 9px; gap: 7px; }
  .control-card-heading strong { font-size: 11px; }
  .control-card-heading small { font-size: 8px; }
  .stt-option, .llm-provider, .tts-option { min-height: 34px; }
  .model-select-wrap select, .voice-select-wrap select { height: 40px; }
  .conversation { padding: 18px 14px; gap: 13px; }
  .message { max-width: 92%; }
  .bubble { padding: 11px 14px; font-size: 14px; }
  .empty-state { padding: 24px 10px; }
  .empty-state h2 { margin-top: 18px; font-size: 26px; }
  .empty-state p { max-width: 300px; margin-inline: auto; font-size: 14px; line-height: 1.4; }
  .orb { width: 84px; height: 84px; }
  .orb span { height: 18px; }
  .orb span:nth-child(2) { height: 28px; }
  .controls { padding: 9px 16px calc(10px + env(safe-area-inset-bottom)); }
  .status { height: auto; min-height: 20px; margin-bottom: 8px; font-size: 13px; }
  .talk-button { width: 60px; height: 60px; }
  .talk-button svg { width: 25px; }
  .hint { margin-top: 7px; }
  .resources-panel { width: 100vw; max-width: 100%; }
  .panel-header { padding: calc(20px + env(safe-area-inset-top)) 20px 16px; }
  .panel-footer { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
}

@media (max-width: 360px) {
  .topbar { padding-inline: 11px; }
  .logo { width: 36px; height: 36px; }
  h1 { max-width: 155px; font-size: 16px; }
  .resource-button { padding-inline: 8px; }
  .provider-tabs { padding-inline: 10px; }
  .model-toolbar { padding-inline: 10px; }
  .conversation { padding-inline: 12px; }
  .empty-state h2 { font-size: 24px; }
}
