:root {
  --bg: #F6F7F9;
  --surface: #FFFFFF;
  --surface-2: #F0F2F5;
  --ink: #14161A;
  --ink-2: #3B4049;
  --muted: #6B7280;
  --line: #E4E7EC;
  --accent: #EF3B24;
  --accent-ink: #FFFFFF;
  --accent-soft: #FDECEA;
  --good: #15803D;
  --good-soft: #E7F6EC;
  --warn: #B45309;
  --warn-soft: #FEF3E2;
  --bad: #B91C1C;
  --bad-soft: #FDECEC;
  --p-original: #E9EDF2;
  --p-sprayed: #F5B83D;
  --p-putty: #F07A2B;
  --p-replaced: #D6332A;
  --p-glass: #CFD8E3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --r: 12px;
  --r-sm: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1114; --surface: #171A1F; --surface-2: #1F232A; --ink: #F2F4F7; --ink-2: #C9CED6;
    --muted: #8D95A1; --line: #2A2F37; --accent: #F2553F; --accent-soft: #3A1D19;
    --good: #4ADE80; --good-soft: #13291B; --warn: #FBBF24; --warn-soft: #2E2410;
    --bad: #F87171; --bad-soft: #2E1515; --p-original: #2A3038; --p-glass: #36414F;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F1114; --surface: #171A1F; --surface-2: #1F232A; --ink: #F2F4F7; --ink-2: #C9CED6;
  --muted: #8D95A1; --line: #2A2F37; --accent: #F2553F; --accent-soft: #3A1D19;
  --good: #4ADE80; --good-soft: #13291B; --warn: #FBBF24; --warn-soft: #2E2410;
  --bad: #F87171; --bad-soft: #2E1515; --p-original: #2A3038; --p-glass: #36414F;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.6 "IBM Plex Sans Arabic", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

.app { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }

/* Top bar */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mark { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); display: grid; place-items: center; flex: none; }
.mark svg { fill: #fff; stroke: none; width: 22px; height: 22px; }
.brand h1 { font-size: 16px; font-weight: 700; margin: 0; line-height: 1.3; }
.brand p { margin: 0; font-size: 12.5px; color: var(--muted); }
.top-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid transparent; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); }

/* Thread */
.thread { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
.msg { max-width: 88%; display: flex; flex-direction: column; gap: 8px; }
.msg.user { align-self: flex-start; }
.msg.bot { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user .bubble { background: var(--ink); color: var(--bg); border-start-start-radius: 4px; }
.msg.bot .bubble { background: var(--surface); border: 1px solid var(--line); border-start-end-radius: 4px; box-shadow: var(--shadow); }
.msg.user .voice-tag { font-size: 11.5px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.voice-tag svg { width: 13px; height: 13px; }
.msg.wide { max-width: 100%; width: 100%; align-self: stretch; }
.msg.wide .bubble.advice { align-self: flex-end; max-width: 88%; }

.typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.typing i { width: 6px; height: 6px; 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 } }
.status-line { font-size: 12.5px; color: var(--muted); padding: 0 4px; }
.status-line.thinking::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-inline-end: 6px; animation: blink 1s infinite; vertical-align: middle; }

.quick { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px;
  font-size: 13.5px; cursor: pointer; color: var(--ink-2); line-height: 1.4;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.solid { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.facts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.fact { font-size: 12.5px; padding: 3px 9px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); }
.fact.miss { background: transparent; border: 1px dashed var(--line); color: var(--muted); }

/* Welcome */
.welcome { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); }
.welcome h2 { margin: 0 0 4px; font-size: 18px; }
.welcome p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.welcome .ex { display: flex; flex-direction: column; gap: 8px; }
.welcome .ex button {
  text-align: start; border: 1px solid var(--line); background: var(--bg); border-radius: var(--r-sm);
  padding: 10px 12px; cursor: pointer; font-size: 14px; color: var(--ink-2);
}
.welcome .ex button:hover { border-color: var(--accent); }
.welcome .how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.welcome .how div { font-size: 12.5px; color: var(--muted); background: var(--surface-2); border-radius: var(--r-sm); padding: 8px 10px; }
.welcome .how b { display: block; color: var(--ink); font-size: 13px; font-weight: 600; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); width: 100%; }
.card-pad { padding: 16px; }

/* Body map */
.bodymap { display: grid; grid-template-columns: 1fr; gap: 12px; }
.brushes { display: flex; gap: 6px; flex-wrap: wrap; }
.brush {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px;
}
.brush i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.brush[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.map-wrap { display: flex; gap: 14px; align-items: flex-start; }
.map-svg { width: 190px; height: auto; flex: none; stroke: none; }
.map-svg .panel { cursor: pointer; stroke: var(--surface); stroke-width: 2; transition: fill .12s; }
.map-svg .panel:hover { opacity: .85; }
.map-svg .glass { fill: var(--p-glass); }
.map-svg text { font-size: 11px; fill: var(--muted); font-family: inherit; stroke: none; }
.map-list { flex: 1; font-size: 13px; color: var(--ink-2); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.map-list .empty { color: var(--muted); }
.map-list span { display: flex; align-items: center; gap: 6px; }
.map-list i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.map-actions { display: flex; gap: 8px; justify-content: flex-start; }

/* Result */
.result-head { padding: 16px 16px 0; display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.result-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.result-head .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.conf { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 6px; white-space: nowrap; }
.conf.high { background: var(--good-soft); color: var(--good); }
.conf.medium { background: var(--warn-soft); color: var(--warn); }
.conf.low { background: var(--bad-soft); color: var(--bad); }
.hero { padding: 14px 16px 16px; display: flex; flex-wrap: wrap; gap: 6px 20px; align-items: baseline; border-bottom: 1px solid var(--line); }
.hero .lbl { font-size: 13px; color: var(--muted); width: 100%; }
.hero .big { font-size: 34px; font-weight: 700; line-height: 1.1; letter-spacing: -.5px; }
.hero .big small { font-size: 15px; font-weight: 500; color: var(--muted); margin-inline-start: 4px; }
.hero .open { font-size: 14px; color: var(--ink-2); }
.hero .open b { font-weight: 600; }
.asking { margin: 12px 16px 0; padding: 10px 12px; border-radius: var(--r-sm); font-size: 14px; }
.asking.over { background: var(--bad-soft); color: var(--bad); }
.asking.under { background: var(--good-soft); color: var(--good); }

.range { padding: 16px; border-bottom: 1px solid var(--line); }
.range .ttl { font-size: 13px; color: var(--muted); margin-bottom: 12px; display: flex; justify-content: space-between; }
.track { position: relative; height: 8px; border-radius: 4px; background: var(--surface-2); margin: 28px 6px 12px; }
.track .band { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--accent) 22%, transparent); border-radius: 4px; }
.track .tick { position: absolute; top: -4px; width: 2px; height: 16px; background: var(--ink-2); transform: translateX(1px); }
.track .tick span { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); font-size: 12px; white-space: nowrap; color: var(--ink-2); }
.track .tick.mid { background: var(--ink); }
.track .tick.mid span { font-weight: 600; color: var(--ink); }
.track .pin { position: absolute; top: -26px; transform: translateX(50%); font-size: 11.5px; white-space: nowrap; color: var(--accent); font-weight: 600; }
.track .pin::after { content: ""; position: absolute; left: 50%; top: 18px; width: 8px; height: 8px; background: var(--accent); border-radius: 50%; transform: translateX(-50%); }

.range-labels { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.range-labels b { color: var(--ink-2); font-weight: 600; }
.range-labels .mid b { color: var(--ink); }
.srcs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.src { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); }
.src.none { color: var(--muted); background: transparent; border: 1px dashed var(--line); }
.calc { padding: 8px 16px 12px; border-bottom: 1px solid var(--line); }
.calc .row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 14px; }
.calc .row + .row { border-top: 1px dashed var(--line); }
.calc .row .k { color: var(--ink-2); }
.calc .row .k small { color: var(--muted); }
.calc .row.total { font-weight: 700; border-top: 1px solid var(--line) !important; }
.calc .neg { color: var(--bad); } .calc .pos { color: var(--good); }

.cond { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cond .ttl { font-size: 13px; color: var(--muted); margin-inline-end: 4px; }
.cond .tag { font-size: 12.5px; padding: 3px 8px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); }
.cond .tag.ok { background: var(--good-soft); color: var(--good); }
.cond .tag.unk { background: var(--surface-2); color: var(--muted); }
.cond .edit { margin-inline-start: auto; }
.cond-editor { padding: 16px; border-bottom: 1px solid var(--line); }

.zero { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.z-ttl { font-size: 13px; color: var(--muted); margin: 6px 0 8px; }
.z-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 10px; }
.z-table th { text-align: start; font-weight: 500; color: var(--muted); padding: 4px 6px; border-bottom: 1px solid var(--line); }
.z-table td { padding: 6px; border-bottom: 1px dashed var(--line); }
.z-table th, .z-table td { text-align: right; }
.z-table td.num { text-align: right; direction: ltr; unicode-bidi: plaintext; font-variant-numeric: tabular-nums; }
.z-table tr.on td { background: var(--accent-soft); font-weight: 600; }
.z-table .neg, .z-offers .neg { color: var(--bad); }
.z-offers { list-style: none; margin: 0; padding: 0; }
.z-offers li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); align-items: center; }
.z-offers .c-main { flex: 1; min-width: 0; }
.z-offers .c-price { font-weight: 600; }
.z-offers .c-price small { font-weight: 400; font-size: 12px; }
.z-offers .c-sub { font-size: 12.5px; color: var(--muted); }
.z-offers a { color: var(--accent); font-size: 13px; text-decoration: none; white-space: nowrap; }
.z-none { font-size: 13px; color: var(--muted); }
.comps summary { padding: 12px 16px; cursor: pointer; font-size: 14px; color: var(--ink-2); list-style: none; display: flex; justify-content: space-between; }
.comps summary::-webkit-details-marker { display: none; }
.comps summary::after { content: "عرض"; color: var(--accent); font-size: 13px; }
.comps[open] summary::after { content: "إخفاء"; }
.comps ul { list-style: none; margin: 0; padding: 0 16px 8px; }
.comps li { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); align-items: center; }
.comps img { width: 56px; height: 42px; object-fit: cover; border-radius: 6px; background: var(--surface-2); flex: none; }
.comps .c-main { flex: 1; min-width: 0; }
.comps .c-price { font-weight: 600; }
.comps .c-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.comps a { color: var(--accent); font-size: 13px; text-decoration: none; white-space: nowrap; }
.foot-note { padding: 12px 16px; font-size: 12px; color: var(--muted); }

.btn { border-radius: 10px; padding: 9px 16px; font-weight: 600; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 14px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 13.5px; }

/* Composer */
.composer { padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.bar { display: flex; gap: 8px; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 6px; }
.bar:focus-within { border-color: var(--ink-2); }
.bar textarea { flex: 1; border: none; outline: none; resize: none; background: transparent; padding: 8px 4px; max-height: 140px; line-height: 1.5; }
.mic, .send { width: 40px; height: 40px; border-radius: 10px; border: none; display: grid; place-items: center; cursor: pointer; flex: none; }
.mic { background: var(--surface-2); color: var(--ink); }
.mic.on { background: var(--accent); color: #fff; animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent) } 100% { box-shadow: 0 0 0 12px transparent } }
.send { background: var(--accent); color: #fff; }
.send:disabled { opacity: .4; cursor: default; }
.rec { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink-2); padding: 0 4px 8px; }
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: blink 1s infinite; }
.rec-hint { color: var(--muted); font-size: 12.5px; }
@media (max-width: 420px) { .rec-hint { display: none; } }
.rec .link-btn { margin-inline-start: auto; }

/* Settings sheet */
.sheet { border: none; padding: 0; background: transparent; max-width: 560px; width: calc(100% - 24px); max-height: calc(100dvh - 24px); }
.sheet::backdrop { background: rgba(10, 12, 16, .45); }
.sheet-inner { background: var(--surface); color: var(--ink); border-radius: 16px; padding: 18px; overflow-y: auto; max-height: calc(100dvh - 24px); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet h2 { margin: 0; font-size: 17px; }
.sheet h3 { font-size: 14px; margin: 20px 0 8px; }
.sheet h3 .sub { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
.sheet label .unit { color: var(--muted); font-size: 12px; }
.sheet input { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--bg); width: 100%; }
.sheet input:focus { outline: none; border-color: var(--ink-2); }
.sheet label.inline { flex-direction: row; align-items: center; gap: 8px; margin-top: 8px; }
.sheet label.inline input { width: 80px; }
.ded { width: 100%; border-collapse: collapse; font-size: 13px; }
.ded th { text-align: start; font-weight: 500; color: var(--muted); padding: 4px; }
.ded td { padding: 3px 4px; }
.ded td:first-child { color: var(--ink-2); }
.ded input { padding: 6px 8px; }
.sheet-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 20px; position: sticky; bottom: -18px; background: var(--surface); padding: 12px 0 0; }

@media (max-width: 520px) {
  .msg { max-width: 94%; }
  .hero .big { font-size: 30px; }
  .map-wrap { flex-direction: column; align-items: center; }
  .map-list { width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
  .welcome .how { grid-template-columns: 1fr; }
}
