/* Light theme. Colors live in these tokens. */

:root {
  color-scheme: light;
  --bg: #f8fafc;
  --bg-2: #ffffff;
  --surface: #ffffff;
  --surface-solid: #ffffff;
  --surface-hover: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-faint: #64748b;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --violet: #1d4ed8;
  --grad: #2563eb;
  --grad-user: #2563eb;
  --danger: #e11d48;
  --danger-soft: #fff1f2;
  --danger-text: #be123c;
  --success: #047857;
  --glow: 0 1px 2px rgba(15, 23, 42, 0.06);
  --ring: 0 0 0 2px #ffffff, 0 0 0 4px #2563eb;
  --radius: 14px;
  --radius-sm: 10px;
  --font: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", "Cascadia Code", ui-monospace, Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* component display rules must not unhide */

body {
  margin: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column;
  font-family: var(--font); font-size: 16px; line-height: 1.5; color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
/* faint holographic grid */
body::before { content: none; }
body > * { position: relative; z-index: 1; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; flex: none; }

button, a.button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: none; box-shadow: var(--ring); }
::selection { background: rgba(34, 211, 238, 0.3); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(125, 165, 255, 0.25) transparent; }

/* ---------- Header ---------- */
header {
  min-height: 60px; padding: 10px 20px; display: flex; align-items: center; gap: 12px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
}
header h1 {
  font-size: 16px; font-weight: 600; letter-spacing: 0.01em; margin: 0; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.logo {
  width: 26px; height: 26px; flex: none; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #a5f3fc 0%, #22d3ee 30%, #6366f1 65%, #4c1d95 100%);
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.45), inset 0 0 6px rgba(255, 255, 255, 0.35);
}
header .actions { display: flex; gap: 8px; align-items: center; flex: none; }
#menu, header .actions button, header .actions a.button {
  min-height: 40px; display: inline-flex; align-items: center; gap: 8px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  font-size: 14px; text-decoration: none; white-space: nowrap;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
#menu:hover, header .actions button:hover, header .actions a.button:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.icon-btn { width: 40px; min-width: 40px; padding: 0 !important; justify-content: center; }
#speak[aria-pressed="true"] { border-color: rgba(34, 211, 238, 0.5); color: var(--primary); }
#convo { border-color: rgba(34, 211, 238, 0.45) !important; color: var(--primary); }
#convo[aria-pressed="true"] {
  background: var(--danger-soft) !important; border-color: rgba(244, 63, 94, 0.6) !important; color: var(--danger-text);
  animation: live-ring 1.8s ease-out infinite;
}
@keyframes live-ring {
  0% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.45); }
  100% { box-shadow: 0 0 0 12px rgba(244, 63, 94, 0); }
}

/* ---------- Layout: history sidebar + page ---------- */
#layout { flex: 1; display: flex; min-height: 0; }
#page { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#sidebar {
  width: 288px; flex: none; display: flex; flex-direction: column; gap: 8px; padding: 14px 12px; overflow-y: auto;
  background: #ffffff;
  border-right: 1px solid var(--border);
}
#sidebar h2 {
  font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-faint); margin: 14px 6px 4px;
}
#newConv {
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid rgba(34, 211, 238, 0.45); border-radius: var(--radius-sm); background: rgba(34, 211, 238, 0.08);
  color: var(--primary); font-weight: 600; transition: box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}
#newConv:hover { box-shadow: var(--glow); background: rgba(34, 211, 238, 0.12); }
#convList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
#convList li.muted { color: var(--text-faint); font-size: 13px; padding: 8px 6px; }
#convList li[data-id] { display: flex; align-items: center; border-radius: var(--radius-sm); position: relative; }
#convList li[data-id] > button:first-child {
  flex: 1; min-width: 0; min-height: 44px; text-align: left; background: none; border: 0; border-radius: var(--radius-sm);
  padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; transition: background 0.15s var(--ease);
}
#convList li[data-id] > button:first-child:hover { background: var(--surface-hover); }
#convList li.active > button:first-child { background: rgba(34, 211, 238, 0.1); }
#convList li.active::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px;
  background: var(--grad); box-shadow: 0 0 10px rgba(34, 211, 238, 0.6);
}
#convList button span { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#convList button small { color: var(--text-faint); font-size: 12px; font-family: var(--mono); }
#convList .delete {
  flex: none; min-width: 36px; height: 36px; margin-right: 4px; border: 0; border-radius: 8px; background: none;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted);
  opacity: 0; transition: opacity 0.15s var(--ease), background 0.15s var(--ease), color 0.15s var(--ease);
}
#convList .delete .icon { width: 16px; height: 16px; }
#convList li:hover .delete, #convList li.active .delete, #convList .delete:focus-visible, #convList .delete.armed { opacity: 1; }
#convList .delete:hover { background: var(--danger-soft); color: var(--danger-text); }
#convList .delete.armed { background: var(--danger); color: #fff; font-size: 12px; font-weight: 600; padding: 0 10px; }
#menu { display: none; width: 40px; padding: 0; justify-content: center; }

/* ---------- New conversation (prompt) ---------- */
#setup {
  flex: 1; overflow-y: auto; max-width: 780px; width: 100%; margin: 0 auto; padding: 40px 20px 48px;
  display: flex; flex-direction: column; gap: 10px;
}
.eyebrow { font-family: var(--mono); font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--primary); margin: 0; }
#setup h2 {
  margin: 0 0 10px; font-size: clamp(26px, 4vw, 34px); line-height: 1.15; font-weight: 700; letter-spacing: -0.02em;
  color: var(--text);
}
#setup label { font-size: 14px; font-weight: 500; color: var(--text-muted); }
#setup textarea {
  width: 100%; min-height: 280px; resize: vertical; padding: 16px; font: 14px/1.6 var(--mono); color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
#setup textarea::placeholder { color: var(--text-faint); }
#setup textarea:focus { outline: none; border-color: rgba(34, 211, 238, 0.6); box-shadow: var(--glow); }
#setup small { color: var(--text-faint); font-size: 13px; }
#setup .between { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
#setup .between small { font-family: var(--mono); font-size: 12px; }
#setup .between button {
  min-height: 36px; padding: 0 14px; border: 1px solid var(--border); border-radius: 999px; background: none;
  font-size: 13px; color: var(--text-muted); transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
#setup .between button:hover { color: var(--text); border-color: var(--border-strong); }
#setup .start { display: flex; gap: 12px; flex-wrap: wrap; margin: 10px 0 2px; }
#setup .start button {
  min-height: 52px; padding: 0 24px; border-radius: var(--radius); font-weight: 600; font-size: 16px;
  display: inline-flex; align-items: center; gap: 10px; transition: transform 0.15s var(--ease), box-shadow 0.2s var(--ease);
}
#setup .start button .icon { width: 20px; height: 20px; }
#startVoice { border: 0; background: var(--grad); color: var(--primary-ink); box-shadow: 0 8px 30px rgba(34, 211, 238, 0.25); }
#startVoice:hover { box-shadow: 0 10px 40px rgba(99, 102, 241, 0.45); transform: translateY(-1px); }
#startText { border: 1px solid var(--border-strong); background: var(--surface); }
#startText:hover { background: var(--surface-hover); }
#setup .start button:disabled { opacity: 0.5; transform: none; }

.warn {
  background: var(--danger-soft); color: var(--danger-text); border: 1px solid rgba(244, 63, 94, 0.35);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 14px;
}

/* Phone call: number + Call button under the prompt */
.phone-box { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.phone-row { display: flex; gap: 10px; flex-wrap: wrap; }
#phoneInput {
  flex: 1 1 220px; min-height: 52px; padding: 0 16px; font: 16px var(--mono); color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
#phoneInput:focus { outline: none; border-color: rgba(34, 211, 238, 0.6); box-shadow: var(--glow); }
#startCall {
  min-height: 52px; padding: 0 22px; border-radius: var(--radius); font-weight: 600; display: inline-flex; align-items: center; gap: 10px;
  border: 1px solid rgba(52, 211, 153, 0.5); background: rgba(52, 211, 153, 0.1); color: var(--success);
}
#startCall:hover { box-shadow: 0 0 24px rgba(52, 211, 153, 0.25); }
#startCall:disabled { opacity: 0.5; }
.call-info {
  max-width: 860px; width: calc(100% - 40px); margin: 14px auto 0; padding: 10px 14px; display: flex; align-items: center; gap: 10px;
  font-family: var(--mono); font-size: 13px; color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.call-info.live { color: var(--success); border-color: rgba(52, 211, 153, 0.45); }
.call-info.live .icon { animation: eq 0.9s ease-in-out infinite alternate; }
#convList button span .icon { width: 14px; height: 14px; margin-right: 6px; vertical-align: -2px; color: var(--success); }

/* ---------- Conversation ---------- */
#session { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#session[hidden], #setup[hidden] { display: none; }
#promptView { max-width: 860px; width: 100%; margin: 12px auto 0; padding: 0 20px; font-size: 13px; color: var(--text-muted); }
#promptView summary {
  cursor: pointer; font-family: var(--mono); font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-faint); padding: 6px 0; width: max-content;
}
#promptView summary:hover { color: var(--primary); }
#promptView pre {
  white-space: pre-wrap; font: 13px/1.6 var(--mono); color: var(--text-muted); margin: 6px 0 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px;
  max-height: 260px; overflow-y: auto;
}
.talk { flex: 1; display: flex; min-height: 0; width: 100%; max-width: 1100px; margin: 0 auto; }
#scoreCard {
  width: 240px; flex: none; margin: 20px 20px 20px 0; padding: 16px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: auto;
}
#scoreCard h2 { margin: 0 0 8px; font-size: 14px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); }
#scoreList { list-style: none; margin: 0; padding: 0; }
#scoreList li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
#scoreNote { margin: 12px 0 0; font-size: 14px; color: var(--text-muted); }
#chat {
  flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px;
  width: 100%; margin: 0;
}
.msg {
  padding: 12px 16px; border-radius: 18px; max-width: 78%; white-space: pre-wrap; line-height: 1.55; overflow-wrap: anywhere;
  animation: msg-in 0.28s var(--ease);
}
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.user { align-self: flex-end; background: var(--grad-user); color: #fff; border-bottom-right-radius: 6px; box-shadow: 0 6px 24px rgba(67, 56, 202, 0.25); }
.assistant {
  align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.error { align-self: flex-start; background: var(--danger-soft); color: var(--danger-text); border: 1px solid rgba(244, 63, 94, 0.35); }
.note, .empty { align-self: center; color: var(--text-faint); font-size: 14px; text-align: center; background: none; }

form#form {
  padding: 14px 20px 18px; background: #ffffff; border-top: 1px solid var(--border);
}
#status {
  max-width: 860px; margin: 0 auto 10px; font-size: 13px; color: var(--text-muted); font-family: var(--mono);
  display: flex; align-items: center; gap: 10px;
}
/* live voice: a small equalizer next to the status */
body.live #status::before {
  content: ""; width: 22px; height: 14px; flex: none;
  background:
    linear-gradient(var(--primary), var(--primary)) 0 50% / 3px 40% no-repeat,
    linear-gradient(var(--primary), var(--primary)) 6px 50% / 3px 90% no-repeat,
    linear-gradient(var(--violet), var(--violet)) 12px 50% / 3px 60% no-repeat,
    linear-gradient(var(--violet), var(--violet)) 18px 50% / 3px 30% no-repeat;
  animation: eq 1s ease-in-out infinite alternate;
}
@keyframes eq { to { background-size: 3px 90%, 3px 35%, 3px 95%, 3px 70%; } }
.row { display: flex; gap: 10px; max-width: 860px; margin: 0 auto; align-items: flex-end; }
#input {
  flex: 1; resize: none; padding: 12px 16px; font: inherit; color: var(--text); min-height: 48px; max-height: 160px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
#input::placeholder { color: var(--text-faint); }
#input:focus { outline: none; border-color: rgba(34, 211, 238, 0.6); box-shadow: var(--glow); }
form#form button {
  min-height: 48px; min-width: 48px; border-radius: var(--radius); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 18px; font-weight: 600; transition: box-shadow 0.2s var(--ease), opacity 0.2s var(--ease);
}
#send { border: 0; background: var(--grad); color: var(--primary-ink); }
#send:hover { box-shadow: 0 6px 24px rgba(34, 211, 238, 0.35); }
#send:disabled { opacity: 0.45; box-shadow: none; }
#stop { border: 1px solid var(--border-strong); background: var(--surface); }
#mic { padding: 0 !important; border: 1px solid var(--border-strong); background: var(--surface); color: var(--primary); }
#mic .icon { width: 20px; height: 20px; }
#mic:disabled { opacity: 0.45; }
#mic.listening { background: var(--danger); border-color: var(--danger); color: #fff; animation: live-ring 1.4s ease-out infinite; }

/* ---------- Configuration page ---------- */
body.config { height: auto; min-height: 100vh; }
body.config header { position: sticky; top: 0; z-index: 5; }
#config { max-width: 680px; width: 100%; margin: 0 auto; padding: 28px 16px 48px; }
#config .note { color: var(--text-muted); font-size: 14px; line-height: 1.6; margin-top: 0; }
#config p.warn { margin: 0 0 16px; }
#settings { padding: 0; background: none; border: 0; display: flex; flex-direction: column; gap: 16px; }
#settings fieldset {
  margin: 0; min-width: 0; padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#settings fieldset[hidden], #settings .group[hidden] { display: none; }
#settings legend {
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--primary);
  padding: 0 8px; background: var(--surface-solid); border-radius: 6px;
}
#settings label { font-size: 14px; font-weight: 500; margin-top: 10px; color: var(--text-muted); }
#settings label.check { display: flex; align-items: center; gap: 10px; margin-top: 0; color: var(--text); min-height: 32px; }
#settings input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }
#settings input:not([type="checkbox"]), #settings select {
  font: inherit; color: var(--text); min-height: 44px; padding: 10px 12px; width: 100%; min-width: 0;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
#settings input:focus, #settings select:focus { outline: none; border-color: rgba(34, 211, 238, 0.6); box-shadow: var(--glow); }
#settings input::placeholder { color: var(--text-faint); }
#settings optgroup { color: var(--text-faint); background: var(--surface-solid); }
#settings option { color: var(--text); background: var(--surface-solid); }
#settings small { color: var(--text-faint); font-size: 13px; }
#settings .group { display: flex; flex-direction: column; gap: 6px; }
#settings .inline { display: flex; gap: 8px; }
#settings .inline button, #settings .buttons button {
  min-height: 44px; display: inline-flex; align-items: center; gap: 8px; padding: 0 16px; white-space: nowrap;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg-2);
  transition: background 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
#settings .inline button:hover, #settings .buttons button:hover { background: var(--surface-hover); }
#listen { color: var(--primary); border-color: rgba(34, 211, 238, 0.45) !important; }
#settings .buttons { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#settings #save { border: 0; background: var(--grad); color: var(--primary-ink); font-weight: 600; }
#settings #save:hover { box-shadow: 0 6px 24px rgba(34, 211, 238, 0.35); }
#settings button:disabled { opacity: 0.45; box-shadow: none; }
#saved { color: var(--success); font-size: 14px; }

/* ---------- Login page ---------- */
body.login { align-items: center; justify-content: center; padding: 16px; }
#login {
  width: 100%; max-width: 380px; padding: 32px 28px; border-radius: 20px; text-align: left;
  background: var(--surface); border: 1px solid var(--border-strong);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}
#login .logo { width: 40px; height: 40px; display: block; margin-bottom: 16px; }
#login h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
#login p { margin: 4px 0 20px; font-family: var(--mono); font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--primary); }
#loginForm { padding: 0; border: 0; background: none; display: flex; flex-direction: column; gap: 6px; }
#loginForm label { font-size: 14px; font-weight: 500; margin-top: 8px; color: var(--text-muted); }
#loginForm input {
  font: inherit; color: var(--text); min-height: 46px; padding: 10px 12px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
#loginForm input:focus { outline: none; border-color: rgba(34, 211, 238, 0.6); box-shadow: var(--glow); }
#loginForm button {
  margin-top: 18px; min-height: 48px; border: 0; border-radius: var(--radius-sm); background: var(--grad);
  color: var(--primary-ink); font-weight: 700; transition: box-shadow 0.2s var(--ease);
}
#loginForm button:hover { box-shadow: 0 8px 30px rgba(34, 211, 238, 0.35); }
#loginForm button:disabled { opacity: 0.6; }
#loginForm .warn { margin-top: 8px; }

/* ---------- Phones ---------- */
@media (max-width: 800px) {
  #menu { display: inline-flex; }
  #sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 20; transform: translateX(-100%);
    transition: transform 0.25s var(--ease); background: var(--surface-solid); box-shadow: 8px 0 40px rgba(0, 0, 0, 0.5);
  }
  #sidebar.open { transform: none; }
  header { padding: 8px 12px; gap: 8px; }
  header .actions .label { display: none; }
  header .actions button, header .actions a.button { width: 40px; padding: 0; justify-content: center; }
  .msg { max-width: 88%; }
  .talk { flex-direction: column; }
  #scoreCard { width: auto; margin: 0 16px 12px; }
  #setup { padding: 24px 16px 40px; }
  #setup .start button { flex: 1 1 100%; justify-content: center; }
  form#form { padding: 10px 12px 14px; }
  #send .label, #stop .label { display: none; }
  #send, #stop { padding: 0 !important; width: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
