:root {
  --bg: #0e1014;
  --panel: #171a21;
  --panel-2: #1e222b;
  --text: #e9eaee;
  --muted: #9ba1ad;
  --line: #2b303b;
  --accent: #e8622a;
  --red: #e5484d;
  --red-bg: #b42318;
  --amber: #f5b041;
  --ok: #3fb950;
  --wa-bg: #0b3d2a;
  --wa-bubble: #b9f5cf;
  --wa-bubble-text: #0b2e1f;
  --ig-head: #ffffff;
  --ig-head-text: #1c1c1e;
  --ig-bubble: #7b4fd6;
  --ig-bubble-text: #ffffff;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --panel-2: #f0f1f4;
    --text: #15171c;
    --muted: #5d6470;
    --line: #d9dce3;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1014;
  --panel: #171a21;
  --panel-2: #1e222b;
  --text: #e9eaee;
  --muted: #9ba1ad;
  --line: #2b303b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", Tahoma, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  overflow-x: hidden;
}

body { min-height: 100vh; }

.wrap {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

header.top {
  padding: 16px 16px 8px;
  max-width: 1200px;
  margin: 0 auto;
}

header.top h1 { font-size: 1.35rem; margin: 6px 0 2px; }
header.top .sub { margin: 0; color: var(--muted); font-size: 0.95rem; }

.demo-tag {
  display: inline-block;
  font-size: 0.78rem;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--accent);
  color: var(--accent);
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  min-width: 0;
}

.card h2 { font-size: 1.05rem; margin: 0 0 8px; }

label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 10px; }

input, select, textarea, button {
  font: inherit;
  color: inherit;
  max-width: 100%;
}

input, select, textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  margin-top: 4px;
}

textarea { min-height: 84px; resize: vertical; }

button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
}

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }
button:disabled { opacity: 0.45; cursor: default; }

.note { font-size: 0.88rem; color: var(--muted); min-height: 1.4em; }
.note.bad { color: var(--red); }
.note.good { color: var(--ok); }

/* ----- patient page ----- */
.patient .newbox form { display: grid; gap: 4px; }
.chat {
  margin-top: 14px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 420px;
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
}
.chat.wa .chat-head { background: var(--wa-bg); color: #e8fff2; }
.chat.ig .chat-head { background: var(--ig-head); color: var(--ig-head-text); border-bottom: 1px solid #e2e2e2; }
.chat.ig .chat-head .demo-tag { border-color: #7b4fd6; color: #7b4fd6; }
.log {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  max-height: 60vh;
  min-height: 260px;
  background: var(--panel-2);
}
.bubble {
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  align-self: flex-start;
}
.bubble.mine { align-self: flex-end; }
.chat.wa .bubble.mine { background: var(--wa-bubble); color: var(--wa-bubble-text); }
.chat.wa .bubble.theirs { background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.chat.ig .bubble.mine { background: var(--ig-bubble); color: var(--ig-bubble-text); }
.chat.ig .bubble.theirs { background: #ececf1; color: #1c1c1e; }
.bubble .tr { display: block; margin-top: 4px; font-size: 0.82rem; opacity: 0.85; }
.bubble.flash { outline: 3px solid var(--amber); }
.bubble .who { display: block; font-size: 0.72rem; opacity: 0.7; }

.composer {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  margin: 0;
}
.composer input { margin: 0; flex: 1; min-width: 0; }

.chat-select { margin-top: 8px; }

.muted { color: var(--muted); }
[hidden] { display: none !important; }
details summary { cursor: pointer; color: var(--muted); }

/* ----- operator page (every rule is scoped to body.operator) ----- */
body.operator {
  --red-bg: #b42318;
  font-size: 16px;
  line-height: 1.8;
}
body.operator .op-top {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 16px 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
}
body.operator .op-top h1 { font-size: 1.25rem; margin: 0; }
body.operator .demo-line { margin: 0; font-size: 14px; color: var(--amber); }
body.operator .op-app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 28px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  align-items: start;
}
body.operator .op-app > * { min-width: 0; }
body.operator .op-list { position: sticky; top: 16px; }
body.operator .list-toggle { display: none; }
body.operator .list-title { font-size: 14px; margin: 0 0 12px; color: var(--muted); font-weight: 700; }
body.operator .convs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
body.operator .conv {
  display: block;
  width: 100%;
  text-align: start;
  background: var(--panel);
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
}
body.operator .conv.active { background: var(--panel-2); box-shadow: inset 0 0 0 2px var(--accent); }
body.operator .conv.urgent { border-inline-start: 6px solid var(--red); padding-inline-start: 12px; }
body.operator .conv-name { display: block; font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
body.operator .conv-meta { display: block; font-size: 14px; color: var(--muted); }
body.operator .conv-last {
  display: block;
  margin-top: 4px;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.operator .conv-last.empty { color: var(--muted); }
body.operator .tag-urgent {
  display: inline-block;
  margin-top: 6px;
  font-size: 14px;
  font-weight: 700;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--red-bg);
  color: #fff;
}
body.operator .tag { display: inline-block; font-size: 0.8rem; padding: 0 8px; border-radius: 999px; border: 1px solid var(--line); margin-inline-end: 4px; }
body.operator .tag.wa { border-color: #25d366; color: #25d366; }
body.operator .tag.ig { border-color: #b57edc; color: #b57edc; }
body.operator .list-note { margin-top: 10px; }

body.operator .op-main { display: flex; flex-direction: column; gap: 18px; }
body.operator .op-empty { color: var(--muted); font-size: 1.05rem; padding: 48px 0; }
body.operator .conv-head { display: flex; flex-direction: column; gap: 8px; }
body.operator .conv-head h2 { font-size: 1.3rem; margin: 0; overflow-wrap: anywhere; }
body.operator .chips { display: flex; flex-wrap: wrap; gap: 8px; }
body.operator .chip {
  font-size: 14px;
  padding: 2px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  overflow-wrap: anywhere;
}
body.operator .chip .k { color: var(--muted); }
body.operator .chip bdi { unicode-bidi: isolate; }

body.operator .urgent-banner {
  background: var(--red-bg);
  color: #fff;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.8;
}

body.operator .log {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 56vh;
  min-height: 200px;
  overflow-y: auto;
  padding: 4px 2px;
  background: transparent;
}
body.operator .msg { display: flex; flex-direction: column; max-width: 80%; }
body.operator .msg.from-patient { align-self: flex-start; }
body.operator .msg.from-op { align-self: flex-end; }
body.operator .msg .who { font-size: 14px; color: var(--muted); margin-bottom: 2px; }
body.operator .msg .text {
  background: var(--panel-2);
  color: var(--text);
  border-radius: 16px;
  padding: 10px 14px;
  font-size: 16px;
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
body.operator .msg.from-op .text { background: rgba(232, 98, 42, 0.18); }
body.operator .msg .tr { margin-top: 4px; padding-inline-start: 14px; font-size: 15px; color: var(--muted); overflow-wrap: anywhere; }
body.operator .msg.flash .text { outline: 3px solid var(--amber); }

body.operator .suggest {
  background: var(--panel);
  border-radius: 16px;
  border-inline-start: 4px solid var(--accent);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
body.operator .suggest p { margin: 0; overflow-wrap: anywhere; }
body.operator .suggest .label { font-size: 14px; font-weight: 700; color: var(--accent); }
body.operator .suggest .gloss { font-size: 1.1rem; line-height: 1.8; }
body.operator .suggest .why { font-size: 16px; }
body.operator .suggest .why b { color: var(--muted); font-weight: 600; margin-inline-end: 4px; }
body.operator .suggest .dir { font-size: 14px; color: var(--muted); }
body.operator .suggest .notice { color: var(--amber); }
body.operator .suggest .route { font-size: 15px; }
body.operator .suggest .gap-line { font-size: 15px; color: var(--amber); }
body.operator details.tech { margin-top: 4px; }
body.operator details.tech summary { font-size: 14px; color: var(--muted); padding: 4px 0; }
body.operator details.tech .tech-body { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; font-size: 14px; color: var(--muted); }
body.operator details.tech .tech-body div { overflow-wrap: anywhere; }
body.operator .why-ref { color: var(--accent); cursor: pointer; text-decoration: underline; margin-inline-end: 6px; }
body.operator .flag {
  display: inline-block;
  font-size: 14px;
  padding: 0 8px;
  border-radius: 8px;
  margin: 2px 4px 2px 0;
  background: rgba(245, 176, 65, 0.18);
  color: var(--amber);
  border: 1px solid var(--amber);
}
body.operator .flag.red { background: rgba(229, 72, 77, 0.18); color: var(--red); border-color: var(--red); }

body.operator .writer { display: flex; flex-direction: column; gap: 10px; }
body.operator .writer label { font-size: 14px; margin: 0; }
body.operator .writer textarea { min-height: 96px; font-size: 16px; line-height: 1.8; background: var(--panel); }
body.operator .writer .row { display: flex; gap: 10px; flex-wrap: wrap; }
body.operator .writer .row button { min-height: 44px; font-size: 16px; padding: 10px 18px; }
body.operator .writer .note { font-size: 14px; }

body.operator .bidi, body.operator .msg .text, body.operator .suggest p, body.operator textarea {
  unicode-bidi: plaintext;
}

/* narrow screens: the list folds behind one button; the main area keeps its order */
@media (max-width: 899px) {
  body.operator .op-app { grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 12px 16px 40px; }
  body.operator .op-list { position: static; }
  body.operator .list-toggle {
    display: block;
    width: 100%;
    min-height: 48px;
    font-size: 16px;
    font-weight: 700;
    text-align: start;
    background: var(--panel);
  }
  body.operator .list-body { display: none; }
  body.operator .op-app.list-open .list-body { display: block; margin-top: 10px; }
  /* no inner scroll box on a phone: the page scrolls and the newest message is brought into view */
  body.operator .log { max-height: none; overflow: visible; }
  .chat .log { max-height: none; overflow: visible; }
  /* the manager's column (urgent news for the manager) comes first on a phone */
  .board #col-manager { order: -1; }
}

/* a suggestion that was already sent (or dismissed) stays visible, dimmed */
body.operator .suggest.used { opacity: 0.55; }
body.operator .used-label { margin: 0 0 6px; font-weight: 700; color: var(--muted); }

/* ----- coordinators page ----- */
.board {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px 24px;
}
.board > * { min-width: 0; }
@media (min-width: 900px) {
  .board { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); align-items: start; }
}
.board .col-head { font-weight: 700; margin-bottom: 4px; }
.board .col-head small { display: block; color: var(--muted); font-weight: 400; }
.news {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin-top: 8px;
  background: var(--panel-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.news.urgent { border-color: var(--red); background: rgba(229, 72, 77, 0.12); }
.news .when { font-size: 0.78rem; color: var(--muted); display: block; }
.news .who { font-weight: 600; display: block; }
.empty { color: var(--muted); font-size: 0.9rem; }

/* direction per text: each message and suggestion runs in its own script's direction */
.bubble, .big, .gloss, .record dd, .news, .guide .big, .guide .gloss, textarea, input.bidi {
  unicode-bidi: plaintext;
}

/* ----- shared tag (patient and coordinators pages) ----- */
.tag { display: inline-block; font-size: 0.74rem; padding: 0 8px; border-radius: 999px; border: 1px solid var(--line); margin-inline-end: 4px; }
.tag.wa { border-color: #25d366; color: #25d366; }
.tag.ig { border-color: #b57edc; color: #b57edc; }
.tag.urgent { background: var(--red); border-color: var(--red); color: #fff; font-weight: 700; }

/* Public sample only (DEMO_MODE=1): sample buttons on the patient page and the side link. */
.demo-nav { margin-inline-start: 12px; font-size: 14px; }
.samples-title { margin: 0 0 8px; font-weight: 600; }
.samples-list { display: flex; flex-wrap: wrap; gap: 8px; }
.sample-btn { font: inherit; padding: 8px 12px; border: 1px solid currentColor; border-radius: 8px; background: transparent; color: inherit; cursor: pointer; }
