/* Charla embed UI — one column, mobile-first (estate mobile rule). Accent comes in
   via the --accent custom property set from /api/config at boot. */
:root {
  --accent: #2563eb;
  --ink: #14213d;
  --ink-soft: #5b6478;
  --bg: #f5f7fb;
  --bubble-bot: #ffffff;
  --bubble-user: var(--accent);
  --radius: 16px;
}
* { box-sizing: border-box; margin: 0; }
html, body, .chat { height: 100%; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
}
.chat { display: flex; flex-direction: column; }

.head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; background: var(--accent); color: #fff;
}
.head-title { font-weight: 700; font-size: 16px; }
.head-sub { font-size: 12.5px; opacity: .85; }
.head-txt { flex: 1; min-width: 0; }

.log {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.msg { max-width: 86%; padding: 10px 14px; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: break-word; }
.msg.bot { background: var(--bubble-bot); border: 1px solid #e5e9f2; align-self: flex-start; border-bottom-left-radius: 6px; }
.msg.user { background: var(--bubble-user); color: #fff; align-self: flex-end; border-bottom-right-radius: 6px; }
.msg .cite { display: block; margin-top: 6px; font-size: 11.5px; color: var(--ink-soft); }
.msg.bot .play { margin-top: 6px; font-size: 12px; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; }
.status { align-self: flex-start; font-size: 12.5px; color: var(--ink-soft); padding: 0 4px; }
.status.rec { color: #d43f3f; font-weight: 600; }

.qprogress {
  padding: 6px 16px; font-size: 12.5px; color: var(--ink-soft);
  background: #eef2f9; border-top: 1px solid #e5e9f2;
}

/* ── Composer: VOICE-FIRST (Liam, 2026-08-05) ──
   The microphone is the primary control, full width, labelled. Typing is one tap
   away behind "Prefiero escribir" — available, but not the default path in. */
.composer {
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  padding: 12px; background: #fff; border-top: 1px solid #e5e9f2;
}
.composer .mic {
  width: 100%; min-height: 60px; border: 0; border-radius: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--accent); color: #fff; font: 700 17px system-ui, sans-serif;
  box-shadow: 0 4px 16px rgba(27,111,191,.28); transition: transform .12s, filter .12s;
}
.composer .mic:hover { filter: brightness(1.07); transform: translateY(-1px); }
.composer .mic svg { width: 24px; height: 24px; }
.composer .mic.rec {
  background: #d43f3f;
  color: #fff;                     /* label + icon MUST contrast the red (never inherit) */
  box-shadow: 0 4px 16px rgba(212,63,63,.34);
  animation: rec-pulse 1.3s ease-in-out infinite;
}
.composer .mic.rec svg { fill: #fff; }
@keyframes rec-pulse { 50% { box-shadow: 0 4px 24px rgba(212,63,63,.62); } }
.mic-hint { margin: 0; text-align: center; font-size: 12.5px; color: var(--ink-soft); }
.type-toggle {
  align-self: center; border: 0; background: none; color: var(--accent);
  font: 600 13.5px system-ui, sans-serif; cursor: pointer; padding: 4px 8px;
  text-decoration: underline; text-underline-offset: 3px;
}
.type-row { display: none; gap: 8px; align-items: flex-end; }
.composer.typing .type-row { display: flex; }
/* Typing mode is TYPING mode: the voice controls get out of the way entirely —
   "Volver a hablar" is the way back (Liam, 2026-08-05). */
.composer.typing .mic-row,
.composer.typing .mic-hint { display: none; }
.composer.typing #input {
  min-height: 88px;                /* a consulta is a sentence or two, not a word */
  max-height: 240px;
}
.choices { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 4px; }
.choices button {
  border: 1.5px solid var(--accent); color: var(--accent); background: #fff;
  border-radius: 999px; padding: 7px 14px; font-size: 14px; cursor: pointer;
}
.choices button:hover { background: var(--accent); color: #fff; }
#input {
  flex: 1; min-width: 0; resize: vertical; border: 1.5px solid #d7deeb;
  border-radius: 12px; padding: 12px 14px; font: inherit; line-height: 1.5;
  min-height: 88px; max-height: 240px; outline-color: var(--accent);
}
.a11y .composer.typing #input { min-height: 104px; font-size: 17px; }
.icon-btn {
  border: 0; background: none; cursor: pointer; width: 40px; height: 40px;
  display: grid; place-items: center; border-radius: 10px; color: inherit;
}
.icon-btn:hover { background: rgba(0,0,0,.06); }
.head .icon-btn:hover { background: rgba(255,255,255,.18); }
/* (the old .mic / .mic.rec rules were removed — they came after .composer .mic in
   source order and repainted the recording label red-on-red, hiding the text) */
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(212,63,63,.15); } }
.send {
  border: 0; background: var(--accent); color: #fff; border-radius: 12px;
  padding: 10px 16px; font: 600 14px system-ui, sans-serif; cursor: pointer;
}
.send:disabled, .mic:disabled { opacity: .5; cursor: default; }

/* Boti-style lettered options in the conversation */
.opts { display: flex; flex-direction: column; gap: 6px; align-self: flex-start; max-width: 86%; }
.opts button {
  text-align: left; border: 1.5px solid var(--accent); background: #fff; color: var(--accent);
  border-radius: 12px; padding: 9px 14px; font: 14px/1.4 system-ui, sans-serif; cursor: pointer;
}
.opts button b { margin-right: 2px; }
.opts button:hover { background: var(--accent); color: #fff; }
.opts.used button { opacity: .45; pointer-events: none; }

/* Collapsed guided menu — conversation-first opening (SPEC §6 W6) */
.opts-collapse { align-self: flex-start; max-width: 86%; }
.opts-toggle {
  border: 1.5px dashed var(--accent); background: #fff; color: var(--accent);
  border-radius: 999px; padding: 7px 15px; font: 600 13.5px system-ui, sans-serif; cursor: pointer;
}
.opts-toggle:hover { background: var(--accent-soft, #eef4ff); }
.opts-collapse .opts { margin-top: 8px; }

/* ── Accessible mode: larger type, high contrast, a big labelled mic ──
   Norberto (2026-08-05): "hay mucha gente que no ve bien… sería muy conveniente
   si es todo hablado". Everything is still shown in writing as well. */
.a11y body { font-size: 17.5px; }
.a11y .msg { max-width: 94%; padding: 13px 16px; font-size: 1.05em; line-height: 1.6; }
.a11y .msg.bot { border-color: #b9c6dd; }
.a11y .msg .cite { font-size: 13px; }
.a11y .msg.bot .play { font-size: 15px; font-weight: 600; padding: 6px 0; }
.a11y .head-title { font-size: 18px; }
.a11y #input { font-size: 17px; padding: 13px 14px; }
.a11y .send { font-size: 16px; padding: 13px 20px; }
.a11y .opts button, .a11y .opts-toggle { font-size: 16px; padding: 12px 18px; }
.a11y .status { font-size: 15px; }
.a11y .composer { padding: 12px; gap: 10px; }
/* accessible mode just makes the (already primary) mic bigger still */
.a11y .composer .mic { min-height: 74px; font-size: 19px; border-radius: 18px; }
.a11y .composer .mic svg { width: 28px; height: 28px; }
.a11y .mic-hint { font-size: 14px; }
.a11y .type-toggle { font-size: 15px; }

/* ── Voice mode: one obvious labelled control, not a bare icon ──
   Liam 2026-08-05: "there needs to be a completely different button to switch to
   voice mode". Turning it on also reads aloud everything not yet spoken. */
.voice-pill {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1.5px solid rgba(255,255,255,.55); background: rgba(255,255,255,.14);
  color: #fff; border-radius: 999px; padding: 7px 14px 7px 11px;
  font: 700 13.5px system-ui, sans-serif; cursor: pointer; white-space: nowrap;
}
.voice-pill:hover { background: rgba(255,255,255,.26); }
.voice-pill.on { background: #fff; color: var(--accent); border-color: #fff; }
.voice-pill svg { display: block; }
.a11y .voice-pill { font-size: 15px; padding: 9px 17px 9px 13px; }
@media (max-width: 380px) { .voice-pill span:last-child { display: none; } }

/* ── Speaking controls in the composer (Liam, 2026-08-05) ──
   Stop sits NEXT TO the mic and is red, visible only while the bot speaks.
   Repeat sits BENEATH the mic and appears once there is something to replay. */
.mic-row { display: flex; gap: 8px; align-items: stretch; }
.mic-row .mic { flex: 1; }
.stop-speak {
  flex: 0 0 auto; min-width: 132px; border: 0; border-radius: 16px; cursor: pointer;
  font: 700 16px system-ui, sans-serif;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.stop-speak.is-stop {
  background: #d43f3f; color: #fff;
  box-shadow: 0 4px 16px rgba(212,63,63,.32);
  animation: stop-pulse 1.5s ease-in-out infinite;
}
.stop-speak.is-repeat {
  background: #fff; color: var(--accent); border: 1.5px solid var(--accent);
  animation: none; box-shadow: none;
}
.stop-speak:hover { filter: brightness(1.06); }
@keyframes stop-pulse { 50% { box-shadow: 0 4px 22px rgba(212,63,63,.55); } }
.repeat-btn {
  align-self: center; border: 1.5px solid var(--accent); background: #fff;
  color: var(--accent); border-radius: 999px; padding: 8px 18px; cursor: pointer;
  font: 600 14px system-ui, sans-serif;
}
.repeat-btn:hover { background: var(--accent); color: #fff; }
.a11y .stop-speak { min-width: 150px; font-size: 18px; }
.a11y .repeat-btn { font-size: 16px; padding: 10px 22px; }
@media (max-width: 420px) {
  .mic-row { flex-direction: column; }
  .stop-speak { min-height: 48px; }
}

/* Live dictation bubble: the citizen's words as they are being said (SPEC §V6).
   Deliberately styled as a user message in progress, not a status line — it is
   what they said, it just isn't finished yet. */
.msg.user.live { opacity: .75; font-style: italic; }
.msg.user.live::after { content: '…'; }

/* Low-data mode: audio is off entirely, so every audio affordance goes away
   rather than sitting there looking broken. */
html.lowdata .mic-row,
html.lowdata .mic-hint,
html.lowdata .play,
html.lowdata .play-box,
html.lowdata #voice-toggle { display: none; }

/* No voice input on this surface (public demo / low-data): remove the mic and
   its hint entirely rather than leaving a control that refuses to work. */
html.novoicein .mic-row,
html.novoicein .mic-hint { display: none; }
/* Text-only assistant (SPEC §6 W9 voice:"off"): no voice affordance exists at all. */
html.novoice .mic-row,
html.novoice .mic-hint,
html.novoice .type-toggle,
html.novoice .play,
html.novoice .play-box,
html.novoice .stop-speak,
html.novoice #voice-toggle,
html.novoice #a11y-toggle,
html.novoice #data-toggle { display: none; }
.close-btn { color: #fff; }
.close-btn[hidden] { display: none; }

/* ── consent gate (SPEC §16 — AI disclosure + Ley 25.326 express consent) ── */
.consent{position:fixed;inset:0;z-index:100;display:grid;place-items:center;
  background:rgba(15,23,42,.55);padding:16px}
.consent-card{background:#fff;border-radius:16px;max-width:480px;width:100%;
  padding:24px 22px;box-shadow:0 12px 40px rgba(0,0,0,.25);font-size:16px;line-height:1.5}
.consent-card h2{margin:0 0 10px;font-size:20px}
.consent-card p{margin:0 0 10px;color:#334155}
.consent-card a{color:var(--accent,#2563eb)}
.consent-check{display:flex;gap:10px;align-items:flex-start;margin:14px 0;cursor:pointer}
.consent-check input{width:22px;height:22px;flex:none;margin-top:1px;accent-color:var(--accent,#2563eb)}
.consent-btn{width:100%;padding:13px;border:0;border-radius:12px;background:var(--accent,#2563eb);
  color:#fff;font-size:17px;font-weight:600;cursor:pointer}
.consent-btn:disabled{opacity:.45;cursor:not-allowed}
.a11y .consent-card{font-size:19px}
.a11y .consent-card h2{font-size:24px}
.a11y .consent-btn{font-size:20px;padding:16px}

/* ── per-message play control: icon-only, beside the bubble (same line) ── */
.msg-row { display: flex; align-items: flex-end; gap: 8px; align-self: flex-start; max-width: 92%; }
.msg-row .msg { max-width: 100%; align-self: auto; }
.play-box { flex: none; }
.play-btn {
  display: grid; place-items: center; width: 38px; height: 34px;
  background: var(--bubble-bot); border: 1px solid #e5e9f2; border-radius: 10px;
  border-top-left-radius: 6px; color: var(--accent); cursor: pointer;
}
.play-btn:hover { background: #eef2f9; }
.play-btn.playing { background: var(--accent); color: #fff; border-color: var(--accent); }
.a11y .play-btn { width: 48px; height: 42px; }
.a11y .play-btn svg { width: 24px; height: 24px; }

/* ── header toggles show their state, not just announce it (2026-09-07) ── */
.icon-btn[aria-pressed="true"] {
  background: #fff; color: var(--accent);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.9);
}
.icon-btn[aria-pressed="true"]:hover { background: #fff; }
/* low-data ON = audio off: the slash says so at a glance */
#data-toggle { position: relative; }
#data-toggle[aria-pressed="true"]::after {
  content: ""; position: absolute; left: 8px; right: 8px; top: 50%;
  height: 2.5px; border-radius: 2px; background: currentColor;
  transform: rotate(-45deg);
}

/* ── confirm dialog buttons (shares the consent overlay/card) ── */
.dialog-row { display: flex; gap: 10px; margin-top: 14px; }
.dialog-row .consent-btn { flex: 1; width: auto; }
.dialog-cancel {
  flex: 1; padding: 13px; border: 1px solid #cbd5e1; border-radius: 12px;
  background: #fff; color: #334155; font-size: 17px; font-weight: 600; cursor: pointer;
}
/* Notice mode (SPEC §16 R16.4): the privacy line under the composer. */
.privacy-notice{margin:0;text-align:center;font-size:11.5px;line-height:1.4;color:var(--ink-soft)}
.privacy-notice a{color:inherit;text-decoration:underline;text-underline-offset:2px}
