﻿:root {
  /* Default theme — The University of Faisalabad brand colors (maroon + terracotta) */
  --bg: #faf6f5;
  --sidebar: #f4ece9;
  --panel: #ffffff;
  --panel-2: #f7eeeb;
  --border: #e9dcd8;
  --border-hover: #d9c3bd;
  --text: #241417;
  --muted: #8a7378;
  --placeholder: #a3898d;
  --accent: #a81d21;
  --accent-2: #ca856f;
  --accent-rgb: 168, 29, 33;
  --accent2-rgb: 202, 133, 111;
  --grad: linear-gradient(135deg, #a81d21 0%, #ca856f 100%);
  --user-bubble: #f6e8e3;
  --danger: #c2410c;
  --danger-rgb: 194, 65, 12;
  --switch-off: #ddcac5;
  --scrollbar: #ddcac5;
  --dev-border: #c9a02e;
  --dev-text: #8a6a12;
  --radius: 16px;
}

:root[data-theme="dark"] {
  --bg: #0b0f1a;
  --sidebar: #0f1524;
  --panel: #151c2e;
  --panel-2: #1b243a;
  --border: #243049;
  --border-hover: #33426a;
  --text: #e8ecf5;
  --muted: #8b97b1;
  --placeholder: #66718c;
  --accent: #6d8bff;
  --accent-2: #8b5cf6;
  --accent-rgb: 109, 139, 255;
  --accent2-rgb: 139, 92, 246;
  --grad: linear-gradient(135deg, #5b7cff 0%, #8b5cf6 100%);
  --user-bubble: #1f2a44;
  --danger: #ff5c72;
  --danger-rgb: 255, 92, 114;
  --switch-off: #2b3654;
  --scrollbar: #232d47;
  --dev-border: #5b4a1f;
  --dev-text: #e9b949;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }

#app { display: flex; height: 100vh; height: 100dvh; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: 290px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 4px 0; }
.logo {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center; color: #fff;
  background: var(--grad);
  box-shadow: 0 6px 18px rgba(var(--accent-rgb), .35);
}
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; }
.brand-sub { font-size: .75rem; color: var(--muted); }

.new-chat {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-weight: 600; font-size: .9rem;
  transition: background .15s, border-color .15s, transform .1s;
}
.new-chat:hover { background: var(--panel-2); border-color: var(--border-hover); }
.new-chat:active { transform: scale(.98); }

.settings { display: flex; flex-direction: column; gap: 14px; }
.section-label {
  font-size: .7rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted); padding: 4px 4px 0;
}

.field { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; color: var(--muted); }
.field span { padding-left: 2px; }

select, input[type="text"] {
  width: 100%;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit; font-size: .92rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a7378' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
select:focus, input[type="text"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .18); }
input::placeholder, textarea::placeholder { color: var(--placeholder); }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; }
.seg-btn { border: none; background: transparent; color: var(--muted); padding: 8px 10px; border-radius: 9px; font-size: .88rem; font-weight: 600; transition: background .2s, color .2s; }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--grad); color: #fff; box-shadow: 0 4px 12px rgba(var(--accent-rgb), .35); }

.switch {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel); font-size: .9rem; cursor: pointer;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.track { width: 38px; height: 22px; border-radius: 99px; background: var(--switch-off); position: relative; transition: background .2s; flex-shrink: 0; }
.thumb { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track .thumb { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .3); }

.sidebar-foot { margin-top: auto; font-size: .72rem; line-height: 1.5; color: var(--muted); padding: 0 4px; }

/* ---------- Main ---------- */
#main { flex: 1; min-width: 0; overflow: hidden; display: flex; flex-direction: column; position: relative; }

.topbar {
  display: none;
  align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1rem; margin: 0; font-weight: 600; }
.icon-btn { background: none; border: none; padding: 6px; border-radius: 8px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--panel); }

#chat {
  flex: 1;
  overflow-y: auto;
  padding: 28px 20px 12px;
  display: flex; flex-direction: column;
  scroll-behavior: smooth;
}
.msg { width: 100%; max-width: 780px; margin: 0 auto 22px; display: flex; gap: 14px; animation: rise .28s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.msg.user { justify-content: flex-end; }
.msg.user .body {
  background: var(--user-bubble);
  border: 1px solid var(--border);
  padding: 11px 16px;
  border-radius: 18px 18px 6px 18px;
  max-width: 82%;
}
.msg.assistant .avatar {
  width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; color: #fff; background: var(--grad);
  margin-top: 2px;
}
.msg.assistant .body { flex: 1; min-width: 0; padding-top: 4px; }
.body { line-height: 1.7; font-size: .97rem; overflow-wrap: anywhere; }
.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }
.body p { margin: 0 0 .8em; }
.body ul, .body ol { padding-inline-start: 1.4em; }
.body[dir="rtl"] { text-align: right; }
/* Urdu reads properly only in a Nastaliq font, at a larger size and taller line-height than Latin/Naskh text */
.body[lang="ur"] { font-family: "Noto Nastaliq Urdu", "Segoe UI", sans-serif; font-size: 1.15em; line-height: 2.1; }
.body[lang="ar"], .body[lang="fa"] { font-family: "Noto Naskh Arabic", "Segoe UI", sans-serif; font-size: 1.05em; line-height: 1.9; }
#message[lang="ur"], #message[dir="rtl"] { font-family: "Noto Nastaliq Urdu", "Segoe UI", sans-serif; }
.body pre {
  background: #0a0e18; border: 1px solid var(--border);
  padding: 14px; border-radius: 12px; overflow-x: auto; font-size: .87rem;
}
.body code { font-family: "JetBrains Mono", Consolas, monospace; font-size: .9em; }
.body :not(pre) > code { background: var(--panel-2); padding: 2px 6px; border-radius: 6px; }
.body table { border-collapse: collapse; }
.body th, .body td { border: 1px solid var(--border); padding: 6px 10px; }

.continue-btn {
  display: inline-flex; align-items: center; margin-top: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 99px;
  padding: 8px 16px; font-size: .85rem; font-weight: 600; color: var(--text);
  transition: background .15s, border-color .15s, transform .1s;
}
.continue-btn:hover { background: var(--panel-2); border-color: var(--accent); }
.continue-btn:active { transform: scale(.97); }

/* Typing dots */
.typing { display: inline-flex; gap: 5px; padding: 10px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: bounce 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .4; } 40% { transform: scale(1); opacity: 1; } }

/* Empty state */
.empty { margin: auto; text-align: center; width: 100%; max-width: 560px; padding: 20px; animation: rise .4s ease both; }
.empty-logo {
  width: 64px; height: 64px; border-radius: 20px; margin: 0 auto 18px;
  display: grid; place-items: center; color: #fff; background: var(--grad);
  box-shadow: 0 12px 36px rgba(var(--accent-rgb), .35);
}
.empty h2 { margin: 0 0 8px; font-size: 1.6rem; letter-spacing: -.02em; }
.empty p { margin: 0 0 22px; color: var(--muted); line-height: 1.6; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  background: var(--panel); border: 1px solid var(--border); border-radius: 99px;
  padding: 9px 15px; font-size: .85rem; color: var(--text);
  transition: background .15s, border-color .15s, transform .1s;
}
.chip:hover { background: var(--panel-2); border-color: var(--accent); }
.chip:active { transform: scale(.97); }

/* Speaking indicator */
.speaking {
  align-self: center;
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 10px; padding: 8px 10px 8px 16px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 99px;
  font-size: .85rem; color: var(--muted);
  animation: rise .25s ease both;
}
.speaking[hidden] { display: none; }
.speaking button {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 99px; padding: 5px 12px; font-size: .8rem;
}
.speaking button:hover { border-color: var(--danger); color: var(--danger); }
.wave { display: inline-flex; align-items: center; gap: 3px; height: 20px; }
.wave i { width: 3px; border-radius: 3px; background: var(--grad); background: var(--accent); animation: wave 1s ease-in-out infinite; }
.wave i:nth-child(1) { animation-delay: 0s; }
.wave i:nth-child(2) { animation-delay: .12s; }
.wave i:nth-child(3) { animation-delay: .24s; }
.wave i:nth-child(4) { animation-delay: .36s; }
.wave i:nth-child(5) { animation-delay: .48s; }
@keyframes wave { 0%, 100% { height: 5px; } 50% { height: 20px; } }

/* ---------- Composer ---------- */
.composer-wrap { padding: 0 20px 18px; }
.composer {
  max-width: 780px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 8px 8px 8px 20px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, .35);
  transition: border-color .2s, box-shadow .2s;
  position: relative;
}
.composer:focus-within { border-color: var(--border-hover); box-shadow: 0 10px 32px rgba(0, 0, 0, .35), 0 0 0 3px rgba(var(--accent-rgb), .12); }

textarea {
  flex: 1; resize: none; border: none; outline: none; background: transparent;
  color: var(--text); font: inherit; font-size: 1rem; line-height: 1.5;
  padding: 9px 0; max-height: 180px;
}

.mic, .send {
  width: 42px; height: 42px; border-radius: 50%; border: none; flex-shrink: 0;
  display: grid; place-items: center;
  transition: transform .12s, background .2s, opacity .2s, box-shadow .2s;
}
.mic { background: transparent; color: var(--muted); }
.mic:hover { background: var(--panel-2); color: var(--text); }
.mic .ic-stop { display: none; }

.send { background: var(--grad); color: #fff; box-shadow: 0 6px 18px rgba(var(--accent-rgb), .4); }
.send:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(var(--accent-rgb), .5); }
.send:active:not(:disabled) { transform: scale(.94); }
.send:disabled { background: var(--panel-2); color: #5a6685; box-shadow: none; cursor: not-allowed; }

.voice-lang {
  width: auto; align-self: center; flex-shrink: 0;
  background-color: var(--panel-2); border: 1px solid var(--border); border-radius: 99px;
  padding: 6px 26px 6px 12px; font-size: .8rem; font-weight: 600; color: var(--muted);
  background-position: right 9px center; cursor: pointer;
}
.voice-lang:hover, .voice-lang:focus { color: var(--text); }
.composer.recording .voice-lang { display: none; }

/* Listening state */
.listening { display: none; flex: 1; align-items: center; gap: 14px; padding: 6px 0; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse-dot 1.2s infinite; flex-shrink: 0; }
@keyframes pulse-dot { 0% { box-shadow: 0 0 0 0 rgba(var(--danger-rgb), .6); } 70% { box-shadow: 0 0 0 10px rgba(var(--danger-rgb), 0); } 100% { box-shadow: 0 0 0 0 rgba(var(--danger-rgb), 0); } }
.bars { display: flex; align-items: center; gap: 4px; height: 32px; flex: 1; max-width: 260px; }
.bars i { flex: 1; min-width: 3px; height: 4px; border-radius: 3px; background: var(--accent); transition: height .08s linear; }

.composer.recording textarea { display: none; }
.composer.recording .listening { display: flex; }
.composer.recording .mic { background: var(--danger); color: #fff; animation: ring 1.4s infinite; }
.composer.recording .mic .ic-mic { display: none; }
.composer.recording .mic .ic-stop { display: block; }
.composer.recording { border-color: rgba(var(--danger-rgb), .5); }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(var(--danger-rgb), .55); } 70% { box-shadow: 0 0 0 14px rgba(var(--danger-rgb), 0); } 100% { box-shadow: 0 0 0 0 rgba(var(--danger-rgb), 0); } }

#status { max-width: 780px; margin: 8px auto 0; text-align: center; font-size: .78rem; color: var(--muted); min-height: 1.1em; }

/* ---------- Mobile ---------- */
#backdrop { display: none; }
@media (max-width: 820px) {
  #sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 30; width: 300px; max-width: 86vw;
    transform: translateX(-100%); transition: transform .25s ease;
  }
  #app.menu-open #sidebar { transform: none; box-shadow: 0 0 60px rgba(0, 0, 0, .6); }
  #app.menu-open #backdrop { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .55); }
  .topbar { display: flex; }
  #chat { padding: 18px 14px 8px; }
  .composer-wrap { padding: 0 12px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 10px; border: 2px solid var(--bg); }

/* ---------- Login ---------- */
.login {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px;
  background:
    radial-gradient(900px 500px at 15% 10%, rgba(var(--accent-rgb), .18), transparent 60%),
    radial-gradient(800px 500px at 90% 90%, rgba(var(--accent2-rgb), .16), transparent 60%),
    var(--bg);
}
.login[hidden], #app[hidden] { display: none; }
.login-card {
  width: 100%; max-width: 420px; text-align: center; padding: 38px 32px 30px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 24px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .5); animation: rise .4s ease both;
}
.logo.big { width: 64px; height: 64px; border-radius: 20px; margin: 0 auto 18px; box-shadow: 0 12px 36px rgba(var(--accent-rgb), .4); }
.login-card h1 { margin: 0 0 4px; font-size: 1.6rem; letter-spacing: -.02em; }
.login-sub { margin: 0 0 22px; color: var(--muted); font-size: .9rem; }
.login-note { margin: 0 0 22px; color: var(--muted); font-size: .9rem; line-height: 1.6; }
.login-note b { color: var(--text); }
.g-btn { display: flex; justify-content: center; min-height: 44px; }
.login-error { min-height: 1.2em; margin: 16px 0 0; color: var(--danger); font-size: .85rem; line-height: 1.5; }
.dev-login { margin-top: 18px; display: grid; gap: 10px; padding: 14px; border: 1px dashed var(--dev-border); border-radius: 14px; background: rgba(250, 190, 60, .09); }
.dev-login[hidden] { display: none; }
.dev-tag { font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--dev-text); }
.dev-login input { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font: inherit; outline: none; }
.dev-login input:focus { border-color: var(--accent); }
.dev-login button { background: var(--grad); color: #fff; border: none; border-radius: 10px; padding: 10px; font-weight: 600; }

/* ---------- Chat history ---------- */
.history { flex: 1; min-height: 110px; overflow-y: auto; margin: 0 -6px; padding: 0 6px; display: flex; flex-direction: column; gap: 2px; }
.history-label { font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 12px 8px 6px; }
.history-empty { color: var(--muted); font-size: .85rem; padding: 16px 8px; text-align: center; }
.chat-item { position: relative; display: flex; align-items: center; border-radius: 10px; transition: background .15s; }
.chat-item:hover, .chat-item.active { background: var(--panel); }
.chat-item.active { box-shadow: inset 2px 0 0 var(--accent); }
.chat-title {
  flex: 1; min-width: 0; text-align: start; background: none; border: none;
  padding: 9px 10px; font-size: .88rem; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-act {
  display: none; background: none; border: none; padding: 6px; margin-inline-end: 2px;
  color: var(--muted); border-radius: 7px; line-height: 0;
}
.chat-item:hover .chat-act, .chat-item:focus-within .chat-act { display: block; }
.chat-act:hover { background: var(--panel-2); color: var(--text); }
.chat-act.danger:hover { color: var(--danger); }
@media (hover: none) { .chat-act { display: block; } }

details.settings { border-top: 1px solid var(--border); padding-top: 12px; }
details.settings > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; padding-bottom: 10px; }
details.settings > summary::-webkit-details-marker { display: none; }
details.settings > summary::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .2s; margin-right: 4px; }
details.settings[open] > summary::after { transform: rotate(-135deg); }
details.settings[open] { display: flex; flex-direction: column; gap: 14px; }
details.settings[open] > summary { padding-bottom: 0; }

/* ---------- User card ---------- */
.user-card { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 14px; background: var(--panel); }
.user-pic { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.user-pic[hidden] { display: none; }
.user-pic.initial { display: grid; place-items: center; background: var(--grad); color: #fff; font-weight: 700; }
.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-card .icon-btn { color: var(--muted); }
.user-card .icon-btn:hover { color: var(--danger); }

/* Logo image (replaces the old inline graduation-cap SVG in these three spots) */
.logo img, .empty-logo img, .msg.assistant .avatar img {
  width: 68%; height: 68%; object-fit: contain; display: block;
}
.logo.big img { width: 62%; height: 62%; object-fit: contain; display: block; }


/* ---------- Live teacher (Gemini Live) ---------- */
.live-toggle {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 12px; flex-shrink: 0;
  border-radius: 999px; border: 1px solid var(--border); background: var(--panel); color: var(--muted);
  font-size: .85rem; font-weight: 600; transition: border-color .15s, color .15s, background .15s;
}
.live-toggle[hidden] { display: none; }
.live-toggle:hover { border-color: var(--accent); color: var(--accent); }
/* an indicator, not a switch: live mode itself is always on */
.live-toggle[data-state="idle"] { background: var(--panel); color: var(--muted); border-color: var(--border); }
.live-toggle[data-state="connecting"] { background: var(--panel); color: var(--accent); border-color: var(--accent); animation: live-connecting 1.2s ease-in-out infinite; }
.live-toggle[data-state="on"] { background: var(--grad); color: #fff; border-color: transparent; }
@keyframes live-connecting { 50% { box-shadow: 0 0 0 4px rgba(var(--accent-rgb), .22); } }

.live-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; width: min(780px, calc(100% - 32px));
  margin: 0 auto 8px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 14px; background: var(--panel-2);
  font-size: .85rem; color: var(--text);
}
.live-bar[hidden] { display: none; }
.live-bar #live-state { flex: 1; min-width: 160px; }
.live-bar button {
  height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); font-size: .82rem;
}
.live-bar button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.live-bar button:disabled { opacity: .5; cursor: not-allowed; }
.live-bar #live-mic.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.live-bar #live-end:hover { border-color: var(--danger); color: var(--danger); }
.live-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex-shrink: 0;
  box-shadow: 0 0 0 0 rgba(var(--accent-rgb), .5); animation: live-pulse 1.8s infinite;
}
@keyframes live-pulse { 70% { box-shadow: 0 0 0 9px rgba(var(--accent-rgb), 0); } 100% { box-shadow: 0 0 0 0 rgba(var(--accent-rgb), 0); } }

.live-notes > :first-child { margin-top: 0; }
.live-says { margin-top: 14px; border-top: 1px dashed var(--border); padding-top: 8px; color: var(--muted); font-size: .85rem; }
.live-says[hidden] { display: none; }
.live-says summary { cursor: pointer; user-select: none; }
.live-says-text { margin-top: 6px; line-height: 1.6; white-space: pre-wrap; font-style: italic; }


/* ---------- Phones (layout fix) ----------
   Before: the composer squeezed the text box to ~120 px between the Live button and the language picker (placeholder wrapped on 3 lines),
   the live bar wrapped onto two rows, notes headings were huge, and iOS zoomed the page when a small select was tapped.
   Now: text box on its own full-width row, one compact action row under it, one-line live bar, calmer headings, safe-area padding. */
#chat { min-height: 0; overflow-x: hidden; }
.body img, .body video, .body svg { max-width: 100%; height: auto; }
.body table { display: block; max-width: 100%; overflow-x: auto; }

@media (max-width: 820px) {
  #app { overflow: hidden; }
  .topbar { padding-top: max(10px, env(safe-area-inset-top)); }
  #chat { padding: 14px 12px 6px; }
  .msg { gap: 8px; margin-bottom: 16px; }
  .msg.assistant .avatar { width: 26px; height: 26px; border-radius: 8px; }
  .msg.user .body { max-width: 90%; padding: 9px 13px; }
  .body { font-size: .95rem; line-height: 1.6; }
  .body h1 { font-size: 1.3rem; margin: .2em 0 .5em; line-height: 1.35; }
  .body h2 { font-size: 1.12rem; margin: 1em 0 .4em; line-height: 1.4; }
  .body h3 { font-size: 1.02rem; margin: .9em 0 .3em; }
  .body[lang="ur"] { font-size: 1.05em; line-height: 1.95; }
  .body[lang="ur"] h1, .body[lang="ur"] h2, .body[lang="ur"] h3,
  .body[lang="ar"] h1, .body[lang="ar"] h2, .body[lang="fa"] h1, .body[lang="fa"] h2 { line-height: 1.8; }
  .body pre { padding: 10px; font-size: .8rem; max-width: 100%; }
  .empty { padding: 12px; }
  .empty h2 { font-size: 1.3rem; }
  .chips { gap: 8px; }

  .speaking { margin: 0 12px 6px; padding: 5px 8px 5px 12px; max-width: calc(100% - 24px); }

  /* live bar: one row, text shortens with an ellipsis, buttons stay compact */
  .live-bar { width: calc(100% - 24px); flex-wrap: nowrap; gap: 8px; padding: 6px 8px 6px 10px; margin-bottom: 6px; }
  .live-bar #live-state { min-width: 0; flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; }
  .live-bar button { height: 30px; padding: 0 10px; font-size: .78rem; flex: 0 0 auto; white-space: nowrap; }

  /* composer: text on top (full width), actions underneath */
  .composer-wrap { padding: 0 10px calc(10px + env(safe-area-inset-bottom)); }
  .composer { flex-wrap: wrap; align-items: center; gap: 4px 6px; padding: 6px 8px 8px 14px; border-radius: 22px; }
  .composer textarea { flex: 1 1 100%; width: 100%; min-width: 0; font-size: 16px; padding: 8px 0 4px; max-height: 140px; }
  .composer .listening { flex: 1 1 100%; }
  .composer .live-toggle { height: 38px; padding: 0 12px; order: 2; }
  .composer .voice-lang { order: 3; font-size: 16px; padding: 6px 26px 6px 10px; min-height: 38px; max-width: 34vw; }
  .composer .mic { order: 5; margin-left: auto; width: 40px; height: 40px; }
  .composer .send { order: 6; width: 40px; height: 40px; }
  .composer.recording .live-toggle { display: none; }
  #status { font-size: .74rem; padding: 0 6px; }
}

@media (max-width: 360px) {
  .composer .live-toggle span { display: none; }              /* icon only on very narrow phones */
  .composer .live-toggle { width: 40px; padding: 0; justify-content: center; }
  .live-bar button#live-end { padding: 0 8px; }
  .body h1 { font-size: 1.2rem; }
}

/* landscape phones: keep the answer visible, shrink the chrome */
@media (max-width: 920px) and (max-height: 480px) {
  .topbar { padding-block: 4px; }
  .empty-logo, .empty p { display: none; }
  .composer textarea { max-height: 64px; }
}

/* iOS zooms the page when a form control under 16 px gets focus */
@media (pointer: coarse) {
  select, input, textarea { font-size: 16px; }
}

/* the crest mark intentionally pops out below its tile: leave room so it does not touch the heading */
.empty-logo { margin-bottom: 34px; }


/* the words being spoken, shown until the written notes arrive (voice and text appear together) */
.live-notes.interim { opacity: .88; white-space: pre-wrap; }
