/* PilarCare theme: Hanken Grotesk (the pilarinformatika.com typeface, self-hosted so a hospital
   install never calls out to Google) and the teal of pilarcare.id. */
@font-face {
  font-family: "Hanken Grotesk";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("../fonts/hanken-grotesk-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F,
    U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --font: "Hanken Grotesk", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --brand-ink: #0f2e2b;     /* top bar: deep teal ink */
  --brand-raised: #15423c;
  --bg: #eff3f3;
  --surface: #ffffff;
  --border: #d9e2e1;
  --text: #14302d;
  --muted: #5c726f;
  /* Buttons use the darker brand teal: white text on #0d9488 is only 3.7:1, on #0f766e 5.5:1. */
  --accent: #0f766e;
  --accent-bright: #0d9488;
  --accent-text: #ffffff;
  --patient: #edf1f1;
  --ai: #dcf3ef;
  --cs: #fdeccf;
  --danger: #b42318;
  --danger-bg: #fee4e2;
  --warn: #92400e;
  --warn-bg: #fef3c7;
  --ok: #067647;
  --radius: 10px;

  /* Charts (validated with the dataviz palette checker, light and dark) */
  --series-1: #0d9488;      /* teal: handled by AI, single-series bars */
  --series-2: #ea580c;      /* orange: handed over to people */
  --ramp-1: #14b8a6;        /* ordinal teal ramp for the funnel, light to dark */
  --ramp-2: #0d9488;
  --ramp-3: #0f766e;
  --ramp-4: #115e59;
  --ramp-5: #0a3d39;
  --grid: #e1e8e7;
  --baseline: #c3cfcd;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1b19;
    --surface: #102a27;
    --border: #1f3e3a;
    --text: #e4f1ef;
    --muted: #8fb0ab;
    --accent: #14b8a6;
    --accent-bright: #14b8a6;
    --accent-text: #04201c;
    --patient: #19322f;
    --ai: #123a35;
    --cs: #3a2d12;
    --danger: #fda29b;
    --danger-bg: #3b1713;
    --warn: #fcd34d;
    --warn-bg: #3a2c0b;
    --ok: #75e0a7;
    --series-1: #0e9f90;
    --series-2: #e8601a;
    --ramp-1: #115e59;      /* on dark, "more" is lighter */
    --ramp-2: #0f766e;
    --ramp-3: #0d9488;
    --ramp-4: #14b8a6;
    --ramp-5: #5eead4;
    --grid: #1b3633;
    --baseline: #2c4f4a;
  }
}

:root[data-theme="dark"] {
  --bg: #0a1b19;
  --surface: #102a27;
  --border: #1f3e3a;
  --text: #e4f1ef;
  --muted: #8fb0ab;
  --accent: #14b8a6;
  --accent-bright: #14b8a6;
  --accent-text: #04201c;
  --patient: #19322f;
  --ai: #123a35;
  --cs: #3a2d12;
  --danger: #fda29b;
  --danger-bg: #3b1713;
  --warn: #fcd34d;
  --warn-bg: #3a2c0b;
  --ok: #75e0a7;
  --series-1: #0e9f90;
  --series-2: #e8601a;
  --ramp-1: #115e59;
  --ramp-2: #0f766e;
  --ramp-3: #0d9488;
  --ramp-4: #14b8a6;
  --ramp-5: #5eead4;
  --grid: #1b3633;
  --baseline: #2c4f4a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
}
button, input, textarea, select { font-family: inherit; }

h1, h2 { margin: 0 0 8px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.error { color: var(--danger); margin: 0; }

/* Controls */
.btn {
  font: inherit;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible,
.conv:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent-bright); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

input, textarea, select {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
textarea { resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); }
label input { margin-top: 4px; }
.check { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.check input { width: auto; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; border-top: 4px solid var(--accent-bright); }
.brand-title { color: var(--accent); font-size: 26px; letter-spacing: 0.01em; }

/* App shell */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 16px;
  background: var(--brand-ink);
  color: #fff;
}
.topbar strong { font-size: 16px; letter-spacing: 0.01em; }
.topbar .muted { color: #9fc4be; }
.topbar .btn { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.28); padding: 5px 12px; }
.topbar .btn:hover:not(:disabled) { border-color: #5eead4; }
.topbar a:focus-visible, .topbar .btn:focus-visible { outline-color: #5eead4; }
.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: #2dd4bf; }
.nav { display: flex; gap: 4px; }
.nav a {
  color: #cfe6e2; text-decoration: none; padding: 6px 12px; border-radius: 8px; font-weight: 500;
}
.nav a:hover { background: var(--brand-raised); color: #fff; }
.nav a[aria-current="page"] { background: var(--brand-raised); color: #fff; box-shadow: inset 0 -2px 0 #2dd4bf; }
.live { font-size: 12px; color: #9fc4be; }
.live.on { color: #5eead4; }
.banner { padding: 10px 16px; background: var(--danger-bg); color: var(--danger); font-weight: 600; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 320px minmax(0, 1fr) 300px; }
.pane { min-height: 0; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; }
.thread-pane { display: flex; flex-direction: column; overflow: hidden; }
.details-pane { border-right: 0; border-left: 1px solid var(--border); padding: 16px; display: grid; gap: 20px; align-content: start; }
.empty { padding: 24px; text-align: center; }

/* List */
.tabs { display: flex; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.tab { flex: 1; font: inherit; padding: 12px; background: none; border: 0; border-bottom: 3px solid transparent; color: var(--muted); cursor: pointer; }
.tab.active { color: var(--text); border-bottom-color: var(--accent-bright); font-weight: 600; }
.count { background: var(--bg); border-radius: 999px; padding: 1px 8px; font-size: 12px; margin-left: 4px; }
.filters { display: flex; gap: 8px; align-items: center; padding: 10px 12px; }
.conv-list { list-style: none; margin: 0; padding: 0; }
.conv { padding: 12px; border-bottom: 1px solid var(--border); cursor: pointer; display: grid; gap: 4px; }
.conv:hover, .conv.selected { background: var(--bg); }
.conv-top { display: flex; gap: 8px; justify-content: space-between; align-items: baseline; }
.conv-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.conv-last { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); }
.badge.emergency, .badge.late { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.badge.sla { background: var(--warn-bg); color: var(--warn); border-color: transparent; }

/* Thread */
.thread { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.thread-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 4px; background: var(--bg); }
#load-older { align-self: center; margin-bottom: 8px; }
#message-list { display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 12px; background: var(--patient); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.ai { align-self: flex-end; background: var(--ai); }
.msg.cs { align-self: flex-end; background: var(--cs); }
.msg.pending { opacity: 0.55; }
.msg .who { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg time { display: block; font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.composer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); align-items: flex-end; }
.composer button { height: 40px; }
.hint { padding: 0 16px 10px; margin: 0; }

/* Details */
.summary { white-space: pre-wrap; margin: 0 0 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Dialog and toasts */
dialog { border: 0; padding: 0; background: transparent; max-width: 440px; width: calc(100% - 32px); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog .card { display: grid; gap: 8px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 10; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; max-width: 320px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25); }
.toast.error { background: var(--danger); color: #fff; }

/* Tablet: drop the details column, shown instead when a conversation is open on wide screens */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 300px minmax(0, 1fr); }
  .details-pane { display: none !important; }
}

/* Phone: one pane at a time */
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .layout .thread-pane { display: none; }
  .layout.show-thread .list-pane { display: none; }
  .layout.show-thread .thread-pane { display: flex; }
  .back { display: inline-block; }
  .msg { max-width: 90%; }
  .filters { flex-wrap: wrap; }
  /* The header would otherwise be wider than the screen. */
  .topbar { flex-wrap: wrap; gap: 6px 10px; padding: 8px 12px; }
  #whoami { display: none; }
  /* At the bottom a toast would cover the composer and its send button. */
  .toasts { top: 64px; bottom: auto; left: 16px; right: 16px; }
  .toast { max-width: none; }
}
