/* =====================================================================
   BASE · reset, tipografía y componentes UI GLOBALES
   =====================================================================
   Este archivo contiene TODO lo que es transversal al sistema:
   - Reset CSS
   - Tipografía base
   - Botones (.btn)
   - Formularios (.form-field)
   - Modales (.modal)
   - Toasts (.page-toast)
   - Utilidades (.sr-only)

   Lo específico de cada módulo vive en /modules/{nombre}.css
   ===================================================================== */

/* ============ RESET ============ */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-app);
    min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    font-weight: var(--fw-bold);
    margin: 0 0 var(--space-3);
    line-height: 1.2;
}

h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }

p { margin: 0 0 var(--space-4); }

a {
    color: var(--text-link);
    text-decoration: none;
    transition: color var(--transition-fast);
}
a:hover { color: var(--brand-primary-hover); }

button {
    font-family: inherit;
    cursor: pointer;
}

img, svg {
    max-width: 100%;
    height: auto;
    display: block;
}

input, select, textarea, button {
    font-family: inherit;
    font-size: inherit;
}

::selection {
    background: var(--brand-primary);
    color: #fff;
}

/* ============ UTILIDADES ============ */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-left { text-align: left; }

/* =====================================================================
   BOTONES — componente global
   ===================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 10px 16px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: var(--fs-sm);
    font-weight: 500;
    font-family: inherit;
    background: var(--bg-surface);
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    line-height: 1;
}
.btn:hover {
    background: var(--bg-app);
    border-color: var(--border-strong);
}
.btn--primary {
    background: var(--brand-primary);
    color: #fff;
    border-color: var(--brand-primary);
}
.btn--primary:hover {
    background: var(--brand-primary-hover);
    border-color: var(--brand-primary-hover);
    color: #fff;
}
.btn--secondary {
    background: var(--bg-app);
    color: var(--text-primary);
}
.btn--ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
}
.btn--ghost:hover {
    background: var(--bg-app);
    color: var(--text-primary);
}
.btn--success {
    background: var(--color-success);
    color: #fff;
    border-color: var(--color-success);
}
.btn--danger {
    background: var(--color-danger);
    color: #fff;
    border-color: var(--color-danger);
}
.btn--sm { padding: 6px 10px; font-size: var(--fs-xs); }
.btn--lg { padding: 14px 22px; font-size: var(--fs-base); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn__icon { font-size: 1.1em; line-height: 1; }

/* =====================================================================
   FORMULARIOS — componente global
   ===================================================================== */
.form-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.form-field--span-2 { grid-column: span 2; }
.form-field label {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.form-field__required { color: var(--color-danger); margin-left: 2px; }
.form-field__hint {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
}
.form-field input[type="text"],
.form-field input[type="number"],
.form-field input[type="email"],
.form-field input[type="password"],
.form-field input[type="file"],
.form-field input[type="tel"],
.form-field input[type="search"],
.form-field input[type="date"],
.form-field input[type="datetime-local"],
.form-field select,
.form-field textarea {
    padding: 10px 12px;
    border: 1.5px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: var(--fs-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: inherit;
    width: 100%;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px var(--brand-primary-light);
}
.form-field input[readonly] {
    background: var(--bg-app);
    color: var(--text-secondary);
}
.form-field__checkbox {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    color: var(--text-primary);
    cursor: pointer;
    font-size: var(--fs-sm);
}
.form-field__checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}
.form-field__input-group {
    display: flex;
    gap: var(--space-2);
}
.form-field__input-group select { flex: 0 0 auto; max-width: 140px; }
.form-field__addon {
    padding: 10px 14px;
    background: var(--bg-app);
    border: 1.5px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}
.form-field__addon:hover {
    background: var(--brand-primary-light);
    color: var(--brand-primary);
    border-color: var(--brand-primary);
}

/* =====================================================================
   MODALES — componente global
   ===================================================================== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: var(--space-4, 16px);
    animation: modal-in 200ms ease;
}
.modal[hidden] {
    display: none !important;
}
@keyframes modal-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    cursor: pointer;
}
.modal__dialog {
    position: relative;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    max-width: 540px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modal-pop 200ms ease;
}
@keyframes modal-pop {
    from { transform: scale(0.95); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}
.modal__header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal__header h3 {
    margin: 0;
    font-family: var(--font-display);
    font-size: var(--fs-lg);
}
.modal__close {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: var(--fs-2xl);
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.modal__close:hover {
    background: var(--bg-app);
    color: var(--color-danger);
}
.modal__body {
    padding: var(--space-5);
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}
.modal__footer {
    padding: var(--space-4) var(--space-5);
    background: var(--bg-app);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
}

/* =====================================================================
   TOASTS — mensajes flash globales
   ===================================================================== */
.page-toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-5);
    font-size: var(--fs-sm);
    animation: toast-slide 200ms ease;
}
@keyframes toast-slide {
    from { transform: translateY(-8px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}
.page-toast--success {
    background: var(--color-success-bg);
    color: var(--color-success);
    border-left: 3px solid var(--color-success);
}
.page-toast--error {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    border-left: 3px solid var(--color-danger);
}
.page-toast--warning {
    background: var(--color-warning-bg);
    color: var(--color-warning);
    border-left: 3px solid var(--color-warning);
}
.page-toast--info {
    background: var(--color-info-bg);
    color: var(--color-info);
    border-left: 3px solid var(--color-info);
}
.page-toast__icon {
    flex: 0 0 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.7);
    display: grid;
    place-items: center;
    font-weight: 700;
}

/* =====================================================================
   BADGES — componente global
   ===================================================================== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: var(--fs-xs);
    font-weight: 600;
    border-radius: var(--radius-pill, 999px);
    line-height: 1.4;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge--success { background: var(--color-success-bg); color: var(--color-success); }
.badge--danger  { background: var(--color-danger-bg); color: var(--color-danger); }
.badge--warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge--info    { background: var(--color-info-bg); color: var(--color-info); }
.badge--neutral { background: var(--bg-app); color: var(--text-secondary); }

/* =====================================================================
   KBD — etiquetas de teclas
   ===================================================================== */
kbd {
    display: inline-block;
    padding: 1px 6px;
    background: var(--bg-app);
    border: 1px solid var(--border-default);
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* =====================================================================
   CODE — código inline
   ===================================================================== */
code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background: var(--bg-app);
    padding: 1px 5px;
    border-radius: 3px;
    color: var(--text-primary);
}
