:root {
    --blue: #184aa0;
    --blue-900: #0b2d62;
    --green: #10a35a;
    --teal: #00a6a6;
    --red: #d9484f;
    --yellow: #f2b84b;
    --ink: #172033;
    --muted: #65738a;
    --line: #dce4ef;
    --surface: #ffffff;
    --surface-2: #f3f7fb;
    --shadow: 0 12px 32px rgba(19, 48, 89, .10);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Inter, Roboto, "Segoe UI", Arial, sans-serif;
    color: var(--ink);
    background: var(--surface-2);
    letter-spacing: 0;
}

body[data-theme="dark"] {
    --ink: #edf4ff;
    --muted: #aebbd0;
    --line: #314057;
    --surface: #172033;
    --surface-2: #0f1727;
    --shadow: 0 14px 34px rgba(0, 0, 0, .25);
}

a { color: inherit; text-decoration: none; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 254px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 18px 14px;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    transform: translateX(0);
    transition: transform .2s ease;
}

.brand {
    display: grid;
    grid-template-columns: 54px 1fr;
    align-items: center;
    gap: 10px;
    padding: 6px 6px 18px;
    color: var(--blue);
    font-weight: 800;
}

.brand img { width: 54px; height: auto; }

.sidebar-nav { display: grid; gap: 6px; }

.sidebar-nav a {
    display: grid;
    grid-template-columns: 22px 1fr;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 650;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(24, 74, 160, .10);
    color: var(--blue);
}

.content-shell {
    flex: 1;
    margin-left: 254px;
    min-width: 0;
    transition: margin-left .2s ease;
}

body.sidebar-collapsed .sidebar { transform: translateX(-100%); }
body.sidebar-collapsed .content-shell { margin-left: 0; }

.topbar {
    height: 72px;
    background: rgba(255,255,255,.86);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(14px);
}

body[data-theme="dark"] .topbar { background: rgba(23,32,51,.88); }

.topbar-title { display: grid; flex: 1; min-width: 0; }
.topbar-title strong, .topbar-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title span { color: var(--muted); font-size: .85rem; }

.main-content { padding: 24px; }

.icon-button {
    width: 40px;
    height: 40px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--blue);
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 7px 12px;
    color: var(--muted);
    max-width: 180px;
}

.user-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 18px;
    margin-bottom: 18px;
}

.page-head h1 { margin: 0; font-size: clamp(1.4rem, 2vw, 2.2rem); font-weight: 800; color: var(--blue-900); }
body[data-theme="dark"] .page-head h1 { color: #dbe9ff; }
.page-head p { margin: 6px 0 0; color: var(--muted); }

.hero {
    min-height: calc(100vh - 118px);
    display: grid;
    align-content: center;
    gap: 28px;
}

.hero-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    align-items: center;
    gap: 28px;
    background: linear-gradient(135deg, rgba(24,74,160,.10), rgba(16,163,90,.14));
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 34px;
}

.hero h1 { font-size: clamp(2rem, 4vw, 4.1rem); line-height: 1.02; margin: 0 0 18px; color: var(--blue-900); }
.hero p { color: var(--muted); font-size: 1.08rem; max-width: 780px; }
.hero-logo { width: 100%; max-width: 300px; justify-self: center; filter: drop-shadow(0 16px 20px rgba(24,74,160,.18)); }

.info-grid,
.kpi-grid,
.controls-grid {
    display: grid;
    gap: 14px;
}

.info-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.controls-grid { grid-template-columns: repeat(6, minmax(150px, 1fr)); align-items: end; }

.panel,
.metric-card,
.info-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.panel { padding: 18px; margin-bottom: 18px; }
.info-card { padding: 22px; }
.info-card i { color: var(--green); font-size: 1.8rem; margin-bottom: 16px; }
.info-card h3 { font-size: 1.05rem; font-weight: 800; }
.info-card p { color: var(--muted); margin-bottom: 0; }

.metric-card {
    padding: 16px;
    display: grid;
    grid-template-columns: 42px 1fr;
    gap: 12px;
    align-items: center;
    transition: transform .15s ease, box-shadow .15s ease;
}

.metric-card:hover { transform: translateY(-2px); }
.metric-icon { width: 42px; height: 42px; border-radius: 8px; display: grid; place-items: center; color: #fff; }
.metric-icon img { width: 30px; height: 30px; object-fit: contain; filter: drop-shadow(0 1px 1px rgba(0,0,0,.18)); }
.metric-card strong { display: block; font-size: 1.45rem; line-height: 1; }
.metric-card span { color: var(--muted); font-size: .86rem; }

.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.chart-box { min-height: 340px; }
.chart-box canvas { width: 100% !important; height: 280px !important; }

.heatmap-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.heatmap-cell { border-radius: 8px; padding: 14px; color: #fff; min-height: 86px; display: grid; align-content: end; }
.heatmap-cell strong { font-size: 1.15rem; }

.auth-wrap { max-width: 460px; margin: 42px auto; }
.auth-card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 28px; box-shadow: var(--shadow); }
.auth-card img.logo { width: 154px; display: block; margin: 0 auto 18px; }

.status-ok { color: var(--green); font-weight: 800; }
.status-bad { color: var(--red); font-weight: 800; }

.patient-grid { display: grid; grid-template-columns: 320px 1fr; gap: 18px; }
.avatar { width: 78px; height: 78px; border-radius: 50%; background: rgba(24,74,160,.12); display: grid; place-items: center; color: var(--blue); font-size: 2rem; }
.med-list { display: flex; flex-wrap: wrap; gap: 8px; }
.med-list span { border: 1px solid var(--line); border-radius: 999px; padding: 7px 10px; color: var(--blue); background: rgba(24,74,160,.08); }

.btn-primary { background: var(--blue); border-color: var(--blue); }
.btn-success { background: var(--green); border-color: var(--green); }
.text-bg-primary { background-color: var(--blue) !important; }
.text-bg-success { background-color: var(--green) !important; }
.text-bg-danger { background-color: var(--red) !important; }
.text-bg-warning { background-color: var(--yellow) !important; color: #172033 !important; }

@media (max-width: 1100px) {
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .controls-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
    .chart-grid, .patient-grid { grid-template-columns: 1fr; }
    .info-grid { grid-template-columns: 1fr; }
    .hero-panel { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-collapsed .sidebar { transform: translateX(-100%); }
    .content-shell { margin-left: 0; }
    body.sidebar-collapsed .content-shell { margin-left: 0; }
    .topbar { padding: 0 12px; }
    .topbar-title span { display: none; }
    .main-content { padding: 16px; }
    .controls-grid, .kpi-grid { grid-template-columns: 1fr; }
    .page-head { align-items: start; flex-direction: column; }
}
