:root {
    --sidebar-width: 210px;
    --sidebar-collapsed-width: 64px;
    --sidebar-bg: #172232;
    --sidebar-secondary: #202d3e;
    --sidebar-active: #2563eb;
    --sidebar-text: #d6deea;
    --sidebar-muted: #8290a3;
    --border-color: #dfe3e8;
    --page-bg: #f5f7fa;
    --text-color: #111827;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--page-bg);
    color: var(--text-color);
    font-size: 13px;
}

.app-wrapper {
    min-height: 100vh;
    display: flex;
}

/* =====================================================
   SIDEBAR
===================================================== */

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    border-right: 1px solid #263548;
    transition: width 0.2s ease;
}

.sidebar-brand {
    height: 76px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 10px;
    overflow: hidden;
    background: #eef4ff;
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
    display: block;
    width: 100%;
    max-width: 185px;
    max-height: 58px;
    object-fit: contain;
}

.brand-icon {
    display: none;
    width: 36px;
    min-width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--sidebar-active);
    color: #ffffff;
    font-size: 17px;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: 10px 9px;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-section {
    margin-bottom: 10px;
}

.sidebar-group-toggle {
    width: 100%;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 11px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #aebbd0;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .45px;
    cursor: pointer;
}

.sidebar-group-toggle:hover {
    background: var(--sidebar-secondary);
    color: #ffffff;
}

.sidebar-group-toggle span {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-group-toggle i:first-child {
    width: 18px;
    text-align: center;
    font-size: 14px;
}

.sidebar-group-arrow {
    font-size: 10px;
    transition: transform .2s ease;
}

.sidebar-group-toggle[aria-expanded="false"] .sidebar-group-arrow {
    transform: rotate(-90deg);
}

.sidebar-group-content {
    max-height: 520px;
    overflow: hidden;
    padding-top: 4px;
    transition: max-height .22s ease, opacity .18s ease, padding .18s ease;
    opacity: 1;
}

.sidebar-group-content.collapsed {
    max-height: 0;
    padding-top: 0;
    opacity: 0;
}

.sidebar-group-content .sidebar-link {
    padding-left: 17px;
}

.sidebar-section-title {
    padding: 7px 10px 5px;
    color: var(--sidebar-muted);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    white-space: nowrap;
}

.sidebar-link {
    height: 38px;
    display: flex;
    align-items: center;
    gap: 11px;
    margin-bottom: 3px;
    padding: 0 11px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 12px;
    border-radius: 6px;
    border-left: 0;
    white-space: nowrap;
    transition:
        background 0.15s ease,
        color 0.15s ease,
        transform 0.15s ease;
}

.sidebar-link:hover {
    background: var(--sidebar-secondary);
    color: #ffffff;
}

.sidebar-link.active {
    background: var(--sidebar-active);
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.2);
}

.sidebar-link.active::after {
    content: "";
    width: 4px;
    height: 4px;
    margin-left: auto;
    border-radius: 50%;
    background: #ffffff;
}

.sidebar-link i {
    width: 18px;
    min-width: 18px;
    text-align: center;
    font-size: 15px;
}

.sidebar-footer {
    padding: 8px 9px 12px;
    border-top: 1px solid #2c394a;
}

.sidebar-logout {
    margin: 0;
    color: #cbd5e1;
}

.sidebar-logout:hover {
    background: #3b2730;
    color: #fecaca;
}

.developer-signature {
    margin-top: 10px;
    padding: 10px 8px 2px;
    border-top: 1px solid #2c394a;
    color: #8290a3;
    font-size: 9px;
    line-height: 1.4;
    text-align: center;
}

.developer-signature span,
.developer-signature strong,
.developer-signature small {
    display: block;
}

.developer-signature strong {
    margin-top: 2px;
    color: #d6deea;
    font-size: 10px;
    font-weight: 600;
}

.developer-signature small {
    color: #8290a3;
    font-size: 9px;
}

/* =====================================================
   SIDEBAR CONTRAÍDO
===================================================== */

body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .main-area {
    margin-left: var(--sidebar-collapsed-width);
    width: calc(100% - var(--sidebar-collapsed-width));
}

body.sidebar-collapsed .sidebar-brand {
    justify-content: center;
    padding: 0;
}

body.sidebar-collapsed .sidebar-logo {
    display: none;
}

body.sidebar-collapsed .brand-icon {
    display: flex;
}

body.sidebar-collapsed .sidebar-section-title,
body.sidebar-collapsed .sidebar-link span,
body.sidebar-collapsed .developer-signature {
    display: none;
}

body.sidebar-collapsed .sidebar-menu {
    padding-left: 8px;
    padding-right: 8px;
}

body.sidebar-collapsed .sidebar-link {
    justify-content: center;
    padding: 0;
}

body.sidebar-collapsed .sidebar-link.active::after {
    display: none;
}

/* =====================================================
   ÁREA PRINCIPAL
===================================================== */

.main-area {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
    transition:
        margin-left 0.2s ease,
        width 0.2s ease;
}

.topbar {
    height: 64px;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.menu-button {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    font-size: 21px;
    color: #475569;
    padding: 0;
}

.menu-button:hover {
    background: #f1f5f9;
    border-color: #e2e8f0;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #111827;
}

.user-avatar {
    width: 31px;
    height: 31px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #e8efff;
    color: #1d4ed8;
    font-size: 10px;
    font-weight: 700;
}

.user-information {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.user-name {
    font-size: 12px;
    font-weight: 600;
}

.user-role {
    margin-top: 2px;
    color: #64748b;
    font-size: 9px;
}

.content-area {
    padding: 16px;
}

.content-area h1,
.content-area h2,
.content-area h3 {
    margin-top: 0;
}

.content-area h2 {
    font-size: 24px;
    margin-bottom: 12px !important;
}

/* =====================================================
   TARJETAS Y FORMULARIOS
===================================================== */

.card {
    border: 1px solid var(--border-color);
    border-radius: 5px;
    box-shadow: none;
    background: #ffffff;
}

.card-header {
    background: #f8fafc;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    padding: 10px 12px;
    font-size: 13px;
}

.card-body {
    padding: 12px;
}

.row.g-3 {
    --bs-gutter-x: 12px;
    --bs-gutter-y: 10px;
}

.form-label {
    font-size: 12px;
    margin-bottom: 4px;
    color: #374151;
}

.form-control,
.form-select {
    min-height: 34px;
    height: 34px;
    border-radius: 4px;
    border: 1px solid #d1d5db;
    font-size: 12px;
    padding: 5px 9px;
}

.form-control:focus,
.form-select:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.08);
}

.form-control[readonly] {
    background: #f8fafc;
    color: #334155;
}

textarea.form-control {
    min-height: 65px;
    height: 65px;
    resize: vertical;
}

/* =====================================================
   BOTONES
===================================================== */

.btn {
    border-radius: 4px;
    font-size: 12px;
    padding: 7px 12px;
}

.btn-primary {
    background: #2563eb;
    border-color: #2563eb;
}

.btn-success {
    background: #16a34a;
    border-color: #16a34a;
}

/* =====================================================
   TABLAS
===================================================== */

.table {
    margin-bottom: 0;
    font-size: 11px;
}

.table th {
    background: #f8fafc;
    font-weight: 600;
    color: #374151;
}

.table td,
.table th {
    padding: 6px 7px;
    vertical-align: middle;
    border-color: var(--border-color);
}

.badge-status {
    display: inline-block;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 500;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

/* =====================================================
   TOTALES
===================================================== */

.invoice-total-box {
    border: 1px solid var(--border-color);
    background: #ffffff;
    padding: 10px;
}

.invoice-total-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 12px;
}

.invoice-total-row.total {
    border-top: 1px solid var(--border-color);
    padding-top: 8px;
    margin-top: 8px;
    font-size: 15px;
    font-weight: 700;
}

.mt-3 {
    margin-top: 10px !important;
}

.mt-4 {
    margin-top: 12px !important;
}

/* =====================================================
   LOGIN
===================================================== */

.login-page {
    min-height: 100vh;
    background: #eef2f7;
}

.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 370px;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid #dfe3e8;
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.login-brand {
    min-height: 105px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 24px;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
}

.login-logo {
    display: block;
    width: 100%;
    max-width: 280px;
    max-height: 80px;
    object-fit: contain;
}

.login-body {
    padding: 22px;
}

.login-title {
    margin-bottom: 4px;
    font-size: 18px;
    font-weight: 600;
}

.login-subtitle {
    margin-bottom: 18px;
    color: #64748b;
    font-size: 12px;
}

.login-footer {
    padding: 12px 20px;
    border-top: 1px solid #e5e7eb;
    color: #64748b;
    font-size: 9px;
    text-align: center;
}

.login-footer strong {
    margin: 0 3px;
    color: #334155;
}

/* =====================================================
   PANTALLAS MEDIANAS
===================================================== */

@media (max-width: 1200px) {

    :root {
        --sidebar-width: 190px;
    }

    body {
        font-size: 12px;
    }

    .sidebar-logo {
        max-width: 165px;
    }

    .sidebar-link {
        font-size: 11px;
    }

    .content-area {
        padding: 12px;
    }

    .content-area h2 {
        font-size: 21px;
    }

    .form-control,
    .form-select {
        font-size: 11px;
    }

    .table {
        font-size: 10px;
    }

}

/* =====================================================
   PANTALLAS PEQUEÑAS
===================================================== */

@media (max-width: 768px) {

    .sidebar {
        width: 210px;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .main-area,
    body.sidebar-collapsed .main-area {
        margin-left: 0;
        width: 100%;
    }

    .content-area {
        padding: 10px;
    }

    .user-role {
        display: none;
    }

}

body.sidebar-collapsed .sidebar-group-toggle span,
body.sidebar-collapsed .sidebar-group-arrow,
body.sidebar-collapsed .sidebar-group-content span {
    display: none;
}

body.sidebar-collapsed .sidebar-group-toggle,
body.sidebar-collapsed .sidebar-group-content .sidebar-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

body.sidebar-collapsed .sidebar-group-content,
body.sidebar-collapsed .sidebar-group-content.collapsed {
    max-height: 520px;
    opacity: 1;
    padding-top: 4px;
}

/* Historia clínica: área de trabajo amplia y navegación siempre visible */
.historia-clinica-form .card-header {
    position: sticky;
    top: 58px;
    z-index: 1010;
    background: #f8fafc;
}

.historia-clinica-form .tab-content {
    min-height: 480px;
}

.historia-clinica-form textarea.form-control {
    min-height: 92px;
    resize: vertical;
}

.historia-clinica-form #consulta textarea[name="enfermedad_actual"],
.historia-clinica-form #examen textarea[name="examen_fisico"] {
    min-height: 165px;
}

/* =====================================================
   LOGIN INSTITUCIONAL
===================================================== */

.login-institucional { background: #e9eef6; }
.login-layout { min-height: 100vh; display: grid; grid-template-columns: 265px 1fr; }
.login-panel-institucional { background: #14245c; color: #fff; display: flex; flex-direction: column; align-items: center; padding: 62px 28px; text-align: center; }
.login-logo-panel { width: 130px; height: 130px; object-fit: contain; padding: 10px; background: #fff; border-radius: 18px; }
.login-panel-institucional h1 { margin: 22px 0 8px; font-size: 23px; font-weight: 700; }
.login-panel-institucional p { margin: 0; color: #dbe5ff; font-size: 13px; }
.login-main { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px; }
.login-box-institucional { width: 100%; max-width: 400px; padding: 30px; background: #fff; border: 1px solid #d9e0ea; border-radius: 10px; box-shadow: 0 18px 45px rgba(15,35,80,.12); }
.login-logo-central { display: block; width: 125px; height: 92px; object-fit: contain; margin: 0 auto 18px; }
.login-box-institucional h2 { margin: 0; text-align: center; font-size: 25px; font-weight: 700; }
.login-ips-name { margin: 8px 0 24px; text-align: center; color: #475569; }
.login-box-institucional .btn-primary { height: 42px; background: #244a86; border-color: #244a86; }
.login-creditos { margin-top: 18px; color: #526071; font-size: 11px; line-height: 1.4; text-align: center; }

@media (max-width: 768px) {
    .login-layout { display: block; }
    .login-panel-institucional { padding: 24px 20px; }
    .login-logo-panel { width: 82px; height: 82px; }
    .login-panel-institucional h1 { margin-top: 12px; font-size: 20px; }
    .login-main { padding: 24px 16px; }
}
/* Historia clínica V7.5 */
.hc-shell{max-width:1680px;margin:0 auto}.hc-patient-banner{border:0;border-left:4px solid #2463eb}.hc-patient-banner .card-body{display:grid;grid-template-columns:1.45fr .75fr .85fr 1.1fr 1fr;gap:20px;align-items:center}.hc-patient-banner small,.hc-patient-banner strong{display:block}.hc-patient-banner small{color:#718096;font-size:.72rem;text-transform:uppercase;letter-spacing:.04em}.hc-patient-name{display:flex;align-items:center;gap:12px}.hc-avatar{display:grid;place-items:center;width:42px;height:42px;border-radius:12px;background:#e8f0ff;color:#1854c8;font-weight:700}.hc-tabs{padding:10px 14px 0;background:#fff}.hc-tabs .nav{gap:4px;flex-wrap:nowrap;overflow-x:auto}.hc-tabs .nav-link{display:flex;gap:7px;align-items:center;white-space:nowrap;color:#526071;border-radius:8px 8px 0 0;padding:10px 14px}.hc-tabs .nav-link.active{background:#eaf1ff;color:#1459d9;font-weight:600}.hc-content{min-height:430px!important;padding:20px}.hc-section-heading{display:flex;justify-content:space-between;align-items:end;gap:16px;border-bottom:1px solid #e5eaf1;padding-bottom:12px;margin-bottom:16px}.hc-section-heading h5{margin:0}.hc-section-heading p{color:#718096;margin:3px 0 0}.hc-field-card{height:100%;padding:13px;border:1px solid #e3e8ef;border-radius:10px;background:#fbfcfe}.hc-field-card label,.hc-order-card label,.hc-vitals label,.hc-diagnosis-row label{display:block;font-size:.78rem;font-weight:600;color:#40506a;margin-bottom:5px}.hc-field-card textarea{min-height:auto!important;resize:vertical}.hc-vitals{display:grid;grid-template-columns:repeat(5,minmax(150px,1fr));gap:12px;padding:14px;border:1px solid #e3e8ef;border-radius:10px;background:#f8fafc}.hc-vitals .input-group-text{font-size:.7rem;padding-inline:7px}.hc-diagnosis-row{display:grid;grid-template-columns:170px 1fr 1.25fr 2fr;gap:12px;align-items:end;border:1px solid #e3e8ef;border-radius:10px;padding:12px;margin-bottom:10px}.hc-dx-label{align-self:center;font-weight:700;color:#1f3555}.hc-order-card{border:1px solid #dce3ec;border-radius:12px;padding:14px;margin-bottom:12px;background:#fff;box-shadow:0 2px 8px rgba(20,40,80,.04)}.hc-order-head{display:flex;justify-content:space-between;gap:12px;align-items:center;padding-bottom:11px;margin-bottom:11px;border-bottom:1px solid #edf0f4}.hc-order-head>div:first-child{display:flex;align-items:center;gap:9px}.hc-order-head small{color:#718096}.hc-order-number{display:grid;place-items:center;width:28px;height:28px;border-radius:8px;background:#eaf1ff;color:#1459d9;font-weight:700}.hc-order-plan{display:flex;align-items:center;gap:8px;margin-top:12px;padding:10px;border-radius:8px;background:#fff8e5;color:#755500}.hc-order-plan.linked{background:#eaf8ef;color:#176b35}.hc-empty-state{text-align:center;padding:55px;color:#718096;border:1px dashed #cbd5e1;border-radius:12px}.hc-empty-state i{font-size:2rem;color:#90a4c0}.hc-actionbar{position:sticky;bottom:0;z-index:20;display:flex;justify-content:space-between;gap:12px;background:rgba(255,255,255,.96);backdrop-filter:blur(8px);padding:12px 16px}.hc-plan-summary{display:flex;flex-direction:column;gap:4px;padding:14px;border-radius:10px;background:#edf7f1;color:#1e5f39}
@media(max-width:1200px){.hc-patient-banner .card-body{grid-template-columns:repeat(3,1fr)}.hc-vitals{grid-template-columns:repeat(3,1fr)}}@media(max-width:768px){.hc-patient-banner .card-body,.hc-vitals{grid-template-columns:1fr 1fr}.hc-diagnosis-row{grid-template-columns:1fr}.hc-actionbar{position:static;flex-direction:column}.hc-section-heading{align-items:start;flex-direction:column}}

/* Historia clínica V7.6: legibilidad y jerarquía profesional */
.hc-shell>div:first-child h2{font-weight:800;color:#17345f;letter-spacing:-.02em}
.historia-clinica-form{border:0;border-radius:14px;overflow:hidden}
.hc-tabs{border-bottom:1px solid #dfe7f1;background:linear-gradient(180deg,#fff,#f8fbff)}
.hc-tabs .nav-link{font-weight:700}
.hc-tabs .nav-link i{font-size:1rem}
.hc-section-heading{border-bottom:2px solid #e6edf6}
.hc-section-heading h5{font-weight:800;color:#17345f;font-size:1.05rem}
.hc-field-card{padding:16px;border-color:#d9e3ef;border-radius:12px;background:#fff;box-shadow:0 3px 12px rgba(23,52,95,.045)}
.hc-field-card:focus-within{border-color:#7aa7e8;box-shadow:0 0 0 3px rgba(36,99,235,.09)}
.hc-field-card label,.hc-order-card label,.hc-vitals label,.hc-diagnosis-row label,.historia-clinica-form .form-label{font-size:.84rem;font-weight:750;color:#203b63;margin-bottom:7px}
.historia-clinica-form textarea.form-control{min-height:88px!important;max-height:220px;resize:vertical;line-height:1.45;background:#fcfdff}
.historia-clinica-form textarea[name="enfermedad_actual"],.historia-clinica-form textarea[name="examen_fisico"],.historia-clinica-form textarea[name="analisis_medico"]{min-height:112px!important}
.hc-vitals{border-radius:12px;border-color:#d9e3ef;background:linear-gradient(135deg,#f7faff,#f9fcfb)}
.hc-diagnosis-row{grid-template-columns:150px 1fr 1fr;align-items:end;padding:10px 12px;border-left:3px solid #3977d6;background:#fbfdff}
.hc-dx-label{grid-column:auto;align-self:center;padding:0;border:0;font-size:.9rem;font-weight:800}
.hc-dx-system{position:relative}.dx-results{position:absolute;z-index:1050;width:100%;max-height:240px;overflow:auto;box-shadow:0 10px 24px rgba(20,40,80,.18)}
.hc-dx-fields{display:grid;grid-template-columns:110px minmax(180px,1fr);gap:8px}.dx-code{font-weight:700;color:#17345f;background:#eef3f8!important}
.hc-order-card{padding:14px;border-radius:12px}.hc-order-head strong{font-weight:800;color:#203b63}
.hc-empty-state{padding:32px}
.historia-clinica-form #antecedentes textarea.form-control{height:72px;min-height:72px!important;max-height:none;overflow-y:hidden;resize:none}
.hc-patient-banner{border-radius:14px;border-left-width:5px;box-shadow:0 6px 20px rgba(23,52,95,.08)!important}
@media(max-width:1200px){.hc-diagnosis-row{grid-template-columns:1fr 1fr}.hc-dx-label{grid-column:1/-1}}
@media(max-width:992px){.hc-patient-banner .card-body{grid-template-columns:1fr 1fr}.hc-vitals{grid-template-columns:repeat(2,1fr)}.hc-content{padding:16px}}
@media(max-width:576px){.hc-patient-banner .card-body,.hc-vitals,.hc-diagnosis-row,.hc-dx-fields{grid-template-columns:1fr}.hc-content{padding:12px}.hc-field-card{padding:11px}.historia-clinica-form textarea.form-control{min-height:92px!important}.hc-tabs .nav-link{padding:9px}.hc-tabs .nav-link span{font-size:.78rem}.hc-actionbar .d-flex{width:100%}.hc-actionbar .btn{flex:1}.hc-dx-label{grid-column:1}}

/* Historia clínica V7.6.3: antecedentes compactos y jerarquía tipográfica */
.hc-patient-banner strong{font-weight:500}
.hc-tabs .nav-link,.hc-tabs .nav-link span{font-weight:700!important}
.historia-clinica-form .hc-section-heading h5{font-weight:800!important}
.historia-clinica-form label,.historia-clinica-form .form-label,.historia-clinica-form .hc-dx-label{font-weight:700!important}
.historia-clinica-form #antecedentes .row{--bs-gutter-y:.65rem}
.historia-clinica-form #antecedentes .hc-field-card{padding:9px 11px}
.historia-clinica-form #antecedentes textarea.form-control{height:56px;min-height:56px!important;max-height:none;overflow-y:hidden!important;resize:none}
