:root {
    --phe-primary: #0d3b66;
    --phe-primary-dark: #082644;
    --phe-accent: #ee6c4d;
    --phe-success: #2a9d8f;
    --phe-warning: #f4a261;
    --phe-danger: #e63946;
    --phe-bg: #f3f5f9;
    --phe-card-radius: .9rem;
    --phe-sidebar-width: 270px;
}

* { box-sizing: border-box; }

html, body {
    overflow-x: hidden;
    max-width: 100%;
}

body {
    background-color: var(--phe-bg);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #1f2933;
}

h1, h2, h3, h4, h5, h6 { font-weight: 650; letter-spacing: -.01em; }

a { text-decoration: none; }

/* ===================== SHELL / LAYOUT ===================== */
.app-shell { min-height: 100vh; }

.sidebar {
    width: var(--phe-sidebar-width);
    min-height: 100vh;
    background: linear-gradient(190deg, var(--phe-primary), var(--phe-primary-dark) 85%);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 1040;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    color: #fff;
    padding: .25rem 0 1rem;
}

.sidebar-brand .brand-icon {
    width: 40px;
    height: 40px;
    border-radius: .65rem;
    background: rgba(255,255,255,.12);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.sidebar-brand .brand-text .name { font-size: 1.05rem; font-weight: 700; line-height: 1.1; }
.sidebar-brand .brand-text .tagline { font-size: .7rem; color: rgba(255,255,255,.6); }

.sidebar-section-label {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: rgba(255,255,255,.45);
    margin: 1.1rem 0 .4rem .6rem;
    font-weight: 600;
}

.sidebar .nav-link {
    color: rgba(255,255,255,.85);
    border-radius: .6rem;
    margin-bottom: .2rem;
    padding: .55rem .75rem;
    font-size: .92rem;
    display: flex;
    align-items: center;
    gap: .65rem;
    transition: background-color .15s ease, color .15s ease;
}

.sidebar .nav-link i { font-size: 1.05rem; width: 1.2rem; text-align: center; }

.sidebar .nav-link:hover { background-color: rgba(255,255,255,.1); color: #fff; }

.sidebar .nav-link.active {
    background-color: var(--phe-accent);
    color: #fff;
    box-shadow: 0 4px 12px rgba(238,108,77,.35);
}

.sidebar-user {
    border-top: 1px solid rgba(255,255,255,.12);
    padding-top: .9rem;
    margin-top: .9rem;
}

.avatar-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,.15);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .85rem;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 1035;
}

.topbar {
    background: #fff;
    border-bottom: 1px solid #e9edf2;
    padding: .75rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.sidebar-toggle-btn {
    display: none;
    border: none;
    background: transparent;
    font-size: 1.4rem;
    color: var(--phe-primary);
}

.content-area {
    min-height: 100vh;
    background-color: var(--phe-bg);
    min-width: 0;
}

.content-inner { padding: 1.75rem; max-width: 1500px; margin: 0 auto; }

.hospital-switcher select { max-width: 100%; }

@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
    }
    .sidebar.show { transform: translateX(0); }
    .sidebar-backdrop.show { display: block; }
    .sidebar-toggle-btn { display: inline-flex; align-items: center; }
    .content-inner { padding: 1.1rem; }
    .hospital-switcher { flex-wrap: wrap; justify-content: flex-end; }
    .hospital-switcher label { display: none; }
    .hospital-switcher select {
        max-width: 58vw;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
    }
}

/* ===================== PAGE HEADER ===================== */
.page-header {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.page-header .breadcrumb {
    margin-bottom: .5rem;
    font-size: .82rem;
}

.page-header-icon {
    width: 48px;
    height: 48px;
    border-radius: .85rem;
    background: linear-gradient(135deg, var(--phe-primary), #1a5f9e);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.page-header h4 { margin-bottom: .15rem; }
.page-header .page-subtitle { color: #6b7785; font-size: .88rem; max-width: 60ch; }

.page-header-actions { display: flex; gap: .5rem; align-items: flex-start; flex-wrap: wrap; }

/* ===================== CARDS / SURFACES ===================== */
.card-kpi {
    border: none;
    border-radius: var(--phe-card-radius);
    box-shadow: 0 2px 14px rgba(20,40,70,.06);
    background: #fff;
    transition: transform .15s ease, box-shadow .15s ease;
}

a .card-kpi:hover, .card-kpi.card-link:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 24px rgba(20,40,70,.12);
}

.card-kpi .kpi-icon {
    width: 42px;
    height: 42px;
    border-radius: .65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin-bottom: .6rem;
}

.card-kpi .kpi-value { font-size: 1.9rem; font-weight: 750; line-height: 1.1; }
.card-kpi .kpi-label { color: #6b7785; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.card-kpi .kpi-caption { color: #8994a3; font-size: .82rem; }

.icon-bg-primary { background: #e7f0fb; color: var(--phe-primary); }
.icon-bg-success { background: #e3f5f2; color: var(--phe-success); }
.icon-bg-warning { background: #fdf1e3; color: #c96f1b; }
.icon-bg-danger  { background: #fbe6e8; color: var(--phe-danger); }
.icon-bg-info    { background: #e6f2fb; color: #1c7ed6; }
.icon-bg-secondary { background: #eef0f3; color: #5a6472; }

.surface-card {
    background: #fff;
    border-radius: var(--phe-card-radius);
    box-shadow: 0 2px 14px rgba(20,40,70,.05);
    padding: 1.4rem;
    margin-bottom: 1.25rem;
}

.surface-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: 1rem;
}

.surface-card-header h6 { margin: 0; font-weight: 700; }
.surface-card-header .surface-desc { color: #8994a3; font-size: .8rem; margin-top: .1rem; }

/* Backwards-compatible alias used by existing views */
.table-responsive-card {
    background: #fff;
    border-radius: var(--phe-card-radius);
    box-shadow: 0 2px 14px rgba(20,40,70,.05);
    padding: 1.4rem;
    margin-bottom: 1.25rem;
}

/* ===================== TABLES ===================== */
.table > :not(caption) > * > * { padding: .7rem .85rem; vertical-align: middle; }
.table thead th {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #8994a3;
    border-bottom-width: 1px;
    font-weight: 700;
    background: #fafbfd;
}
.table tbody tr:hover { background-color: #f8fafc; }
.table-search-wrap { position: relative; max-width: 320px; width: 100%; }
.table-search-wrap i {
    position: absolute;
    left: .75rem;
    top: 50%;
    transform: translateY(-50%);
    color: #a3adba;
}
.table-search-wrap input { padding-left: 2.1rem; }

/* ===================== EMPTY STATES ===================== */
.empty-state {
    text-align: center;
    padding: 2.75rem 1rem;
    color: #8994a3;
}
.empty-state i { font-size: 2.6rem; color: #c9d1db; display: block; margin-bottom: .75rem; }
.empty-state h6 { color: #4a5563; margin-bottom: .25rem; }
.empty-state p { max-width: 42ch; margin: 0 auto; }

/* ===================== BADGES / MISC ===================== */
.badge-alerta { background-color: var(--phe-danger); }
.badge-soft-pill { border-radius: 50rem; font-weight: 600; padding: .38em .75em; font-size: .74rem; }

.btn-icon {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: .55rem;
}

.progress-thin { height: 8px; border-radius: 50rem; background-color: #eef0f3; }

.nav-tabs .nav-link {
    border: none;
    color: #6b7785;
    font-weight: 600;
    padding: .6rem 1.1rem;
    border-radius: .6rem .6rem 0 0;
}
.nav-tabs .nav-link.active {
    color: var(--phe-primary);
    background: #fff;
    border-bottom: 3px solid var(--phe-accent);
}

.modal-content { border: none; border-radius: 1rem; overflow: hidden; }
.modal-header { background: #f8fafc; border-bottom: 1px solid #eef0f3; }
.form-label { font-weight: 600; font-size: .85rem; color: #414c59; }

/* ===================== LOGIN ===================== */
.login-wrapper {
    min-height: 100vh;
    background: radial-gradient(circle at 20% 20%, #145c8e, var(--phe-primary-dark) 65%);
    display: flex;
    align-items: stretch;
}

.login-hero {
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 4rem;
}

.login-hero .feature-item {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
    margin-bottom: 1.1rem;
}

.login-hero .feature-item i {
    background: rgba(255,255,255,.12);
    width: 38px;
    height: 38px;
    border-radius: .6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.login-card {
    border: none;
    border-radius: 1.1rem;
    box-shadow: 0 20px 50px rgba(0,0,0,.25);
}

/* ===================== UTIL ===================== */
.text-muted-soft { color: #8994a3; }
.section-divider { border: none; border-top: 1px solid #eef0f3; margin: 1.5rem 0; }
