/* ============================================
   TeleResQ – Clean Medical Dashboard
   Light / Dark Theme + Mobile Responsive
   ============================================ */

/* ---- Theme Variables ---- */
[data-theme="dark"] {
    --bg: #090c13;
    --bg-card: #0f1219;
    --bg-raised: #151a24;
    --bg-input: #1a1f2b;
    --border: rgba(255,255,255,.06);
    --border-light: rgba(255,255,255,.1);
    --text: #e4e8ee;
    --text-dim: #6b7a90;
    --text-faint: #3e4a5c;
    --shadow-card: 0 1px 3px rgba(0,0,0,.3);
    --nav-bg: rgba(9,12,19,.85);
    --table-hover: rgba(255,255,255,.02);
    --chart-grid: rgba(255,255,255,.06);
    --chart-text: #6b7a90;
}
[data-theme="light"] {
    --bg: #f0f2f5;
    --bg-card: #ffffff;
    --bg-raised: #f7f8fa;
    --bg-input: #f0f2f5;
    --border: rgba(0,0,0,.08);
    --border-light: rgba(0,0,0,.12);
    --text: #1a202c;
    --text-dim: #5a6577;
    --text-faint: #94a3b8;
    --shadow-card: 0 1px 4px rgba(0,0,0,.06), 0 0 0 1px rgba(0,0,0,.04);
    --nav-bg: rgba(255,255,255,.9);
    --table-hover: rgba(0,0,0,.02);
    --chart-grid: rgba(0,0,0,.08);
    --chart-text: #5a6577;
}

:root {
    --c-spo2: #0ea5e9; --c-pulse: #10b981; --c-bp: #ef4444; --c-bp2: #f97316;
    --c-temp: #eab308; --c-resp: #8b5cf6; --c-height: #06b6d4; --c-weight: #f97316;
    --radius: 14px; --radius-sm: 8px;
}
[data-theme="dark"] {
    --c-spo2: #38bdf8; --c-pulse: #34d399; --c-bp: #f87171; --c-bp2: #fb923c;
    --c-temp: #fbbf24; --c-resp: #a78bfa; --c-height: #67e8f9; --c-weight: #fb923c;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg); color: var(--text);
    -webkit-font-smoothing: antialiased;
    transition: background .25s, color .25s;
    overflow-x: hidden;
}

/* ---- Bootstrap reboot compat ----
   Bootstrap (bundled via Vite) sets `body` bg/color from its own `--bs-*`
   custom properties and never switches colour mode (there is no
   `data-bs-theme`), so its reboot — loaded after this file — painted the body
   white and text dark in dark mode. Point Bootstrap's vars at the theme and
   win the `body` rule on specificity so the `[data-theme]` system owns the
   base surface. Higher specificity than Bootstrap's `:root`/`body`, so cascade
   order does not matter. */
html[data-theme] {
    --bs-body-bg: var(--bg);
    --bs-body-color: var(--text);
    --bs-border-color: var(--border);
    --bs-secondary-bg: var(--bg-raised);
    --bs-tertiary-bg: var(--bg-card);
}
html[data-theme] body { background: var(--bg); color: var(--text); }

/* ================= NAVBAR ================= */
.top-nav {
    position: sticky; top: 0; z-index: 100;
    background: var(--nav-bg);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}
.nav-inner {
    max-width: 1600px; margin: 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; height: 56px;
}
.nav-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-icon {
    width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
    background: linear-gradient(135deg, #ef4444, #f97316);
    display: grid; place-items: center; color: #fff; font-size: .85rem;
}
.brand-icon i { animation: pulse-beat 1.2s ease-in-out infinite; }
@keyframes pulse-beat { 0%,100%{transform:scale(1)} 50%{transform:scale(1.15)} }
.brand-name { font-weight: 700; font-size: 1rem; letter-spacing: -.3px; white-space: nowrap; }
.brand-desc { font-size: .65rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1.5px; }

.nav-right { display: flex; align-items: center; gap: 8px; }
.nav-right-mobile { display: none; }

.nav-chip {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 6px;
    background: var(--bg-raised); font-size: .72rem;
    color: var(--text-dim); border: 1px solid var(--border);
    max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nav-chip i { font-size: .6rem; opacity: .6; }
.nav-divider { width: 1px; height: 24px; background: var(--border-light); margin: 0 4px; }

.nav-setting { display: flex; align-items: center; gap: 6px; }
.nav-setting label {
    font-size: .62rem; text-transform: uppercase; letter-spacing: .8px;
    color: var(--text-faint); font-weight: 600;
}
.nav-setting select {
    background: var(--bg-input); border: 1px solid var(--border-light); border-radius: 6px;
    color: var(--text); padding: 3px 8px; font-size: .72rem;
    font-family: 'JetBrains Mono', monospace; outline: none; cursor: pointer;
    -webkit-appearance: none; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7a90'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 6px center;
    padding-right: 20px;
}
.nav-setting select:focus { border-color: var(--c-spo2); }
.skip-badge {
    font-size: .6rem; font-weight: 600; padding: 2px 7px; border-radius: 4px;
    background: rgba(234,179,8,.12); color: var(--c-temp); white-space: nowrap;
}

.status-dot {
    display: flex; align-items: center; gap: 6px;
    font-size: .72rem; font-weight: 500; color: var(--text-dim);
}
.status-dot .dot {
    width: 7px; height: 7px; border-radius: 50%; background: #ef4444; flex-shrink: 0;
}
.status-dot[data-status="connected"] .dot { background: #22c55e; box-shadow: 0 0 6px #22c55e88; }
.status-dot[data-status="connected"] .status-text { color: #16a34a; }
[data-theme="dark"] .status-dot[data-status="connected"] .status-text { color: #86efac; }
.status-dot[data-status="connecting"] .dot { background: #eab308; animation: blink .8s infinite; }
.status-dot[data-status="connecting"] .status-text { color: #ca8a04; }
[data-theme="dark"] .status-dot[data-status="connecting"] .status-text { color: #fde047; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.25} }

.btn-icon {
    width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border-light);
    background: transparent; color: var(--text-dim);
    display: grid; place-items: center; cursor: pointer; font-size: .8rem;
    transition: .15s; -webkit-tap-highlight-color: transparent;
}
.btn-icon:hover { background: var(--bg-raised); color: var(--text); }
/* Active section: the one you're on reads in signal sky, with a solid underline as
   the non-colour cue (so the active state survives colour blindness). */
.btn-icon.is-active {
    color: var(--c-spo2);
    background: color-mix(in oklab, var(--c-spo2) 12%, transparent);
    border-color: color-mix(in oklab, var(--c-spo2) 40%, var(--border-light));
    position: relative;
}
.btn-icon.is-active::after {
    content: ""; position: absolute; left: 7px; right: 7px; bottom: -5px; height: 2px;
    border-radius: 2px; background: var(--c-spo2);
}

/* Mobile Info Bar (hidden on desktop) */
.mobile-info-bar {
    display: none;
    background: var(--bg-card); border-bottom: 1px solid var(--border);
    padding: 8px 16px; gap: 12px; align-items: center; justify-content: space-between;
}
.mib-item {
    display: flex; align-items: center; gap: 6px;
    font-size: .72rem; color: var(--text-dim);
}
.mib-item i { font-size: .6rem; opacity: .5; }
.mib-item label { font-size: .6rem; color: var(--text-faint); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.mib-item select {
    background: var(--bg-input); border: 1px solid var(--border-light); border-radius: 5px;
    color: var(--text); padding: 2px 6px; font-size: .68rem;
    font-family: 'JetBrains Mono', monospace; outline: none;
}

/* ================= CONNECTION PANEL ================= */
.conn-panel {
    max-width: 1600px; margin: 0 auto;
    padding: 16px 24px; border-bottom: 1px solid var(--border);
}
.conn-grid { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.conn-field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 140px; }
.conn-field-sm { max-width: 80px; flex: 0 0 80px; }
.conn-field label {
    font-size: .65rem; text-transform: uppercase; letter-spacing: 1px;
    color: var(--text-faint); font-weight: 600;
}
.conn-field input {
    background: var(--bg-input); border: 1px solid var(--border-light); border-radius: 6px;
    color: var(--text); padding: 7px 10px; font-size: .78rem;
    font-family: 'JetBrains Mono', monospace; outline: none; transition: .15s;
    width: 100%;
}
.conn-field input:focus { border-color: var(--c-spo2); }
.conn-field input[readonly] { opacity: .6; }
.conn-actions { display: flex; gap: 6px; padding-bottom: 1px; }
.btn-conn {
    padding: 7px 16px; border-radius: 6px; border: none;
    font-size: .78rem; font-weight: 600; cursor: pointer; transition: .15s;
    display: flex; align-items: center; gap: 6px; white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.btn-conn-connect { background: #22c55e; color: #fff; }
.btn-conn-connect:hover { background: #16a34a; }
.btn-conn-connect:disabled { opacity: .4; cursor: default; }
.btn-conn-disconnect { background: var(--bg-input); color: var(--c-bp); border: 1px solid rgba(239,68,68,.2); }
.btn-conn-disconnect:hover:not(:disabled) { background: rgba(239,68,68,.08); }
.btn-conn-disconnect:disabled { opacity: .3; cursor: default; }
.conn-log {
    margin-top: 10px; padding: 8px 12px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
    height: 64px; overflow-y: auto;
    font-family: 'JetBrains Mono', monospace; font-size: .68rem; color: var(--text-dim); line-height: 1.6;
}

/* ================= MAIN ================= */
.main-content { max-width: 1600px; margin: 0 auto; padding: 20px 24px 40px; }

/* ================= PRIMARY VITAL CARDS ================= */
.vitals-grid {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 16px; margin-bottom: 16px;
}
.v-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px 20px 10px;
    position: relative; overflow: hidden;
    box-shadow: var(--shadow-card); transition: border-color .3s, box-shadow .3s;
}
.v-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0;
    height: 2px; border-radius: 2px 2px 0 0;
}
.v-spo2::before  { background: var(--c-spo2); }
.v-pulse::before { background: var(--c-pulse); }
.v-bp::before    { background: var(--c-bp); }
.v-temp::before  { background: var(--c-temp); }
.v-card:hover { border-color: var(--border-light); }

.v-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.v-name { font-size: .78rem; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.v-head-icon { font-size: .65rem; margin-right: 4px; }
.v-spo2 .v-name  { color: var(--c-spo2); }
.v-pulse .v-name { color: var(--c-pulse); }
.v-bp .v-name    { color: var(--c-bp); }
.v-temp .v-name  { color: var(--c-temp); }
.v-badge {
    font-size: .6rem; font-weight: 600; padding: 2px 8px; border-radius: 4px;
    background: var(--bg-raised); color: var(--text-faint);
    text-transform: uppercase; letter-spacing: .5px; border: 1px solid var(--border);
}
.v-body { display: flex; align-items: baseline; padding: 6px 0 2px; }
.v-number {
    font-family: 'JetBrains Mono', monospace;
    font-size: 3.2rem; font-weight: 700; line-height: 1; letter-spacing: -2px; transition: .3s;
}
.v-spo2 .v-number  { color: var(--c-spo2); }
.v-pulse .v-number { color: var(--c-pulse); }
.v-bp .v-number    { color: var(--c-bp); }
.v-temp .v-number  { color: var(--c-temp); }
.v-separator { font-size: 2rem; opacity: .3; margin: 0 2px; letter-spacing: 0; }
.v-number-secondary { font-size: 2.4rem; opacity: .7; }
.v-number.value-update { animation: val-pop .4s ease; }
@keyframes val-pop { 0%{transform:scale(1)} 40%{transform:scale(1.06);filter:brightness(1.3)} 100%{transform:scale(1)} }
.v-chart { height: 56px; margin: 4px -4px 0; }
.v-foot {
    display: flex; justify-content: space-between; align-items: center;
    padding-top: 6px; border-top: 1px solid var(--border); margin-top: 4px;
}
.v-desc { font-size: .68rem; color: var(--text-faint); }
.v-status {
    font-size: .6rem; font-weight: 700; text-transform: uppercase; letter-spacing: .8px;
    padding: 2px 8px; border-radius: 4px;
}
.v-status:empty { display: none; }
.status-normal  { background: rgba(16,185,129,.1); color: #10b981; }
.status-warning { background: rgba(234,179,8,.1);  color: #ca8a04; }
.status-critical { background: rgba(239,68,68,.1); color: #ef4444; animation: blink .8s infinite; }
[data-theme="dark"] .status-normal  { background: rgba(52,211,153,.1);  color: #34d399; }
[data-theme="dark"] .status-warning { background: rgba(251,191,36,.1);  color: #fbbf24; }
[data-theme="dark"] .status-critical { background: rgba(248,113,113,.12); color: #f87171; }
.v-card.alert-critical { border-color: rgba(239,68,68,.3); }

/* ================= SECONDARY CARDS ================= */
.secondary-grid {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 16px; margin-bottom: 16px;
}
.s-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px 16px;
    display: flex; align-items: center; gap: 12px;
    position: relative; box-shadow: var(--shadow-card); transition: border-color .3s;
}
.s-card:hover { border-color: var(--border-light); }
.s-icon {
    width: 40px; height: 40px; border-radius: 10px;
    display: grid; place-items: center; font-size: .9rem; flex-shrink: 0;
}
.s-resp .s-icon   { background: rgba(139,92,246,.1); color: var(--c-resp); }
.s-height .s-icon { background: rgba(6,182,212,.1);  color: var(--c-height); }
.s-weight .s-icon { background: rgba(249,115,22,.1); color: var(--c-weight); }
.s-mqtt .s-icon   { background: rgba(14,165,233,.1); color: var(--c-spo2); }
.s-info { flex: 1; min-width: 0; }
.s-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.5rem; font-weight: 700; line-height: 1.1; display: block;
}
.s-value-sm { font-size: .82rem; font-weight: 600; word-break: break-all; }
.s-resp .s-value   { color: var(--c-resp); }
.s-height .s-value { color: var(--c-height); }
.s-weight .s-value { color: var(--c-weight); }
.s-mqtt .s-value   { color: var(--c-spo2); }
.s-label { font-size: .68rem; color: var(--text-faint); display: block; margin-top: 2px; }
.s-label small { opacity: .7; }
.s-chart { width: 80px; height: 36px; flex-shrink: 0; }
.s-card .v-status { position: absolute; top: 10px; right: 12px; }

/* ================= TREND CHARTS ================= */
.trend-section {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
    margin-bottom: 16px; box-shadow: var(--shadow-card);
}
.trend-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0; }
.trend-card {
    padding: 14px 18px 10px;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
}
.trend-card:nth-child(even) { border-right: none; }
.trend-card:nth-last-child(-n+2) { border-bottom: none; }
.trend-grid > .trend-card:last-child:nth-child(odd) { grid-column: 1 / -1; }
.trend-head { margin-bottom: 6px; }
.trend-label { font-size: .72rem; font-weight: 600; letter-spacing: .3px; }
.trend-body { height: 150px; }

/* ================= DEVICE TABS ================= */
.device-tab-bar {
    display: flex; gap: 8px; margin-bottom: 16px;
    overflow-x: auto; padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.device-tab-bar::-webkit-scrollbar { display: none; }

.dtab {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--bg-card);
    color: var(--text-dim); font-size: .72rem; font-weight: 500;
    cursor: pointer; white-space: nowrap;
    transition: .15s; box-shadow: var(--shadow-card);
    -webkit-tap-highlight-color: transparent;
}
.dtab:hover { border-color: var(--border-light); color: var(--text); }
.dtab-active {
    background: var(--c-spo2); color: #fff; border-color: var(--c-spo2);
    font-weight: 600;
}
.dtab-active:hover { color: #fff; }
.dtab i { font-size: .6rem; }
.dtab-count {
    font-size: .6rem; font-weight: 700;
    background: rgba(255,255,255,.2); padding: 1px 6px; border-radius: 4px;
}
.dtab-active .dtab-count { background: rgba(255,255,255,.3); }
.dtab-ago {
    font-size: .58rem; opacity: .6;
    font-family: 'JetBrains Mono', monospace;
}

/* ================= RECONNECT BAR ================= */
.reconnect-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 24px; background: rgba(234,179,8,.1);
    border-bottom: 1px solid rgba(234,179,8,.2);
    position: relative; overflow: hidden;
}
.recon-progress {
    position: absolute; left: 0; top: 0; bottom: 0;
    background: rgba(234,179,8,.1); width: 0%;
    transition: width 1s linear;
}
.recon-text {
    font-size: .72rem; font-weight: 600; color: var(--c-temp);
    position: relative; z-index: 1;
}

/* ================= ALERT BUTTON ================= */
.btn-icon.alert-off { color: var(--text-faint); opacity: .5; }

/* ================= MAP ================= */
.map-section {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
    margin-bottom: 16px; box-shadow: var(--shadow-card);
}
#map { height: 320px; }
[data-theme="dark"] .leaflet-container { background: var(--bg-raised) !important; }

/* ================= SECTION HEADER ================= */
.section-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 18px; font-size: .78rem; font-weight: 600;
    color: var(--text-dim); border-bottom: 1px solid var(--border);
    flex-wrap: wrap; gap: 8px;
}
.section-header i { margin-right: 6px; opacity: .6; }
.section-title { display: flex; align-items: center; }
.section-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.msg-count {
    font-family: 'JetBrains Mono', monospace; font-size: .68rem; font-weight: 600;
    padding: 2px 8px; border-radius: 4px;
    background: rgba(14,165,233,.1); color: var(--c-spo2);
}
.btn-clear {
    background: none; border: 1px solid var(--border-light); border-radius: 6px;
    color: var(--text-faint); font-size: .68rem; padding: 3px 10px;
    cursor: pointer; transition: .15s; -webkit-tap-highlight-color: transparent;
}
.btn-clear:hover { color: var(--c-bp); border-color: rgba(239,68,68,.3); }

/* ----- Export Dropdown ----- */
.export-group { position: relative; }
.btn-export {
    display: inline-flex; align-items: center; gap: 6px;
    background: #0369a1;
    color: #fff; border: none; border-radius: 6px;
    font-size: .68rem; font-weight: 600;
    padding: 4px 10px; cursor: pointer;
    transition: transform .1s, background .15s;
    -webkit-tap-highlight-color: transparent;
}
.btn-export:hover { background: #0277b5; }
.btn-export:active { transform: translateY(1px); }
.btn-export .export-caret { font-size: .6rem; transition: transform .2s; }
.export-group.open .btn-export .export-caret { transform: rotate(180deg); }

.export-menu {
    position: fixed; z-index: 9999;
    min-width: 220px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,.12), 0 0 0 1px var(--border);
    padding: 6px;
    display: none;
    animation: export-pop .15s ease-out;
}
.export-group.open .export-menu { display: block; }
@keyframes export-pop {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.export-item {
    width: 100%;
    display: flex; align-items: center; gap: 10px;
    background: transparent; border: none;
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    text-align: left;
    transition: background .12s;
    color: var(--text);
}
.export-item:hover { background: var(--bg-raised); }
.export-item i { font-size: 1.05rem; width: 22px; text-align: center; }
.export-item-title { font-size: .82rem; font-weight: 600; color: var(--text); }
.export-item-sub { font-size: .68rem; color: var(--text-dim); }
.export-item:disabled, .export-item.disabled { opacity: .45; cursor: not-allowed; }

/* ================= DATA TABLE ================= */
.table-section {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
    margin-bottom: 16px; box-shadow: var(--shadow-card);
}
.table-wrap { max-height: 380px; overflow: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: .76rem; }
.data-table thead { position: sticky; top: 0; z-index: 2; }
.data-table th {
    background: var(--bg-raised); padding: 9px 12px;
    font-size: .62rem; font-weight: 600; text-transform: uppercase; letter-spacing: .8px;
    color: var(--text-faint); border-bottom: 1px solid var(--border);
    white-space: nowrap; text-align: left;
}
.data-table td {
    padding: 8px 12px; border-bottom: 1px solid var(--border);
    font-family: 'JetBrains Mono', monospace; font-size: .72rem;
    color: var(--text-dim); white-space: nowrap;
}
.data-table tbody tr { transition: background .15s; }
.data-table tbody tr:hover { background: var(--table-hover); }
.empty-state {
    text-align: center !important; padding: 40px 12px !important; color: var(--text-faint) !important;
}
.empty-state i { font-size: 1.5rem; display: block; margin-bottom: 8px; opacity: .4; }
.empty-state span { font-family: 'Inter', sans-serif; }

.td-spo2   { color: var(--c-spo2) !important; font-weight: 600; }
.td-pulse  { color: var(--c-pulse) !important; font-weight: 600; }
.td-bp     { color: var(--c-bp) !important; font-weight: 600; }
.td-bp2    { color: var(--c-bp2) !important; font-weight: 600; }
.td-temp   { color: var(--c-temp) !important; font-weight: 600; }
.td-resp   { color: var(--c-resp) !important; font-weight: 600; }
.td-height { color: var(--c-height) !important; font-weight: 600; }
.td-weight { color: var(--c-weight) !important; font-weight: 600; }
.td-device { background: var(--bg-raised); border-radius: 4px; padding: 2px 6px !important; font-size: .65rem; }
.fade-in-row { animation: rowIn .4s ease; }
@keyframes rowIn { from{opacity:0;transform:translateY(-4px)} to{opacity:1;transform:translateY(0)} }

/* ================= FOOTER ================= */
.dash-footer { text-align: center; padding: 16px 0; font-size: .68rem; color: var(--text-faint); }

/* ================= SCROLLBAR ================= */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ================= RESPONSIVE ================= */

/* Tablet */
@media (max-width: 1100px) {
    .vitals-grid { grid-template-columns: repeat(2, 1fr); }
    .secondary-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Tablet small */
@media (max-width: 900px) {
    .trend-grid { grid-template-columns: 1fr; }
    .trend-card { border-right: none !important; }
    .trend-card:last-child { border-bottom: none; }
    .trend-card:nth-last-child(-n+2) { border-bottom: 1px solid var(--border); }
    .trend-card:last-child { border-bottom: none; }
}

/* Mobile */
@media (max-width: 768px) {
    .nav-inner { padding: 0 12px; height: 50px; }
    .brand-name { font-size: .88rem; }
    .brand-desc { display: none; }

    /* Hide desktop nav, show mobile nav */
    .nav-right-desktop { display: none; }
    .nav-right-mobile { display: flex; }
    .mobile-info-bar { display: flex; }

    .main-content { padding: 12px 12px 80px; }

    .vitals-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .v-card { padding: 14px 14px 8px; border-radius: 12px; }
    .v-number { font-size: 2.2rem; letter-spacing: -1px; }
    .v-number-secondary { font-size: 1.6rem; }
    .v-separator { font-size: 1.5rem; }
    .v-chart { height: 44px; }
    .v-name { font-size: .68rem; }
    .v-badge { font-size: .52rem; padding: 1px 6px; }
    .v-desc { font-size: .6rem; }

    .secondary-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .s-card { padding: 10px 12px; border-radius: 12px; gap: 8px; }
    .s-icon { width: 34px; height: 34px; font-size: .75rem; }
    .s-value { font-size: 1.2rem; }
    .s-chart { width: 60px; height: 28px; }

    .trend-body { height: 120px; }

    #map { height: 250px; }

    .conn-panel { padding: 12px; }
    .conn-grid { flex-direction: column; gap: 8px; }
    .conn-field { min-width: auto; }
    .conn-field-sm { max-width: none; flex: 1; }
    .conn-actions { width: 100%; }
    .btn-conn { flex: 1; justify-content: center; }

    .device-tab-bar { gap: 6px; margin-bottom: 12px; }
    .dtab { padding: 6px 10px; font-size: .66rem; }
    .reconnect-bar { padding: 6px 12px; }

    .section-header { padding: 10px 12px; font-size: .72rem; }
    .data-table th { padding: 7px 8px; font-size: .56rem; }
    .data-table td { padding: 6px 8px; font-size: .64rem; }
}

/* Small phone */
@media (max-width: 480px) {
    .vitals-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .v-number { font-size: 1.8rem; }
    .v-number-secondary { font-size: 1.3rem; }
    .v-chart { height: 36px; }

    .secondary-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .s-chart { display: none; }
    .s-value { font-size: 1rem; }
    .s-icon { width: 30px; height: 30px; font-size: .7rem; border-radius: 8px; }

    .trend-body { height: 100px; }
}

/* Very small phone */
@media (max-width: 360px) {
    .vitals-grid { grid-template-columns: 1fr; gap: 8px; }
    .secondary-grid { grid-template-columns: 1fr; gap: 8px; }
    .v-number { font-size: 2.4rem; }
}

/* ================= USER CHIP (navbar) ================= */
.user-chip {
    display: flex; align-items: center; gap: 10px;
    padding: 4px 10px 4px 4px;
    border-radius: 999px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
}
.user-chip .user-avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: linear-gradient(135deg, #ef4444, #f97316);
    color: #fff; font-weight: 700; font-size: .8rem;
    display: grid; place-items: center;
    flex-shrink: 0;
}
.user-chip .user-meta { line-height: 1.1; }
.user-chip .user-name { font-size: .8rem; font-weight: 600; color: var(--text); }
.user-chip .user-role {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .5px;
    display: inline-flex; align-items: center; gap: 4px;
    color: var(--text-dim); font-weight: 600;
}
.user-chip .role-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--text-faint);
    box-shadow: 0 0 0 2px rgba(0,0,0,0);
}
.user-chip.role-admin .role-dot  { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,.5); }
.user-chip.role-admin .user-role { color: #ef4444; }
.user-chip.role-doctor .role-dot  { background: #0ea5e9; box-shadow: 0 0 6px rgba(14,165,233,.5); }
.user-chip.role-doctor .user-role { color: #0ea5e9; }
.user-chip.role-nurse .role-dot   { background: #10b981; box-shadow: 0 0 6px rgba(16,185,129,.5); }
.user-chip.role-nurse .user-role  { color: #10b981; }

/* Locked/disabled RBAC buttons */
.btn-export.btn-locked,
.btn-export:disabled,
.btn-clear:disabled {
    background: var(--bg-raised) !important;
    color: var(--text-faint) !important;
    border: 1px solid var(--border) !important;
    cursor: not-allowed !important;
    box-shadow: none !important;
    filter: none !important;
    opacity: .8;
}
.btn-conn:disabled { cursor: not-allowed; opacity: .55; }
input[readonly] { cursor: not-allowed; opacity: .85; }

@media (max-width: 900px) {
    .user-chip .user-meta { display: none; }
    .user-chip { padding: 4px; }
}

/* ================= ADMIN PANEL ================= */
.btn-admin { color: #ef4444 !important; }
.btn-admin:hover { background: rgba(239,68,68,.08); }

.admin-body { background: var(--bg); }
.admin-main { max-width: 1200px; padding: 24px; }

.admin-header {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 20px;
    margin-bottom: 20px; flex-wrap: wrap;
}
.admin-title {
    font-size: 1.5rem; font-weight: 800; color: var(--text);
    letter-spacing: -.4px; display: flex; align-items: center; gap: 10px;
    margin-bottom: 4px;
}
.admin-title i { color: #0ea5e9; }
.admin-subtitle { font-size: .85rem; color: var(--text-dim); }

.admin-tabs {
    display: inline-flex; background: var(--bg-card);
    border: 1px solid var(--border); border-radius: 10px;
    padding: 4px; gap: 4px;
}
.admin-tab {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 16px; border-radius: 8px;
    font-size: .82rem; font-weight: 600; color: var(--text-dim);
    text-decoration: none; transition: .15s; cursor: pointer;
}
.admin-tab:hover { color: var(--text); background: var(--bg-raised); }
.admin-tab.active {
    background: #0369a1;
    color: #fff;
}

.admin-tab-content { display: none; }
.admin-tab-content.active { display: block; }

.admin-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-card);
    padding: 24px; margin-bottom: 20px;
}
.admin-card-head { margin-bottom: 20px; }
.admin-card-head h2 {
    font-size: 1.05rem; font-weight: 700; color: var(--text);
    display: flex; align-items: center; gap: 10px; margin-bottom: 4px;
}
.admin-card-head h2 i { color: #0ea5e9; }
.admin-card-head p { font-size: .8rem; color: var(--text-dim); }
.admin-card-head code {
    background: var(--bg-raised); color: var(--text-dim);
    padding: 1px 5px; border-radius: 4px;
    font-family: 'JetBrains Mono', monospace; font-size: .75rem;
}

.count-badge {
    display: inline-block; background: var(--bg-raised); color: var(--text-dim);
    border: 1px solid var(--border);
    font-size: .7rem; font-weight: 700; padding: 2px 8px;
    border-radius: 999px; margin-left: 6px;
}

/* ---- Flash ---- */
.flash {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; border-radius: 10px;
    margin-bottom: 16px; font-size: .85rem; font-weight: 500;
    animation: flash-slide .25s ease-out;
}
@keyframes flash-slide {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}
.flash-success {
    background: rgba(16,185,129,.1); color: #10b981;
    border: 1px solid rgba(16,185,129,.25);
}
.flash-error {
    background: rgba(239,68,68,.1); color: #ef4444;
    border: 1px solid rgba(239,68,68,.25);
}
.flash span { flex: 1; }
.flash-close {
    background: transparent; border: none; color: inherit;
    cursor: pointer; opacity: .55; font-size: .85rem;
}
.flash-close:hover { opacity: 1; }

/* ---- Permission Matrix Table ---- */
.perm-table-wrap {
    overflow-x: auto; margin-bottom: 20px;
    border: 1px solid var(--border); border-radius: 10px;
}
.perm-table {
    width: 100%; border-collapse: collapse;
    font-size: .85rem;
}
.perm-table th, .perm-table td {
    padding: 12px 16px; text-align: left;
    border-bottom: 1px solid var(--border);
}
.perm-table thead th {
    background: var(--bg-raised); font-weight: 700;
    color: var(--text); font-size: .78rem;
    text-transform: uppercase; letter-spacing: .5px;
    position: sticky; top: 0; z-index: 1;
}
.perm-table tbody tr:hover { background: var(--table-hover); }
.perm-table tbody tr:last-child td { border-bottom: none; }

.perm-name-col { width: 40%; }
.role-col { text-align: center !important; min-width: 140px; }
.perm-cell { text-align: center; }

.perm-name .perm-label {
    font-weight: 600; color: var(--text);
    font-size: .88rem; margin-bottom: 3px;
}
.perm-name code {
    background: var(--bg-raised); color: var(--text-dim);
    padding: 1px 6px; border-radius: 4px;
    font-family: 'JetBrains Mono', monospace; font-size: .7rem;
}

.role-pill {
    display: inline-flex; align-items: center; gap: 6px;
    font-weight: 700; font-size: .82rem;
    letter-spacing: -.2px;
}
.role-pill .role-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--text-faint);
}
.role-col.role-admin .role-dot  { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,.5); }
.role-col.role-admin .role-pill { color: #ef4444; }
.role-col.role-doctor .role-dot  { background: #0ea5e9; box-shadow: 0 0 6px rgba(14,165,233,.5); }
.role-col.role-doctor .role-pill { color: #0ea5e9; }
.role-col.role-nurse .role-dot   { background: #10b981; box-shadow: 0 0 6px rgba(16,185,129,.5); }
.role-col.role-nurse .role-pill  { color: #10b981; }

.role-delete {
    background: transparent; border: none;
    color: var(--text-faint); cursor: pointer;
    width: 20px; height: 20px; border-radius: 5px;
    margin-left: 6px; font-size: .65rem;
    transition: .15s;
}
.role-delete:hover { background: rgba(239,68,68,.12); color: #ef4444; }

/* ---- Toggle Switch ---- */
.perm-toggle {
    position: relative; display: inline-block;
    width: 42px; height: 22px; cursor: pointer;
}
.perm-toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; inset: 0;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 999px;
    transition: .2s;
}
.toggle-slider::before {
    content: ""; position: absolute;
    width: 16px; height: 16px; left: 2px; top: 2px;
    background: var(--text-faint);
    border-radius: 50%; transition: .2s;
}
.perm-toggle input:checked + .toggle-slider {
    background: #0ea5e9;
    border-color: transparent;
}
.perm-toggle input:checked + .toggle-slider::before {
    transform: translateX(20px); background: #fff;
}
.perm-toggle.locked {
    opacity: .65; cursor: not-allowed;
}
.perm-toggle.locked::after {
    content: "\f023"; font-family: "Font Awesome 6 Free"; font-weight: 900;
    position: absolute; top: -4px; right: -14px;
    font-size: .6rem; color: var(--text-faint);
}

/* ---- Forms ---- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label {
    font-size: .72rem; font-weight: 700;
    color: var(--text-dim); text-transform: uppercase;
    letter-spacing: .5px;
}
.field label small { text-transform: none; font-weight: 400; opacity: .7; letter-spacing: 0; }
.field input, .field select {
    padding: 10px 12px; background: var(--bg-input);
    border: 1.5px solid var(--border); border-radius: 8px;
    color: var(--text); font-family: inherit; font-size: .88rem;
    transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
    outline: none; border-color: #0ea5e9;
    box-shadow: 0 0 0 3px rgba(14,165,233,.15);
}
.field input:disabled, .field select:disabled {
    opacity: .55; cursor: not-allowed;
}
.field .hint {
    font-size: .7rem; color: var(--text-faint);
    margin-top: 2px; display: flex; align-items: center; gap: 5px;
}

.grid-4 {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
    margin-bottom: 12px;
}
@media (max-width: 900px) { .grid-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .grid-4 { grid-template-columns: 1fr; } }

.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

.btn-primary, .btn-secondary, .btn-danger {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 18px; border: none; border-radius: 8px;
    font-weight: 700; font-size: .82rem; cursor: pointer;
    transition: transform .1s, box-shadow .15s, filter .15s;
}
/* Primary = Signal Sky (interactive accent, per DESIGN.md). Flat, AA on white.
   Red is reserved for destructive/critical, so it no longer carries actions. */
.btn-primary {
    background: #0369a1; color: #fff;
}
.btn-primary:hover { background: #0277b5; }
.btn-secondary {
    background: var(--bg-raised); color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--border-light); }
.btn-danger {
    background: transparent; color: #ef4444;
    border: 1px solid rgba(239,68,68,.3);
}
.btn-danger:hover { background: rgba(239,68,68,.1); border-color: #ef4444; }
.btn-sm { padding: 7px 12px; font-size: .75rem; }

.inline-form {
    display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.inline-form input {
    flex: 1; min-width: 200px;
    padding: 10px 12px; background: var(--bg-input);
    border: 1.5px solid var(--border); border-radius: 8px;
    color: var(--text); font-size: .88rem;
}
.inline-form input:focus {
    outline: none; border-color: #0ea5e9;
    box-shadow: 0 0 0 3px rgba(14,165,233,.15);
}

/* ---- User cards ---- */
.user-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}
.user-card {
    background: var(--bg-raised);
    border: 1px solid var(--border); border-radius: 12px;
    padding: 18px; transition: border-color .15s, transform .15s;
}
.user-card:hover { border-color: var(--border-light); transform: translateY(-2px); }
.user-card-head {
    display: flex; align-items: center; gap: 12px;
    margin-bottom: 16px; padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}
.user-card-avatar {
    width: 44px; height: 44px; border-radius: 12px;
    background: linear-gradient(135deg, #94a3b8, #64748b);
    color: #fff; font-weight: 800; font-size: 1.1rem;
    display: grid; place-items: center; flex-shrink: 0;
}
.user-card-avatar.role-admin  { background: linear-gradient(135deg, #ef4444, #f97316); }
.user-card-avatar.role-doctor { background: linear-gradient(135deg, #0ea5e9, #06b6d4); }
.user-card-avatar.role-nurse  { background: linear-gradient(135deg, #10b981, #34d399); }

.uc-name {
    font-size: .95rem; font-weight: 700; color: var(--text);
    display: flex; align-items: center; gap: 8px;
}
.uc-uname {
    font-size: .74rem; color: var(--text-dim);
    font-family: 'JetBrains Mono', monospace; margin-top: 2px;
}
.self-tag {
    background: rgba(239,68,68,.1); color: #ef4444;
    font-size: .6rem; font-weight: 700;
    padding: 2px 6px; border-radius: 4px;
    text-transform: uppercase; letter-spacing: .5px;
}
.user-card-actions {
    display: flex; gap: 8px; margin-top: 8px;
}
.user-card-actions .btn-primary,
.user-card-actions .btn-danger { flex: 1; justify-content: center; }

/* ================= REDUCED MOTION ================= */
/* Honor the OS "reduce motion" setting: blink, pulse-beat, val-pop, row/flash
   slide-ins and all transitions collapse to a still, still-legible state. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}


