* { box-sizing: border-box; margin: 0; }

:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1c2733;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #0f6f6a;
  --accent-soft: #e0f0ef;
  --urgent: #b91c1c;
  --urgent-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --flag: #4338ca;
  --flag-soft: #e0e7ff;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 26px; color: var(--accent); }
h1 { font-size: 16px; }
.sub { font-size: 11px; color: var(--muted); letter-spacing: 0.02em; }

main { display: flex; flex: 1; min-height: 0; }

#thread-list {
  width: 280px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
.thread-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.thread-item:hover { background: #f8fafc; }
.thread-item.active { background: var(--accent-soft); }
.thread-item .who { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.thread-item .snippet {
  font-size: 12px; color: var(--muted); margin-top: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

#conversation { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#conv-header {
  padding: 12px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-weight: 600; display: flex; align-items: center; gap: 10px;
}
#messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.bubble {
  max-width: 62%; padding: 10px 14px; border-radius: 14px;
  font-size: 14px; line-height: 1.45; white-space: pre-wrap;
}
.bubble.patient { background: var(--panel); border: 1px solid var(--line); align-self: flex-start; }
.bubble.practice { background: var(--accent); color: #fff; align-self: flex-end; }
.bubble.internal {
  background: var(--flag-soft); border: 1px dashed var(--flag); color: var(--flag);
  align-self: stretch; max-width: 100%; font-size: 13px;
}
.internal-label {
  display: block; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; margin-bottom: 4px; opacity: 0.8;
}
.bubble .ts { display: block; font-size: 10px; opacity: 0.65; margin-top: 5px; }

#draft-panel { border-top: 1px solid var(--line); background: var(--panel); padding: 14px 20px; }
.suggest-btn {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 8px 14px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.suggest-btn:disabled { opacity: 0.5; cursor: default; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  letter-spacing: 0.03em; text-transform: uppercase;
}
.chip.admin { background: var(--accent-soft); color: var(--accent); }
.chip.urgent { background: var(--urgent-soft); color: var(--urgent); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.flag { background: var(--flag-soft); color: var(--flag); }
.chip.muted { background: #eef2f7; color: var(--muted); text-transform: none; }

.banner {
  border-radius: 10px; padding: 12px 14px; font-size: 13px; margin-bottom: 10px; line-height: 1.5;
}
.banner.urgent { background: var(--urgent-soft); color: var(--urgent); border: 1px solid #fca5a5; font-weight: 600; }
.banner.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #fcd34d; }
.banner.flag { background: var(--flag-soft); color: var(--flag); border: 1px solid #c7d2fe; }

.draft-box {
  width: 100%; min-height: 150px; font: inherit; font-size: 14px; line-height: 1.5;
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; resize: vertical;
}
.panel-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bar-spacer { flex: 1; }
.ghost.escalate { border-color: #c7d2fe; color: var(--flag); }
.ghost:disabled { opacity: .5; cursor: default; }
.ghost.emergency { border-color: #fecaca; color: var(--urgent); font-weight: 600; }
#flash {
  margin: 0 0 10px; padding: 9px 12px; border-radius: 8px; font-size: 13px;
  background: var(--flag-soft); color: var(--flag); border: 1px solid #c7d2fe;
}
#flash.hidden { display: none; }

/* Split editor: suggestion and blank pane side by side, so a coordinator can
   write their own reply while still reading the suggestion. */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pane {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px;
  background: #fff; transition: border-color .15s ease, background-color .15s ease;
}
.pane.active { border-color: var(--accent); background: #fbfdff; }
.pane-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; margin-bottom: 8px; min-height: 26px;
}
.pane-title { font-size: 12px; font-weight: 600; color: var(--ink); }
.send.small { padding: 4px 11px; font-size: 11px; margin-left: auto; }
.pane .draft-box { border: none; padding: 0; min-height: 190px; }
.pane .draft-box:focus { outline: none; }
.ghost.tiny { padding: 4px 9px; font-size: 11px; }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
  .pane .draft-box { min-height: 130px; }
}

.draft-actions { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.draft-actions .send:disabled { opacity: .45; cursor: not-allowed; }
.send {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 7px 13px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.send:disabled { opacity: .45; cursor: not-allowed; }
.draft-actions .discard {
  background: #fff; color: var(--muted); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 12px; font-size: 12px; cursor: pointer;
}
.edited-note { font-size: 12px; color: var(--warn); }
.fields-note { font-size: 11px; color: var(--muted); margin-top: 8px; }

.header-actions { display: flex; gap: 8px; align-items: center; }
.ghost.linkbtn { text-decoration: none; display: inline-block; }

.ghost {
  background: none; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; font-size: 12px; cursor: pointer; color: var(--ink);
}
.panel-bar.bottom { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }

#audit-drawer {
  position: fixed; right: 0; top: 0; bottom: 0; width: 480px;
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(0,0,0,0.08);
  display: flex; flex-direction: column; z-index: 20;
}
#audit-drawer.hidden { display: none; }
.drawer-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { font-size: 15px; }
#audit-entries { overflow-y: auto; padding: 12px 18px; flex: 1; }
.audit-entry {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
  margin-bottom: 10px; font-size: 12px; line-height: 1.55;
}
.audit-entry .head { font-weight: 600; margin-bottom: 3px; }
.audit-full { margin-top: 6px; }
.audit-full summary { cursor: pointer; color: var(--accent); font-size: 11px; }
.audit-full pre {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 6px;
  padding: 8px; margin-top: 5px; font-size: 10px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow-y: auto;
}
.audit-entry code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 11px; }

.empty { color: var(--muted); font-size: 13px; padding: 30px; text-align: center; }
