/* Assistance Injaz — back-office. Nour wa Dhiaa language: olive, copper,
   gold on olive, white cards with a hairline, Cairo for titles and figures,
   Tajawal for text. */
:root {
  --olive: #33402d;
  --olive-deep: #2a3525;
  --olive-tint: #e8ece3;
  --olive-mist: #f0f2ec;
  --copper: #c3753e;
  --copper-text: #a35f2e;
  --copper-soft: #f3e6db;
  --gold: #e3c26f;
  --paper: #f7f7f7;
  --white: #fff;
  --ink: #313131;
  --ink-soft: #4a4a4a;
  --muted: #6b6b6b;
  --line: #e5e5e5;
  --hair: #eeeeea;
  --success: #3d6632;
  --success-soft: #e7eedf;
  --success-dot: #6e8f4e;
  --danger: #a8231b;
  --danger-soft: #f9e1df;
  --display: Cairo, 'Segoe UI', system-ui, sans-serif;
  --text: Tajawal, 'Segoe UI', system-ui, sans-serif;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--paper); color: var(--ink); font: 400 15px/1.45 var(--text); -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--olive); }
.title { font-family: var(--display); font-weight: 700; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
#app { height: 100%; }

/* ── buttons ─────────────────────────────────────────────────────────── */
.btn { height: 46px; padding: 0 18px; border-radius: 14px; border: 1px solid transparent; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-family: var(--display); font-weight: 700; font-size: 14.5px; transition: transform 160ms var(--ease), background 160ms, opacity 160ms; white-space: nowrap; }
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--olive); color: #fff; }
.btn.gold { background: var(--gold); color: var(--olive-deep); }
.btn.ghost { background: transparent; color: var(--copper-text); }
.btn.line { background: #fff; border-color: var(--line); }
.btn.small { height: 36px; padding: 0 12px; font-size: 13px; border-radius: 11px; }
.icon-btn { width: 42px; height: 42px; flex: none; border-radius: 99px; border: 1px solid var(--line); background: #fff; display: grid; place-items: center; transition: transform 160ms var(--ease), background 160ms; }
.icon-btn:active { transform: scale(0.9); }
.icon-btn.on { background: var(--olive); border-color: var(--olive); color: #fff; }
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ── login ───────────────────────────────────────────────────────────── */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(120% 70% at 50% 0%, #3d4b35 0%, var(--olive) 45%, var(--olive-deep) 100%); overflow: auto; }
.auth-card { width: 100%; max-width: 400px; background: var(--paper); border-radius: 28px; padding: 28px 24px 24px; box-shadow: 0 30px 60px -30px rgba(0, 0, 0, 0.6); animation: rise 520ms var(--ease) both; }
.auth-logo { width: 56px; height: 56px; border-radius: 16px; background: var(--olive); display: grid; place-items: center; margin-bottom: 16px; }
.auth h1 { font: 800 24px/1.2 var(--display); margin: 0 0 4px; }
.auth p { margin: 0 0 18px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.field input { height: 48px; border-radius: 14px; border: 1px solid var(--line); background: #fff; padding: 0 14px; outline: none; transition: border-color 160ms, box-shadow 160ms; }
.field input:focus { border-color: var(--olive); box-shadow: 0 0 0 3px rgba(51, 64, 45, 0.12); }
.err { color: var(--danger); background: var(--danger-soft); border-radius: 12px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; animation: shake 360ms var(--ease); }

/* ── layout ──────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 360px minmax(0, 1fr); height: 100%; }
.side { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: #fff; border-right: 1px solid var(--line); }
.side-head { padding: calc(18px + var(--safe-t)) 16px 10px; display: flex; flex-direction: column; gap: 12px; }
.brand { gap: 10px; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; background: var(--olive); display: grid; place-items: center; flex: none; }
.brand h1 { margin: 0; font: 800 19px/1.2 var(--display); }
.brand small { display: block; color: var(--muted); font-size: 12.5px; }
.live { width: 8px; height: 8px; border-radius: 99px; background: var(--success-dot); box-shadow: 0 0 0 0 rgba(110, 143, 78, 0.5); animation: pulse 2s infinite; display: inline-block; margin-inline-end: 6px; }
.live.off { background: #c9c9c4; animation: none; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: #ebebe6; position: relative; }
.seg button { flex: 1; min-width: 0; white-space: nowrap; height: 34px; padding: 0 4px; border: 0; border-radius: 10px; background: transparent; font-weight: 700; font-size: 12.5px; color: var(--ink-soft); transition: background 220ms var(--ease), color 220ms; display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.seg button.on { background: #fff; color: var(--olive); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }
.seg .n { font-family: var(--display); font-size: 12px; color: var(--copper-text); }
.search { height: 42px; border-radius: 21px; border: 1px solid var(--line); background: var(--paper); padding: 0 14px 0 38px; width: 100%; outline: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-size: 18px; background-position: 13px center; }
.search:focus { border-color: var(--olive); background-color: #fff; }
.list { flex: 1; overflow-y: auto; padding: 4px 8px calc(16px + var(--safe-b)); }
.thread { display: flex; gap: 12px; width: 100%; padding: 12px 10px; border: 0; border-radius: 16px; background: transparent; text-align: start; transition: background 160ms; animation: rise 420ms var(--ease) both; position: relative; }
.thread:hover { background: var(--olive-mist); }
.thread.on { background: var(--olive-tint); }
.av { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; flex: none; font: 800 15px var(--display); background: rgba(51, 64, 45, 0.08); color: var(--olive); }
.thread .t1 { display: flex; gap: 8px; align-items: baseline; }
.thread b { font-weight: 700; font-size: 15px; }
.thread time { font-size: 12px; color: var(--muted); flex: none; }
.thread .t2 { font-size: 13px; color: var(--muted); margin-top: 1px; }
.thread.unread b, .thread.unread .t2 { color: var(--ink); font-weight: 700; }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 99px; background: var(--copper); color: #fff; font: 700 12px/22px var(--display); text-align: center; flex: none; animation: pop 320ms var(--ease) both; }
.tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 99px; font-size: 11.5px; font-weight: 700; }
.tag.open { background: var(--copper-soft); color: var(--copper-text); }
.tag.waiting { background: var(--olive-tint); color: var(--olive); }
.tag.resolved { background: var(--success-soft); color: var(--success); }
.empty { text-align: center; padding: 48px 24px; color: var(--muted); animation: rise 420ms var(--ease) both; }
.empty .plate { width: 64px; height: 64px; border-radius: 20px; background: var(--olive-mist); color: var(--olive); display: grid; place-items: center; margin: 0 auto 14px; }
.empty h2 { color: var(--ink); font: 700 17px var(--display); margin: 0 0 4px; }

/* ── conversation ────────────────────────────────────────────────────── */
.main { display: grid; grid-template-columns: minmax(0, 1fr) 300px; min-width: 0; min-height: 0; }
.conv { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.conv-head { display: flex; align-items: center; gap: 10px; padding: calc(14px + var(--safe-t)) 18px 12px; border-bottom: 1px solid var(--line); background: rgba(247, 247, 247, 0.92); backdrop-filter: blur(16px); }
.conv-head h2 { margin: 0; font: 800 18px/1.25 var(--display); }
.conv-head .sub { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.conv-head .sub > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.back { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 18px 22px; display: flex; flex-direction: column; gap: 6px; scroll-behavior: smooth; }
.day { align-self: center; font-size: 12px; font-weight: 700; color: var(--muted); margin: 10px 0 4px; }
.sys { align-self: center; font-size: 12px; color: var(--muted); }
.msg { display: flex; flex-direction: column; max-width: 72%; align-self: flex-start; animation: rise 380ms var(--ease) both; }
.msg.team { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 10px 14px; border-radius: 20px 20px 20px 6px; background: #fff; border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.msg.team .bubble { background: var(--olive); color: #fff; border-color: var(--olive); border-radius: 20px 20px 6px 20px; }
.msg.team .bubble a { color: var(--gold); }
.meta { font-size: 11.5px; color: var(--muted); margin: 3px 4px 0; }
.files { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.msg.team .files { align-items: flex-end; }
.shot { display: block; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); background: #eef0ea; max-width: 300px; }
.shot img { display: block; max-width: 300px; max-height: 240px; object-fit: cover; transition: transform 300ms var(--ease); }
.shot:hover img { transform: scale(1.02); }
.file { display: flex; gap: 10px; align-items: center; width: 280px; padding: 10px 12px; border-radius: 16px; background: #fff; border: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.file .ext { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--danger-soft); color: var(--danger); font: 800 10.5px var(--display); flex: none; }
.file .ext.txt { background: var(--olive-tint); color: var(--olive); }
.gone { font-size: 12.5px; color: var(--muted); font-style: italic; }
.seen { font-size: 11.5px; color: var(--success); font-weight: 700; margin: 2px 4px 0; }

.composer { border-top: 1px solid var(--line); background: #fff; padding: 10px 14px calc(10px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; }
.pending { display: flex; gap: 8px; flex-wrap: wrap; }
.pf { position: relative; width: 92px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: #fff; animation: pop 300ms var(--ease) both; }
.pf img, .pf .pfi { width: 100%; height: 64px; object-fit: cover; display: grid; place-items: center; background: var(--olive-mist); color: var(--olive); }
.pf span { display: block; font-size: 11px; padding: 3px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pf button { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border: 0; border-radius: 99px; background: rgba(0, 0, 0, 0.55); color: #fff; display: grid; place-items: center; }
.compose-row { display: flex; gap: 8px; align-items: flex-end; }
.compose-row textarea { flex: 1; min-height: 44px; max-height: 160px; resize: none; border-radius: 22px; border: 1px solid var(--line); background: var(--paper); padding: 11px 16px; outline: none; field-sizing: content; transition: border-color 160ms, background 160ms; }
.compose-row textarea:focus { border-color: var(--olive); background: #fff; }
.send { width: 44px; height: 44px; border-radius: 99px; border: 0; background: var(--olive); color: #fff; display: grid; place-items: center; flex: none; transition: transform 220ms var(--ease), opacity 160ms; }
.send:disabled { opacity: 0.35; transform: scale(0.88); cursor: default; }
.attach { width: 44px; height: 44px; border-radius: 99px; border: 0; background: var(--olive-mist); color: var(--olive); display: grid; place-items: center; flex: none; }
.suggest { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: #fff; animation: rise 220ms var(--ease) both; }
.suggest button { text-align: start; border: 0; background: #fff; padding: 9px 12px; display: flex; gap: 10px; }
.suggest button + button { border-top: 1px solid var(--hair); }
.suggest button.on, .suggest button:hover { background: var(--olive-mist); }
.suggest b { font-family: var(--display); color: var(--copper-text); flex: none; }
.drop { position: absolute; inset: 0; background: rgba(51, 64, 45, 0.08); border: 2px dashed var(--olive); border-radius: 18px; display: grid; place-items: center; font: 700 16px var(--display); color: var(--olive); pointer-events: none; animation: fade 160ms both; }

/* ── pharmacy panel ──────────────────────────────────────────────────── */
.panel { border-left: 1px solid var(--line); background: #fff; overflow-y: auto; padding: calc(18px + var(--safe-t)) 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.hero { border-radius: 22px; background: var(--olive); color: #fff; padding: 16px; position: relative; overflow: hidden; }
.hero::after { content: ''; position: absolute; inset: 0; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56'%3E%3Cg fill='none' stroke='%23e3c26f' stroke-opacity='0.5' stroke-width='1.5' stroke-linecap='round'%3E%3Cpath d='M14 8v12M8 14h12'/%3E%3Cg transform='translate(42 42) rotate(-45)'%3E%3Crect x='-9.5' y='-4' width='19' height='8' rx='4'/%3E%3Cpath d='M0 -4v8'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"); -webkit-mask: linear-gradient(270deg, #fff, rgba(255, 255, 255, 0.1) 75%, transparent); mask: linear-gradient(270deg, #fff, rgba(255, 255, 255, 0.1) 75%, transparent); pointer-events: none; }
.hero h3 { margin: 0; font: 800 18px/1.25 var(--display); position: relative; }
.hero p { margin: 2px 0 0; color: #cdd2c6; font-size: 13px; position: relative; }
.kv { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; font-size: 13.5px; }
.kv div + div { border-top: 1px solid var(--hair); }
.kv span { color: var(--muted); }
.kv b { font-weight: 700; text-align: end; overflow-wrap: anywhere; }
.actions { display: flex; flex-direction: column; gap: 8px; }

/* ── sheet (settings) ────────────────────────────────────────────────── */
.scrim { position: fixed; inset: 0; background: rgba(22, 28, 19, 0.45); animation: fade 220ms both; z-index: 20; }
.sheet { position: fixed; z-index: 21; top: 0; right: 0; bottom: 0; width: min(420px, 100%); background: var(--paper); padding: calc(18px + var(--safe-t)) 18px calc(18px + var(--safe-b)); overflow-y: auto; animation: slide-in 380ms var(--ease) both; display: flex; flex-direction: column; gap: 14px; }
.sheet h2 { margin: 0; font: 800 22px var(--display); }
.card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card h3 { margin: 0; font: 700 15px var(--display); }
.reply-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--hair); }
.reply-item:first-of-type { border-top: 0; }
.reply-item b { font-family: var(--display); color: var(--copper-text); }
.hint { background: var(--copper-soft); color: #7f4a24; border-radius: 12px; padding: 10px 12px; font-size: 13px; }
.card input, .card textarea { border-radius: 12px; border: 1px solid var(--line); padding: 9px 12px; outline: none; resize: vertical; }

#toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: var(--olive); color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 220ms, transform 320ms var(--ease); z-index: 40; max-width: calc(100% - 32px); }
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-in { from { transform: translateX(100%); } to { transform: none; } }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(110, 143, 78, 0.5); } 70% { box-shadow: 0 0 0 8px rgba(110, 143, 78, 0); } 100% { box-shadow: 0 0 0 0 rgba(110, 143, 78, 0); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; } }

/* ── narrow screens: list, then conversation full screen ─────────────── */
@media (max-width: 1100px) { .main { grid-template-columns: minmax(0, 1fr); } .panel { display: none; } .panel.open { display: flex; position: fixed; inset: 0; z-index: 15; border: 0; animation: slide-in 380ms var(--ease) both; } }
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .conv-head [data-status] { display: none; }
  .conv-head { padding-left: 12px; padding-right: 12px; }
  .side { border-right: 0; }
  .shell.in-thread .side { display: none; }
  .shell:not(.in-thread) .main { display: none; }
  .back { display: grid; }
  .msgs { padding: 14px 12px; }
  .msg { max-width: 86%; }
  .shot img, .shot { max-width: 240px; }
  .file { width: 240px; }
  .conv { animation: slide-in 360ms var(--ease) both; }
}
