/* ==========================================================================
   IDA customer service chat
   Palette: institutional petrol + industrial signal-amber (used sparingly).
   Type: IBM Plex Sans Arabic (Arabic + Latin) — one family, clear scale.
   ========================================================================== */
:root {
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface-2: #f6f8f9;
  --ink: #0c2233;
  --ink-2: #44596a;
  --ink-3: #6f8291;
  --line: #d6dfe5;
  --line-2: #b9c7d0;
  --petrol: #0b5b6e;
  --petrol-d: #084657;
  --petrol-soft: #e1edf0;
  --amber: #f2a900;
  --amber-soft: #fff4d6;
  --amber-ink: #6b4a00;
  --danger: #b42318;
  --ok: #087443;
  --user-bubble: var(--petrol);
  --user-ink: #ffffff;
  --shadow: 0 1px 2px rgba(12, 34, 51, .06), 0 8px 24px -12px rgba(12, 34, 51, .18);
  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 7px;
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a161d; --surface: #0f212b; --surface-2: #132a36;
    --ink: #e5eef2; --ink-2: #a9bcc7; --ink-3: #7f95a2;
    --line: #20394a; --line-2: #2d4c60;
    --petrol: #2f97ad; --petrol-d: #4fb0c4; --petrol-soft: #123543;
    --amber: #f2b31d; --amber-soft: #2e2510; --amber-ink: #f5cf72;
    --danger: #f2827a; --ok: #4cc38a;
    --user-bubble: #1a5466; --user-ink: #eaf6f9;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -14px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a161d; --surface: #0f212b; --surface-2: #132a36;
  --ink: #e5eef2; --ink-2: #a9bcc7; --ink-3: #7f95a2;
  --line: #20394a; --line-2: #2d4c60;
  --petrol: #2f97ad; --petrol-d: #4fb0c4; --petrol-soft: #123543;
  --amber: #f2b31d; --amber-soft: #2e2510; --amber-ink: #f5cf72;
  --danger: #f2827a; --ok: #4cc38a;
  --user-bubble: #1a5466; --user-ink: #eaf6f9;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 16px/1.7 var(--font);
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; min-height: 100dvh;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip { position: absolute; inset-inline-start: 12px; top: -60px; background: var(--ink); color: var(--bg);
        padding: 8px 14px; border-radius: 8px; z-index: 50; }
.skip:focus { top: 12px; }
.muted { color: var(--ink-2); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px;
  border-radius: var(--r-md); border: 1px solid transparent; background: none; cursor: pointer;
  font-weight: 500; font-size: 14.5px; text-decoration: none; color: var(--ink); white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn.ghost { border-color: var(--line); background: var(--surface); }
.btn.ghost:hover { border-color: var(--line-2); background: var(--surface-2); }
.btn.primary { background: var(--petrol); color: #fff; }
.btn.primary:hover { background: var(--petrol-d); }
.btn.icon { width: 40px; padding: 0; justify-content: center; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; padding: 12px clamp(16px, 3vw, 28px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; margin-inline-end: auto; }
.mark { width: 42px; height: 42px; stroke: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
.brand-text strong { font-size: 16.5px; font-weight: 700; letter-spacing: -.01em; }
.brand-text > span { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
        box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.top-actions { display: flex; align-items: center; gap: 8px; }

/* language picker */
.lang-picker { position: relative; }
.flag { width: 22px; height: 15px; border-radius: 3px; overflow: hidden; display: inline-flex;
        box-shadow: 0 0 0 1px rgba(0,0,0,.12); }
.flag svg { width: 100%; height: 100%; stroke: none; }
.chev { width: 15px; height: 15px; color: var(--ink-3); }
.lang-menu {
  position: absolute; inset-inline-end: 0; top: calc(100% + 6px); margin: 0; padding: 6px; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow);
  min-width: 190px; max-height: 360px; overflow: auto; display: none; z-index: 30;
}
.lang-menu.open { display: block; }
.lang-menu li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px;
                cursor: pointer; font-size: 14.5px; }
.lang-menu li:hover, .lang-menu li:focus { background: var(--surface-2); outline: none; }
.lang-menu li[aria-selected="true"] { font-weight: 600; }
.lang-menu li[aria-selected="true"]::after { content: ""; margin-inline-start: auto; width: 8px; height: 8px;
                                              border-radius: 2px; background: var(--amber); }

/* ---------- layout ---------- */
.layout {
  flex: 1; width: 100%; max-width: 1240px; margin: 0 auto;
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px;
  padding: 0 clamp(16px, 3vw, 28px);
}
.chat-col { display: flex; flex-direction: column; min-height: 0; max-width: 820px; width: 100%; margin-inline: auto; }
.chat { flex: 1; padding: 28px 0 12px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- welcome + site plan ---------- */
.welcome h1 { font-size: clamp(24px, 3.2vw, 31px); line-height: 1.3; margin: 8px 0 8px; font-weight: 700;
              letter-spacing: -.015em; }
.welcome .lead { margin: 0 0 24px; color: var(--ink-2); max-width: 62ch; }

/* The site plan: topic "plots" laid out like an industrial-zone master plan,
   divided by a service road. This is the one bold element on the page. */
.siteplan {
  --road: 14px;
  position: relative; display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--road);
  padding: var(--road); border-radius: var(--r-lg);
  background:
    repeating-linear-gradient(90deg, transparent 0 18px, color-mix(in srgb, var(--amber) 70%, transparent) 18px 30px) center / 100% 2px no-repeat,
    var(--surface-2);
  border: 1px solid var(--line);
}
.plot {
  position: relative; text-align: start; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 14px 14px 16px; min-height: 118px; display: flex; flex-direction: column; gap: 6px;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 22px 22px; background-position: -1px -1px;
  background-blend-mode: normal;
  transition: border-color .15s, transform .15s;
}
.plot::before {      /* white wash so the survey grid stays faint behind text */
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: linear-gradient(160deg, var(--surface) 35%, color-mix(in srgb, var(--surface) 70%, transparent));
}
.plot > * { position: relative; }
.plot .p-ico { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
               background: var(--petrol-soft); color: var(--petrol); }
.plot .p-ico svg { width: 19px; height: 19px; }
.plot .p-name { font-weight: 600; font-size: 15.5px; }
.plot .p-q { font-size: 13.5px; color: var(--ink-2); line-height: 1.55; }
.plot:hover { border-color: var(--petrol); }
.plot:hover .p-ico { background: var(--petrol); color: #fff; }
.plot:active { transform: translateY(1px); }

/* ---------- messages ---------- */
.msg { display: flex; flex-direction: column; gap: 6px; max-width: 100%; animation: in .22s ease-out both; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }
.msg.user { align-items: flex-start; }
.msg.user .bubble {
  background: var(--user-bubble); color: var(--user-ink); padding: 10px 16px; border-radius: 16px 16px 4px 16px;
  max-width: min(78%, 620px); white-space: pre-wrap; word-wrap: break-word;
}
[dir="ltr"] .msg.user .bubble { border-radius: 16px 16px 16px 4px; }
.msg.bot .who { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-3); font-weight: 500; }
.msg.bot .who .dot { width: 22px; height: 22px; border-radius: 6px; background: var(--petrol); color: #fff;
                     display: grid; place-items: center; font-size: 9.5px; font-weight: 700; letter-spacing: .3px; }
.msg.bot .card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 14px 18px; box-shadow: var(--shadow); overflow-wrap: anywhere;
}
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .7em; }
.md ul, .md ol { margin: 0 0 .8em; padding-inline-start: 1.4em; }
.md li { margin: .2em 0; }
.md li::marker { color: var(--petrol); font-weight: 600; }
.md strong { font-weight: 600; }
.md h1, .md h2, .md h3, .md h4 { font-size: 16.5px; margin: 1em 0 .4em; }
.md table { border-collapse: collapse; width: 100%; margin: .4em 0 1em; font-size: 14.5px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 10px; text-align: start; vertical-align: top; }
.md th { background: var(--surface-2); font-weight: 600; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.md blockquote { margin: 0 0 .8em; padding: 4px 12px; border-inline-start: 3px solid var(--line-2); color: var(--ink-2); }

.typing { display: inline-flex; gap: 5px; padding: 6px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.status-line { font-size: 13px; color: var(--ink-3); margin-inline-start: 8px; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding-inline-start: 4px; }
.act { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: 8px;
       border: 1px solid transparent; background: none; cursor: pointer; color: var(--ink-3); font-size: 13px; }
.act:hover { background: var(--surface); border-color: var(--line); color: var(--ink); }
.act svg { width: 16px; height: 16px; }
.act[aria-pressed="true"] { color: var(--petrol); background: var(--petrol-soft); }
.act.down[aria-pressed="true"] { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.fb-note { display: flex; gap: 8px; width: 100%; margin-top: 4px; }
.fb-note input { flex: 1; height: 36px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px;
                 background: var(--surface); }
.fb-thanks { font-size: 13px; color: var(--ok); padding: 0 8px; }

.escalate {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--amber-soft); color: var(--amber-ink);
  border: 1px solid color-mix(in srgb, var(--amber) 45%, transparent);
  border-inline-start: 4px solid var(--amber);
  padding: 10px 14px; border-radius: var(--r-md); font-size: 14.5px;
}
.escalate span { flex: 1; min-width: 200px; }
.escalate .btn { height: 36px; background: var(--ink); color: var(--bg); }

.err-card { border-color: color-mix(in srgb, var(--danger) 40%, var(--line)) !important; color: var(--danger); }

/* ---------- composer ---------- */
.composer { position: sticky; bottom: 0; padding: 10px 0 14px;
            background: linear-gradient(to top, var(--bg) 70%, transparent); }
.field {
  display: flex; align-items: flex-end; gap: 8px; background: var(--surface);
  border: 1px solid var(--line-2); border-radius: 16px; padding: 8px 8px 8px 8px; box-shadow: var(--shadow);
  transition: border-color .15s;
}
.field:focus-within { border-color: var(--petrol); }
.field textarea { flex: 1; border: 0; outline: 0; resize: none; background: none; padding: 8px 10px;
                  max-height: 180px; line-height: 1.6; }
.send { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--petrol); color: #fff;
        display: grid; place-items: center; cursor: pointer; }
.send:hover { background: var(--petrol-d); }
.send:disabled { background: var(--line-2); cursor: default; }
[dir="rtl"] .send svg { transform: scaleX(-1); }
.fineprint { margin: 8px 4px 0; font-size: 12.5px; color: var(--ink-3); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.demo-tag { background: var(--amber-soft); color: var(--amber-ink); padding: 1px 8px; border-radius: 5px; font-weight: 600; }

/* ---------- side ---------- */
.side { padding-top: 28px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 70px; align-self: start; }
.side-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; }
.side-card h2 { font-size: 15.5px; margin: 0 0 4px; font-weight: 600; }
.side-card p { margin: 0 0 14px; font-size: 14px; color: var(--ink-2); line-height: 1.65; }
.side-card.human { border-top: 3px solid var(--amber); }
.tips { margin: 6px 0 0; padding: 0; list-style: none; font-size: 14px; color: var(--ink-2); }
.tips li { padding: 7px 0; border-top: 1px dashed var(--line); }
.tips li:first-child { border-top: 0; }

/* ---------- dialog ---------- */
.dlg { border: 0; padding: 0; border-radius: 16px; width: min(620px, calc(100vw - 24px));
       background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px -20px rgba(0,0,0,.45); }
.dlg::backdrop { background: rgba(8, 22, 30, .5); backdrop-filter: blur(2px); }
.dlg-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 17px; margin: 0; flex: 1; }
.dlg-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.dlg-body p { margin: 0; font-size: 14px; }
.dlg label { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; font-weight: 500; color: var(--ink-2); }
.dlg input, .dlg select, .dlg textarea {
  border: 1px solid var(--line-2); border-radius: 9px; padding: 9px 11px; background: var(--surface); color: var(--ink);
  font-size: 15px; font-weight: 400; width: 100%; min-width: 0;
}
.dlg input:focus, .dlg select:focus, .dlg textarea:focus { outline: 2px solid var(--petrol); outline-offset: -1px; }
.dlg [aria-invalid="true"] { border-color: var(--danger); }
.grid2 { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 12px; }
.err { color: var(--danger); font-size: 12.5px; min-height: 0; }
.err:empty { display: none; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line);
            background: var(--surface-2); border-radius: 0 0 16px 16px; }
.ref-box { display: flex; flex-direction: column; gap: 6px; padding: 18px; border-radius: 12px; text-align: center;
           background: var(--petrol-soft); color: var(--ink); }
.ref-box strong { font-size: 26px; letter-spacing: .04em; color: var(--petrol); font-variant-numeric: tabular-nums; }

/* ---------- toast ---------- */
.toast { position: fixed; bottom: 96px; inset-inline-start: 50%; transform: translateX(50%);
         background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; z-index: 60; }
[dir="ltr"] .toast { transform: translateX(-50%); }

/* ---------- responsive ---------- */
@media (max-width: 1020px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
}
@media (max-width: 720px) {
  .siteplan { grid-template-columns: repeat(2, 1fr); --road: 10px; background: var(--surface-2); }
  .hide-sm { display: none; }
  .top-actions .btn span:not(.flag) { display: none; }
  .top-actions .btn { padding: 0 10px; }
  .brand-text strong { font-size: 14.5px; }
  .brand-text > span { font-size: 12px; }
  .grid2 { grid-template-columns: 1fr; }
  .msg.user .bubble { max-width: 90%; }
}
@media (max-width: 420px) {
  .brand-text > span { display: none; }
  .plot { min-height: 100px; padding: 12px; }
  .plot .p-q { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
