:root {
  --bg: #FBF6EF;
  --surface: #FFFFFF;
  --surface-2: #F4ECE1;
  --ink: #2A1E17;
  --muted: #7A6A5E;
  --line: #E8DDCF;
  --brand: #E4572E;
  --brand-ink: #FFFFFF;
  --brand-soft: #FCE3D9;
  --accent: #2E8B57;
  --bubble-me: #E4572E;
  --bubble-me-ink: #FFFFFF;
  --bubble-bot: #FFFFFF;
  --shadow: 0 10px 30px rgba(74, 42, 20, .10);
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17120F; --surface: #221B16; --surface-2: #2C231D; --ink: #F5ECE3; --muted: #B3A294;
    --line: #3A2F27; --brand: #F26A43; --brand-soft: #3D2419; --accent: #5BC38A;
    --bubble-me: #C9492A; --bubble-bot: #2A221C; --shadow: 0 10px 30px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --bg: #17120F; --surface: #221B16; --surface-2: #2C231D; --ink: #F5ECE3; --muted: #B3A294;
  --line: #3A2F27; --brand: #F26A43; --brand-soft: #3D2419; --accent: #5BC38A;
  --bubble-me: #C9492A; --bubble-bot: #2A221C; --shadow: 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: "Tajawal", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }

.layout { height: 100dvh; display: grid; grid-template-columns: 1fr; }
.hero { display: none; }

@media (min-width: 960px) {
  .layout { grid-template-columns: 1fr 440px; gap: 56px; max-width: 1120px; margin: 0 auto; padding: 32px; align-items: center; }
  .hero { display: block; }
  .app { height: min(820px, calc(100dvh - 64px)); border-radius: 28px; box-shadow: var(--shadow); border: 1px solid var(--line); }
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 28px; color: var(--brand); }
.brand.small { font-size: 20px; gap: 8px; }
.hero h1 { font-size: 52px; line-height: 1.05; letter-spacing: -.02em; margin: 28px 0 16px; font-weight: 800; }
.hero .lead { font-size: 19px; color: var(--muted); max-width: 30em; margin: 0 0 32px; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.steps li { display: flex; gap: 14px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); padding: 14px 16px; border-radius: 16px; }
.steps .n { flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 800; }
.steps b { display: block; }
.steps small { color: var(--muted); font-size: 14px; }

.app { display: flex; flex-direction: column; background: var(--bg); overflow: hidden; min-height: 0; }

.topbar { display: flex; align-items: center; gap: 8px; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); background: var(--surface); border-bottom: 1px solid var(--line); }
.address { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; background: var(--surface-2); border: 0; border-radius: 999px; padding: 7px 12px; font-size: 14px; color: var(--muted); }
.address span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.address.set { color: var(--ink); }
.icon-btn { flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--surface-2); display: grid; place-items: center; font-weight: 700; }
.icon-btn.danger { color: var(--brand); background: transparent; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px; scrollbar-width: none; border-bottom: 1px solid var(--line); background: var(--surface); }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--bg); padding: 6px 12px; border-radius: 999px; font-size: 14px; white-space: nowrap; }
.chip:hover { border-color: var(--brand); }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.msg { max-width: 84%; padding: 10px 14px; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; animation: pop .18s ease-out; }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }
.msg.bot { align-self: flex-start; background: var(--bubble-bot); border: 1px solid var(--line); border-start-start-radius: 6px; }
.msg.me { align-self: flex-end; background: var(--bubble-me); color: var(--bubble-me-ink); border-start-end-radius: 6px; }
.msg.error { align-self: center; background: transparent; color: var(--brand); font-size: 14px; text-align: center; }
.msg[dir="auto"] { unicode-bidi: plaintext; }

.voice { display: flex; flex-direction: column; gap: 6px; min-width: 220px; }
.voice-row { display: flex; align-items: center; gap: 10px; }
.play { width: 34px; height: 34px; border-radius: 50%; border: 0; background: rgba(255,255,255,.22); color: inherit; display: grid; place-items: center; flex: none; }
.wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 26px; }
.wave i { flex: 1; background: currentColor; opacity: .55; border-radius: 2px; min-height: 3px; }
.wave.playing i { opacity: .9; }
.dur { font-size: 12px; opacity: .85; }
.transcript { font-size: 14px; opacity: .92; border-top: 1px solid rgba(255,255,255,.25); padding-top: 6px; unicode-bidi: plaintext; }

.typing { align-self: flex-start; background: var(--bubble-bot); border: 1px solid var(--line); padding: 12px 16px; border-radius: var(--radius); display: flex; gap: 4px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.card { align-self: stretch; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); animation: pop .18s ease-out; }
.card h3 { margin: 0 0 2px; font-size: 16px; display: flex; justify-content: space-between; gap: 8px; }
.card .sub { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.line { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 15px; }
.line .q { color: var(--brand); font-weight: 700; margin-inline-end: 6px; }
.line small { display: block; color: var(--muted); font-size: 12px; }
.totals { margin-top: 8px; font-size: 14px; color: var(--muted); }
.totals div { display: flex; justify-content: space-between; }
.totals .grand { color: var(--ink); font-weight: 800; font-size: 17px; margin-top: 4px; }
.card .actions { display: flex; gap: 8px; margin-top: 12px; }
.primary { flex: 1; border: 0; background: var(--brand); color: var(--brand-ink); padding: 12px; border-radius: 12px; font-weight: 700; }
.primary:disabled { opacity: .6; }
.ghost { border: 1px solid var(--line); background: transparent; padding: 12px 16px; border-radius: 12px; }
.tag { font-size: 12px; font-weight: 700; color: var(--brand); background: var(--brand-soft); padding: 2px 8px; border-radius: 999px; white-space: nowrap; }

.track { display: flex; gap: 6px; margin-top: 12px; }
.track div { flex: 1; text-align: center; font-size: 12px; color: var(--muted); }
.track div::before { content: ""; display: block; height: 5px; border-radius: 3px; background: var(--line); margin-bottom: 6px; }
.track div.done { color: var(--ink); font-weight: 700; }
.track div.done::before { background: var(--accent); }

.composer { display: flex; gap: 8px; padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
.composer input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 999px; padding: 12px 16px; font: inherit; outline: none; unicode-bidi: plaintext; }
.composer input:focus { border-color: var(--brand); }
.mic, .send { flex: none; width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; box-shadow: 0 4px 14px rgba(228, 87, 46, .35); }
.mic .i-send { display: none; }
.mic.has-text .i-send { display: block; }
.mic.has-text .i-mic { display: none; }
[dir="rtl"] .i-send, [dir="rtl"] .send svg { transform: scaleX(-1); }

.recorder { display: flex; align-items: center; gap: 10px; padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
.recorder[hidden] { display: none; }
.rec-main { flex: 1; min-width: 0; }
.rec-top { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; font-weight: 700; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #E53935; animation: blink 1s infinite; }
.rec-lang { margin-inline-start: auto; display: flex; background: var(--surface-2); border-radius: 999px; padding: 2px; }
.rec-lang button { border: 0; background: transparent; padding: 2px 10px; border-radius: 999px; font-size: 13px; }
.rec-lang button.on { background: var(--brand); color: var(--brand-ink); }
.live { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; unicode-bidi: plaintext; }

dialog { border: 0; border-radius: 20px; padding: 0; background: var(--surface); color: var(--ink); width: min(420px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(20, 10, 5, .45); }
.dlg { padding: 20px; display: grid; gap: 12px; }
.dlg h2 { margin: 0; font-size: 18px; }
.dlg textarea { font: inherit; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--bg); color: var(--ink); resize: vertical; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; }
.dlg-actions .primary { flex: none; padding: 10px 20px; }

.welcome { text-align: center; color: var(--muted); padding: 24px 8px 8px; }
.welcome .big { font-size: 44px; }
.welcome h2 { color: var(--ink); margin: 6px 0; font-size: 20px; }
.examples { display: grid; gap: 8px; margin-top: 14px; }
.examples button { border: 1px dashed var(--line); background: var(--surface); border-radius: 14px; padding: 10px 12px; font-size: 14px; text-align: start; unicode-bidi: plaintext; }
.examples button:hover { border-color: var(--brand); }
