:root {
  --bg: #f4f6f9; --card: #ffffff; --ink: #1b2430; --muted: #6b7684;
  --line: #e2e7ee; --accent: #2563eb; --ok: #16a34a; --busy: #dc2626;
  --ring: #d97706; --shadow: 0 1px 3px rgba(20,30,50,.08), 0 6px 20px rgba(20,30,50,.05);
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#0f141b; --card:#171e28; --ink:#e6ebf2; --muted:#94a2b3; --line:#26303c; --accent:#3b82f6; }
}
* { box-sizing: border-box; }
/* `hidden` must win over layout rules like `.center{display:grid}` below,
   otherwise the login section never actually hides when the panel shows. */
[hidden] { display: none !important; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--ink); }
.muted { color: var(--muted); }
.error { color: var(--busy); min-height: 1.2em; margin-top: .5rem; }
.warn { color: var(--ring); font-size: .85rem; }

.center { min-height: 100vh; display: grid; place-items: center; }
.loginbox { background: var(--card); padding: 2rem; border-radius: 14px; box-shadow: var(--shadow); width: min(360px, 92vw); display: flex; flex-direction: column; gap: .5rem; }
.loginbox h1 { margin: 0; }
.loginbox label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); margin-top: .5rem; }
input, select, button { font: inherit; padding: .6rem .7rem; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
button { cursor: pointer; border-color: transparent; background: var(--accent); color: #fff; font-weight: 600; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }

.bar { display: flex; align-items: center; gap: 1rem; padding: .8rem 1.2rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; }
.bar .spacer { flex: 1; }
main { max-width: 900px; margin: 0 auto; padding: 1.2rem; }
main h2 { font-size: .95rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 1.4rem 0 .6rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; box-shadow: var(--shadow); }
.card.muted { color: var(--muted); }
.card .row { display: flex; align-items: center; gap: .5rem; }
.card .sub { color: var(--muted); font-size: .85rem; margin: .25rem 0 .8rem; }
.card .dial { display: flex; flex-wrap: wrap; gap: .5rem; }
.card .dial .num { flex: 1 1 140px; }
.card .dial button { flex: 0 0 auto; }
.badge { font-size: .7rem; padding: .1rem .4rem; border-radius: 6px; }
.badge.warn { background: var(--ring); color: #fff; }

.dot { width: 10px; height: 10px; border-radius: 50%; margin-left: auto; background: var(--muted); }
.dot.idle { background: var(--ok); }
.dot.busy, .dot.incoming { background: var(--busy); animation: pulse 1s infinite; }
.dot.registering { background: var(--ring); }
.dot.offline, .dot.error { background: var(--muted); }
.card.state-busy, .card.state-incoming { border-color: var(--busy); }
.card.state-idle { border-color: var(--ok); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* Team status module: compact, read-only at-a-glance tiles */
.grid.status { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; }
.status-tile { padding: .7rem .85rem; }
.status-tile .sub { margin: .2rem 0 0; }
.status-tile .stlabel { font-weight: 600; color: var(--ink); }
.card.state-oncall { border-color: var(--busy); }
.card.state-offline { opacity: .7; }
.badge.me { background: var(--accent); color: #fff; }

/* header mode toggle + controller link */
.modewrap { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; }
.modewrap select { padding: .35rem .5rem; }
a.ghost { text-decoration: none; padding: .45rem .7rem; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: transparent; font-weight: 600; }

/* Inbound screen-pop */
.pop { position: fixed; right: 1.2rem; bottom: 1.2rem; z-index: 50; width: min(360px, 92vw); }
.pop-card { background: var(--card); border: 1px solid var(--busy); border-radius: 14px; padding: 1.1rem 1.2rem; box-shadow: var(--shadow); position: relative; }
.pop-card h3 { margin: .1rem 0 .2rem; }
.pop-x { position: absolute; top: .5rem; right: .5rem; background: transparent; color: var(--muted); border: none; font-size: 1.3rem; line-height: 1; padding: .1rem .4rem; cursor: pointer; font-weight: 700; }
.pop-card a.ghost { display: inline-block; margin-top: .2rem; }

/* Call history */
.history { display: flex; flex-direction: column; gap: .3rem; }
.hrow { display: grid; grid-template-columns: 46px 1.3fr 1.1fr .9fr .8fr 60px 96px; gap: .5rem; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .7rem; font-size: .85rem; }
.hrow .hdir { font-weight: 700; }
.hrow.inbound .hdir { color: var(--ok); }
.hrow.outbound .hdir { color: var(--accent); }
.hrow.missed { border-color: var(--busy); }
.hrow.missed .hdir { color: var(--busy); }
.hrow .hparty { font-weight: 600; }
.hrow .hwhen { text-align: right; }
/* Patient chip (reverse-mapped from caller-ID). Clickable = opens the OD chart. */
.hpat { font-size: .78rem; font-weight: 600; padding: .1rem .45rem; border-radius: 6px; background: transparent; color: var(--accent); border: 1px solid var(--line); text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.hpat.pat-open { cursor: pointer; border-color: var(--accent); }
.hpat.empty { border-color: transparent; }

/* segmented toggle in the Call history heading */
.seg { display: inline-flex; gap: 0; margin-left: .6rem; vertical-align: middle; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-btn { background: transparent; color: var(--ink); border: none; border-radius: 0; padding: .3rem .6rem; font-size: .72rem; font-weight: 600; text-transform: none; letter-spacing: 0; }
.seg-btn.on { background: var(--accent); color: #fff; }
button.ghost.small { padding: .2rem .5rem; font-size: .72rem; margin-left: .5rem; vertical-align: middle; }

/* Voicemail rows: own layout (has an inline audio player, no "by" column) */
.hrow.vm { grid-template-columns: 40px 1.2fr 1.1fr .9fr 56px 96px; }
.hrow.vm .vmaudio { grid-column: 1 / -1; width: 100%; height: 34px; margin-top: .2rem; }
.hrow.vm.unread { border-color: var(--accent); }
.hrow.vm.unread .hdir { color: var(--accent); }

@media (max-width: 640px) {
  .hrow { grid-template-columns: 40px 1fr auto; }
  .hrow .hline, .hrow .hby, .hrow .hdur, .hrow .hpat { display: none; }
  .hrow.vm { grid-template-columns: 40px 1fr auto; }
  .hrow.vm .vmaudio { display: block; }
}

/* ---- Video visit ---- */
button.danger { background: var(--busy); color: #fff; }
.videostage { position: relative; margin-top: 1rem; background: #0b0f14; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; aspect-ratio: 16 / 9; box-shadow: var(--shadow); }
.videostage.full { margin: 0; border-radius: 0; height: 100vh; aspect-ratio: auto; }
.remotevid { width: 100%; height: 100%; object-fit: cover; background: #0b0f14; display: block; }
.localvid { position: absolute; right: 12px; bottom: 64px; width: 22%; max-width: 220px; min-width: 110px; aspect-ratio: 16 / 9; object-fit: cover; border: 2px solid rgba(255,255,255,.7); border-radius: 10px; background: #000; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.vcontrols { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: .6rem; padding: .6rem .9rem; background: linear-gradient(transparent, rgba(0,0,0,.55)); }
.vcontrols .spacer { flex: 1; }
.vstatus { color: #fff; font-weight: 600; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.vcontrols button.ghost { background: rgba(255,255,255,.15); color: #fff; border-color: rgba(255,255,255,.35); }
