/* HMIS design system — Wyet Num Unity Sanctuary Hospital brand (blue / white / red). No build step required. */
:root {
    /* Wyet Num Unity Sanctuary Hospital brand: blue (primary), red (alerts / accents), white */
    --primary: #1677C8;          /* Primary Blue */
    --primary-600: #1366AD;
    --primary-700: #0F4F8A;      /* Dark Blue */
    --primary-50: #EAF4FC;       /* Light Blue */
    --primary-100: #D3E8F8;
    --brand-red: #D94B4B;        /* Brand red: accents, emergency, destructive */
    --brand-red-50: #FDECEC;
    --secondary: #2563EB;        /* Info */
    --secondary-50: #EFF6FF;
    --success: #16A34A;
    --success-700: #15803D;
    --success-50: #ECFDF3;
    --warning: #F59E0B;
    --warning-700: #B45309;
    --warning-50: #FFF7E8;
    --danger: #DC2626;           /* Error / critical */
    --danger-700: #B91C1C;
    --danger-50: #FEECEC;
    --purple: #7C3AED;
    --purple-50: #F5F3FF;
    --n900: #1F2937;             /* Text primary */
    --n700: #374151;
    --n500: #6B7280;             /* Text secondary */
    --n400: #9CA3AF;             /* Muted */
    --n300: #D1D5DB;
    --n200: #E5E7EB;
    --n100: #F3F6FA;             /* Hover gray */
    --bg: #F7F9FC;               /* Page background */
    --surface: #FFFFFF;
    --surface-2: #F8FAFC;
    --border: #E5E7EB;
    --border-soft: #EEF2F7;
    --border-strong: #D5DCE5;
    --text: var(--n900);
    --muted: var(--n500);
    --sidebar: #0F4F8A;
    --sidebar-2: #0B3A66;
    --sidebar-text: #D3E3F3;
    --focus: rgba(22, 119, 200, .18);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
    --shadow-md: 0 6px 16px rgba(16, 24, 40, .08);
    --shadow-lg: 0 12px 32px rgba(15, 79, 138, .12);
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --font-display: "Manrope", "Inter", system-ui, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-family: var(--font-display); color: var(--n900); letter-spacing: -.01em; }
h1 { font-size: 1.625rem; font-weight: 700; } h2 { font-size: 1.15rem; font-weight: 700; } h3 { font-size: 1rem; font-weight: 600; }
small, .muted { color: var(--muted); }
.mono { font-family: var(--font-mono); font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
kbd { font-family: var(--font-mono); font-size: .72rem; padding: .05rem .35rem; border: 1px solid var(--border-strong); border-radius: 4px; background: var(--surface-2); color: var(--muted); }
.icon { width: 18px; height: 18px; flex-shrink: 0; vertical-align: middle; }
.icon-sm { width: 15px; height: 15px; }
.icon-lg { width: 22px; height: 22px; }
:focus-visible { outline: 2px solid rgba(22, 119, 200, .6); outline-offset: 2px; }

/* ---------- brand ---------- */
.brand-mark { display: flex; align-items: center; gap: .65rem; }
.brand-mark img { width: 40px; height: auto; flex-shrink: 0; filter: drop-shadow(0 1px 2px rgba(0,0,0,.18)); }
.brand-mark .brand-name { font-family: var(--font-display); font-weight: 800; font-size: .98rem; letter-spacing: -.01em; line-height: 1.15; }
.brand-mark .brand-sub { font-size: .72rem; opacity: .8; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 248px; background: radial-gradient(circle at 12% 4%, rgba(57,145,218,.25), transparent 24%), linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%); color: var(--sidebar-text); flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.sidebar .brand { padding: 1.15rem 1.1rem 1rem; color: #fff; }
.sidebar nav { flex: 1; padding: .25rem .65rem 1rem; }
.sidebar .nav-bottom { padding: .65rem .65rem 1rem; border-top: 1px solid rgba(255,255,255,.09); }
.nav-item { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: 10px; color: var(--sidebar-text); font-weight: 500; cursor: pointer; list-style: none; user-select: none; }
.nav-item::-webkit-details-marker { display: none; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item.active, details[open] > .nav-item.has-active { background: rgba(255,255,255,.10); color: #fff; }
.nav-item.active { background: var(--primary); box-shadow: 0 4px 12px rgba(0,0,0,.18); }
.nav-item .chev { margin-left: auto; width: 14px; height: 14px; transition: transform .15s; opacity: .7; }
details[open] > .nav-item .chev { transform: rotate(180deg); }
.nav-sub { padding: .15rem 0 .35rem 2.35rem; }
.nav-sub a { display: block; padding: .32rem .6rem; border-radius: 8px; color: var(--sidebar-text); font-size: .86rem; opacity: .9; }
.nav-sub a:hover { color: #fff; background: rgba(255,255,255,.05); text-decoration: none; }
.nav-sub a.active { color: #fff; background: rgba(255,255,255,.14); font-weight: 600; opacity: 1; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { min-height: 68px; background: rgba(255,255,255,.9); backdrop-filter: saturate(150%) blur(16px); -webkit-backdrop-filter: saturate(150%) blur(16px); border-bottom: 1px solid rgba(213,220,229,.78); padding: .72rem 1.5rem; display: flex; align-items: center; gap: 1rem; position: sticky; top: 0; z-index: 10; box-shadow: 0 8px 28px -24px rgba(15,79,138,.48); }
.topbar .search { flex: 1; max-width: 480px; position: relative; }
.topbar .search input { min-height: 43px; padding-left: 2.55rem; padding-right: 3rem; background: rgba(247,249,252,.9); border-color: #DCE4EC; border-radius: 13px; box-shadow: inset 0 1px 2px rgba(15,38,61,.025); transition: background-color .2s, border-color .2s, box-shadow .2s; }
.topbar .search input:focus { background: #fff; border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.topbar .search .icon { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.topbar .search kbd { position: absolute; right: .7rem; top: 50%; transform: translateY(-50%); }
.topbar .user { margin-left: auto; display: flex; align-items: center; gap: .9rem; }
.icon-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 10px; color: var(--n700); }
.icon-btn:hover { background: var(--n100); text-decoration: none; }
.icon-btn .dot { position: absolute; top: 7px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); border: 2px solid #fff; }
.user-menu { position: relative; }
.user-menu > summary { list-style: none; display: flex; align-items: center; gap: .65rem; cursor: pointer; padding: .3rem .5rem .3rem .35rem; border: 1px solid transparent; border-radius: 13px; transition: background-color .2s, border-color .2s, box-shadow .2s; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover, .user-menu[open] > summary { background: #fff; border-color: var(--border); box-shadow: var(--shadow); }
.user-menu .who { line-height: 1.15; }
.user-menu .who strong { display: block; font-size: .88rem; }
.user-menu .who small { font-size: .74rem; }
.user-menu .menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: .35rem; z-index: 30; }
.user-menu .menu a, .user-menu .menu button { display: flex; align-items: center; gap: .55rem; width: 100%; padding: .5rem .6rem; border-radius: 8px; color: var(--n700); background: none; border: 0; font: inherit; cursor: pointer; text-align: left; }
.user-menu .menu a:hover, .user-menu .menu button:hover { background: var(--n100); text-decoration: none; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%); color: #fff; font-weight: 700; font-size: .82rem; flex-shrink: 0; font-family: var(--font-display); }
.avatar-lg { width: 64px; height: 64px; font-size: 1.3rem; }
.avatar-sm { width: 30px; height: 30px; font-size: .72rem; }
.content { padding: 1.5rem; max-width: 1480px; width: 100%; }
.menu-toggle { display: none; }

@media (max-width: 960px) {
    .sidebar { position: fixed; left: -270px; z-index: 50; transition: left .2s; }
    .sidebar.open { left: 0; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
    .menu-toggle { display: inline-flex; }
    .content { padding: 1rem; }
    .topbar { padding: .6rem 1rem; }
    .topbar .search { display: none; }
    .user-menu .who { display: none; }
}

/* ---------- layout helpers ---------- */
.page-header { position: relative; overflow: hidden; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.35rem; padding: 1rem 1.15rem; background: linear-gradient(118deg, #FFFFFF 0%, #F7FAFD 72%, #EDF6FD 100%); border: 1px solid #E0E8F0; border-radius: 16px; box-shadow: 0 10px 30px -26px rgba(15,79,138,.62); }
.page-header::after { content: ""; position: absolute; width: 9rem; height: 9rem; right: -4.5rem; top: -5.4rem; border-radius: 50%; background: rgba(22,119,200,.07); pointer-events: none; }
.page-header-copy { position: relative; z-index: 1; display: flex; align-items: stretch; gap: .85rem; min-width: 0; }
.page-header-mark { width: 5px; min-height: 2.8rem; flex-shrink: 0; border-radius: 999px; background: linear-gradient(180deg, var(--primary), var(--brand-red)); box-shadow: 0 5px 14px rgba(22,119,200,.2); }
.page-header h1 { margin: 0; font-size: clamp(1.45rem, 2.2vw, 1.8rem); font-weight: 800; letter-spacing: -.03em; color: #13283D; }
.page-header .subtitle { color: var(--muted); margin-top: .18rem; max-width: 58rem; line-height: 1.45; }
.page-header > .actions { position: relative; z-index: 1; }
.breadcrumb { font-size: .8rem; color: var(--muted); margin-bottom: .35rem; }
.breadcrumb a { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.grid { display: grid; gap: 1.1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
@media (max-width: 700px) { .span-2 { grid-column: auto; } }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-sidebar { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-dash { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 1200px) { .grid-dash { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-sidebar { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 700px) { .grid-2, .grid-3, .grid-4, .grid-dash { grid-template-columns: minmax(0, 1fr); } }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.text-right { text-align: right; } .text-center { text-align: center; }
.mt-0 { margin-top: 0 !important; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1.1rem; } .mb-0 { margin-bottom: 0 !important; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1.1rem; }
.w-full { width: 100%; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: .95rem 1.15rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.card-header h2, .card-header h3 { margin: 0; font-size: 1rem; font-weight: 700; }
.card-header a { font-size: .85rem; font-weight: 600; }
.card-body { padding: 1.15rem; }
.card-body.flush { padding: 0; }
.card-footer { padding: .8rem 1.15rem; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }

/* stat cards */
.stat { padding: 1.05rem 1.15rem; display: flex; align-items: center; gap: .95rem; color: inherit; }
a.stat:hover { text-decoration: none; box-shadow: var(--shadow-lg); border-color: var(--primary-100); }
.stat .stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--primary-50); color: var(--primary); }
.stat .stat-icon .icon { width: 24px; height: 24px; }
.stat .label { color: var(--n700); font-size: .82rem; font-weight: 500; }
.stat .value { font-size: 1.6rem; font-weight: 700; font-family: var(--font-display); margin-top: .1rem; line-height: 1.15; color: var(--n900); }
.stat .hint { font-size: .76rem; color: var(--muted); margin-top: .1rem; }
.stat:not(:has(.stat-icon)) { display: block; }
.tone-teal .stat-icon { background: var(--primary-50); color: var(--primary); }
.tone-blue .stat-icon { background: var(--secondary-50); color: var(--secondary); }
.tone-green .stat-icon { background: var(--success-50); color: var(--success-700); }
.tone-amber .stat-icon { background: var(--warning-50); color: var(--warning-700); }
.tone-red .stat-icon { background: var(--danger-50); color: var(--danger-700); }
.tone-purple .stat-icon { background: var(--purple-50); color: var(--purple); }
.trend { display: inline-flex; align-items: center; gap: .15rem; font-size: .74rem; font-weight: 600; padding: .05rem .4rem; border-radius: 999px; background: var(--success-50); color: var(--success-700); }
.trend.down { background: var(--danger-50); color: var(--danger-700); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .7rem .9rem; border-bottom: 1px solid var(--n100); text-align: left; vertical-align: middle; }
.table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); font-weight: 600; white-space: nowrap; border-bottom-color: var(--border); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover, .table > tr:hover { background: var(--n100); }
.table thead th { position: sticky; top: 0; z-index: 1; }
.table td.num, .table th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table tfoot td { font-weight: 700; background: var(--surface-2); }
.table.compact th, .table.compact td { padding: .45rem .65rem; }
.person { display: flex; align-items: center; gap: .6rem; }
.person strong { display: block; line-height: 1.2; }
.person small { line-height: 1.2; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1rem; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }
.field label { display: block; font-weight: 600; font-size: .82rem; margin-bottom: .3rem; color: var(--n700); }
.field .req { color: var(--danger); }
.field .help { font-size: .76rem; color: var(--muted); margin-top: .25rem; }
.field .error { font-size: .78rem; color: var(--danger-700); margin-top: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=time], input[type=search], input[type=tel], input[type=file], select, textarea {
    width: 100%; min-height: 44px; padding: .6rem .8rem; border: 1px solid var(--border-strong); border-radius: 8px; font: inherit; background: #fff; color: var(--text); transition: border-color .12s, box-shadow .12s;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.is-invalid { border-color: var(--danger) !important; background: var(--danger-50) !important; }
.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 500; color: var(--n700); }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); }
input[type=checkbox], input[type=radio] { accent-color: var(--primary); }
.inline-form { display: inline; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.filters .field { min-width: 160px; }
.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon > input { padding-left: 2.35rem; }
.input-icon > .toggle-pw { position: absolute; right: .5rem; top: 50%; transform: translateY(-50%); background: none; border: 0; color: var(--muted); cursor: pointer; padding: .25rem; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 40px; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border-strong); background: #fff; color: var(--n700); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none !important; line-height: 1.2; transition: background .12s, border-color .12s, box-shadow .12s; }
.btn:hover { background: var(--surface-2); border-color: var(--n300); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); box-shadow: 0 4px 12px rgba(22,119,200,.28); }
.btn-secondary { background: var(--primary-50); border-color: var(--primary-100); color: var(--primary-700); }
.btn-secondary:hover { background: var(--primary-100); border-color: var(--primary-100); }
.btn-outline { background: #fff; border-color: var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary-50); border-color: var(--primary); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-700); border-color: var(--danger-700); }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-ghost, .btn-link { border-color: transparent; background: none; color: var(--primary); }
.btn-ghost:hover, .btn-link:hover { background: var(--primary-50); border-color: transparent; }
.btn-sm { min-height: 32px; padding: .32rem .65rem; font-size: .8rem; border-radius: 7px; }
.btn-lg { min-height: 48px; padding: .75rem 1.2rem; font-size: .95rem; }
.btn[disabled], .btn.disabled { opacity: .55; cursor: not-allowed; }

/* ---------- chips / alerts ---------- */
.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .16rem .6rem; border-radius: 999px; font-size: .74rem; font-weight: 600; white-space: nowrap; background: var(--n100); color: var(--n700); border: 1px solid transparent; line-height: 1.4; }
.badge.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge-success { background: var(--success-50); color: var(--success-700); }
.badge-danger { background: var(--danger-50); color: var(--danger-700); }
.badge-warning { background: var(--warning-50); color: var(--warning-700); }
.badge-info { background: var(--secondary-50); color: var(--secondary); }
.badge-purple { background: var(--purple-50); color: var(--purple); }
.badge-muted { background: var(--n100); color: var(--n500); }
.badge-neutral { background: var(--n100); color: var(--n700); }
.badge-p1 { background: var(--danger); color: #fff; }
.badge-p2 { background: var(--warning); color: #fff; }
.alert { display: flex; gap: .6rem; align-items: flex-start; padding: .8rem 1rem; border-radius: 10px; border: 1px solid; margin-bottom: 1rem; }
.alert > div { flex: 1; }
.alert-success { background: var(--success-50); border-color: #A7F3D0; color: #065F46; }
.alert-danger { background: var(--danger-50); border-color: #FECACA; color: #7F1D1D; }
.alert-warning { background: var(--warning-50); border-color: #FDE68A; color: #78350F; }
.alert-info { background: var(--secondary-50); border-color: #BFDBFE; color: #1E3A8A; }
.alert ul { margin: .25rem 0 0 1rem; padding: 0; }

/* ---------- patient banner ---------- */
.patient-banner { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; align-items: center; padding: 1.1rem 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1.1rem; box-shadow: var(--shadow); }
.patient-banner .name { font-size: 1.3rem; font-weight: 700; font-family: var(--font-display); display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.patient-banner .meta { color: var(--muted); font-size: .85rem; display: flex; flex-wrap: wrap; gap: .25rem .9rem; margin-top: .2rem; }
.patient-banner .meta span { display: inline-flex; align-items: center; gap: .3rem; }
.patient-banner .chips { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .45rem; }

/* ---------- misc ---------- */
.empty { padding: 2.2rem 1rem; text-align: center; color: var(--muted); }
.empty .empty-icon { width: 48px; height: 48px; border-radius: 50%; background: var(--n100); display: inline-flex; align-items: center; justify-content: center; margin-bottom: .6rem; color: var(--n500); }
.empty strong { display: block; color: var(--n700); margin-bottom: .2rem; font-family: var(--font-display); }
.tabs { display: flex; gap: .35rem; margin-bottom: 1.1rem; flex-wrap: wrap; padding: .3rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; width: fit-content; max-width: 100%; }
.tabs a { padding: .42rem .9rem; border-radius: 8px; color: var(--n700); font-weight: 600; font-size: .86rem; }
.tabs a.active { color: #fff; background: var(--primary); }
.tabs a:hover:not(.active) { text-decoration: none; background: var(--n100); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 1.05rem 1.35rem; border-left: 2px solid var(--n200); margin-left: .4rem; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: .2rem; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid var(--primary); }
.timeline li.restricted::before { border-color: var(--purple); }
.timeline .when { font-size: .76rem; color: var(--muted); }
.timeline .title { font-weight: 600; color: var(--n900); }
.timeline .summary { white-space: pre-wrap; font-size: .86rem; color: var(--n700); }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--n100); }
.activity li:last-child { border-bottom: 0; }
.activity .a-icon { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--secondary-50); color: var(--secondary); }
.activity .a-time { font-size: .74rem; color: var(--muted); white-space: nowrap; }
.dl { display: grid; grid-template-columns: 170px 1fr; gap: .45rem .9rem; margin: 0; }
.dl dt { color: var(--muted); font-size: .84rem; }
.dl dd { margin: 0; }
@media (max-width: 600px) { .dl { grid-template-columns: 1fr; } .dl dt { margin-top: .4rem; } }
.pagination { display: flex; gap: .3rem; flex-wrap: wrap; padding: .8rem 1.15rem; align-items: center; justify-content: flex-end; border-top: 1px solid var(--n100); }
.pagination a, .pagination span { padding: .3rem .7rem; border: 1px solid var(--border); border-radius: 8px; background: #fff; font-size: .84rem; }
.pagination .muted { border: 0; background: none; margin-right: auto; }
.pagination .disabled { color: var(--n300); }
.progress { height: 8px; background: var(--n100); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: var(--primary); }
.bed-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .65rem; }
.bed { border: 1px solid #A7F3D0; border-radius: 10px; padding: .65rem .75rem; background: var(--success-50); min-height: 80px; }
.bed.occupied { background: var(--secondary-50); border-color: #BFDBFE; }
.bed.maintenance, .bed.closed { background: var(--n100); border-color: var(--n200); color: var(--n500); }
.bed.dirty { background: #FFFBEB; border-color: #FDE68A; }
.bed.reserved { background: #F5F3FF; border-color: #DDD6FE; }
.bed .code { font-weight: 800; font-family: var(--font-display); }
.flag-critical_low, .flag-critical_high { color: #fff; background: var(--danger); padding: 0 .35rem; border-radius: 4px; font-weight: 700; }
.flag-low, .flag-high, .flag-abnormal { color: var(--danger-700); font-weight: 700; }
.board { font-size: 1.2rem; }
.board td { padding: .9rem 1rem; }
.chart-legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .78rem; color: var(--n700); margin-top: .4rem; }
.chart-legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-right: .35rem; }
.greeting { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.greeting .when { text-align: right; color: var(--muted); font-size: .85rem; }
.greeting .when strong { display: block; color: var(--n900); font-size: 1rem; }
.skeleton { background: linear-gradient(90deg, #eef2f7 25%, #f8fafc 50%, #eef2f7 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 6px; height: 1rem; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.print-only { display: none; }

/* ---------- auth (split screen) ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; background: radial-gradient(circle at 8% 8%, #EAF4FC 0%, transparent 45%), radial-gradient(circle at 92% 92%, #FDECEC 0%, transparent 40%), var(--bg); }
.auth-shell { width: 100%; max-width: 1120px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); background: #fff; border-radius: var(--radius-lg); box-shadow: 0 24px 64px rgba(15, 79, 138, .16); overflow: hidden; min-height: 640px; }
.auth-form { padding: 2.5rem 3rem; display: flex; flex-direction: column; }
.auth-logo { display: block; width: 100%; max-width: 340px; height: auto; margin-bottom: .6rem; }
.auth-system { font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 1.8rem; }
.auth-form h1 { font-size: 1.75rem; margin-bottom: .3rem; }
.auth-form .lead { color: var(--muted); margin-bottom: 1.5rem; }
.auth-form .foot { margin-top: auto; padding-top: 1.5rem; font-size: .78rem; color: var(--muted); text-align: center; line-height: 1.6; }
.auth-form .foot .secure { display: inline-flex; align-items: center; gap: .35rem; color: var(--n700); font-weight: 600; }
.auth-art { position: relative; color: #fff; padding: 2.5rem; display: flex; flex-direction: column; justify-content: flex-end; overflow: hidden; background: var(--primary-700) var(--art-image, none) center / cover no-repeat; }
.auth-art::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(11, 58, 102, .15) 0%, rgba(11, 58, 102, .55) 38%, rgba(11, 58, 102, .94) 72%, #0B3A66 100%); }
.auth-art > * { position: relative; }
.auth-art .art-figure { position: absolute; top: 2rem; left: 50%; transform: translateX(-50%); width: 150px; height: 150px; border-radius: 50%; background: rgba(255,255,255,.12); display: flex; align-items: center; justify-content: center; box-shadow: 0 0 0 20px rgba(255,255,255,.05); }
.auth-art .art-figure svg { width: 72px; height: 72px; }
.auth-art .eyebrow { display: inline-flex; align-items: center; gap: .45rem; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: #fff; background: var(--brand-red); padding: .3rem .7rem; border-radius: 999px; width: fit-content; margin-bottom: .8rem; }
.auth-art h2 { color: #fff; font-size: 1.6rem; font-weight: 800; margin-bottom: .5rem; }
.auth-art p { opacity: .92; margin: 0 0 1rem; line-height: 1.6; }
.auth-art .purpose { font-style: italic; border-left: 3px solid var(--brand-red); padding-left: .8rem; }
.auth-art ul { list-style: none; padding: 0; margin: 0; display: grid; gap: .55rem; }
.auth-art li { display: flex; gap: .55rem; align-items: center; font-size: .88rem; }
.auth-art li .icon { color: #93C5FD; }
.auth-art .values { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .2rem; }
.auth-art .values span { background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.22); padding: .25rem .7rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.auth-art .trust { margin-top: 1.3rem; display: inline-flex; gap: .6rem; align-items: center; background: rgba(255,255,255,.12); padding: .55rem .85rem; border-radius: 12px; font-size: .8rem; width: fit-content; }
.pw-rules { list-style: none; padding: .75rem .9rem; margin: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; font-size: .8rem; display: grid; gap: .25rem; }
.pw-rules li { display: flex; gap: .45rem; align-items: center; color: var(--muted); }
.pw-rules li.ok { color: var(--success-700); }
.pw-rules li .icon { width: 15px; height: 15px; }
.strength { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: .4rem; }
.strength span { height: 5px; border-radius: 999px; background: var(--n200); }
.strength[data-score="1"] span:nth-child(-n+1) { background: var(--danger); }
.strength[data-score="2"] span:nth-child(-n+2) { background: var(--warning); }
.strength[data-score="3"] span:nth-child(-n+3) { background: var(--success); }
.strength[data-score="4"] span:nth-child(-n+4) { background: var(--success); }
@media (max-width: 860px) { .auth-shell { grid-template-columns: 1fr; min-height: 0; } .auth-art { display: none; } .auth-form { padding: 2rem 1.25rem; } .auth-page { padding: 1rem; } }

@media print {
    .sidebar, .topbar, .no-print, .actions, .btn { display: none !important; }
    .content { padding: 0; max-width: none; }
    body { background: #fff; font-size: 12px; }
    .card { box-shadow: none; border: 0; }
    .print-only { display: block; }
}

/* ---------- Sprint 1: patient management ---------- */
.avatar-img { object-fit: cover; background: var(--n100); }
.avatar-xl { width: 96px; height: 96px; font-size: 1.8rem; }
.summary-section + .summary-section { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--n100); }
.summary-section h3 { display: flex; align-items: center; justify-content: space-between; font-size: .9rem; }
.summary-item { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; padding: .45rem 0; border-bottom: 1px dashed var(--n100); }
.summary-item:last-child { border-bottom: 0; }
.summary-item .what strong { display: block; font-size: .88rem; }
.summary-item .what small { display: block; }
.inline-actions { display: flex; gap: .3rem; flex-wrap: wrap; align-items: center; }
.inline-actions input[type=text] { width: 140px; padding: .3rem .5rem; font-size: .8rem; }
details.inline-form-toggle > summary { cursor: pointer; color: var(--primary); font-weight: 600; font-size: .82rem; list-style: none; }
details.inline-form-toggle > summary::-webkit-details-marker { display: none; }
.sev-life_threatening, .sev-severe { background: var(--danger-50); color: var(--danger-700); }
.sev-moderate { background: var(--warning-50); color: var(--warning-700); }
.sev-mild { background: var(--n100); color: var(--n700); }
.filter-panel { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .6rem; align-items: end; }
.sort-link { color: inherit; }
.sort-link:hover { color: var(--primary); text-decoration: none; }

/* MAR grid */
.mar-grid td, .mar-grid th { vertical-align: middle; }
.mar-cell { display: inline-block; position: relative; }
.mar-cell > summary { cursor: pointer; list-style: none; }
.mar-cell > summary::-webkit-details-marker { display: none; }
.mar-cell[open] > form { position: absolute; z-index: 30; left: 50%; transform: translateX(-50%); background: var(--surface, #fff); border: 1px solid var(--border); border-radius: 10px; padding: 10px; box-shadow: 0 8px 24px rgba(15, 23, 42, .15); text-align: left; }

/* appointment week / month calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.cal-head { background: var(--surface-2); padding: 8px; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--n500, #64748B); }
.cal-day { background: var(--surface); padding: 6px; min-height: 110px; display: flex; flex-direction: column; gap: 3px; }
.cal-week .cal-day { min-height: 340px; }
.cal-day.outside { background: var(--surface-2); opacity: .6; }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--primary); }
.cal-date { font-weight: 700; font-size: .82rem; color: inherit; text-decoration: none; margin-bottom: 2px; }
.cal-ev { display: block; font-size: .74rem; line-height: 1.25; padding: 3px 6px; border-radius: 6px; background: var(--primary-50); color: var(--primary-700); text-decoration: none; border-left: 3px solid var(--primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-week .cal-ev { white-space: normal; }
.cal-ev.st-confirmed { background: #EFF6FF; color: #1E40AF; border-color: #2563EB; }
.cal-ev.st-arrived, .cal-ev.st-completed { background: #ECFDF5; color: #065F46; border-color: #059669; }
.cal-ev.st-cancelled, .cal-ev.st-no_show { background: #F3F4F6; color: #6B7280; border-color: #9CA3AF; text-decoration: line-through; }
.cal-more { font-size: .72rem; color: var(--primary); }
@media (max-width: 700px) { .cal { grid-template-columns: 1fr; } .cal-head { display: none; } .cal-day, .cal-week .cal-day { min-height: 0; } .cal-day.outside { display: none; } }
.cal-ev[draggable=true] { cursor: grab; }
.cal-ev.dragging { opacity: .45; }
.cal-ev.clash { border-left-color: var(--danger, #DC2626); background: #FEF2F2; color: #991B1B; }
.cal-day.drop-target { box-shadow: inset 0 0 0 2px var(--secondary, #2563EB); background: #EFF6FF; }
.cal-absence { display: block; font-size: .7rem; padding: 2px 6px; border-radius: 6px; background: #FEF3C7; color: #92400E; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* registration wizard */
.wizard-steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 1rem; flex-wrap: wrap; counter-reset: none; }
.wizard-steps li { flex: 1; min-width: 150px; display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); font-weight: 600; font-size: .85rem; color: var(--n500, #64748B); cursor: pointer; }
.wizard-steps li span { width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--n100, #F1F5F9); font-size: .78rem; }
.wizard-steps li.active { border-color: var(--primary); color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.wizard-steps li.active span, .wizard-steps li.done span { background: var(--primary); color: #fff; }
.wizard-steps li.done { color: var(--text, #0F172A); }

/* ---------- hospital identity (About page) ---------- */
.about-hero { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); overflow: hidden; }
.about-photo { min-height: 320px; background: var(--primary-50) center / cover no-repeat; }
.about-intro { padding: 1.5rem 1.75rem; border-top: 4px solid var(--brand-red); }
.about-logo { width: 100%; max-width: 360px; height: auto; margin-bottom: 1.1rem; }
.about-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--brand-red); }
.about-purpose { font-family: var(--font-display); font-size: 1.1rem; font-weight: 600; color: var(--primary-700); margin: .25rem 0 1.1rem; }
.value-list { display: flex; flex-wrap: wrap; gap: .5rem; }
.value-chip { display: inline-flex; align-items: center; gap: .35rem; padding: .4rem .8rem; border-radius: 999px; background: var(--primary-50); color: var(--primary-700); font-weight: 600; font-size: .88rem; }
@media (max-width: 900px) { .about-hero { grid-template-columns: 1fr; } .about-photo { min-height: 200px; } }

/* sidebar brand on dark blue */
.sidebar .brand { border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: .5rem; }
.sidebar .brand-mark img { background: #fff; border-radius: 10px; padding: 3px; width: 42px; }
.sidebar .brand-name { color: #fff; font-size: .9rem; }
.sidebar { border-top: 4px solid var(--brand-red); }
.sidebar-session { display: flex; align-items: center; gap: .65rem; margin: .75rem .25rem .45rem; padding: .72rem .65rem; border-top: 1px solid rgba(255,255,255,.1); color: #fff; min-width: 0; }
.sidebar-session > span:last-child { min-width: 0; line-height: 1.18; }
.sidebar-session strong, .sidebar-session small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sidebar-session strong { font-size: .8rem; font-weight: 700; }
.sidebar-session small { margin-top: .16rem; color: #BBD2E8; font-size: .69rem; }
.sidebar-session .avatar { background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.2); }
.sidebar-logout { margin: 0; }
.sidebar-logout .nav-item { width: 100%; border: 1px solid rgba(255,255,255,.13); background: rgba(255,255,255,.055); font: inherit; text-align: left; }
.sidebar-logout .nav-item:hover { color: #fff; border-color: rgba(255,177,177,.35); background: rgba(217,75,75,.2); }
.badge-brand { background: var(--brand-red-50); color: var(--brand-red); }
.error-card { width: 100%; max-width: 480px; background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 2rem; text-align: center; border-top: 4px solid var(--brand-red); }
.error-card img { width: 220px; max-width: 100%; height: auto; margin-bottom: 1.2rem; }
.error-card .code { font-family: var(--font-display); font-size: 2.6rem; font-weight: 800; color: var(--primary-700); line-height: 1; }

/* sign-in page (mockup: centred stacked logo, headline + feature tiles over the building) */
.auth-form { position: relative; text-align: left; }
.auth-back { position: absolute; top: 1.1rem; left: 1.4rem; display: inline-flex; align-items: center; gap: .3rem; font-size: .82rem; font-weight: 600; color: var(--muted); }
.auth-logo { max-width: 230px; margin: .8rem auto .4rem; }
.auth-system { text-align: center; }
.auth-art { justify-content: flex-start; padding-top: 3rem; }
.auth-art::before { background: linear-gradient(180deg, rgba(15, 79, 138, .92) 0%, rgba(22, 119, 200, .62) 45%, rgba(11, 58, 102, .55) 75%, rgba(11, 58, 102, .9) 100%); }
.auth-headline { font-size: 2.1rem !important; line-height: 1.15; max-width: 22rem; }
.auth-tiles { margin-top: auto; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .6rem; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.22); backdrop-filter: blur(6px); border-radius: 16px; padding: .9rem .6rem; }
.auth-tiles div { display: flex; flex-direction: column; align-items: center; gap: .4rem; text-align: center; font-size: .78rem; font-weight: 600; }
.auth-tiles .icon { width: 26px; height: 26px; }
.auth-art:has(.art-figure) { justify-content: flex-end; padding-top: 2.5rem; }

/* ---------- large & ultra-wide screens (staff app) ---------- */
.content { margin-inline: auto; }
@media (min-width: 1680px) {
    .content { max-width: 1640px; padding: 1.75rem 2.25rem; }
    .topbar { padding-left: 2.25rem; padding-right: 2.25rem; }
    .topbar .search { max-width: 620px; }
    .sidebar { width: 264px; }
}
@media (min-width: 1920px) {
    body { font-size: 15px; }
    .content { max-width: 1840px; padding: 2rem 2.75rem; }
    .grid { gap: 1.35rem; }
    .form-grid { gap: 1rem 1.4rem; }
    .card-body { padding: 1.35rem; }
    .stat .value { font-size: 1.8rem; }
    .bed-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
}
@media (min-width: 2400px) {
    body { font-size: 16px; }
    .content { max-width: none; padding-left: 3rem; padding-right: 3rem; }
    .sidebar { width: 288px; }
    .cal-day { min-height: 140px; }
}

/* sign-in entrance */
@keyframes auth-rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes auth-zoom { from { background-size: 112%; } to { background-size: 100%; } }
.auth-shell { animation: auth-rise .8s cubic-bezier(.16, 1, .3, 1) both; }
.auth-form > * { animation: auth-rise .7s cubic-bezier(.16, 1, .3, 1) both; }
.auth-form > :nth-child(2) { animation-delay: .08s; } .auth-form > :nth-child(3) { animation-delay: .14s; } .auth-form > :nth-child(n+4) { animation-delay: .2s; }
.auth-art { transition: background-position 1.2s; }
.auth-headline, .auth-art > p { animation: auth-rise .9s .25s cubic-bezier(.16, 1, .3, 1) both; }
.auth-tiles { animation: auth-rise .9s .4s cubic-bezier(.16, 1, .3, 1) both; }
.auth-tiles div { transition: transform .3s; } .auth-tiles div:hover { transform: translateY(-3px); }
.auth-form .btn-primary { transition: transform .2s, box-shadow .2s, background-color .2s; }
.auth-form .btn-primary:hover { transform: translateY(-1px); }
@media (min-width: 1920px) { .auth-shell { max-width: 1320px; min-height: 720px; } }
@media (prefers-reduced-motion: reduce) { .auth-shell, .auth-form > *, .auth-headline, .auth-art > p, .auth-tiles { animation: none !important; } }


/* ---------- phones & tablets: nothing may push the page wider than the screen ---------- */
.grid > *, .form-grid > *, .row > *, .stack > * { min-width: 0; }
.card { min-width: 0; }
img, svg, video, canvas { max-width: 100%; }
@media (max-width: 960px) {
    /* wide tables scroll sideways inside their card instead of stretching the page */
    .card-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .card-body:has(.mar-grid), .card-body:has(details[open] > form) { overflow: visible; }
    .content > .table, .stack > .table, .content > table { display: block; overflow-x: auto; }
    .table th, .table td { padding: .6rem .7rem; }
    .table.board td { padding: .6rem .7rem; font-size: 1rem; }
    /* fixed-width inline inputs and selects shrink to the screen */
    input, select, textarea { max-width: 100%; }
    [style*="width:"] { max-width: 100%; }
    .filters .field { min-width: 0; flex: 1 1 140px; }
    /* headers and action bars wrap cleanly */
    .page-header { flex-direction: column; align-items: stretch; }
    .page-header .actions { width: 100%; }
    .page-header .actions > form.row { width: 100%; }
    .card-header { align-items: flex-start; }
    .tabs { width: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
    .tabs::-webkit-scrollbar { display: none; }
    .tabs a { white-space: nowrap; flex-shrink: 0; }
    .patient-banner { padding: .9rem 1rem; gap: .6rem 1rem; }
    .patient-banner .name { font-size: 1.1rem; }
    .greeting { flex-direction: column; align-items: flex-start; }
    .greeting .when { text-align: left; }
    .dl { grid-template-columns: minmax(0, 1fr); gap: .15rem; }
    .dl dt { margin-top: .5rem; }
    .dl dd { word-break: break-word; }
    .inline-actions input[type=text] { width: 100%; }
    .wizard-steps li { min-width: 0; flex: 1 1 45%; }
    .bed-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
    .user-menu .menu { right: -.5rem; max-width: calc(100vw - 1.5rem); }
}
@media (max-width: 600px) {
    h1 { font-size: 1.35rem; }
    .content { padding: .85rem; }
    .card-header, .card-body { padding-left: .9rem; padding-right: .9rem; }
    .card-body.flush { padding: 0; }
    .stat { padding: .85rem .9rem; }
    .stat .value { font-size: 1.35rem; }
    .stat .stat-icon { width: 40px; height: 40px; }
    .page-header { padding: .85rem .9rem; border-radius: 14px; margin-bottom: 1rem; }
    .page-header-copy { gap: .65rem; }
    .page-header-mark { width: 4px; min-height: 2.35rem; }
    .page-header h1 { font-size: 1.35rem; }
    .page-header .subtitle { font-size: .82rem; }
    .page-header .actions > .btn, .page-header .actions > a.btn { flex: 1 1 auto; }
    .actions { gap: .4rem; }
    .btn { min-height: 42px; }
    .btn-sm { min-height: 34px; }
    .pagination { justify-content: center; }
    .pagination .muted { width: 100%; text-align: center; margin: 0 0 .3rem; }
    .topbar { gap: .5rem; }
    .alert { padding: .7rem .8rem; }
}
/* touch devices: comfortable tap targets, no hover-only affordances */
@media (hover: none) and (pointer: coarse) {
    .nav-item, .nav-sub a { min-height: 44px; display: flex; align-items: center; }
    .icon-btn { width: 44px; height: 44px; }
}

/* inline "add" forms inside section headings take the full width when opened */
.summary-section h3 { flex-wrap: wrap; gap: .4rem; }
.summary-section h3 details[open] { flex-basis: 100%; }
.summary-section h3 details[open] > form { font-size: .9rem; }

/* pop-over forms (e.g. "Record status") sit inline on phones instead of floating off-screen */
@media (max-width: 600px) {
    .inline-form-toggle { width: 100%; }
    .inline-form-toggle > .card[style*="position:absolute"] { position: static !important; width: 100% !important; margin-top: .5rem; }
}

/* stat tiles: two per row on phones (one on very narrow screens) */
@media (max-width: 700px) {
    .grid.grid-4:has(> .stat) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; }
    .grid-4 > .stat { flex-direction: column; align-items: flex-start; gap: .55rem; }
    .grid-4 > .stat .label { font-size: .78rem; }
}
@media (max-width: 340px) { .grid.grid-4:has(> .stat) { grid-template-columns: minmax(0, 1fr); } }

/* ---------- portal on phones: top bar, drawer, stacked tables, folded actions ---------- */
.topbar-brand, .search-toggle, .sidebar-close, .sidebar-backdrop { display: none; }
@media (max-width: 960px) {
    .topbar { position: sticky; top: 0; z-index: 40; flex-wrap: wrap; }
    .topbar-brand { display: inline-flex; align-items: center; gap: .5rem; text-decoration: none !important; color: var(--primary-700); font-family: var(--font-display); font-weight: 800; font-size: 1rem; min-width: 0; }
    .topbar-brand img { width: 30px; height: auto; flex-shrink: 0; }
    .topbar-brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .topbar .user { gap: .3rem; }
    .search-toggle { display: inline-flex; }
    .topbar .search { order: 10; flex-basis: 100%; max-width: none; display: none; }
    .topbar.searching .search { display: block; animation: slide-down .2s ease both; }
    .topbar.searching .search kbd { display: none; }
    .topbar .search input { min-height: 46px; font-size: 16px; }
    @keyframes slide-down { from { opacity: 0; transform: translateY(-6px); } }
    /* drawer */
    .sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: min(300px, 86vw); height: 100%; transform: translateX(-102%); transition: transform .28s cubic-bezier(.16, 1, .3, 1); z-index: 60; box-shadow: none; }
    .sidebar.open { left: 0; transform: none; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
    .sidebar .brand { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
    .sidebar-close { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; border: 0; background: rgba(255,255,255,.1); color: #fff; cursor: pointer; flex-shrink: 0; }
    .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(8, 25, 45, .5); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity .25s; }
    body.nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
    body.nav-open { overflow: hidden; }
}
/* stacked tables (labels added by app.js) */
@media (max-width: 640px) {
    .card-body:has(> .table.stackable), .table-wrap:has(> .table.stackable) { overflow-x: visible; }
    table.table.stackable, .table.stackable thead, .table.stackable tbody, .table.stackable tfoot { display: block; width: 100%; }
    .table.stackable thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .table.stackable tr { display: block; padding: .75rem .9rem; border-bottom: 1px solid var(--border); }
    .table.stackable tbody tr:hover { background: none; }
    .table.stackable td { display: flex; align-items: flex-start; justify-content: space-between; gap: .9rem; padding: .3rem 0; border: 0; text-align: right; white-space: normal; }
    .table.stackable td[data-label]::before { content: attr(data-label); flex-shrink: 0; max-width: 45%; text-align: left; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding-top: .15rem; }
    .table.stackable td > * { max-width: 100%; }
    .table.stackable td[data-label]::before { font-family: var(--font); }
    .table.stackable td > .cv { min-width: 0; text-align: right; overflow-wrap: anywhere; }
    .table.stackable td > .cv > .row, .table.stackable td > .cv > form, .table.stackable td > .cv > .inline-actions { justify-content: flex-end; }
    .table.stackable td:first-child { font-weight: 600; }
    .table.stackable td.full, .table.stackable td:not([data-label]) { display: block; text-align: left; }
    .table.stackable td.empty { display: none; }
    .table.stackable td.num { text-align: right; }
    .table.stackable td .row, .table.stackable td form.row { justify-content: flex-end; }
    .table.stackable tfoot tr { background: var(--surface-2); }
    .table.stackable .person { justify-content: flex-end; text-align: left; }
}
/* folded header actions */
.actions-more { position: relative; }
.actions-more > summary { list-style: none; cursor: pointer; }
.actions-more > summary::-webkit-details-marker { display: none; }
.actions-more-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 220px; max-width: calc(100vw - 2rem); display: grid; gap: .35rem; padding: .5rem; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.actions-more-menu > .btn, .actions-more-menu > a, .actions-more-menu > form, .actions-more-menu > details { width: 100%; justify-content: flex-start; }
.actions-more-menu > form .btn { width: 100%; justify-content: flex-start; }
@media (max-width: 640px) {
    .page-header .actions { flex-wrap: wrap; }
    .page-header .actions > .actions-more { flex: 1 1 auto; }
    .page-header .actions > .actions-more > summary { width: 100%; justify-content: center; }
    .content > .row.between > .actions { width: 100%; }
    .content > .row.between > .actions > .btn { flex: 1 1 auto; }
    .content > .row.between > .actions > .actions-more { flex: 1 1 auto; } .content > .row.between > .actions > .actions-more > summary { width: 100%; justify-content: center; }
}

/* registration wizard: one-row numbered stepper on phones */
@media (max-width: 640px) {
    .wizard-steps { flex-wrap: nowrap; gap: .35rem; }
    .wizard-steps li { flex: 1 1 0; min-width: 0; justify-content: center; padding: .5rem .3rem; font-size: 0; }
    .wizard-steps li span { font-size: .8rem; }
    .wizard-steps li.active { flex: 2.6 1 0; font-size: .8rem; justify-content: flex-start; padding-left: .5rem; }
}

/* ---------- modern icon buttons (top bar) ---------- */
button.icon-btn { border: 0; background: transparent; font: inherit; cursor: pointer; padding: 0; -webkit-tap-highlight-color: transparent; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; color: var(--n700); transition: background-color .2s, color .2s, transform .15s; }
.icon-btn:hover { background: var(--n100); color: var(--primary-700); }
.icon-btn:active { transform: scale(.94); }
.icon-btn:focus-visible { outline: 2px solid rgba(22, 119, 200, .5); outline-offset: 2px; }
.icon-btn .icon { width: 20px; height: 20px; }
.burger { display: inline-flex; flex-direction: column; justify-content: center; gap: 4px; width: 18px; }
.burger i { display: block; height: 2px; border-radius: 2px; background: currentColor; transition: transform .28s cubic-bezier(.16, 1, .3, 1), opacity .2s, width .28s; }
.burger i:nth-child(2) { width: 70%; }
.menu-toggle:hover .burger i:nth-child(2) { width: 100%; }
body.nav-open .burger i:nth-child(1) { transform: translateY(6px) rotate(45deg); }
body.nav-open .burger i:nth-child(2) { opacity: 0; }
body.nav-open .burger i:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
.topbar.searching .search-toggle { background: var(--primary-50); color: var(--primary); }
@media (max-width: 960px) {
    .topbar { padding: .55rem .85rem; gap: .35rem; min-height: 60px; }
    .menu-toggle { background: var(--n100); }
    .search-toggle { background: var(--n100); }
    .topbar .user > .icon-btn { width: 38px; height: 38px; }
    .user-menu > summary { padding: .15rem; }
    .user-menu > summary .icon-sm { display: none; }
    .avatar { width: 36px; height: 36px; }
    /* sidebar close: soft round button with a plain cross */
    .sidebar-close { width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.14); color: #E6EEF7; transition: background-color .2s, transform .2s; }
    .sidebar-close:hover { background: rgba(255,255,255,.2); transform: rotate(90deg); }
    .sidebar-close .icon { width: 18px; height: 18px; }
}

/* file inputs: modern button instead of the browser default */
input[type=file] { padding: .45rem; cursor: pointer; color: var(--n500); font-size: .9rem; }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; font-size: .85rem; margin-right: .75rem; padding: .5rem .9rem; border: 0; border-radius: 8px; background: var(--primary-50); color: var(--primary-700); cursor: pointer; transition: background-color .2s, color .2s; }
input[type=file]:hover::file-selector-button { background: var(--primary); color: #fff; }

/* idle privacy lock */
.idle-lock { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 1rem; background: rgba(8, 25, 45, .55); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.idle-lock[hidden] { display: none; }
.idle-lock-card { width: 100%; max-width: 380px; background: #fff; border-radius: var(--radius-lg); padding: 1.8rem; text-align: center; box-shadow: var(--shadow-lg); border-top: 4px solid var(--brand-red); }
.idle-lock-icon { display: inline-flex; width: 56px; height: 56px; border-radius: 50%; align-items: center; justify-content: center; background: var(--primary-50); color: var(--primary); margin-bottom: .8rem; }
.idle-lock-icon .icon { width: 26px; height: 26px; }
.idle-lock-card p { color: var(--n500); }

/* environment badge: DEV / PILOT (nothing on production) */
.env-badge { display: inline-flex; align-items: center; gap: .3rem; padding: .22rem .6rem; border-radius: 999px; font-size: .7rem; font-weight: 800; letter-spacing: .08em; white-space: nowrap; flex-shrink: 0; }
.env-badge.env-dev { background: #FEF3C7; color: #92400E; border: 1px solid #FCD34D; }
.env-badge.env-pilot { background: var(--brand-red); color: #fff; box-shadow: 0 0 0 3px rgba(217, 75, 75, .18); }
.auth2-top .env-badge { margin-left: auto; margin-right: .5rem; }
