/* =============================================================================
   ECE - Expediente Clínico Electrónico
   app.css — Mobile First, Branding médico en gama de azules
   ============================================================================= */

/* --- Variables --- */
:root {
    --ece-primary: #1B4F72;
    --ece-primary-light: #2E86C1;
    --ece-primary-lighter: #AED6F1;
    --ece-primary-subtle: #EBF5FB;
    --ece-success: #27AE60;
    --ece-danger: #E74C3C;
    --ece-warning: #F39C12;
    --ece-info: #3498DB;
    --ece-bg: #F0F4F8;
    --ece-card-bg: #FFFFFF;
    --ece-text: #2C3E50;
    --ece-text-muted: #7F8C8D;
    --ece-border: #DEE2E6;
    --ece-sidebar-width: 250px;
    --ece-topbar-height: 56px;
    --ece-bottom-nav-height: 60px;
    --ece-radius: 10px;
    --ece-radius-sm: 6px;
    --ece-shadow: 0 1px 3px rgba(0,0,0,0.08);
    --ece-shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --ece-transition: 0.2s ease;
}

/* --- Reset / Base --- */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px;
    color: var(--ece-text);
    background: var(--ece-bg);
    -webkit-font-smoothing: antialiased;
    margin: 0;
}

/* =============================================
   AUTH LAYOUT
   ============================================= */
.auth-body {
    background: linear-gradient(135deg, var(--ece-primary) 0%, var(--ece-primary-light) 100%);
    min-height: 100vh;
}

.auth-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.auth-card {
    background: var(--ece-card-bg);
    border-radius: var(--ece-radius);
    box-shadow: var(--ece-shadow-md);
    width: 100%;
    max-width: 400px;
    padding: 2rem 1.5rem;
}

.auth-icon-circle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--ece-primary-subtle);
    color: var(--ece-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    margin: 0 auto 0.75rem;
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ece-primary);
    margin: 0;
}

.auth-subtitle {
    font-size: 0.85rem;
    color: var(--ece-text-muted);
    margin: 0;
}

.auth-footer small {
    color: rgba(255,255,255,0.7);
}

/* =============================================
   TOPBAR
   ============================================= */
.app-topbar, .portal-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--ece-topbar-height);
    background: var(--ece-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 1040;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.topbar-left { display: flex; align-items: center; gap: 0.5rem; }

.topbar-toggle {
    color: #fff;
    font-size: 1.4rem;
    padding: 0.25rem;
    text-decoration: none;
}

.topbar-brand {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: 0.5px;
}

.topbar-page-title {
    font-size: 0.95rem;
    font-weight: 500;
}

.topbar-right { display: flex; align-items: center; gap: 0.75rem; }
.topbar-user { font-size: 0.85rem; }
.topbar-logout {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 0.25rem;
}
.topbar-logout:hover { color: #fff; }

/* =============================================
   SIDEBAR (desktop)
   ============================================= */
.app-sidebar {
    background: var(--ece-card-bg);
    border-right: 1px solid var(--ece-border);
}

@media (min-width: 992px) {
    .app-sidebar {
        position: fixed;
        top: var(--ece-topbar-height);
        left: 0;
        bottom: 0;
        width: var(--ece-sidebar-width);
        overflow-y: auto;
        z-index: 1030;
    }
}

.sidebar-nav { padding: 0.5rem 0; }

.sidebar-brand {
    padding: 1rem 1.25rem 0.75rem;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid var(--ece-border);
    margin-bottom: 0.5rem;
}

.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--ece-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.sidebar-brand span {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--ece-primary);
}

.sidebar-section { margin-bottom: 0.25rem; }

.sidebar-section-title {
    padding: 0.75rem 1.25rem 0.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--ece-text-muted);
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    color: var(--ece-text);
    text-decoration: none;
    font-size: 0.9rem;
    border-radius: 0;
    transition: background var(--ece-transition), color var(--ece-transition);
}

.sidebar-item:hover {
    background: var(--ece-primary-subtle);
    color: var(--ece-primary);
}

.sidebar-item.active {
    background: var(--ece-primary-subtle);
    color: var(--ece-primary);
    font-weight: 600;
    border-left: 3px solid var(--ece-primary);
}

.sidebar-item i { font-size: 1.1rem; width: 20px; text-align: center; }

/* =============================================
   MAIN CONTENT
   ============================================= */
.app-main {
    margin-top: var(--ece-topbar-height);
    padding-bottom: calc(var(--ece-bottom-nav-height) + 1rem);
    min-height: calc(100vh - var(--ece-topbar-height));
}

@media (min-width: 992px) {
    .app-main {
        margin-left: var(--ece-sidebar-width);
        padding-bottom: 1rem;
    }
}

.portal-main {
    margin-top: var(--ece-topbar-height);
    padding-bottom: calc(var(--ece-bottom-nav-height) + 1rem);
    min-height: calc(100vh - var(--ece-topbar-height));
    max-width: 640px;
    margin-left: auto;
    margin-right: auto;
}

@media (min-width: 992px) {
    .portal-main { padding-bottom: 1rem; }
}

/* =============================================
   BOTTOM NAVIGATION (móvil)
   ============================================= */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--ece-bottom-nav-height);
    background: var(--ece-card-bg);
    border-top: 1px solid var(--ece-border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 1040;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--ece-text-muted);
    text-decoration: none;
    font-size: 0.65rem;
    padding: 0.35rem 0.5rem;
    border: none;
    background: none;
    cursor: pointer;
    min-width: 48px;
    min-height: 44px;
    transition: color var(--ece-transition);
}

.bottom-nav-item i { font-size: 1.25rem; }

.bottom-nav-item.active {
    color: var(--ece-primary);
    font-weight: 600;
}

.bottom-nav-item:hover,
.bottom-nav-item:active {
    color: var(--ece-primary);
}

/* =============================================
   CARDS
   ============================================= */
.card {
    border: 1px solid var(--ece-border);
    border-radius: var(--ece-radius);
    box-shadow: var(--ece-shadow);
    background: var(--ece-card-bg);
    overflow: hidden;
}

.card-header {
    background: var(--ece-card-bg);
    border-bottom: 1px solid var(--ece-border);
    padding: 0.75rem 1rem;
    font-weight: 600;
}

/* Stat cards */
.stat-card {
    background: var(--ece-card-bg);
    border: 1px solid var(--ece-border);
    border-radius: var(--ece-radius);
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--ece-shadow);
}

.stat-card-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--ece-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.stat-card-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--ece-text);
    line-height: 1.2;
}

.stat-card-label {
    font-size: 0.75rem;
    color: var(--ece-text-muted);
}

/* Quick action cards (portal) */
.quick-action-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1.25rem 0.5rem;
    background: var(--ece-card-bg);
    border: 1px solid var(--ece-border);
    border-radius: var(--ece-radius);
    text-decoration: none;
    color: var(--ece-text);
    font-size: 0.85rem;
    font-weight: 500;
    transition: box-shadow var(--ece-transition), transform var(--ece-transition);
    box-shadow: var(--ece-shadow);
    text-align: center;
}

.quick-action-card i { font-size: 1.6rem; }

.quick-action-card:active {
    transform: scale(0.97);
    box-shadow: var(--ece-shadow-md);
}

/* Appointment cards (móvil) */
.appointment-card {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--ece-border);
}

.appointment-card:last-child { border-bottom: none; }

.appointment-card-time {
    font-size: 0.8rem;
    color: var(--ece-primary);
    font-weight: 600;
    min-width: 70px;
}

.appointment-card-body { flex: 1; }

.appointment-card-patient {
    font-weight: 500;
    font-size: 0.95rem;
}

.appointment-card-status { margin-top: 2px; }

.appointment-card-action {
    width: 100%;
    margin-top: 0.25rem;
}

/* =============================================
   BUTTONS — Touch friendly (min 44px)
   ============================================= */
.btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border-radius: var(--ece-radius-sm);
    font-weight: 500;
    transition: all var(--ece-transition);
}

.btn-sm { min-height: 36px; font-size: 0.85rem; }

.btn-primary {
    background: var(--ece-primary);
    border-color: var(--ece-primary);
}

.btn-primary:hover, .btn-primary:active {
    background: var(--ece-primary-light);
    border-color: var(--ece-primary-light);
}

/* FAB (Floating Action Button) */
.fab {
    position: fixed;
    bottom: calc(var(--ece-bottom-nav-height) + 1rem);
    right: 1rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--ece-primary);
    color: #fff;
    border: none;
    box-shadow: 0 4px 12px rgba(27,79,114,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    z-index: 1035;
    cursor: pointer;
    transition: transform var(--ece-transition);
}

.fab:active { transform: scale(0.9); }

@media (min-width: 992px) {
    .fab { bottom: 2rem; }
}

/* =============================================
   FORMS
   ============================================= */
.form-control, .form-select {
    min-height: 44px;
    border-radius: var(--ece-radius-sm);
    border-color: var(--ece-border);
    font-size: 1rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--ece-primary-light);
    box-shadow: 0 0 0 3px rgba(46,134,193,0.15);
}

.form-label {
    font-weight: 500;
    font-size: 0.9rem;
    margin-bottom: 0.35rem;
    color: var(--ece-text);
}

.input-group-text {
    background: var(--ece-primary-subtle);
    border-color: var(--ece-border);
    color: var(--ece-primary);
}

/* =============================================
   TABLES (desktop only — cards en móvil)
   ============================================= */
.table {
    font-size: 0.9rem;
}

.table thead th {
    background: var(--ece-primary-subtle);
    color: var(--ece-primary);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--ece-primary-lighter);
    padding: 0.6rem 0.75rem;
}

.table tbody td {
    padding: 0.6rem 0.75rem;
    vertical-align: middle;
}

/* =============================================
   BADGES
   ============================================= */
.badge {
    font-weight: 500;
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
    border-radius: var(--ece-radius-sm);
}

/* =============================================
   ALERTS
   ============================================= */
.alert {
    border-radius: var(--ece-radius-sm);
    font-size: 0.9rem;
    border-left: 4px solid;
}

.alert-success { border-left-color: var(--ece-success); }
.alert-danger  { border-left-color: var(--ece-danger); }
.alert-warning { border-left-color: var(--ece-warning); }
.alert-info    { border-left-color: var(--ece-info); }

/* =============================================
   UTILITIES
   ============================================= */
.text-primary { color: var(--ece-primary) !important; }

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

.page-header h4 { margin: 0; font-size: 1.25rem; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--ece-text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 0.75rem;
    display: block;
}

/* =============================================
   RESPONSIVE (Desktop enhancements)
   ============================================= */
@media (min-width: 768px) {
    .stat-card { padding: 1.25rem; }
    .stat-card-value { font-size: 1.6rem; }
}

@media (min-width: 992px) {
    .bottom-nav { display: none !important; }

    .portal-main {
        max-width: 720px;
    }

    .appointment-card-action {
        width: auto;
        margin-top: 0;
    }
}

/* =============================================================================
   ETAPA 4 — REFINAMIENTO PREMIUM
   ============================================================================= */

/* Smooth page transitions */
.tab-pane { animation: fadeIn 0.2s ease-in-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* Better card hover on desktop */
@media (min-width: 992px) {
    .card { transition: box-shadow var(--ece-transition); }
    .card:hover { box-shadow: var(--ece-shadow-md); }
    .stat-card { transition: transform var(--ece-transition), box-shadow var(--ece-transition); }
    .stat-card:hover { transform: translateY(-2px); box-shadow: var(--ece-shadow-md); }
}

/* Portal PayPal button */
.btn-paypal {
    background: #0070ba;
    color: #fff;
    border: none;
    font-weight: 600;
}
.btn-paypal:hover, .btn-paypal:active { background: #005ea6; color: #fff; }

/* Code/monospace for IDs */
.text-monospace { font-family: 'SF Mono', SFMono-Regular, Consolas, monospace; font-size: 0.85em; }

/* Better form sections */
.nav-tabs .nav-link {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--ece-text-muted);
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.6rem 1rem;
    white-space: nowrap;
}
.nav-tabs .nav-link.active {
    color: var(--ece-primary);
    border-bottom-color: var(--ece-primary);
    background: none;
}

/* Diagnosis badges */
.diagnosis-row {
    background: var(--ece-primary-subtle);
    border-radius: var(--ece-radius-sm);
    padding: 0.4rem 0.6rem;
}

/* Timeline items */
.border.rounded { transition: background var(--ece-transition); }
.border.rounded:hover { background: var(--ece-primary-subtle); }

/* Print styles for PDFs */
@media print {
    .app-topbar, .app-sidebar, .bottom-nav, .fab, .btn, nav, .page-header .btn { display: none !important; }
    .app-main { margin: 0 !important; padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
}

/* Loading spinner */
.spinner-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.7); z-index: 9999;
    display: flex; align-items: center; justify-content: center;
}

/* Accessible focus styles */
:focus-visible {
    outline: 2px solid var(--ece-primary-light);
    outline-offset: 2px;
}
.btn:focus-visible { box-shadow: 0 0 0 3px rgba(46,134,193,0.3); }

/* Portal PayPal payment card */
.payment-pending-card {
    border-left: 4px solid var(--ece-warning);
}
.payment-completed-card {
    border-left: 4px solid var(--ece-success);
}
