/* =============================================================================
   AppRex RRHH — Estilos base
   ============================================================================= */

/* --- Variables institucionales (fuente única de verdad) --- */
:root {
    --rex-purple:       #6B21A8;
    --rex-purple-dark:  #4C1D95;
    --rex-purple-light: #EDE9FE;
    --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;

    /* Semáforo saldos */
    --semaforo-rojo:    #EF4444;
    --semaforo-amarillo: #FACC15;
    --semaforo-verde:   #22C55E;

    /* Estados licencias */
    --estado-solicitada: #F59E0B;
    --estado-aprobada:   #22C55E;
    --estado-rechazada:  #EF4444;
    --estado-cancelada:  #9CA3AF;

    /* Layout */
    --navbar-h:         60px;
    --sidebar-w:        220px;
    --radius:           8px;
    --radius-lg:        12px;
    --shadow-sm:        0 1px 3px rgba(107,33,168,.12);
    --shadow-md:        0 4px 12px rgba(107,33,168,.15);
    --shadow-lg:        0 8px 24px rgba(107,33,168,.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;

    /* Transiciones */
    --transition:       .2s ease;
}

/* --- Reset mínimo --- */
*, *::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-purple); text-decoration: none; }
a:hover { color: var(--rex-purple-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;
}

/* --- Layout principal --- */
#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-yellow);
}

#navbar .navbar-menu {
    display: flex;
    align-items: center;
    gap: .25rem;
    flex: 1;
}

#navbar .nav-link {
    color: rgba(255,255,255,.8);
    padding: .4rem .8rem;
    border-radius: var(--radius);
    font-size: var(--text-sm);
    font-weight: 500;
    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: 1rem;
    margin-left: auto;
}

#navbar .sector-badge {
    background: var(--rex-yellow);
    color: var(--rex-gray-900);
    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);
}

#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);
    transition: background var(--transition);
}

#navbar .btn-logout:hover {
    background: rgba(255,255,255,.25);
}

/* Área de contenido (debajo del navbar) */
#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-purple);
    color: var(--rex-white);
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--rex-purple-dark); }

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

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

.btn-outline {
    background: transparent;
    color: var(--rex-purple);
    border: 1.5px solid var(--rex-purple);
}
.btn-outline:hover { background: var(--rex-purple-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: 1.25rem 1.5rem;
}

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

.card-title {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--rex-purple-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-purple);
    box-shadow: 0 0 0 3px rgba(107,33,168,.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-purple-light);
    color: var(--rex-purple-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 de estado --- */
.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-solicitada { background: #FEF3C7; color: #92400E; }
.badge-aprobada   { background: #DCFCE7; color: #166534; }
.badge-rechazada  { background: #FEE2E2; color: #991B1B; }
.badge-cancelada  { background: #F3F4F6; color: #6B7280; }

/* Semáforo saldos */
.semaforo {
    display: inline-block;
    width: 12px; height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}
.semaforo-0 { background: var(--semaforo-rojo); }
.semaforo-1 { background: var(--semaforo-amarillo); }
.semaforo-2 { background: var(--semaforo-verde); }

/* --- 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-purple-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 notifications --- */
#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-yellow);
}

.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-purple); }

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

/* --- Loading spinner --- */
.spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--rex-purple-light);
    border-top-color: var(--rex-purple);
    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;
}

/* --- Página de 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-purple) 60%, var(--rex-purple-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-yellow-dark);
}

.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.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.page-title {
    font-size: var(--text-2xl);
    font-weight: 800;
    color: var(--rex-purple-dark);
}

.page-subtitle {
    font-size: var(--text-sm);
    color: var(--rex-gray-600);
    margin-top: .1rem;
}

/* --- Grid de tarjetas métricas (dashboard) --- */
.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-purple);
    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-purple-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-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;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    #navbar .navbar-menu { display: none; }

    #page-content { padding: 1rem; }

    .metrics-grid { grid-template-columns: repeat(2, 1fr); }

    .modal { max-width: 100%; margin: 0 .5rem; }
}

@media (max-width: 480px) {
    .metrics-grid { grid-template-columns: 1fr; }
}
