/* Live Transcription — v2 operator console.
   Mobile-first, OLED dark, RTL-aware. No build step; plain CSS custom properties. */

:root {
  --bg: #020617;
  --surface: #0b1426;
  --surface-2: #111c33;
  --surface-3: #16223d;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #f8fafc;
  --muted: #94a3b8;
  --muted-2: #64748b;
  --accent: #22c55e;
  --accent-press: #16a34a;
  --accent-soft: rgba(34, 197, 94, 0.14);
  --danger: #f43f5e;
  --danger-soft: rgba(244, 63, 94, 0.14);
  --warn: #f59e0b;
  --info: #38bdf8;
  --radius: 16px;
  --radius-sm: 10px;
  --tap: 44px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --font-ui: "Noto Sans Arabic", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-read: "Noto Naskh Arabic", "Noto Sans Arabic", ui-serif, Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(34, 197, 94, 0.08), transparent 60%),
    var(--bg);
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
button { font-family: inherit; }
.muted { color: var(--muted); font-size: 0.85rem; }
.rtl { direction: rtl; unicode-bidi: plaintext; text-align: right; }
[hidden] { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color 0.18s ease, border-color 0.18s ease, opacity 0.18s ease, transform 0.05s ease;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: transparent; color: #04140a; }
.btn-primary:hover { background: var(--accent-press); }
.btn-danger { background: transparent; border-color: rgba(244, 63, 94, 0.5); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { background: transparent; }
.btn-lg { min-height: 56px; flex: 1; font-size: 1.05rem; }
.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Chips & banners ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); }
.chip-live::before { background: var(--accent); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); animation: pulse 1.8s infinite; }
.chip-live { color: var(--accent); border-color: rgba(34, 197, 94, 0.35); }
.chip-error::before { background: var(--danger); }
.chip-error { color: var(--danger); }
.chip-warn::before { background: var(--warn); }
.chip-ok::before { background: var(--accent); }
.chip-idle::before { background: var(--muted-2); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.banner {
  margin: 8px 12px 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: var(--warn);
}
.banner-error { background: var(--danger-soft); border-color: rgba(244, 63, 94, 0.4); color: var(--danger); }

.install-banner {
  margin: 8px 12px 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, var(--accent-soft), var(--surface));
  border: 1px solid rgba(34, 197, 94, 0.35);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.88rem;
}
.install-banner .install-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.install-banner .btn { min-height: 36px; padding: 0 14px; }
.install-banner .icon-btn { width: 36px; height: 36px; }

/* ---------- App shell ---------- */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px 12px;
  background: linear-gradient(180deg, rgba(2, 6, 23, 0.96), rgba(2, 6, 23, 0.82));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand strong { display: block; font-size: 0.98rem; line-height: 1.1; }
.brand .muted { display: block; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo-dot {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--accent), #0ea5e9);
  box-shadow: 0 0 18px rgba(34, 197, 94, 0.35);
}
.topbar-status { display: flex; align-items: center; gap: 8px; flex: none; }

/* ---------- Views ---------- */
.views { flex: 1; }
.view { display: none; padding: 14px 12px 0; max-width: 1100px; margin: 0 auto; width: 100%; }
.view.is-active { display: block; animation: fade 0.2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.card-head h2 { font-size: 0.95rem; color: var(--muted); font-weight: 600; }

/* Live */
.live-controls { display: flex; gap: 10px; margin-bottom: 12px; }

/* Attach prompt shown when a session is already running but not yet loaded */
.attach-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-color: rgba(34, 197, 94, 0.4);
  background: linear-gradient(180deg, var(--accent-soft), var(--surface));
}
.attach-card .attach-title { display: flex; align-items: center; gap: 8px; }
.attach-card .attach-title::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); animation: pulse 1.8s infinite; }
.attach-card #attachMeta { display: block; margin-top: 2px; }
.attach-card .btn { flex: none; }
/* While awaiting attach, only the attach card shows in the Live view */
#view-live.awaiting-attach > * { display: none; }
#view-live.awaiting-attach > #attachCard { display: flex; }
.loading-note { color: var(--muted); text-align: center; padding: 18px; font-size: 0.85rem; }
.mini-card {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border-color: rgba(34, 197, 94, 0.25);
}
.mini-card .card-body { font-family: var(--font-read); font-size: 1.18rem; line-height: 1.9; white-space: pre-wrap; }
.mini-card footer { margin-top: 8px; }

.metrics-strip {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.metric span { display: block; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.metric strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }

.feed-wrap { position: relative; }
.feed-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.feed-head h2 { font-size: 0.95rem; }
.feed {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 56vh;
  overflow-y: auto;
  padding: 4px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.transcript-feed { max-height: 60vh; }
.feed::-webkit-scrollbar { width: 8px; }
.feed::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; }
.tx-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--font-read);
  font-size: 1.05rem;
  line-height: 1.85;
  animation: fade 0.18s ease;
}
.tx-item .seq { color: var(--muted-2); font-size: 0.72rem; font-family: var(--font-ui); }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; font-size: 0.9rem; }
.pill {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #04140a;
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 5;
}

/* Summaries */
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px; margin-bottom: 12px; gap: 4px; }
.seg button { appearance: none; border: none; background: transparent; color: var(--muted); min-height: 36px; padding: 0 16px; border-radius: 999px; font-weight: 600; cursor: pointer; }
.seg button.is-active { background: var(--accent-soft); color: var(--accent); }
.summary-list { display: flex; flex-direction: column; gap: 12px; }
.summary-card .card-body { font-family: var(--font-read); font-size: 1.1rem; line-height: 1.95; white-space: pre-wrap; }

/* Sessions */
.sessions-head, .feed-head { gap: 10px; }
.session-list { display: flex; flex-direction: column; gap: 8px; }
.session-row {
  text-align: start;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  display: grid;
  gap: 4px;
  color: var(--text);
  transition: border-color 0.18s ease, background 0.18s ease;
}
.session-row:hover { background: var(--surface-2); }
.session-row.selected { border-color: var(--accent); background: var(--accent-soft); }
.session-row .row-top { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.session-row .row-sub, .session-row small { color: var(--muted); font-size: 0.8rem; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.8s infinite; }
.session-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

/* Settings */
.form-grid { display: grid; gap: 12px; }
.form-grid label, .prompt-grid label { display: grid; gap: 6px; font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.form-grid input, .form-grid select, .prompt-grid textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  min-height: var(--tap);
  font-size: 0.95rem;
  font-family: inherit;
}
.prompt-grid textarea { min-height: 110px; padding: 10px 12px; line-height: 1.7; resize: vertical; }
.form-grid input:focus, .form-grid select:focus, .prompt-grid textarea:focus { outline: 2px solid var(--info); outline-offset: 1px; border-color: var(--info); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin: 14px 0 0; }
legend { padding: 0 6px; color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.events-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.events-grid label { display: flex; align-items: center; gap: 8px; flex-direction: row; color: var(--text); font-weight: 500; min-height: 36px; }
.events-grid input { width: 20px; height: 20px; accent-color: var(--accent); }
.settings-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.preview-box { background: #04070f; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; font-size: 0.8rem; color: var(--muted); white-space: pre-wrap; max-height: 220px; overflow: auto; }
.help-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 0.85rem; color: var(--muted); }
.help-box code { background: #04070f; padding: 2px 6px; border-radius: 6px; color: var(--info); font-size: 0.82rem; overflow-wrap: anywhere; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.section-title h2 { font-size: 1.05rem; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(8, 13, 26, 0.94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  position: relative;
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button.is-active { color: var(--accent); }
.tabbar button.is-active::after {
  content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent);
}
.tab-badge { position: absolute; top: 8px; inset-inline-end: 50%; transform: translateX(50%) translateX(14px); background: var(--danger); color: #fff; border-radius: 999px; font-size: 0.6rem; min-width: 16px; height: 16px; padding: 0 4px; display: flex; align-items: center; justify-content: center; }

/* ---------- Login overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: radial-gradient(800px 500px at 50% 0%, rgba(34, 197, 94, 0.1), transparent 60%), var(--bg);
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 22px;
  box-shadow: var(--shadow);
  display: grid; gap: 14px;
  text-align: center;
}
.login-card .logo-dot { width: 44px; height: 44px; margin: 0 auto 4px; }
.login-card h1 { font-size: 1.25rem; }
.login-card label { text-align: start; color: var(--muted); font-size: 0.82rem; font-weight: 600; display: grid; gap: 6px; }
.login-card input { background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text); border-radius: var(--radius-sm); min-height: var(--tap); padding: 0 12px; font-size: 1rem; }
.login-card .error { color: var(--danger); font-size: 0.85rem; margin: 0; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 440px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-inline-start: 4px solid var(--info);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  animation: toastIn 0.22s ease;
}
.toast-error { border-inline-start-color: var(--danger); }
.toast-success { border-inline-start-color: var(--accent); }
.toast-warn { border-inline-start-color: var(--warn); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Desktop ---------- */
@media (min-width: 820px) {
  .metrics-strip { grid-template-columns: repeat(5, 1fr); }
  .events-grid { grid-template-columns: repeat(3, 1fr); }
  .brand .muted { max-width: 320px; }
  .view { padding: 20px 24px 0; }
  .feed, .transcript-feed { max-height: 62vh; }
}

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

.spk-chip {
  display: inline-block;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  font: 600 12px/1.4 "Noto Sans Arabic", sans-serif;
  padding: 2px 8px;
  margin-bottom: 4px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: rgba(148, 163, 184, 0.18);
  color: #cbd5e1;
  cursor: pointer;
}
.spk-chip.spk-sharih   { background: rgba(56, 189, 248, 0.18);  color: #7dd3fc; border-color: rgba(56, 189, 248, 0.4); }
.spk-chip.spk-qari     { background: rgba(52, 211, 153, 0.18);  color: #6ee7b7; border-color: rgba(52, 211, 153, 0.4); }
.spk-chip.spk-sail     { background: rgba(251, 191, 36, 0.18);  color: #fcd34d; border-color: rgba(251, 191, 36, 0.4); }
.spk-chip.spk-muqaddim { background: rgba(148, 163, 184, 0.18); color: #cbd5e1; border-color: rgba(148, 163, 184, 0.35); }

/* ---------- Start-config sheet ---------- */
.start-sheet {
  margin: 12px 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.start-sheet .form-grid textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.7;
  resize: vertical;
}
.start-sheet .form-grid input,
.start-sheet .form-grid select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  min-height: var(--tap);
  font-size: 0.95rem;
  font-family: inherit;
}
.start-sheet .form-grid input:focus,
.start-sheet .form-grid select:focus,
.start-sheet .form-grid textarea:focus {
  outline: 2px solid var(--info);
  outline-offset: 1px;
  border-color: var(--info);
}

/* ---------- Unexpected-voice banner ---------- */
.unexpected-banner {
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.40);
  border-inline-start: 4px solid var(--warn);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.88rem;
  color: var(--warn);
  margin: 6px 0;
}

/* ---------- Attribution bar (speaker proposal confirm chips) ---------- */
.attribution-bar { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 12px 0; }
.attr-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 999px;
  background: rgba(56, 189, 248, 0.12); border: 1px dashed rgba(56, 189, 248, 0.5);
  color: #e2e8f0; font-size: 0.85rem;
}
.attr-chip .attr-conf { font-size: 0.75rem; }
.attr-chip .attr-confirm, .attr-chip .attr-dismiss {
  appearance: none; border: none; cursor: pointer; border-radius: 8px;
  padding: 3px 10px; font: inherit; font-size: 0.8rem; font-weight: 600;
}
.attr-chip .attr-confirm { background: var(--accent, #22c55e); color: #04140a; }
.attr-chip .attr-dismiss { background: transparent; color: var(--muted, #94a3b8); }
.spk-chip--proposed { border-style: dashed !important; box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.4); }
