/* ============ Klinik Hijraa Bangi — WhatsApp inbox ============ */

:root {
  --brand: #0117e6;
  --brand-dark: #0112b8;
  --brand-deep: #0a0d66;
  --brand-soft: #e8ebfe;
  --accent: #fe0000;
  --ink: #0f172a;
  --ink-soft: #475569;
  --ink-faint: #94a3b8;
  --bg: #f2f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --line-soft: #eef2f7;
  --hover: #f5f7fb;
  --sel: #eef1ff;
  --bubble-in: #ffffff;
  --bubble-out: #0117e6;
  --bubble-out-ink: #ffffff;
  --note-bg: #fff8e1;
  --note-line: #f4d77a;
  --chat-bg: #eef2f8;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 14px;
  --shadow: 0 8px 24px -12px rgba(15, 23, 42, .16);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-soft: #1b2156;
    --ink: #e5e9f5;
    --ink-soft: #a9b3c9;
    --ink-faint: #6b7590;
    --bg: #0b1020;
    --card: #121a2e;
    --line: #232d47;
    --line-soft: #1a2339;
    --hover: #17203a;
    --sel: #1b2550;
    --bubble-in: #1a2440;
    --bubble-out: #2a3cf0;
    --note-bg: #3a3214;
    --note-line: #6b5a1f;
    --chat-bg: #0e1528;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand-soft: #1b2156;
  --ink: #e5e9f5;
  --ink-soft: #a9b3c9;
  --ink-faint: #6b7590;
  --bg: #0b1020;
  --card: #121a2e;
  --line: #232d47;
  --line-soft: #1a2339;
  --hover: #17203a;
  --sel: #1b2550;
  --bubble-in: #1a2440;
  --bubble-out: #2a3cf0;
  --note-bg: #3a3214;
  --note-line: #6b5a1f;
  --chat-bg: #0e1528;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

input[type="text"], input[type="search"], input[type="email"], input[type="password"], select, textarea {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(1, 23, 230, .12); }

.btn-primary {
  background: var(--brand); color: #fff; font-weight: 600;
  padding: 9px 16px; border-radius: 10px; white-space: nowrap;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-ghost {
  border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; font-weight: 500; background: var(--card);
}
.btn-ghost:hover { background: var(--hover); }

.app { display: flex; height: 100vh; height: 100dvh; }

/* ================= rail ================= */

.rail {
  width: 220px; flex: none;
  background: linear-gradient(180deg, var(--brand-deep), #0d1a8a 60%, var(--brand-dark));
  color: #fff;
  display: flex; flex-direction: column;
  padding: 16px 12px;
}
.rail-brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.rail-logo {
  width: 42px; height: 42px; border-radius: 12px; background: #fff;
  display: grid; place-items: center; overflow: hidden; flex: none;
}
.rail-logo img { width: 36px; display: block; }
.rail-title b { display: block; font-size: 14px; letter-spacing: -.2px; }
.rail-title span { font-size: 11px; opacity: .7; }

.rail-links { display: flex; flex-direction: column; gap: 3px; }
.rail-links a, .rail-out {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  color: rgba(255, 255, 255, .82); text-decoration: none; font-weight: 500;
}
.rail-links a:hover, .rail-out:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.rail-links a.on { background: rgba(255, 255, 255, .16); color: #fff; }
.rail-links .ic, .rail-out .ic { width: 20px; text-align: center; }
.rail-links em {
  margin-left: auto; font-style: normal; font-size: 11px; font-weight: 700;
  background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 7px;
}

.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.theme-toggle {
  display: flex; background: rgba(255, 255, 255, .08); border-radius: 10px; padding: 3px;
}
.theme-toggle button { flex: 1; padding: 6px 0; border-radius: 8px; font-size: 13px; }
.theme-toggle button.on { background: rgba(255, 255, 255, .2); }
.me { padding: 0 6px; }
.me b { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me span { font-size: 11px; opacity: .7; }

/* ================= views ================= */

.view { flex: 1; min-width: 0; display: flex; }
.view-page { overflow-y: auto; }

/* ---------- list pane ---------- */

.list-pane {
  width: 360px; flex: none;
  background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.list-head h1, .page-head h1 { font-size: 19px; letter-spacing: -.3px; }
.count {
  background: var(--line-soft); color: var(--ink-soft); font-size: 12px; font-weight: 600;
  padding: 2px 9px; border-radius: 999px;
}
.list-tools { padding: 4px 16px 10px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.filters { display: flex; gap: 4px; flex-wrap: wrap; }
.filters button {
  font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 999px;
  color: var(--ink-soft); background: var(--line-soft);
}
.filters button.on { background: var(--brand); color: #fff; }

.conv-list { flex: 1; overflow-y: auto; }
.conv {
  display: flex; gap: 11px; padding: 12px 16px; cursor: pointer;
  border-bottom: 1px solid var(--line-soft);
}
.conv:hover { background: var(--hover); }
.conv.on { background: var(--sel); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
:root[data-theme="dark"] .avatar { color: #aab4ff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .avatar { color: #aab4ff; } }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; align-items: baseline; gap: 8px; }
.conv-top b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.conv-time { font-size: 11px; color: var(--ink-faint); flex: none; }
.conv.unread .conv-time { color: var(--brand); font-weight: 600; }
.conv-prev {
  display: flex; align-items: center; gap: 6px; margin-top: 2px;
  color: var(--ink-soft); font-size: 13px;
}
.conv-prev span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.unread .conv-prev span { color: var(--ink); font-weight: 600; }
.badge {
  flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--brand); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.chip {
  font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 6px;
  background: var(--line-soft); color: var(--ink-soft);
}
.chip.st-new { background: #e0f2fe; color: #0369a1; }
.chip.st-follow_up { background: #fef3c7; color: #92400e; }
.chip.st-booking { background: #dcfce7; color: #166534; }
.chip.st-done { background: #e2e8f0; color: #334155; }
.chip.st-no_response { background: #fee2e2; color: #991b1b; }
.chip.tag { background: #ede9fe; color: #5b21b6; }
.chip.who { background: transparent; border: 1px solid var(--line); }
.list-empty { padding: 40px 20px; text-align: center; color: var(--ink-faint); font-size: 13px; }

/* ---------- chat pane ---------- */

.chat-pane { flex: 1; min-width: 0; display: flex; background: var(--chat-bg); }
.chat-empty {
  margin: auto; text-align: center; color: var(--ink-faint);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.chat-empty b { color: var(--ink); font-size: 15px; }
.empty-ic {
  width: 52px; height: 52px; border-radius: 14px; background: var(--card);
  display: grid; place-items: center; font-size: 22px; box-shadow: var(--shadow); margin-bottom: 6px;
}
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.chat-head {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.back { display: none; font-size: 28px; line-height: 1; min-width: 36px; min-height: 40px; margin-left: -8px; color: var(--brand); }
.chat-who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-name {
  text-align: left; font-weight: 700; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-name:hover { color: var(--brand); }
.chat-phone { font-size: 12px; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.window-pill {
  font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap;
  background: #dcfce7; color: #166534;
}
.window-pill.closed { background: #fee2e2; color: #991b1b; }

.chat-bar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line-soft);
}
.chat-bar select { width: auto; padding: 6px 10px; font-size: 13px; }
.btn-chip {
  margin-left: auto; font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card);
}
.btn-chip:hover { background: var(--hover); }
.tag-bar {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  padding: 6px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.tag-bar .chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; }
.tag-bar .chip button { font-size: 12px; line-height: 1; opacity: .7; }
.tag-bar .chip button:hover { opacity: 1; }
.tag-add { font-size: 12px; font-weight: 600; color: var(--ink-soft); padding: 2px 6px; }
.tag-add:hover { color: var(--brand); }
.tag-input { width: 140px !important; padding: 3px 8px !important; font-size: 12px; border-radius: 6px !important; }

.msgs { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.day-sep {
  align-self: center; font-size: 11px; font-weight: 600; color: var(--ink-soft);
  background: var(--card); padding: 3px 10px; border-radius: 999px; margin: 8px 0; box-shadow: var(--shadow);
}
.msg {
  max-width: min(72%, 560px); padding: 8px 11px 6px; border-radius: 12px;
  box-shadow: 0 1px 1px rgba(15, 23, 42, .06); word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--bubble-out); color: var(--bubble-out-ink); border-top-right-radius: 4px; }
.msg.note {
  align-self: center; max-width: min(85%, 640px); background: var(--note-bg);
  border: 1px dashed var(--note-line); border-radius: 10px;
}
.msg .who { font-size: 11px; font-weight: 700; color: var(--warn); margin-bottom: 2px; }
.msg-body { white-space: pre-wrap; line-height: 1.42; }
.msg-body a { color: inherit; }
.msg-meta { display: flex; justify-content: flex-end; gap: 6px; font-size: 10.5px; opacity: .7; margin-top: 3px; }
.msg.out .msg-meta { opacity: .85; }
.tick-read { color: #7dd3fc; }
.msg.failed { background: #fee2e2; color: #7f1d1d; }
.msg-err { font-size: 11px; margin-top: 3px; }
.media-img { display: block; max-width: 260px; max-height: 320px; border-radius: 8px; margin-bottom: 4px; cursor: zoom-in; }
.media-btn {
  display: inline-flex; gap: 6px; align-items: center; margin-bottom: 4px;
  padding: 6px 10px; border-radius: 8px; background: rgba(15, 23, 42, .06); font-size: 13px;
}
.msg.out .media-btn { background: rgba(255, 255, 255, .18); }

.composer { background: var(--card); border-top: 1px solid var(--line); padding: 8px 16px 12px; }
.comp-tabs { display: flex; gap: 4px; align-items: center; margin-bottom: 8px; }
.comp-tabs > button, .qr-wrap > button {
  font-size: 12.5px; font-weight: 600; padding: 5px 10px; border-radius: 8px; color: var(--ink-soft);
}
.comp-tabs > button.on { background: var(--brand-soft); color: var(--brand); }
.composer.note .comp-tabs > button.on { background: var(--note-bg); color: var(--warn); }
.qr-wrap { position: relative; margin-left: auto; }
.qr-wrap > button:hover { color: var(--brand); }
.qr-pop {
  position: absolute; bottom: calc(100% + 6px); right: 0; width: 320px; max-height: 300px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); z-index: 10;
}
.qr-pop button { display: block; width: 100%; text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
.qr-pop button:hover { background: var(--hover); }
.qr-pop b { display: block; font-size: 13px; }
.qr-pop span { display: block; font-size: 12px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qr-pop .qr-none { padding: 14px; font-size: 12.5px; color: var(--ink-faint); }
.window-warn {
  font-size: 12.5px; background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa;
  border-radius: 10px; padding: 8px 11px; margin-bottom: 8px; line-height: 1.4;
}
.comp-row { display: flex; gap: 8px; align-items: flex-end; }
.comp-row textarea { resize: none; max-height: 160px; line-height: 1.4; }
.composer.note textarea { background: var(--note-bg); border-color: var(--note-line); }
.btn-send {
  background: var(--brand); color: #fff; font-weight: 600; padding: 10px 18px; border-radius: 10px; flex: none;
}
.btn-send:disabled { opacity: .5; cursor: default; }
.composer.note .btn-send { background: var(--warn); }

/* ---------- pages ---------- */

.page { max-width: 980px; width: 100%; margin: 0 auto; padding: 22px 24px 60px; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; align-items: center; gap: 10px; }
.page-head .spacer { flex: 1; }
.page-head input { width: 260px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card h2 { font-size: 15px; margin-bottom: 4px; }
.hint { font-size: 12.5px; color: var(--ink-faint); margin-bottom: 12px; }
.row { display: flex; gap: 8px; }
.row input { max-width: 320px; }

.table-card { padding: 0; overflow-x: auto; }
.ctable { width: 100%; border-collapse: collapse; font-size: 13px; }
.ctable th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--ink-faint); padding: 11px 14px; border-bottom: 1px solid var(--line);
}
.ctable td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.ctable tr:hover td { background: var(--hover); }
.ctable .nm { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.ctable .nm .avatar { width: 32px; height: 32px; font-size: 12px; }
.ctable .prev { color: var(--ink-soft); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.qr-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.qr-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.qr-item div { flex: 1; min-width: 0; }
.qr-item b { display: block; font-size: 13px; }
.qr-item p { font-size: 12.5px; color: var(--ink-soft); white-space: pre-wrap; margin-top: 2px; }
.qr-item button { color: var(--ink-faint); font-size: 13px; }
.qr-item button:hover { color: var(--accent); }
.qr-add { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }

.staff-list { display: flex; flex-direction: column; gap: 6px; }
.staff { display: flex; align-items: center; gap: 10px; }
.staff .avatar { width: 32px; height: 32px; font-size: 12px; }
.staff b { font-size: 13px; display: block; }
.staff span { font-size: 12px; color: var(--ink-faint); }

.kv { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; align-items: baseline; flex-wrap: wrap; }
.kv span { color: var(--ink-soft); width: 200px; flex: none; }
.kv code { font-size: 12px; background: var(--line-soft); padding: 3px 7px; border-radius: 6px; word-break: break-all; }

/* ---------- login & toast ---------- */

.login-scrim {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(135deg, var(--brand-deep), var(--brand));
  display: grid; place-items: center; padding: 16px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--card); border-radius: 18px; padding: 28px 24px;
  text-align: center; box-shadow: 0 30px 60px -20px rgba(0, 0, 0, .4);
}
.login-logo img { width: 72px; }
.login-card h2 { font-size: 19px; margin-top: 8px; }
.login-card p { font-size: 12.5px; color: var(--ink-faint); margin: 4px 0 20px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.login-error { font-size: 12.5px; color: #b91c1c; background: #fee2e2; padding: 8px 10px; border-radius: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px); opacity: 0;
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px;
  pointer-events: none; transition: .2s; z-index: 200; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ================= responsive ================= */

@media (max-width: 1100px) {
  .rail { width: 68px; padding: 14px 8px; }
  .rail-title, .rail-links .lb, .rail-out .lb, .me, .theme-toggle { display: none; }
  .rail-brand { justify-content: center; padding: 0 0 16px; }
  .rail-links a, .rail-out { justify-content: center; position: relative; }
  .rail-links em { position: absolute; top: 2px; right: 2px; padding: 0 5px; }
  .list-pane { width: 320px; }
}

@media (max-width: 760px) {
  .app { flex-direction: column-reverse; }
  .rail {
    width: 100%; flex-direction: row; padding: 4px 8px; background: var(--brand-deep);
    border-top: 1px solid rgba(255, 255, 255, .1);
  }
  .rail-brand { display: none; }
  .rail-links { flex-direction: row; flex: 1; justify-content: space-around; }
  .rail-foot { margin: 0; flex-direction: row; }
  .view { min-height: 0; }
  .list-pane { width: 100%; border-right: 0; }
  .chat-pane { display: none; }
  .view-inbox.chatting .list-pane { display: none; }
  .view-inbox.chatting .chat-pane { display: flex; }
  .back { display: block; }
  .msg { max-width: 86%; }
  .page { padding: 16px 16px 40px; }
  .page-head { flex-wrap: wrap; }
  .page-head input { width: 100%; }
  .kv span { width: 100%; }
  .ctable th:nth-child(4), .ctable td:nth-child(4),
  .ctable th:nth-child(5), .ctable td:nth-child(5) { display: none; }
  .ctable td, .ctable th { padding: 10px 8px; white-space: nowrap; }
  .ctable .nm { white-space: normal; }
  .qr-pop { width: min(320px, calc(100vw - 32px)); }
}

/* ---------- clinic PC bridge status ---------- */
.list-head { gap: 8px; }
.list-head h1 { margin-right: auto; }
.bridge-pill {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; cursor: default;
}
.bridge-pill.on { background: #dcfce7; color: #166534; }
.bridge-pill.off { background: #fee2e2; color: #991b1b; }
.bridge-qr { margin-top: 12px; padding: 12px; background: #fff; border-radius: 12px; width: max-content; border: 1px solid var(--line); }
.bridge-qr img, .bridge-qr canvas { display: block; }
.bridge-code { margin-top: 12px; padding: 16px; border-radius: 14px; background: var(--brand-soft); border: 1px solid var(--line); }
.bridge-code > span { font-size: 12px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .5px; }
.bridge-code > b { display: block; font-size: 34px; letter-spacing: 4px; font-family: ui-monospace, "Consolas", monospace; color: var(--brand); margin: 6px 0 10px; user-select: all; }
:root[data-theme="dark"] .bridge-code > b { color: #aab4ff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bridge-code > b { color: #aab4ff; } }
.bridge-code ol { padding-left: 18px; font-size: 13px; color: var(--ink-soft); line-height: 1.6; }
