/* =============================================================================
   AppRex PRV — Estilos base
   ============================================================================= */

:root {
    --rex-purple:       #6B21A8;
    --rex-purple-dark:  #4C1D95;
    --rex-purple-light: #EDE9FE;
    --rex-teal:         #0D9488;
    --rex-teal-dark:    #0F766E;
    --rex-teal-light:   #CCFBF1;
    --rex-yellow:       #FACC15;
    --rex-yellow-dark:  #D97706;
    --rex-white:        #FFFFFF;
    --rex-gray-50:      #F8F7FF;
    --rex-gray-100:     #F0EDFB;
    --rex-gray-300:     #C4B8E8;
    --rex-gray-600:     #6B5E8A;
    --rex-gray-900:     #1E1530;

    /* Estados */
    --semaforo-rojo:     #EF4444;
    --semaforo-amarillo: #FACC15;
    --semaforo-verde:    #22C55E;

    /* Estados APs / liquidaciones */
    --estado-borrador:          #F59E0B;
    --estado-solicitadainterno: #3B82F6;
    --estado-aprobada:          #22C55E;
    --estado-pagada:            #6B21A8;
    --estado-rechazada:         #EF4444;
    --estado-estimada:          #9CA3AF;
    --estado-facturada:         #3B82F6;
    --estado-anulada:           #9CA3AF;

    /* Layout */
    --navbar-h:         60px;
    --radius:           8px;
    --radius-lg:        12px;
    --shadow-sm:        0 1px 3px rgba(13,148,136,.12);
    --shadow-md:        0 4px 12px rgba(13,148,136,.15);
    --shadow-lg:        0 8px 24px rgba(13,148,136,.18);

    /* Tipografía */
    --font:             'Segoe UI', system-ui, -apple-system, sans-serif;
    --text-xs:          .75rem;
    --text-sm:          .875rem;
    --text-base:        1rem;
    --text-lg:          1.125rem;
    --text-xl:          1.25rem;
    --text-2xl:         1.5rem;

    --transition:       .2s ease;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font);
    font-size: var(--text-base);
    color: var(--rex-gray-900);
    background: var(--rex-gray-50);
    min-height: 100vh;
    line-height: 1.5;
}

a { color: var(--rex-teal); text-decoration: none; }
a:hover { color: var(--rex-teal-dark); }

img, svg { display: block; max-width: 100%; }
ul, ol { list-style: none; }
button { cursor: pointer; font-family: inherit; font-size: inherit; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: inherit; }

#app { display: flex; flex-direction: column; min-height: 100vh; }

/* Navbar */
#navbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--navbar-h);
    background: var(--rex-purple);
    color: var(--rex-white);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

#navbar .navbar-brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    font-weight: 700;
    font-size: var(--text-lg);
    color: var(--rex-white);
    flex-shrink: 0;
}

#navbar .navbar-brand span.accent { color: var(--rex-teal-light); }

#navbar .navbar-menu {
    display: flex;
    align-items: center;
    gap: .15rem;
    flex: 1;
    min-width: 0;
}

#navbar .nav-link {
    color: rgba(255,255,255,.8);
    padding: .4rem .65rem;
    border-radius: var(--radius);
    font-size: var(--text-sm);
    font-weight: 500;
    white-space: nowrap;
    transition: background var(--transition), color var(--transition);
}

#navbar .nav-link:hover,
#navbar .nav-link.active { background: rgba(255,255,255,.15); color: var(--rex-white); }
#navbar .nav-link.active { background: rgba(255,255,255,.2); }

#navbar .navbar-right {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-left: auto;
    flex-shrink: 0;
}

/* Badge de área (teal en lugar de amarillo) */
#navbar .area-badge {
    background: var(--rex-teal);
    color: var(--rex-white);
    font-size: var(--text-xs);
    font-weight: 700;
    padding: .25rem .65rem;
    border-radius: 999px;
    letter-spacing: .03em;
    white-space: nowrap;
}

#navbar .user-info {
    font-size: var(--text-sm);
    color: rgba(255,255,255,.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
}

#navbar .btn-logout {
    background: rgba(255,255,255,.15);
    color: var(--rex-white);
    border: 1px solid rgba(255,255,255,.3);
    padding: .3rem .75rem;
    border-radius: var(--radius);
    font-size: var(--text-sm);
    flex-shrink: 0;
    white-space: nowrap;
    transition: background var(--transition);
}
#navbar .btn-logout:hover { background: rgba(255,255,255,.25); }

#navbar .btn-cambiar-pwd {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px; height: 28px;
    background: rgba(255,255,255,.12);
    color: rgba(255,255,255,.7);
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 50%;
    transition: background var(--transition), color var(--transition);
    flex-shrink: 0;
}
#navbar .btn-cambiar-pwd:hover { background: rgba(255,255,255,.25); color: var(--rex-white); }

#page-content {
    margin-top: var(--navbar-h);
    flex: 1;
    padding: 1.5rem;
    max-width: 1280px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

/* Botones */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1.1rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: var(--text-sm);
    transition: background var(--transition), box-shadow var(--transition), opacity var(--transition);
    white-space: nowrap;
}

.btn-primary { background: var(--rex-teal); color: var(--rex-white); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--rex-teal-dark); }

.btn-secondary { background: var(--rex-teal-light); color: var(--rex-teal-dark); }
.btn-secondary:hover { background: var(--rex-gray-300); }

.btn-purple { background: var(--rex-purple); color: var(--rex-white); }
.btn-purple:hover { background: var(--rex-purple-dark); }

.btn-danger { background: var(--semaforo-rojo); color: var(--rex-white); }
.btn-danger:hover { opacity: .85; }

.btn-outline { background: transparent; color: var(--rex-teal); border: 1.5px solid var(--rex-teal); }
.btn-outline:hover { background: var(--rex-teal-light); }

.btn-sm { padding: .3rem .75rem; font-size: var(--text-xs); }
.btn-lg { padding: .75rem 1.5rem; font-size: var(--text-base); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Tarjetas */
.card {
    background: var(--rex-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1rem 1.25rem;
}

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

.card-title { font-size: var(--text-lg); font-weight: 700; color: var(--rex-teal-dark); }

/* Formularios */
.form-group { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.form-group label { font-size: var(--text-sm); font-weight: 600; color: var(--rex-gray-600); }

.form-control {
    width: 100%;
    padding: .55rem .85rem;
    border: 1.5px solid var(--rex-gray-300);
    border-radius: var(--radius);
    background: var(--rex-white);
    color: var(--rex-gray-900);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}
.form-control:focus { border-color: var(--rex-teal); box-shadow: 0 0 0 3px rgba(13,148,136,.12); }
.form-control.error { border-color: var(--semaforo-rojo); }
.form-error { font-size: var(--text-xs); color: var(--semaforo-rojo); }

/* Tablas */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th {
    background: var(--rex-teal-light);
    color: var(--rex-teal-dark);
    font-weight: 700;
    padding: .65rem 1rem;
    text-align: left;
    white-space: nowrap;
    border-bottom: 2px solid var(--rex-gray-300);
}
.table td { padding: .6rem 1rem; border-bottom: 1px solid var(--rex-gray-100); vertical-align: middle; }
.table tr:hover td { background: var(--rex-gray-50); }
.table tr:last-child td { border-bottom: none; }

/* Badges */
.badge {
    display: inline-block;
    padding: .2rem .6rem;
    border-radius: 999px;
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: .03em;
    white-space: nowrap;
}

.badge-borrador          { background: #FEF3C7; color: #92400E; }
.badge-solicitadainterno { background: #DBEAFE; color: #1E40AF; }
.badge-aprobada          { background: #DCFCE7; color: #166534; }
.badge-pagada            { background: #EDE9FE; color: #4C1D95; }
.badge-rechazada         { background: #FEE2E2; color: #991B1B; }
.badge-estimada          { background: #F3F4F6; color: #6B7280; }
.badge-facturada         { background: #DBEAFE; color: #1E40AF; }
.badge-anulada           { background: #F3F4F6; color: #6B7280; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(30,21,48,.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 1rem;
}
.modal-overlay.hidden { display: none; }

.modal {
    background: var(--rex-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn .18s ease;
}

@keyframes modalIn {
    from { transform: translateY(-12px); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.1rem 1.5rem;
    border-bottom: 1px solid var(--rex-gray-100);
}
.modal-title { font-size: var(--text-lg); font-weight: 700; color: var(--rex-teal-dark); }
.modal-close { color: var(--rex-gray-600); font-size: 1.4rem; line-height: 1; transition: color var(--transition); }
.modal-close:hover { color: var(--rex-gray-900); }
.modal-body { padding: 1.25rem 1.5rem; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: .75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--rex-gray-100);
}

/* Toast */
#toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    z-index: 300;
    pointer-events: none;
}
.toast {
    background: var(--rex-gray-900);
    color: var(--rex-white);
    padding: .75rem 1.25rem;
    border-radius: var(--radius);
    font-size: var(--text-sm);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    max-width: 360px;
    animation: toastIn .2s ease;
    pointer-events: auto;
    border-left: 4px solid var(--rex-teal);
}
.toast.toast-success { border-left-color: var(--semaforo-verde); }
.toast.toast-error   { border-left-color: var(--semaforo-rojo); }
.toast.toast-info    { border-left-color: var(--rex-teal); }

@keyframes toastIn {
    from { transform: translateX(20px); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

/* Spinner */
.spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--rex-teal-light);
    border-top-color: var(--rex-teal);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { display: flex; align-items: center; justify-content: center; padding: 3rem; }

/* Login */
#page-login {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--rex-purple-dark) 0%, var(--rex-teal-dark) 60%, var(--rex-teal-light) 100%);
    padding: 1rem;
}
.login-card {
    background: var(--rex-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 380px;
}
.login-logo { text-align: center; margin-bottom: 1.75rem; }
.login-logo .brand-name { font-size: var(--text-2xl); font-weight: 800; color: var(--rex-purple); }
.login-logo .brand-name span { color: var(--rex-teal); }
.login-logo .brand-sub { font-size: var(--text-sm); color: var(--rex-gray-600); margin-top: .25rem; }
.login-card h2 { font-size: var(--text-xl); font-weight: 700; color: var(--rex-gray-900); margin-bottom: 1.5rem; text-align: center; }

/* Encabezado de página */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    gap: 1rem;
    flex-wrap: wrap;
}
.page-title { font-size: var(--text-2xl); font-weight: 800; color: var(--rex-teal-dark); }
.page-subtitle { font-size: var(--text-sm); color: var(--rex-gray-600); margin-top: .1rem; }

/* Métricas */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.metric-card {
    background: var(--rex-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem 1.5rem;
    border-left: 4px solid var(--rex-teal);
    display: flex;
    flex-direction: column;
    gap: .35rem;
}
.metric-card .metric-label {
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--rex-gray-600);
    text-transform: uppercase;
    letter-spacing: .05em;
}
.metric-card .metric-value { font-size: var(--text-2xl); font-weight: 800; color: var(--rex-teal-dark); }

/* Utilidades */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-muted  { color: var(--rex-gray-600); font-size: var(--text-sm); }
.text-purple { color: var(--rex-purple); }
.text-teal   { color: var(--rex-teal); }
.text-danger { color: var(--semaforo-rojo); }
.text-success { color: var(--semaforo-verde); }
.fw-bold { font-weight: 700; }
.fw-semibold { font-weight: 600; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: .75rem; }
.mt-4 { margin-top: 1rem; }
.mb-1 { margin-bottom: .25rem; }
.mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: .75rem; }
.mb-4 { margin-bottom: 1rem; }
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-1 { gap: .25rem; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.hidden { display: none !important; }
.divider { border: none; border-top: 1px solid var(--rex-gray-100); margin: 1rem 0; }

/* Hamburguesa */
.navbar-hamburger {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 36px; height: 36px;
    padding: 8px;
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.2);
    border-radius: var(--radius);
    flex-shrink: 0;
    cursor: pointer;
}
.navbar-hamburger span { display: block; height: 2px; background: var(--rex-white); border-radius: 2px; transition: transform .22s ease, opacity .22s ease; transform-origin: center; }
.navbar-hamburger.open span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
.navbar-hamburger.open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.navbar-hamburger.open span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

/* Mobile overlay */
.navbar-mobile-overlay {
    position: fixed; inset: 0; top: var(--navbar-h);
    background: rgba(0,0,0,.45); z-index: 98;
    visibility: hidden; opacity: 0;
    transition: opacity .22s ease, visibility .22s;
}
.navbar-mobile-overlay.visible { visibility: visible; opacity: 1; }

/* Mobile drawer */
.navbar-mobile-drawer {
    position: fixed; top: var(--navbar-h); left: 0; right: 0;
    background: var(--rex-purple-dark); z-index: 99;
    display: flex; flex-direction: column;
    overflow-y: auto; max-height: calc(100vh - var(--navbar-h));
    visibility: hidden; opacity: 0; transform: translateY(-6px);
    transition: opacity .2s ease, transform .2s ease, visibility .2s;
    pointer-events: none;
}
.navbar-mobile-drawer.open { visibility: visible; opacity: 1; transform: translateY(0); pointer-events: auto; }

.mobile-drawer-user {
    display: flex; align-items: flex-start; gap: .75rem;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,.1);
}
.mobile-user-avatar {
    width: 42px; height: 42px; border-radius: 50%;
    background: var(--rex-teal); color: var(--rex-white);
    font-weight: 800; font-size: 1.1rem;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.mobile-user-info { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.mobile-user-name { font-size: var(--text-sm); font-weight: 700; color: var(--rex-white); }
.mobile-area-badges { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .1rem; }
.mobile-area-pill {
    font-size: .72rem; font-weight: 600;
    padding: .2rem .55rem; border-radius: 999px;
    border: 1px solid rgba(255,255,255,.25);
    background: rgba(255,255,255,.1); color: rgba(255,255,255,.8);
    cursor: pointer; transition: background var(--transition); white-space: nowrap;
}
.mobile-area-pill.active { background: var(--rex-teal); color: var(--rex-white); border-color: var(--rex-teal); }
.mobile-area-pill:hover:not(.active) { background: rgba(255,255,255,.2); }

.mobile-drawer-nav { display: flex; flex-direction: column; padding: .4rem 0; }
.mobile-drawer-nav .nav-link {
    padding: .9rem 1.25rem; font-size: var(--text-base); font-weight: 500;
    border-radius: 0; border-bottom: 1px solid rgba(255,255,255,.07);
    color: rgba(255,255,255,.8);
}
.mobile-drawer-nav .nav-link:last-child { border-bottom: none; }
.mobile-drawer-nav .nav-link.active { background: rgba(255,255,255,.15); color: var(--rex-white); font-weight: 600; }
.mobile-drawer-nav .nav-link:hover { background: rgba(255,255,255,.1); color: var(--rex-white); }

.mobile-drawer-footer {
    display: flex; gap: .75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,.1);
}
.mobile-btn-secondary { flex: 1; justify-content: center; color: rgba(255,255,255,.85) !important; border-color: rgba(255,255,255,.3) !important; font-size: var(--text-sm); }
.mobile-btn-secondary:hover { background: rgba(255,255,255,.1) !important; color: var(--rex-white) !important; }
.mobile-btn-logout { flex: 1; justify-content: center; background: rgba(255,255,255,.12); color: var(--rex-white); border: 1px solid rgba(255,255,255,.3); font-size: var(--text-sm); }
.mobile-btn-logout:hover { background: rgba(255,255,255,.22); }

/* Responsive */
@media (max-width: 768px) {
    #navbar { padding: 0 1rem; }
    #navbar .navbar-menu { display: none; }
    #navbar .navbar-hamburger { display: flex; }
    #navbar .area-badge,
    #navbar .area-selector,
    #navbar .user-info,
    #navbar .btn-cambiar-pwd,
    #navbar #navbar-version,
    #navbar .btn-logout { display: none; }

    #page-content { padding: 1rem; }
    .metrics-grid { grid-template-columns: repeat(2, 1fr); }
    .modal-overlay { align-items: flex-end; }
    .modal { max-width: 100%; width: 100%; margin: 0; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
}

@media (max-width: 480px) {
    .metrics-grid { grid-template-columns: 1fr; }
    #page-content { padding: .75rem; }
}
