/* ==========================================================================
   Safana360 Live App — Interactive Clinical Handover Platform (Demo)
   ========================================================================== */
:root {
  --primary: #0d8253;
  --primary-hover: #0a6942;
  --primary-light: #e6f7f0;
  --sidebar: #0b2a20;
  --sidebar-hover: #12402f;
  --sidebar-text: #cfe6dc;
  --cyan: #0284c7;
  --cyan-light: #e0f2fe;
  --amber: #d97706;
  --amber-light: #fef3c7;
  --rose: #e11d48;
  --rose-light: #ffe4e6;
  --purple: #7c3aed;
  --purple-light: #ede9fe;
  --bg: #f4f7f6;
  --surface: #ffffff;
  --alt: #f1f5f9;
  --text: #0f172a;
  --muted: #475569;
  --subtle: #94a3b8;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 4px 12px -4px rgba(15,23,42,.08);
  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); text-decoration: none; }
.mono { font-family: var(--mono); }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 1rem .75rem; z-index: 40; }
.brand { display: flex; align-items: center; gap: .6rem; padding: .25rem .5rem 1.25rem; color: #fff; font-weight: 800; font-size: 1.15rem; }
/* Source logo has stray pixels on its right edge; show only the wordmark part */
.logo-crop { aspect-ratio: 204 / 63; object-fit: cover; object-position: left center; width: auto; display: block; }
.brand img.wordmark { width: 100%; height: auto; background: #fff; border-radius: 10px; padding: 6px 8px; display: block; }
.brand small { display: block; font-size: .65rem; font-weight: 600; color: #8fc9b0; letter-spacing: .02em; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: .65rem; padding: .6rem .75rem; border-radius: 9px; color: var(--sidebar-text); font-weight: 600; font-size: .88rem; }
.nav a:hover { background: var(--sidebar-hover); }
.nav a.active { background: var(--primary); color: #fff; }
.nav .ico { width: 20px; text-align: center; }
.nav .count { margin-left: auto; background: var(--rose); color: #fff; font-size: .7rem; border-radius: 999px; padding: 0 .45rem; min-width: 20px; text-align: center; }
.nav-sep { height: 1px; background: rgba(255,255,255,.08); margin: .5rem .25rem; }
.side-user { display: flex; align-items: center; gap: .6rem; padding: .75rem .5rem .25rem; border-top: 1px solid rgba(255,255,255,.08); margin-top: .5rem; }
.side-user .who { font-size: .8rem; color: #fff; font-weight: 700; line-height: 1.2; }
.side-user .who small { display: block; font-weight: 500; color: #8fc9b0; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .75rem; padding: .65rem 1.5rem; }
.topbar h1 { font-size: 1.1rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; background: none; border: 1px solid var(--border); border-radius: 8px; width: 36px; height: 36px; font-size: 1.1rem; }
.search { position: relative; }
.search input { border: 1px solid var(--border); border-radius: 9px; padding: .45rem .75rem .45rem 2rem; width: 230px; background: var(--alt); }
.search::before { content: '⌕'; position: absolute; left: .7rem; top: 50%; transform: translateY(-52%); color: var(--subtle); font-size: 1rem; }
.bell { position: relative; background: none; border: 1px solid var(--border); border-radius: 9px; width: 38px; height: 36px; font-size: 1rem; }
.bell .dot { position: absolute; top: -6px; right: -6px; background: var(--rose); color: #fff; font-size: .65rem; font-weight: 700; border-radius: 999px; padding: 1px 5px; }
.user-switch select { border: 1px solid var(--border); border-radius: 9px; padding: .45rem .5rem; background: var(--surface); max-width: 220px; font-weight: 600; font-size: .82rem; }
.demo-pill { font-size: .7rem; font-weight: 700; background: var(--amber-light); color: #92400e; padding: .25rem .6rem; border-radius: 999px; white-space: nowrap; }

.content { padding: 1.5rem; max-width: 1400px; width: 100%; }

/* ---------- Primitives ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; }
.card h3 { font-size: .95rem; font-weight: 800; margin-bottom: .75rem; display: flex; align-items: center; gap: .5rem; }
.card h3 .right { margin-left: auto; font-size: .78rem; font-weight: 600; }
.grid { display: grid; gap: 1rem; }
.g-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g-6 { grid-template-columns: repeat(6, minmax(0,1fr)); }
.span-2 { grid-column: span 2; }
.row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.stack > * + * { margin-top: 1rem; }
.muted { color: var(--muted); }
.subtle { color: var(--subtle); font-size: .78rem; }
.mt { margin-top: 1rem; }

.stat .label { font-size: .78rem; font-weight: 700; color: var(--muted); display: flex; align-items: center; gap: .4rem; }
.stat .value { font-size: 1.9rem; font-weight: 800; margin: .2rem 0; letter-spacing: -.02em; }
.stat .sub { font-size: .75rem; font-weight: 600; }
.up { color: var(--primary); } .down { color: var(--rose); } .warn { color: var(--amber); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid transparent; border-radius: 9px; padding: .5rem .9rem; font-weight: 700; font-size: .84rem; background: var(--primary); color: #fff; transition: background .15s; white-space: nowrap; }
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--alt); }
.btn.danger { background: var(--rose); }
.btn.amber { background: var(--amber); }
.btn.sm { padding: .3rem .6rem; font-size: .76rem; border-radius: 7px; }
.btn.block { width: 100%; }

.chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .72rem; font-weight: 700; padding: .18rem .55rem; border-radius: 999px; white-space: nowrap; }
.chip.critical, .chip.escalated, .chip.High { background: var(--rose-light); color: var(--rose); }
.chip.review, .chip.pending, .chip.Medium, .chip.warning { background: var(--amber-light); color: #b45309; }
.chip.stable, .chip.accepted, .chip.done, .chip.success { background: var(--primary-light); color: var(--primary); }
.chip.submitted, .chip.info, .chip.Low, .chip.open { background: var(--cyan-light); color: var(--cyan); }
.chip.draft { background: var(--alt); color: var(--muted); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: .7rem .85rem; background: var(--alt); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: .65rem .85rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8fbfa; }
.name-link { font-weight: 700; color: var(--cyan); }

.bar { height: 7px; background: var(--alt); border-radius: 99px; overflow: hidden; min-width: 70px; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .4s; }
.bar.amber > span { background: var(--amber); } .bar.rose > span { background: var(--rose); }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: center; }
.filters select, .filters input { border: 1px solid var(--border); border-radius: 9px; padding: .45rem .7rem; background: var(--surface); }
.seg { display: inline-flex; background: var(--alt); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: none; background: none; padding: .35rem .75rem; border-radius: 7px; font-weight: 700; font-size: .8rem; color: var(--muted); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .65rem .9rem; font-weight: 700; font-size: .85rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }

/* ---------- Dashboard ---------- */
.dept-card { border: 1px solid var(--border); border-radius: 10px; padding: .7rem .8rem; cursor: pointer; background: var(--surface); transition: border-color .15s, transform .15s; }
.dept-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.dept-card .n { font-size: 1.4rem; font-weight: 800; }
.dept-card .d { font-size: .78rem; font-weight: 700; }
.dept-card .c { font-size: .7rem; color: var(--rose); font-weight: 600; }
.alert-item { display: flex; gap: .6rem; padding: .55rem 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.alert-item:last-child { border-bottom: none; }
.alert-item .ai { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; flex: none; }
.ai.critical { background: var(--rose-light); } .ai.warning { background: var(--amber-light); } .ai.info { background: var(--cyan-light); } .ai.success { background: var(--primary-light); }
.alert-item .t { font-weight: 700; font-size: .83rem; }
.alert-item .x { font-size: .78rem; color: var(--muted); }
.alert-item .time { margin-left: auto; font-size: .72rem; color: var(--subtle); white-space: nowrap; }
.alert-item.unread .t::before { content: ''; display: inline-block; width: 7px; height: 7px; background: var(--rose); border-radius: 50%; margin-right: .35rem; vertical-align: middle; }
.empty { padding: 1.5rem; text-align: center; color: var(--subtle); font-size: .85rem; }

/* ---------- Patient ---------- */
.pt-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--primary-light); color: var(--primary); display: grid; place-items: center; font-weight: 800; flex: none; }
.avatar.sm { width: 30px; height: 30px; font-size: .72rem; }
.pt-head .nm { font-size: 1.25rem; font-weight: 800; }
.pt-meta { display: flex; gap: 1.25rem; flex-wrap: wrap; font-size: .82rem; color: var(--muted); }
.pt-meta b { color: var(--text); }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: .35rem .75rem; font-size: .84rem; }
.kv dt { color: var(--muted); font-weight: 600; }
.disc-row { display: flex; align-items: center; gap: .6rem; padding: .5rem 0; border-bottom: 1px solid var(--border); font-size: .84rem; cursor: pointer; }
.disc-row:last-child { border-bottom: none; }
.disc-row .dn { font-weight: 700; min-width: 140px; }
.disc-row .by { color: var(--muted); flex: 1; }

.disc-tabs { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: .5rem; margin-bottom: 1rem; }
.disc-tab { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: .55rem .6rem; text-align: left; }
.disc-tab .l { font-weight: 800; font-size: .82rem; display: block; margin-bottom: .25rem; }
.disc-tab.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .85rem 1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: .78rem; font-weight: 700; color: var(--muted); }
.field label .req { color: var(--rose); }
.field input, .field select, .field textarea, .modal input, .modal select, .modal textarea { border: 1px solid var(--border); border-radius: 9px; padding: .55rem .7rem; background: var(--surface); width: 100%; }
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.field.missing input, .field.missing select, .field.missing textarea { border-color: var(--rose); background: #fff7f8; }
.field.missing label::after { content: ' — missing'; color: var(--rose); }
.field .ro { padding: .5rem .7rem; background: var(--alt); border-radius: 9px; min-height: 2.2rem; white-space: pre-wrap; font-size: .85rem; }

.banner { border-radius: 10px; padding: .75rem 1rem; font-size: .85rem; display: flex; gap: .6rem; align-items: flex-start; margin-bottom: 1rem; }
.banner.info { background: var(--cyan-light); color: #075985; }
.banner.warn { background: var(--amber-light); color: #92400e; }
.banner.err { background: var(--rose-light); color: #9f1239; }
.banner.ok { background: var(--primary-light); color: #065f46; }
.banner b { font-weight: 800; }

.loop { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: .5rem; margin-bottom: 1rem; }
.loop .st { border: 1px dashed var(--border); border-radius: 10px; padding: .55rem .7rem; font-size: .76rem; color: var(--subtle); }
.loop .st b { display: block; font-size: .8rem; color: var(--muted); }
.loop .st.on { border-style: solid; border-color: var(--primary); background: var(--primary-light); color: #065f46; }
.loop .st.on b { color: #065f46; }
.loop .st.bad { border-style: solid; border-color: var(--rose); background: var(--rose-light); color: #9f1239; }
.loop .st.bad b { color: #9f1239; }

.ai-box { background: linear-gradient(135deg, #f5f3ff, #eef6ff); border: 1px solid #ddd6fe; border-radius: 10px; padding: .9rem 1rem; font-size: .85rem; white-space: pre-wrap; }

/* ---------- Vitals ---------- */
.vital { border: 1px solid var(--border); border-radius: 12px; padding: .8rem .9rem; background: var(--surface); }
.vital .vl { font-size: .72rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.vital .vv { font-family: var(--mono); font-size: 1.7rem; font-weight: 600; margin: .1rem 0; }
.vital .vv small { font-size: .75rem; color: var(--subtle); font-family: var(--font); }
.vital.abn { border-color: var(--rose); background: #fff7f8; }
.vital.abn .vv { color: var(--rose); }
.vital svg { display: block; width: 100%; height: 38px; }
.monitor-tile { border: 1px solid var(--border); border-radius: 12px; padding: .8rem; background: #0b1a14; color: #d1fae5; cursor: pointer; }
.monitor-tile:hover { border-color: var(--primary); }
.monitor-tile .hd { display: flex; justify-content: space-between; font-size: .78rem; font-weight: 700; color: #a7f3d0; margin-bottom: .4rem; }
.monitor-tile .vals { display: grid; grid-template-columns: repeat(4, 1fr); gap: .3rem; font-family: var(--mono); }
.monitor-tile .vals div { font-size: 1.05rem; }
.monitor-tile .vals small { display: block; font-family: var(--font); font-size: .6rem; color: #6ee7b7; }
.monitor-tile .abn { color: #fb7185; animation: blink 1s steps(2) infinite; }
.monitor-tile svg { width: 100%; height: 30px; display: block; margin-top: .3rem; }
@keyframes blink { 50% { opacity: .45; } }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #10b981; margin-right: .35rem; animation: blink 1.2s steps(2) infinite; }

/* ---------- Handover board ---------- */
.board td.cell { text-align: center; cursor: pointer; }
.board td.cell:hover { background: #f8fbfa; }

/* ---------- Charts ---------- */
.chart svg { width: 100%; height: auto; display: block; }
.chart text { font-size: 10px; fill: var(--muted); font-family: var(--font); }

/* ---------- Modal & Toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 100; padding: 1rem; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 480px; padding: 1.4rem; box-shadow: 0 24px 48px -12px rgba(15,23,42,.3); max-height: 92vh; overflow-y: auto; }
.modal h2 { font-size: 1.1rem; margin-bottom: 1rem; }
.modal .field { margin-bottom: .75rem; }
.modal .actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 200; max-width: 360px; }
.toast { background: #0f172a; color: #fff; border-radius: 12px; padding: .75rem 1rem; font-size: .84rem; box-shadow: 0 12px 28px -6px rgba(0,0,0,.35); display: flex; gap: .6rem; animation: tin .25s ease; cursor: pointer; }
.toast b { display: block; }
.toast.critical { border-left: 4px solid var(--rose); }
.toast.warning { border-left: 4px solid var(--amber); }
.toast.success { border-left: 4px solid #10b981; }
.toast.info { border-left: 4px solid #38bdf8; }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(circle at 20% 10%, #d1fae5 0, transparent 40%), radial-gradient(circle at 90% 90%, #e0f2fe 0, transparent 40%), var(--bg); }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: 0 24px 48px -12px rgba(15,23,42,.15); padding: 2rem; width: 100%; max-width: 880px; }
.login-box .brand { color: var(--text); padding: 0 0 .5rem; font-size: 1.4rem; }
.login-box .brand small { color: var(--primary); font-size: .75rem; }
.user-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: .6rem; margin-top: 1.25rem; }
.user-card { display: flex; align-items: center; gap: .6rem; border: 1px solid var(--border); border-radius: 12px; padding: .65rem .75rem; background: var(--surface); text-align: left; transition: border-color .15s, box-shadow .15s; }
.user-card:hover { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.user-card .n { font-weight: 800; font-size: .85rem; }
.user-card .r { font-size: .74rem; color: var(--muted); }

.scrim { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .g-4, .g-6 { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .disc-tabs { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .search input { width: 160px; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; transform: translateX(-100%); transition: transform .25s; }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  .menu-btn { display: block; }
  .g-3, .g-2 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .user-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .search, .demo-pill { display: none; }
  .topbar { padding: .6rem 1rem; }
  .content { padding: 1rem; }
}
@media (max-width: 600px) {
  .g-4, .g-6 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .disc-tabs { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .loop { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .user-grid { grid-template-columns: 1fr; }
  .user-switch select { max-width: 110px; }
  #clock { display: none; }
  .topbar { gap: .5rem; }
  .toasts { left: 1rem; right: 1rem; max-width: none; }
  .kv { grid-template-columns: 110px 1fr; }
  .topbar h1 { font-size: .95rem; }
  .login-box { padding: 1.25rem; }
}
