:root {
  --bg: #f4f3ef;
  --card: #ffffff;
  --soft: #efeee9;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --faint: #9a9993;
  --line: rgba(0, 0, 0, 0.09);
  --green: #0f6e56;
  --green-bg: #e1f5ee;
  --amber: #854f0b;
  --amber-bg: #faeeda;
  --amber-fill: #ef9f27;
  --red: #a32d2d;
  --red-bg: #fcebeb;
  --blue: #185fa5;
  --blue-bg: #e6f1fb;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --card: #1e1e1c;
    --soft: #2a2a27;
    --text: #f1efe8;
    --muted: #b4b2a9;
    --faint: #888780;
    --line: rgba(255, 255, 255, 0.1);
    --green: #5dcaa5;
    --green-bg: #083d31;
    --amber: #fac775;
    --amber-bg: #412402;
    --amber-fill: #ef9f27;
    --red: #f09595;
    --red-bg: #501313;
    --blue: #85b7eb;
    --blue-bg: #042c53;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, "SF Arabic", "Segoe UI", Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding: env(safe-area-inset-top) 0 calc(140px + env(safe-area-inset-bottom));
}
main { max-width: 520px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; font-weight: 600; margin: 4px 0 12px; }
h2 { font-size: 16px; font-weight: 600; margin: 20px 0 8px; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.loading { text-align: center; color: var(--muted); padding: 40vh 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; color: var(--faint); }
.num { font-variant-numeric: tabular-nums; }
.center { text-align: center; }

.card { background: var(--card); border-radius: 16px; padding: 14px 16px; border: 1px solid var(--line); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.hero { text-align: center; padding: 22px 16px 18px; }
.hero .big { font-size: 56px; font-weight: 700; line-height: 1.1; margin: 4px 0; }
.good { color: var(--green); }
.warn { color: var(--amber); }
.bad { color: var(--red); }

.bar { height: 8px; border-radius: 4px; background: var(--soft); overflow: hidden; margin-top: 10px; }
.bar > span { display: block; height: 100%; border-radius: 4px; background: var(--green); }
.bar.warn > span { background: var(--amber-fill); }
.bar.bad > span { background: var(--red); }
.bar.blue > span { background: var(--blue); }

.pill { display: inline-block; font-size: 12px; padding: 3px 10px; border-radius: 999px; }
.pill.warn { background: var(--amber-bg); color: var(--amber); }
.pill.good { background: var(--green-bg); color: var(--green); }
.pill.bad { background: var(--red-bg); color: var(--red); }

.row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: none; }
.row .emoji { font-size: 20px; width: 28px; text-align: center; }
.row .grow { flex: 1; min-width: 0; }
.row .grow div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amt { font-weight: 600; direction: ltr; }
.row.tap { cursor: pointer; }
.in { color: var(--green); }

.btn { display: block; width: 100%; padding: 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #04342c; } }
.btn.ghost { background: transparent; color: var(--muted); font-weight: 400; }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: 0.5; }
.btn + .btn { margin-top: 8px; }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
}
.field textarea { min-height: 110px; resize: vertical; }
input[type="number"], input[inputmode="decimal"] { direction: ltr; text-align: right; }

.cats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cat { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 4px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-size: 13px; }
.cat b { font-size: 24px; font-weight: 400; }
.cat.on { border: 2px solid var(--green); background: var(--green-bg); color: var(--green); padding: 11px 3px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 14px; }
.chip.on { border-color: var(--green); background: var(--green-bg); color: var(--green); }

.inbox-amt { font-size: 48px; font-weight: 700; line-height: 1.1; }
.raw { white-space: pre-wrap; font-size: 12px; color: var(--muted); background: var(--soft); border-radius: 10px; padding: 10px; margin-top: 8px; text-align: right; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin: 12px 0; }
.check input { width: 20px; height: 20px; accent-color: var(--green); }

.step { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.step:last-child { border-bottom: none; }
.step .box { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--faint); display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.step.done .box { background: var(--green); border-color: var(--green); color: #fff; }
.step.done .label { color: var(--muted); text-decoration: line-through; }
.step .label { flex: 1; }

.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; direction: ltr; text-align: left; word-break: break-all; background: var(--soft); padding: 10px; border-radius: 10px; }
ol.steps { padding-inline-start: 20px; margin: 8px 0; }
ol.steps li { margin-bottom: 6px; }

#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 5;
}
#tabs[hidden] { display: none; }
#tabs button { flex: 1; border: none; background: none; font-size: 11px; color: var(--faint); display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 0; }
#tabs button span { font-size: 20px; filter: grayscale(1); opacity: 0.6; }
#tabs button.on { color: var(--green); }
#tabs button.on span { filter: none; opacity: 1; }

.fab { position: fixed; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%; border: none; background: var(--green); color: #fff; font-size: 30px; line-height: 1; z-index: 4; }

#sheet { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
#sheet[hidden] { display: none; }
#sheet .panel { background: var(--bg); width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }

#toast { position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 14px 10px 18px; border-radius: 12px; font-size: 14px; z-index: 20; width: max-content; max-width: 92vw; display: flex; align-items: center; gap: 12px; }
#toast[hidden] { display: none; }
.toast-btn { border: none; background: var(--green); color: #fff; font-weight: 600; font-size: 14px; padding: 6px 12px; border-radius: 8px; flex-shrink: 0; }
.cat.more { color: var(--muted); }
.card.dim { opacity: 0.55; }
.err { color: var(--red); font-size: 13px; margin: -4px 0 10px; }

.chat { display: flex; flex-direction: column; gap: 10px; padding-bottom: 150px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; line-height: 1.6; font-size: 15px; word-wrap: break-word; }
.msg.user { align-self: flex-start; background: var(--green); color: #fff; border-bottom-right-radius: 4px; }
@media (prefers-color-scheme: dark) { .msg.user { color: #04342c; } }
.msg.bot { align-self: flex-end; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.bot.error { border-color: var(--red); color: var(--red); }
.msg a { color: var(--blue); }
.msg .steps-line { font-size: 12px; color: var(--faint); margin-top: 6px; }
.msg ul { margin: 4px 0; padding-inline-start: 18px; }
.typing { display: flex; flex-direction: column; gap: 4px; }
.typing .dots::after { content: '…'; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: 0.2; } }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 4;
  background: var(--bg); border-top: 1px solid var(--line); padding: 8px 12px;
}
.composer .inner { max-width: 520px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; max-height: 120px; min-height: 42px; padding: 10px 12px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--card); line-height: 1.4;
}
.composer button { width: 42px; height: 42px; border-radius: 50%; border: none; background: var(--green); color: #fff; font-size: 18px; flex-shrink: 0; }
.composer button:disabled { opacity: 0.4; }
.quick { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; max-width: 520px; margin: 0 auto; }
.quick .chip { white-space: nowrap; font-size: 13px; padding: 6px 12px; }
.adj { font-size: 12px; background: var(--blue-bg); color: var(--blue); border-radius: 10px; padding: 6px 10px; margin-top: 8px; }

/* الكيبورد مفتوح في الشات: نخفي التبويبات وصندوق الكتابة ينزل تحت */
body.typing #tabs { display: none; }
body.typing .composer { bottom: 0; padding-bottom: 8px; }
.tiny.bad { color: var(--red); }

/* وضع التطوير */
.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: none; background: none; padding: 8px; border-radius: 10px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; }
.devcard { border: 2px solid var(--green); }
.devcard .btn + .btn { margin-top: 6px; }
.mono-inline { font-family: ui-monospace, Menlo, monospace; direction: ltr; text-align: left; }
pre.diff { font-family: ui-monospace, Menlo, monospace; font-size: 11px; line-height: 1.5; direction: ltr; text-align: left; white-space: pre-wrap; word-break: break-all; background: var(--soft); border-radius: 10px; padding: 10px; max-height: 60vh; overflow: auto; }
