/* ============================================================================
   BPS — clinical UI design system. Zero-build: modern CSS + custom properties.
   Light + dark theming via :root[data-theme]. ========================================================================= */

:root {
    --bg: #eef1f5;
    --surface: #ffffff;
    --surface-2: #f5f8fb;
    --line: #e4e9f0;
    --line-strong: #d2dae5;
    --text: #15212e;
    --text-2: #3c4a5a;
    --muted: #6a7888;

    --primary: #0e7490;
    --primary-strong: #0b5566;
    --primary-weak: #e2f3f7;
    --on-primary: #ffffff;

    --ok: #15803d;        --ok-bg: #dcfce7;
    --warn: #b45309;      --warn-bg: #fdf0d5;
    --danger: #b91c1c;    --danger-bg: #fde4e4;
    --info: #1d4ed8;      --info-bg: #dde8fe;
    --blood: #b11217;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --shadow-md: 0 6px 18px rgba(16, 24, 40, .10);
    --shadow-lg: 0 18px 40px rgba(16, 24, 40, .18);

    --radius: 14px;
    --radius-sm: 9px;
    --pill: 999px;
    --sidebar-w: 256px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
    --bg: #0a0f1a;
    --surface: #111a28;
    --surface-2: #17222f;
    --line: #243245;
    --line-strong: #30415a;
    --text: #e8eef7;
    --text-2: #c3cedb;
    --muted: #8a97a8;

    --primary: #22b8d6;
    --primary-strong: #4cc9e4;
    --primary-weak: #0f3a45;
    --on-primary: #05222a;

    --ok: #4ade80;        --ok-bg: #0f2c1e;
    --warn: #fbbf24;      --warn-bg: #2f2510;
    --danger: #f87171;    --danger-bg: #36171b;
    --info: #60a5fa;      --info-bg: #112138;
    --blood: #f04444;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .45);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .5);
    --shadow-lg: 0 24px 50px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

::selection { background: color-mix(in srgb, var(--primary) 28%, transparent); }

/* ============================ Shell layout ============================ */
.shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

/* ============================ Sidebar ============================ */
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 16px 12px;
    gap: 4px;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 6px 8px 16px;
}
.brand-mark {
    font-size: 22px;
    width: 38px; height: 38px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, color-mix(in srgb, var(--blood) 16%, transparent), color-mix(in srgb, var(--blood) 4%, transparent));
    border-radius: 11px;
    box-shadow: inset 0 0 0 1px var(--line);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 14.5px; letter-spacing: -0.01em; }
.brand-text small { font-size: 11px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-group {
    font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
    color: var(--muted); margin: 14px 10px 4px;
}
.nav-group:first-child { margin-top: 2px; }

.nav-item {
    display: flex; align-items: center; gap: 11px;
    width: 100%; text-align: left;
    border: none; background: none; cursor: pointer;
    padding: 9px 11px; border-radius: 10px;
    font-size: 13.5px; font-weight: 500; color: var(--text-2);
    font-family: inherit;
    transition: background .14s, color .14s;
}
.nav-item .ic { width: 19px; height: 19px; flex: none; opacity: .85; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.nav-item.active {
    background: var(--primary-weak);
    color: var(--primary-strong);
    font-weight: 650;
}
:root[data-theme="dark"] .nav-item.active { color: var(--primary-strong); }
.nav-item.active .ic { opacity: 1; color: var(--primary); }

.sidebar-foot {
    display: flex; align-items: center; gap: 8px;
    font-size: 11px; color: var(--muted);
    padding: 12px 10px 4px; border-top: 1px solid var(--line); margin-top: 8px;
}
.dot-live {
    width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent);
}

/* ============================ Main column ============================ */
.main-col { display: flex; flex-direction: column; min-width: 0; }

.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 14px;
    padding: 13px 26px;
    background: color-mix(in srgb, var(--surface) 86%, transparent);
    backdrop-filter: saturate(1.2) blur(8px);
    border-bottom: 1px solid var(--line);
}
.topbar-title { display: flex; flex-direction: column; min-width: 0; }
.topbar-title h1 { margin: 0; font-size: 17px; font-weight: 680; letter-spacing: -0.01em; }
.topbar-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 9px; }

/* Hidden on desktop (sidebar is permanent). Higher specificity than .icon-btn so the
   button doesn't leak onto desktop where toggling the sticky sidebar would do nothing. */
.topbar .nav-toggle { display: none; }

main { padding: 24px 26px 56px; max-width: 1160px; width: 100%; }

/* ============================ Buttons ============================ */
.btn, button.action {
    display: inline-flex; align-items: center; gap: 7px;
    border: 1px solid transparent; border-radius: 10px;
    padding: 9px 15px; font-size: 13.5px; font-weight: 600; font-family: inherit;
    cursor: pointer; transition: background .14s, border-color .14s, transform .05s;
    background: var(--primary); color: var(--on-primary);
}
.btn:active, button.action:active { transform: translateY(1px); }
.btn:hover, button.action:hover { background: var(--primary-strong); }
button.action.ghost, .btn-ghost {
    background: transparent; color: var(--primary-strong); border-color: var(--line-strong);
}
button.action.ghost:hover, .btn-ghost:hover { background: var(--primary-weak); border-color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 84%, #000); }

.btn-demo {
    background: color-mix(in srgb, var(--blood) 12%, var(--surface));
    color: var(--blood); border: 1px solid color-mix(in srgb, var(--blood) 35%, transparent);
}
.btn-demo:hover { background: color-mix(in srgb, var(--blood) 20%, var(--surface)); }

.icon-btn {
    display: grid; place-items: center;
    width: 38px; height: 38px; border-radius: 10px;
    border: 1px solid var(--line); background: var(--surface); color: var(--text-2);
    cursor: pointer; transition: background .14s, color .14s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn .ic { width: 19px; height: 19px; }
/* theme toggle: show the icon for the *other* mode */
.ic-moon { display: none; }
:root[data-theme="dark"] .ic-sun { display: none; }
:root[data-theme="dark"] .ic-moon { display: block; }

/* Shared icon defaults (inline SVGs) */
.ic { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ============================ Cards ============================ */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
}
.card > h3 {
    margin: 0 0 14px; font-size: 13px; font-weight: 700;
    letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
    display: flex; align-items: center; gap: 8px;
}
.card.span-2 { grid-column: 1 / -1; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }

/* ============================ Toolbar / forms ============================ */
.toolbar { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 18px; flex-wrap: wrap; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 11.5px; font-weight: 600; color: var(--muted); }
input, select {
    padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 9px;
    font-size: 14px; font-family: inherit; background: var(--surface); color: var(--text);
    transition: border-color .14s, box-shadow .14s;
}
input:focus, select:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}

/* ============================ Patient banner + KPIs ============================ */
.patient-banner {
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.avatar {
    width: 52px; height: 52px; border-radius: 14px; flex: none;
    display: grid; place-items: center; font-weight: 700; font-size: 18px;
    color: var(--primary-strong);
    background: var(--primary-weak); box-shadow: inset 0 0 0 1px var(--line);
}
.patient-meta { display: flex; flex-wrap: wrap; gap: 6px 30px; flex: 1; }
.patient-meta .name { font-size: 18px; font-weight: 700; width: 100%; letter-spacing: -0.01em; }
.patient-head { display: flex; flex-wrap: wrap; gap: 8px 28px; }
.field { font-size: 14px; }
.field span, .patient-head span { display: block; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .02em; margin-bottom: 1px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
    padding: 14px 16px; box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column; gap: 2px;
}
.kpi b { font-size: 26px; font-weight: 720; letter-spacing: -0.02em; }
.kpi span { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi.accent b { color: var(--primary); }

/* ============================ Tables ============================ */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
thead th {
    position: sticky; top: 0;
    color: var(--muted); font-weight: 700; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
    background: var(--surface-2);
    border-bottom: 1px solid var(--line-strong);
}
tbody tr { transition: background .1s; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

/* ============================ Status badges ============================ */
.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px 3px 8px; border-radius: var(--pill);
    font-size: 11.5px; font-weight: 650; white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.badge.active { background: var(--ok-bg); color: var(--ok); }
.badge.returned { background: var(--warn-bg); color: var(--warn); }
.badge.reaction { background: var(--danger-bg); color: var(--danger); }
.badge.neutral { background: var(--surface-2); color: var(--muted); }

/* ============================ States ============================ */
.empty {
    color: var(--muted); font-size: 13.5px; padding: 18px; text-align: center;
    border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-2);
}
.result-ok { color: var(--ok); font-weight: 650; }
.result-err { color: var(--danger); font-weight: 650; }
.muted-line { color: var(--muted); font-size: 13px; margin: 2px 0 14px; line-height: 1.5; }

/* ============================ Bedside safety gate ============================ */
.gate-banner {
    display: flex; align-items: center; gap: 14px;
    padding: 16px 20px; border-radius: var(--radius); margin-bottom: 16px;
    border: 1px solid;
}
.gate-banner .gate-ico { width: 30px; height: 30px; flex: none; }
.gate-banner .gate-text { display: flex; flex-direction: column; }
.gate-banner b { font-size: 17px; letter-spacing: .01em; }
.gate-banner small { font-size: 12.5px; opacity: .9; }
.gate-banner.ok { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 40%, transparent); color: var(--ok); }
.gate-banner.bad { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }

/* keep .gate pill (used in seg-head) */
.gate { padding: 4px 12px; border-radius: var(--pill); font-weight: 700; font-size: 12px; letter-spacing: .04em; }
.gate.ok { background: var(--ok-bg); color: var(--ok); }
.gate.bad { background: var(--danger-bg); color: var(--danger); }

.checks { list-style: none; padding: 0; margin: 4px 0 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.checks li {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 13px; font-weight: 600;
    padding: 7px 12px; border-radius: var(--pill); border: 1px solid var(--line);
    background: var(--surface-2);
}
.chk-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent) !important; background: var(--ok-bg) !important; }
.chk-bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent) !important; background: var(--danger-bg) !important; }

.reaction-box {
    margin-top: 14px; padding: 14px 16px; border-radius: var(--radius-sm);
    border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
    background: var(--danger-bg);
}
.reaction-box strong { color: var(--danger); font-size: 13px; display: block; margin-bottom: 10px; }

.seg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.seg-head h3 { margin: 0; font-size: 16px; }
.seg-pt { color: var(--primary-strong); font-weight: 700; font-size: 12.5px; white-space: nowrap; }

/* ============================ Assessment view ============================ */
.pt-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.pt {
    background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
    padding: 16px 18px; display: flex; flex-direction: column; gap: 3px;
}
.pt span { color: var(--muted); font-size: 12px; font-weight: 600; }
.pt b { font-size: 27px; font-weight: 730; letter-spacing: -0.02em; }
.pt em { color: var(--muted); font-size: 12px; font-style: normal; }
.pt.hot { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.pt.hot b, .pt.hot em { color: var(--danger); }
code { font-family: var(--mono); font-size: 12px; }
code.impl { color: var(--ok); }
.tt {
    font-family: var(--mono); background: var(--info-bg); color: var(--info);
    padding: 1px 7px; border-radius: 5px; font-size: 11px; font-weight: 600;
}
.story { color: var(--muted); font-size: 12px; font-style: italic; margin-top: 3px; }

/* ============================ Labels / barcodes ============================ */
.labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.label {
    border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 16px 16px 14px;
    background: var(--surface); text-align: center; box-shadow: var(--shadow-sm);
}
.label .barcode { display: block; margin: 0 auto 6px; max-width: 100%; height: 48px; }
:root[data-theme="dark"] .label .barcode { background: #fff; border-radius: 4px; padding: 4px; }
.label-code { font-family: var(--mono); font-size: 12px; letter-spacing: .04em; color: var(--text-2); }
.label-title { font-size: 13px; font-weight: 650; margin-top: 5px; }
.label-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* ============================ Auto-demo chrome ============================ */
#demo-cursor {
    position: fixed; left: 50%; top: 40%; z-index: 10000; pointer-events: none;
    width: 26px; height: 26px; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .35));
    transform: translate(-3px, -2px); opacity: 0;
    transition: left .68s cubic-bezier(.22, .61, .36, 1), top .68s cubic-bezier(.22, .61, .36, 1);
}
body.demo-on #demo-cursor { opacity: 1; }
#demo-cursor.click { transform: translate(-3px, -2px) scale(.78); }

.demo-ripple {
    position: fixed; z-index: 9999; pointer-events: none;
    width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
    background: color-mix(in srgb, var(--primary) 45%, transparent);
    animation: demo-ripple .5s ease-out forwards;
}
@keyframes demo-ripple { from { transform: scale(.4); opacity: .8; } to { transform: scale(4.5); opacity: 0; } }

.demo-focus {
    outline: 3px solid var(--primary) !important; outline-offset: 2px; border-radius: 10px;
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--primary) 20%, transparent) !important;
    transition: outline .15s, box-shadow .15s;
}

#demo-balloon {
    position: fixed; z-index: 10001; max-width: 330px; pointer-events: none;
    background: #0f1726; color: #f3f6fb; padding: 13px 17px; border-radius: 13px;
    font-size: 14px; line-height: 1.45; box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255, 255, 255, .08);
    opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s;
}
#demo-balloon.show { opacity: 1; transform: translateY(0); }
#demo-balloon::before { content: ""; position: absolute; left: 26px; width: 0; height: 0; border: 9px solid transparent; }
#demo-balloon[data-dir="up"]::before { top: -16px; border-bottom-color: #0f1726; }
#demo-balloon[data-dir="down"]::before { bottom: -16px; border-top-color: #0f1726; }
#demo-balloon .caret { animation: demo-blink .8s steps(1) infinite; color: var(--primary-strong); }
@keyframes demo-blink { 50% { opacity: 0; } }

/* ============================ Responsive ============================ */
@media (max-width: 920px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 50;
        transform: translateX(-100%); transition: transform .22s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .topbar .nav-toggle { display: grid; }
    main { padding: 18px 16px 48px; }
    .grid-2 { grid-template-columns: 1fr; }
    .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 45; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
    #demo-cursor { transition: none !important; }
}

/* Transfusionsrückmeldung — highlight fields the chosen category makes obligatory
   (dynamic field control, ABAP CLC_BPS_TRANSFUSIONSRM). */
label.req > input, label.req > select { outline: 2px solid rgba(214, 69, 69, .45); outline-offset: 1px; }
