/* بِدلي — نظام التصميم: Swiss/Minimal، أخضر تِيل موثوق، IBM Plex Sans Arabic */
:root {
  --bg: #f4f7f7; --surface: #ffffff; --surface-2: #eef4f3; --line: #dbe4e2; --line-strong: #b9c8c5;
  --ink: #0f1f1d; --ink-2: #3f5250; --muted: #5f7370;
  --brand: #0f766e; --brand-2: #0b5f59; --brand-soft: #d9f0ed; --brand-ink: #ffffff;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2; --info: #1d4ed8; --info-soft: #dbeafe;
  --buyer: #ffffff; --ours: #dcf3ee; --agent: #e0ecff;
  --r: 14px; --r-sm: 10px; --shadow: 0 1px 2px rgba(15, 31, 29, .06), 0 6px 20px -12px rgba(15, 31, 29, .18);
  --nav-h: 64px; --top-h: 56px; --t: 200ms cubic-bezier(.2, .7, .2, 1);
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1716; --surface: #142120; --surface-2: #1b2a29; --line: #23413d; --line-strong: #2f5651;
    --ink: #e6efee; --ink-2: #c1d0ce; --muted: #8fa5a2;
    --brand: #2dd4bf; --brand-2: #5eead4; --brand-soft: #123c38; --brand-ink: #062b28;
    --ok: #4ade80; --ok-soft: #12351f; --warn: #fbbf24; --warn-soft: #3a2a08; --bad: #f87171; --bad-soft: #3d1414; --info: #93c5fd; --info-soft: #14284a;
    --buyer: #1b2a29; --ours: #123c38; --agent: #1a2b48;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 var(--font); font-feature-settings: "tnum"; }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 1.4rem; font-weight: 700; margin: 0; letter-spacing: -.01em; }
h2 { font-size: .8rem; font-weight: 600; margin: 1.5rem 0 .6rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

/* ---------- الهيكل ---------- */
#top { position: sticky; top: 0; z-index: 30; height: var(--top-h); display: flex; align-items: center; gap: .75rem; padding: 0 1rem; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .5rem; color: var(--ink); font-weight: 700; }
.mark { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; line-height: 1; }
.brand-name { font-size: 1.15rem; }
.office { flex: 1; min-width: 0; color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#view { max-width: 1040px; margin: 0 auto; padding: 1.25rem 1rem calc(var(--nav-h) + 1.5rem); }
#nav { position: fixed; bottom: 0; inset-inline: 0; height: var(--nav-h); z-index: 30; display: flex; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#nav a { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .74rem; font-weight: 500; color: var(--muted); transition: color var(--t); }
#nav a.active { color: var(--brand); }
#nav a.active svg { stroke-width: 2.2; }
#nav .dot { position: absolute; top: 8px; inset-inline-start: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--bad); color: #fff; font-size: .68rem; font-weight: 700; display: grid; place-items: center; }
@media (min-width: 900px) {
  body { padding-inline-start: 220px; }
  #top { padding-inline-start: 1.25rem; }
  #nav { position: fixed; top: 0; bottom: 0; inset-inline-start: 0; inset-inline-end: auto; width: 220px; height: auto; flex-direction: column; justify-content: flex-start; padding: calc(var(--top-h) + 1rem) .75rem 1rem; border-top: 0; border-inline-end: 1px solid var(--line); gap: .25rem; }
  #nav a { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: .75rem; padding: .7rem .9rem; border-radius: var(--r-sm); font-size: .95rem; }
  #nav a.active { background: var(--brand-soft); }
  #nav .dot { position: static; margin-inline-start: auto; }
  #view { padding-bottom: 2rem; }
}

/* ---------- المكوّنات ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 1rem 1.1rem; margin-bottom: .75rem; box-shadow: var(--shadow); }
a.card, .card.link { display: block; color: inherit; cursor: pointer; transition: border-color var(--t), box-shadow var(--t), background var(--t); }
a.card:hover, .card.link:hover { border-color: var(--line-strong); box-shadow: 0 8px 24px -14px rgba(15, 31, 29, .3); }
.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack { display: grid; gap: .75rem; }
.muted { color: var(--muted); font-size: .9rem; }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: .15rem; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); display: grid; place-items: center; cursor: pointer; transition: background var(--t), border-color var(--t); }
.icon-btn:hover { background: var(--surface-2); border-color: var(--line-strong); }

.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .6rem; border-radius: 999px; font-size: .76rem; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge svg { width: 14px; height: 14px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand-2); }

.btn, button.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 44px; padding: .55rem 1.1rem; border-radius: var(--r-sm); border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); font-weight: 600; cursor: pointer; transition: background var(--t), border-color var(--t), color var(--t), opacity var(--t); }
.btn:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.neutral { background: var(--surface); border-color: var(--line); color: var(--ink-2); }
.btn.neutral:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.btn.block { width: 100%; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin: .9rem 0; }
.pill { display: inline-flex; align-items: center; gap: .4rem; min-height: 36px; padding: .3rem .8rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-size: .85rem; font-weight: 600; cursor: pointer; transition: background var(--t), border-color var(--t); }
.pill svg { width: 16px; height: 16px; }
.pill.on { border-color: color-mix(in srgb, var(--ok) 40%, transparent); color: var(--ok); }
.pill.off { border-color: color-mix(in srgb, var(--warn) 40%, transparent); color: var(--warn); }

/* نماذج */
form label, .field > span { display: block; margin: .8rem 0 .3rem; font-size: .85rem; font-weight: 500; color: var(--ink-2); }
input, select, textarea { width: 100%; min-height: 44px; padding: .55rem .8rem; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface); transition: border-color var(--t), box-shadow var(--t); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
input[readonly] { background: var(--surface-2); color: var(--ink-2); }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; margin: 0; accent-color: var(--brand); }
.check { display: flex; align-items: center; gap: .6rem; margin-top: 1rem; color: var(--ink); font-size: .95rem; }
.check span, .check a { margin: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.err { color: var(--bad); margin: .5rem 0 0; font-size: .9rem; min-height: 1.2em; }
.hint { display: flex; gap: .5rem; align-items: center; background: var(--warn-soft); color: var(--warn); border-radius: var(--r-sm); padding: .55rem .8rem; font-size: .9rem; margin-top: .6rem; }
.otp { letter-spacing: .5em; text-align: center; font-size: 1.4rem; font-weight: 600; }

/* تبويبات */
.tabs { display: flex; gap: .35rem; overflow-x: auto; margin-bottom: 1rem; padding-bottom: 2px; scrollbar-width: none; }
.tabs a { padding: .4rem .9rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); white-space: nowrap; font-size: .88rem; font-weight: 500; transition: background var(--t), color var(--t), border-color var(--t); }
.tabs a:hover { border-color: var(--line-strong); }
.tabs a.active { background: var(--ink); border-color: var(--ink); color: var(--bg); }

/* إحصاءات اليوم */
.stats { display: grid; gap: .75rem; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(3, 1fr); } }
.stat, a.card.stat { position: relative; display: flex; flex-direction: column; gap: .35rem; min-height: 112px; }
.stat .ic { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-2); }
.stat .ic svg { width: 18px; height: 18px; }
.stat b { font-size: 2rem; line-height: 1.1; font-weight: 700; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.alert .ic { background: var(--bad-soft); color: var(--bad); }
.stat.alert b { color: var(--bad); }
.status-card { display: flex; align-items: center; gap: .9rem; }
.status-card .ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--ok-soft); color: var(--ok); }
.status-card.off .ic { background: var(--warn-soft); color: var(--warn); }

/* الدرج */
.ladder { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.rung { display: inline-flex; flex-direction: column; align-items: center; padding: .35rem .65rem; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--line); font-size: .9rem; font-weight: 600; line-height: 1.2; }
.rung small { font-weight: 400; color: var(--muted); font-size: .68rem; margin-top: 2px; }
.rung.ask { background: var(--surface); }
.rung.used { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 40%, transparent); color: var(--brand-2); }
.rung.floor { border-style: dashed; background: transparent; }
.ladder .sep { color: var(--line-strong); }
.ladder .sep svg { width: 14px; height: 14px; transform: scaleX(-1); }

/* قوائم */
.item { display: flex; gap: .85rem; align-items: flex-start; }
.avatar { width: 42px; height: 42px; border-radius: 12px; background: var(--brand-soft); color: var(--brand-2); display: grid; place-items: center; font-weight: 700; flex: none; }
.avatar.bad { background: var(--bad-soft); color: var(--bad); }
.item .body { flex: 1; min-width: 0; }
.item .title { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.item .title b { font-size: 1rem; }
.item .snippet { color: var(--muted); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: .25rem; }
.item .meta { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .4rem; }
.time { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty svg { width: 44px; height: 44px; stroke: var(--line-strong); margin-bottom: .6rem; }
.empty p { margin: 0 auto; max-width: 34ch; }

/* المحادثة */
.conv-head { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.conv-head .back { color: var(--ink-2); }
.conv-head .back svg { transform: scaleX(-1); }
.conv-head .who { flex: 1; min-width: 0; }
.conv-head .who b { display: block; font-size: 1.05rem; }
.conv-head .who .muted { direction: ltr; text-align: end; unicode-bidi: embed; }
.detail { display: grid; gap: 1rem; }
@media (min-width: 900px) { .detail { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; } .detail aside { position: sticky; top: calc(var(--top-h) + 1rem); } }
.chat { display: flex; flex-direction: column; gap: .35rem; padding: .25rem 0 .75rem; }
.msg { max-width: 82%; padding: .55rem .8rem; border-radius: 16px; background: var(--buyer); border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; line-height: 1.55; }
.msg.in { align-self: flex-start; border-start-start-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--ours); border-color: transparent; border-start-end-radius: 4px; }
.msg.out.agent { background: var(--agent); }
.msg .meta { display: block; font-size: .7rem; color: var(--muted); margin-top: .25rem; }
.msg.guarded { border: 1px solid var(--warn); }
.day { align-self: center; font-size: .72rem; color: var(--muted); background: var(--surface-2); padding: .15rem .6rem; border-radius: 999px; margin: .4rem 0; }
.compose { position: sticky; bottom: calc(var(--nav-h) + .5rem); display: flex; gap: .5rem; align-items: flex-end; background: var(--bg); padding: .5rem 0; }
@media (min-width: 900px) { .compose { bottom: 0; } }
.compose textarea { resize: none; min-height: 44px; max-height: 140px; border-radius: 22px; padding: .6rem 1rem; }
.compose .btn { width: 44px; height: 44px; padding: 0; border-radius: 50%; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .35rem .9rem; margin: 0; font-size: .95rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.timeline { list-style: none; margin: 0; padding: 0; border-inline-start: 2px solid var(--line); }
.timeline li { position: relative; padding: .15rem 0 .5rem 0; padding-inline-start: 1rem; font-size: .85rem; color: var(--ink-2); }
.timeline li::before { content: ""; position: absolute; inset-inline-start: -6px; top: .55em; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--line-strong); }
.timeline li .time { display: block; }

/* البطاقات */
.hcard { position: relative; overflow: hidden; }
.hcard::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 5px; background: var(--muted); }
.hcard.high::before { background: var(--ok); }
.hcard.medium::before { background: var(--warn); }
.hcard.urgent::before { background: var(--bad); }
.outcomes { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
@media (min-width: 640px) { .outcomes { grid-template-columns: repeat(4, 1fr); } }
.outcomes .btn.selected { background: var(--ink); border-color: var(--ink); color: var(--bg); }

/* الدخول */
.auth { max-width: 440px; margin: 2rem auto; }
.auth .logo { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.25rem; }
.auth .logo .mark { width: 44px; height: 44px; border-radius: 12px; font-size: 1.4rem; }
.auth .tag { color: var(--muted); font-size: .95rem; }
.steps { display: flex; gap: .4rem; margin: 1rem 0 1.25rem; }
.steps i { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.steps i.done { background: var(--brand); }

/* أسئلة شائعة */
.faq-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: .5rem; align-items: center; margin-top: .5rem; }
.faq-row .icon-btn { width: 36px; height: 36px; }

/* هيكل التحميل */
.skel { border-radius: var(--r); background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; height: 84px; margin-bottom: .75rem; }
@keyframes shimmer { to { background-position: -200% 0; } }

#toast { position: fixed; bottom: calc(var(--nav-h) + 1rem); inset-inline: 1rem; margin: auto; max-width: 420px; background: var(--ink); color: var(--bg); padding: .7rem 1rem; border-radius: var(--r-sm); z-index: 50; text-align: center; box-shadow: var(--shadow); }
@media (min-width: 900px) { #toast { bottom: 1.5rem; inset-inline-start: calc(220px + 1rem); } }
