/* ============================================================
   MHCP Desk · Design System
   Premium modern clinic. Calm, dense enough to scan, high contrast.
   ============================================================ */

:root {
  --teal: #008080;
  --teal-dark: #006666;
  --teal-soft: #E6F2F2;
  --teal-softer: #F0F7F7;

  --navy: #1B2A4A;
  --navy-soft: #E8EDF5;
  --navy-softer: #F2F5FA;

  --sky: #5B9BD5;
  --sky-soft: #EAF2FA;

  --gold: #C5A030;
  --gold-soft: #F7F0DC;

  --red: #CC0000;
  --red-soft: #FBEBEB;

  --bg: #FAF8F5;
  --panel: #FFFFFF;
  --text: #333333;
  --muted: #6E6A63;
  --faint: #9A958C;
  --line: #E8E3DB;
  --line-strong: #D9D3C8;

  --wa: #25D366;
  --wa-dark: #128C7E;

  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(27, 42, 74, 0.06);
  --shadow-md: 0 6px 20px rgba(27, 42, 74, 0.10);

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", "Noto Sans Thai", "Sarabun", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 {
  color: var(--navy);
  font-weight: 650;
  margin: 0;
  letter-spacing: -0.01em;
}

/* Eyebrow / uppercase branding label */
.eyebrow {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 600;
}

/* ============================================================
   App shell · three panes (desktop)
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: 232px 352px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Channel rail (left) ---------- */
.rail {
  background: var(--navy);
  color: #E9EEF6;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
}

.rail .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
}
.rail .brand img {
  width: 34px; height: 34px;
  border-radius: 8px;
  object-fit: cover;
  background: #fff;
}
.rail .brand .name {
  font-weight: 650;
  color: #fff;
  font-size: 15px;
  line-height: 1.15;
}
.rail .brand .sub {
  font-size: 11px;
  color: #9FB0CE;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.rail-label {
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #8A9BBE;
  padding: 6px 10px 8px;
}

.chan {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: #E9EEF6;
  position: relative;
}
.chan:hover { background: rgba(255, 255, 255, 0.06); }
.chan.active { background: rgba(255, 255, 255, 0.12); }

.chan .icon {
  width: 34px; height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  flex: none;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}
.chan .icon.wa  { background: rgba(37, 211, 102, 0.16); color: #4BE08A; }
.chan .icon.mail{ background: rgba(91, 155, 213, 0.20); color: #8EC2EE; }
.chan .icon.meta{ background: rgba(154, 149, 140, 0.18); color: #B8B3AA; }

.chan .chan-name { font-weight: 600; font-size: 13.5px; }
.chan .chan-sub { font-size: 11px; color: #8A9BBE; }

.chan .counts { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.chan .unreplied {
  background: var(--teal);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  padding: 0 6px;
}
.chan .unread {
  color: #9FB0CE;
  font-size: 11.5px;
  font-weight: 600;
}
.chan .unread::before { content: "unread "; opacity: 0.7; font-weight: 400; }

.chan.disabled { opacity: 0.55; cursor: default; }
.chan.disabled .coming {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #B8B3AA;
}

.rail .admin-label { margin-top: 18px; }

.rail .foot {
  margin-top: auto;
  padding: 12px 8px 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
}
.rail .user {
  display: flex;
  align-items: center;
  gap: 9px;
}
.rail .avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  flex: none;
}
.rail .user .who { font-size: 12.5px; font-weight: 600; color: #fff; }
.rail .user .role { font-size: 11px; color: #9FB0CE; }
.rail .signout {
  margin-top: 8px;
  font-size: 12px;
  color: #9FB0CE;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
}
.rail .signout:hover { color: #fff; }

/* ---------- Conversation list (middle) ---------- */
.list-pane {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.list-pane .pane-head {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.list-pane .pane-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.list-pane .pane-title h2 { font-size: 17px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { border-color: var(--teal); color: var(--teal); }
.chip.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
.chip .n {
  opacity: 0.7;
  font-weight: 600;
  margin-left: 2px;
}

.search {
  margin: 0 16px 10px;
  position: relative;
}
.search input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px 8px 34px;
  font-size: 13px;
  font-family: var(--font-ui);
  background: var(--bg);
}
.search input:focus { outline: 2px solid var(--teal); outline-offset: -1px; background: #fff; }
.search .mag {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--faint);
}

.convo-scroll { flex: 1; overflow-y: auto; }

.row {
  display: flex;
  gap: 11px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  position: relative;
}
.row:hover { background: var(--navy-softer); }
.row.active { background: var(--teal-softer); }
.row.active::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--teal);
}

.row .contact-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--sky-soft);
  color: var(--navy);
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
  flex: none;
}
.row .r-main { flex: 1; min-width: 0; }
.row .r-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.row .r-name { font-weight: 650; color: var(--navy); font-size: 13.5px; }
.row .r-time { font-size: 11.5px; color: var(--muted); flex: none; }
.row .r-preview {
  font-size: 12.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}
.row .r-meta { display: flex; align-items: center; gap: 7px; margin-top: 4px; }

.row.unreplied .r-name { color: var(--navy); }
.row.unreplied .r-preview { color: var(--text); }

.badge-unreplied {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--teal-dark);
  background: var(--teal-soft);
  border: 1px solid rgba(0, 128, 128, 0.25);
  padding: 1px 7px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.badge-replied {
  font-size: 11px;
  color: var(--muted);
}
.badge-replied b { color: var(--navy); font-weight: 600; }

.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--teal);
  flex: none;
}
.row .dot { position: absolute; right: 16px; top: 14px; }

.chan-flag {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.chan-flag.wa { background: rgba(37, 211, 102, 0.14); color: var(--wa-dark); }
.chan-flag.email { background: var(--sky-soft); color: var(--sky); }

/* Email Patients / Other sub-tabs */
.subtabs {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 3px;
  margin-bottom: 10px;
}
.subtab {
  flex: 1;
  text-align: center;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.subtab.active { background: #fff; color: var(--navy); box-shadow: var(--shadow-sm); }
.subtab .n { opacity: 0.7; }

/* ---------- Conversation (right) ---------- */
.conversation { display: flex; flex-direction: column; background: var(--bg); min-width: 0; }
.convo-head {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.convo-head .h-name { font-size: 15px; font-weight: 650; color: var(--navy); }
.convo-head .h-sub { font-size: 12px; color: var(--muted); }
.convo-head .h-actions { margin-left: auto; display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--navy);
  border-radius: var(--radius);
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-ui);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { border-color: var(--teal); color: var(--teal); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-dark); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--navy); background: var(--navy-softer); }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.small { padding: 5px 10px; font-size: 12px; border-radius: var(--radius-sm); }

/* Contact side panel */
.sidepanel {
  width: 264px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 18px;
  overflow-y: auto;
  flex: none;
}
.sidepanel h4 { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin: 16px 0 8px; }
.sidepanel .sp-name { font-size: 16px; font-weight: 650; color: var(--navy); }
.sidepanel .sp-chan { font-size: 12px; color: var(--muted); margin-top: 2px; }
.sidepanel .kv { display: flex; justify-content: space-between; font-size: 12.5px; padding: 4px 0; }
.sidepanel .kv .k { color: var(--muted); }
.sidepanel .kv .v { font-weight: 600; color: var(--navy); }
.sidepanel textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px;
  font-size: 12.5px;
  font-family: var(--font-ui);
  min-height: 72px;
  resize: vertical;
  background: var(--bg);
}

.convo-body { flex: 1; overflow-y: auto; padding: 18px; }

/* WhatsApp chat bubbles */
.chat { max-width: 760px; margin: 0 auto; }
.msg { display: flex; margin-bottom: 14px; }
.msg.patient { justify-content: flex-start; }
.msg.clinic  { justify-content: flex-end; }
.bubble {
  max-width: 68%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
  word-wrap: break-word;
}
.msg.patient .bubble {
  background: #fff;
  border: 1px solid var(--line);
  border-top-left-radius: 4px;
}
.msg.clinic .bubble {
  background: var(--teal-soft);
  border: 1px solid rgba(0, 128, 128, 0.18);
  border-top-right-radius: 4px;
}
.bubble .meta {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}
.bubble .origin {
  font-size: 10px;
  color: var(--muted);
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px dashed var(--line-strong);
}
.bubble .origin b { color: var(--navy); font-weight: 600; }

.ticks { display: inline-flex; gap: 1px; align-items: center; }
.ticks span { font-size: 12px; line-height: 1; }
.ticks.read span { color: var(--sky); }

/* Quoted reply */
.quote {
  border-left: 3px solid var(--teal);
  background: rgba(0, 128, 128, 0.06);
  padding: 5px 9px;
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
}
.quote .q-who { font-weight: 650; color: var(--teal-dark); font-size: 11.5px; display: block; }

/* Reactions */
.reactions {
  display: inline-flex;
  gap: 4px;
  margin-top: 4px;
}
.reaction {
  background: var(--sky-soft);
  border: 1px solid rgba(91, 155, 213, 0.35);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
}

/* Media attachments inside bubbles */
.attach {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-top: 7px;
  font-size: 12.5px;
}
.attach .filetype {
  width: 34px; height: 34px;
  border-radius: 7px;
  display: grid; place-items: center;
  font-size: 10px; font-weight: 700;
  color: #fff;
  flex: none;
  text-transform: uppercase;
}
.attach .ft-pdf { background: var(--red); }
.attach .ft-img { background: var(--sky); }
.attach .ft-doc { background: var(--navy); }
.attach .a-name { font-weight: 600; color: var(--navy); }
.attach .a-size { font-size: 11px; color: var(--muted); }

.img-attach { border-radius: 10px; margin-top: 7px; overflow: hidden; }
.img-attach .ph {
  background: linear-gradient(135deg, #d9e7ea, #bcd3d6);
  color: #557c80;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
}
.img-attach img { display: block; width: 100%; }

/* WhatsApp 24h window indicator */
.window {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--gold-soft);
  border: 1px solid rgba(197, 160, 48, 0.35);
  border-radius: var(--radius);
  padding: 8px 13px;
  font-size: 12px;
  color: #7A6620;
}
.window.closed { background: var(--red-soft); border-color: rgba(204, 0, 0, 0.3); color: #8A1A1A; }
.window .pill {
  font-weight: 700;
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--gold);
  color: #fff;
  flex: none;
}
.window.closed .pill { background: var(--red); }

/* Day divider */
.day-divider {
  text-align: center;
  margin: 20px 0 14px;
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.day-divider::before, .day-divider::after {
  content: "";
  display: inline-block;
  width: 40px; height: 1px;
  background: var(--line);
  vertical-align: middle;
  margin: 0 10px;
}

/* Email thread view */
.email-thread { max-width: 780px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.email-head { padding: 18px 20px; border-bottom: 1px solid var(--line); }
.email-head h3 { font-size: 18px; margin-bottom: 10px; }
.email-meta { font-size: 12.5px; color: var(--muted); }
.email-meta .row-line { display: flex; padding: 2px 0; gap: 8px; }
.email-meta .lbl { color: var(--faint); width: 34px; flex: none; }
.email-meta .val { color: var(--text); }
.email-body { padding: 20px; font-size: 13.5px; }
.email-body p { margin: 0 0 12px; }
.email-body .signature { margin-top: 18px; color: var(--muted); font-size: 12.5px; border-top: 1px solid var(--line); padding-top: 12px; }
.email-actions { display: flex; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* Collapsed quoted history */
.collapsed-quote {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  background: var(--bg);
}
.collapsed-quote:hover { border-color: var(--teal); }

/* ============================================================
   Composer
   ============================================================ */
.composer {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 14px 18px 16px;
}
.composer .draft-shell {
  border: 1px solid var(--sky);
  border-radius: var(--radius-lg);
  background: var(--sky-soft);
  padding: 12px 14px;
  margin-bottom: 10px;
  position: relative;
}
.draft-shell .draft-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--sky);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  margin-bottom: 8px;
}
.draft-shell .draft-tag .spark { font-size: 13px; }
.draft-shell .draft-text {
  font-size: 13.5px;
  color: var(--navy);
  white-space: pre-wrap;
  background: rgba(255, 255, 255, 0.65);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.draft-shell.edited {
  border-color: var(--teal);
  background: var(--teal-softer);
}
.draft-shell.edited .draft-tag { background: var(--teal); }

.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.source-chip {
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 11.5px;
  color: var(--navy);
  padding: 3px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.source-chip:hover { border-color: var(--sky); }
.source-chip .k { color: var(--faint); }
.source-chip.plus { border-style: dashed; color: var(--muted); }

.gap-note {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 9px 12px;
  background: var(--gold-soft);
  border: 1px solid rgba(197, 160, 48, 0.35);
  border-radius: var(--radius);
  font-size: 12.5px;
  color: #7A6620;
}
.gap-note .suggest-btn {
  margin-left: auto;
  background: var(--gold);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 13px;
  font-size: 13.5px;
  font-family: var(--font-ui);
  min-height: 72px;
  resize: vertical;
  background: #fff;
}
.composer textarea:focus { outline: 2px solid var(--teal); outline-offset: -1px; }

.composer-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.composer-bar .spacer { flex: 1; }
.send-hint {
  font-size: 11px;
  color: var(--faint);
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Composer state chips / strip */
.state-strip { display: flex; gap: 10px; flex-wrap: wrap; }
.state-card {
  flex: 1;
  min-width: 150px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  padding: 14px;
}
.state-card .st-label {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 8px;
}
.state-card .st-body { font-size: 12.5px; color: var(--text); }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--sky-soft);
  border-top-color: var(--sky);
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Failed banner */
.failed-banner {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--red-soft);
  border: 1px solid rgba(204, 0, 0, 0.3);
  color: #8A1A1A;
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12.5px;
  margin-top: 8px;
}

/* ============================================================
   Knowledge
   ============================================================ */
.workspace { padding: 26px 30px; max-width: 1160px; }
.workspace .page-title { font-size: 22px; margin-bottom: 4px; }
.workspace .page-sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }

.kb-nav {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.kb-nav a {
  padding: 10px 15px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.kb-nav a:hover { color: var(--navy); }
.kb-nav a.active { color: var(--navy); border-bottom-color: var(--teal); }

.category-group { margin-bottom: 24px; }
.category-group .cat-title {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--navy);
  font-weight: 700;
  padding-bottom: 6px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.entry-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
}
.entry-card:hover { border-color: var(--teal); }
.entry-card .e-top { display: flex; align-items: center; gap: 10px; }
.entry-card .e-q { font-weight: 650; color: var(--navy); font-size: 13.5px; }
.entry-card .e-answer { color: var(--muted); font-size: 12.5px; margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.entry-card .e-foot { display: flex; align-items: center; gap: 12px; margin-top: 10px; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }

.status {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
}
.status.approved { background: var(--teal-soft); color: var(--teal-dark); }
.status.draft { background: var(--navy-soft); color: var(--navy); }
.status.review { background: var(--gold-soft); color: #8A6A10; }
.status.archived { background: #EFECE6; color: var(--faint); }

.lang-tag {
  font-size: 10px;
  font-weight: 700;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--muted);
}
.usage { color: var(--teal-dark); font-weight: 650; }

/* Form layout */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-field { margin-bottom: 14px; }
.form-field label {
  display: block;
  font-size: 12px;
  font-weight: 650;
  color: var(--navy);
  margin-bottom: 5px;
}
.form-field .hint { font-size: 11px; color: var(--faint); margin-top: 4px; }
.form-field input, .form-field textarea, .form-field select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 9px 11px;
  font-size: 13px;
  font-family: var(--font-ui);
  background: #fff;
}
.form-field input:focus, .form-field textarea:focus, .form-field select:focus {
  outline: 2px solid var(--teal); outline-offset: -1px;
}

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px 20px; }
.card h3 { font-size: 15px; margin-bottom: 12px; }
.card + .card { margin-top: 16px; }

/* Suggestion queue */
.suggestion {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  padding: 16px 18px;
  margin-bottom: 12px;
}
.suggestion .s-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.suggestion .s-type {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
}
.suggestion .s-type.gap { background: var(--sky-soft); color: var(--sky); }
.suggestion .s-type.rewrite { background: var(--gold-soft); color: #8A6A10; }
.suggestion .s-type.staff { background: var(--teal-soft); color: var(--teal-dark); }
.suggestion .s-q { font-weight: 650; color: var(--navy); margin-top: 8px; }
.suggestion .s-freq { font-size: 12px; color: var(--muted); margin-left: auto; }
.suggestion .side-by-side { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.suggestion .col-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 5px; }
.suggestion .col-body { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; font-size: 12.5px; }
.suggestion .s-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* Freshness dashboard */
.fresh-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
}
.metric .m-num { font-size: 30px; font-weight: 700; color: var(--navy); line-height: 1; }
.metric .m-label { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.metric.warn .m-num { color: var(--gold); }
.metric.alert .m-num { color: var(--red); }

/* Test bench */
.testbench { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tb-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px; }
.tb-panel h4 { font-size: 13px; margin-bottom: 10px; }

/* ============================================================
   Tables (settings)
   ============================================================ */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-strong);
}
.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  vertical-align: middle;
}
.table tr:hover td { background: var(--navy-softer); }
.table .role-admin { color: var(--teal-dark); font-weight: 700; }
.table .role-staff { color: var(--muted); }

.toggle {
  width: 34px; height: 20px;
  border-radius: 999px;
  background: var(--line-strong);
  position: relative;
  cursor: pointer;
}
.toggle.on { background: var(--teal); }
.toggle::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.15s;
}
.toggle.on::after { left: 16px; }

/* Empty / loading / states */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
}
.empty .e-ico { font-size: 34px; margin-bottom: 10px; }
.empty h4 { color: var(--navy); font-size: 15px; margin-bottom: 6px; }
.empty p { font-size: 12.5px; max-width: 320px; margin: 0 auto; }

.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px; color: var(--muted); }

/* Sign in */
.signin {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1100px 600px at 20% -10%, rgba(91, 155, 213, 0.10), transparent 60%),
    radial-gradient(900px 500px at 90% 110%, rgba(0, 128, 128, 0.10), transparent 55%),
    var(--bg);
}
.signin .card {
  width: 400px;
  max-width: 92vw;
  text-align: center;
  padding: 38px 34px;
}
.signin .logo { width: 64px; height: 64px; border-radius: 16px; object-fit: cover; margin-bottom: 18px; }
.signin h1 { font-size: 21px; margin-bottom: 6px; }
.signin .sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.signin .google-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: var(--radius);
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  color: var(--navy);
  cursor: pointer;
  font-family: var(--font-ui);
}
.signin .google-btn:hover { border-color: var(--teal); box-shadow: var(--shadow-sm); }
.signin .google-btn svg { width: 18px; height: 18px; }
.signin .only-clinic { font-size: 12px; color: var(--faint); margin-top: 16px; }
.signin .error {
  margin-top: 16px;
  background: var(--red-soft);
  border: 1px solid rgba(204, 0, 0, 0.3);
  color: #8A1A1A;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12.5px;
  text-align: left;
}
.signin .error b { display: block; margin-bottom: 2px; }

/* Misc */
.note-tag { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.teal { color: var(--teal); }
.navy { color: var(--navy); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* ============================================================
   Mobile
   ============================================================ */
.phone {
  width: 390px;
  margin: 24px auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 34px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  min-height: 760px;
}
.phone .statusbar {
  height: 40px;
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  font-size: 12px;
  font-weight: 600;
}
.phone .appbar {
  background: var(--navy);
  color: #fff;
  padding: 12px 16px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.phone .appbar .title { font-weight: 650; font-size: 16px; }
.phone .appbar .back { font-size: 18px; cursor: pointer; color: #fff; }
.phone .m-chips { display: flex; gap: 6px; padding: 12px 14px; overflow-x: auto; background: #fff; border-bottom: 1px solid var(--line); }
.phone .m-row { display: flex; gap: 11px; padding: 13px 16px; border-bottom: 1px solid var(--line); align-items: center; }
.phone .m-chat { padding: 14px; background: var(--bg); min-height: 520px; }
.phone .m-composer {
  border-top: 1px solid var(--line);
  background: #fff;
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.phone .m-composer textarea {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 9px 13px;
  font-size: 13.5px;
  font-family: var(--font-ui);
  resize: none;
  min-height: 40px;
}
.phone .m-send {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  border: none;
  display: grid; place-items: center;
  font-size: 16px;
  cursor: pointer;
  flex: none;
}
.phone .bottom-tab {
  display: flex;
  border-top: 1px solid var(--line);
  background: #fff;
}
.phone .bottom-tab div {
  flex: 1;
  text-align: center;
  padding: 10px 0;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}
.phone .bottom-tab div.active { color: var(--teal); }

/* ============================================================
   Media: photo viewer, voice, PDF, failed download
   ============================================================ */
.photo-msg {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  margin-top: 7px;
  cursor: pointer;
  border: 1px solid var(--line);
}
.photo-msg .ph { display: grid; place-items: center; color: #557c80; font-size: 11px; font-weight: 600; }
.photo-msg .view-hint {
  position: absolute; left: 8px; bottom: 8px;
  background: rgba(27, 42, 74, 0.78);
  color: #fff;
  font-size: 10.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}

/* Full-size viewer (lightbox) */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(16, 24, 43, 0.90);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 30px;
}
.lightbox .lb-frame {
  background: #0e1420;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  overflow: hidden;
  max-width: 720px;
  width: 100%;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
.lightbox .lb-img {
  display: grid; place-items: center;
  color: #bcd3d6;
  font-size: 13px;
}
.lightbox .lb-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: #141c30;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
}
.lightbox .lb-bar .cap { color: #b8c4dc; font-size: 12.5px; flex: 1; }
.lightbox .lb-bar .btn { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.2); color: #fff; }
.lightbox .lb-bar .btn:hover { border-color: var(--sky); color: #fff; }

/* Voice note player + transcript */
.voice-player { display: flex; align-items: center; gap: 10px; }
.voice-player .play {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  display: grid; place-items: center;
  font-size: 13px;
  flex: none;
}
.voice-player .bar {
  flex: 1;
  height: 4px;
  background: rgba(0, 128, 128, 0.18);
  border-radius: 999px;
  position: relative;
  overflow: hidden;
}
.voice-player .bar .fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 40%;
  background: var(--teal);
  border-radius: 999px;
}
.voice-player .dur { font-size: 12px; color: var(--muted); flex: none; }
.voice-transcript {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px dashed var(--line-strong);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
}
.voice-transcript .t-label {
  display: block;
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 700;
  margin-bottom: 2px;
}

/* PDF first-page thumbnail */
.pdf-thumb {
  display: flex; gap: 10px; align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px;
  margin-top: 7px;
}
.pdf-thumb .page {
  width: 58px; height: 76px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #f2f4f7, #e2e7ee);
  display: grid; place-items: center;
  color: var(--faint);
  font-size: 9px;
  font-weight: 700;
  flex: none;
}

/* Failed download placeholder */
.failed-media {
  display: flex; align-items: center; gap: 10px;
  background: var(--red-soft);
  border: 1px dashed rgba(204, 0, 0, 0.4);
  border-radius: 9px;
  padding: 10px 12px;
  margin-top: 7px;
  font-size: 12.5px;
  color: #8A1A1A;
}
.failed-media .retry {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

/* Medical photo flag */
.medical-flag {
  display: flex; align-items: center; gap: 10px;
  background: var(--gold-soft);
  border: 1px solid rgba(197, 160, 48, 0.45);
  border-radius: var(--radius);
  padding: 9px 13px;
  font-size: 12.5px;
  color: #7A6620;
  margin-bottom: 14px;
}
.medical-flag .flag-ico {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--gold);
  color: #fff;
  display: grid; place-items: center;
  font-size: 12px;
  flex: none;
}
.medical-flag b { color: #6a5816; }

/* Draft markers (photo / PDF / voice note) */
.draft-marker {
  display: inline-flex; align-items: center; gap: 5px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: var(--navy);
  padding: 2px 9px;
}
.draft-marker.photo { border-color: var(--sky); color: var(--sky); }
.draft-marker.pdf { border-color: var(--red); color: var(--red); }
.draft-marker.voice { border-color: var(--teal); color: var(--teal-dark); }

/* Attachment tray in composer */
.attachment-tray { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.attach-thumb {
  position: relative;
  width: 66px; height: 66px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  display: grid; place-items: center;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  overflow: hidden;
}
.attach-thumb .remove {
  position: absolute; top: 3px; right: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: rgba(27, 42, 74, 0.72);
  color: #fff;
  border: none;
  display: grid; place-items: center;
  font-size: 12px;
  cursor: pointer;
  line-height: 1;
}
.attach-thumb .thumb-ph {
  position: absolute; inset: 0;
  background: linear-gradient(135deg, #d9e7ea, #bcd3d6);
  color: #557c80;
  display: grid; place-items: center;
  font-size: 9px; font-weight: 700;
}
.attach-thumb .cap {
  position: absolute; left: 0; right: 0; bottom: 0;
  font-size: 8.5px;
  padding: 1px 4px;
  background: rgba(27, 42, 74, 0.72);
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.size-limit-note { font-size: 11px; color: var(--faint); }

/* Settings switch row */
.switch-row {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.switch-row:last-child { border-bottom: none; }
.switch-row .sw-main { flex: 1; }
.switch-row .sw-title { font-weight: 650; color: var(--navy); font-size: 13.5px; }
.switch-row .sw-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
