/* ============================================
   TRANSPORTE ESCOLAR - MAIN CSS
   
   Este archivo importa todos los módulos CSS.
   El orden de importación es importante.
   
   ESTRUCTURA:
   1. Variables (tokens de diseño)
   2. Base (reset, tipografía, utilidades)
   3. Componentes (buttons, forms, cards, alerts)
   4. Layouts (auth, dashboard)
   
   Para modificar estilos:
   - Cambiar tema global → editar variables.css
   - Cambiar un componente → editar su archivo en components/
   - Cambiar un layout → editar su archivo en layouts/
   ============================================ */

/* 1. Variables y Tokens */
@import url('./variables.css');

/* 2. Base y Reset */
@import url('./base.css');

/* 3. Componentes */
@import url('./components/buttons.css');
@import url('./components/forms.css');
@import url('./components/cards.css');
@import url('./components/badges.css');
@import url('./components/tabs.css');
@import url('./components/alerts.css');
@import url('./components/tables.css');
@import url('./components/driver.css');

/* 4. Layouts */
@import url('./layouts/auth.css');
@import url('./layouts/dashboard.css');

/* ============================================
   ESTILOS ADICIONALES GLOBALES
   (mantener mínimo, preferir componentes)
   ============================================ */

/* ============================================
   MODAL — kit-aligned, mobile-first
   - Card surface uses --bg-card so it sits cleanly over the dimmed overlay
   - Form fields use --bg-tertiary (kit forms pattern), radius-md (not pill)
   - On mobile the modal becomes a near-fullscreen sheet with safe-area inset
   ============================================ */

.modal-overlay,
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-3);
    animation: modal-fade-in 0.2s ease;
}

@keyframes modal-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    max-height: calc(100vh - var(--space-6));
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modal-appear 0.3s ease;
}

/* Two modal structures coexist in the project:
   1. <form> WRAPS <modal-body> + <modal-footer> — needs flex column + hidden
      overflow so the body can scroll independently and the footer stays put.
   2. <form class="modal-body"> IS the body — needs to scroll itself; the
      :not(.modal-body) selector excludes this case from the wrapper rule so
      the .modal-body { overflow-y: auto } rule below wins. */
.modal > form:not(.modal-body) {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

/* When the form IS the body, give it the full body treatment explicitly so it
   wins over any conflicting flex/overflow rule. */
.modal > form.modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
    flex-shrink: 0;
}

.modal-header h3,
.modal-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
    flex-shrink: 0;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.modal-body .form-group {
    margin-bottom: 16px;
}

.modal-body .form-group:last-child {
    margin-bottom: 0;
}

.modal-body label,
.modal-body .form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.modal-body input,
.modal-body textarea,
.modal-body select,
.modal-body .form-input {
    width: 100%;
    padding: 10px 14px;
    min-height: 44px;
    font-family: inherit;
    font-size: 15px;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.modal-body input::placeholder,
.modal-body textarea::placeholder {
    color: var(--text-muted);
}

.modal-body input:focus,
.modal-body textarea:focus,
.modal-body select:focus,
.modal-body .form-input:focus {
    outline: none;
    background: var(--bg-card);
    border-color: var(--link-color);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

.modal-body textarea {
    resize: vertical;
    min-height: 80px;
    line-height: 1.5;
}

.modal-body select.form-input,
.modal-body select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2376777d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='M6 9l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.modal-body .help-text,
.modal-body .form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
    line-height: 1.4;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-card);
    flex-shrink: 0;
}

/* Form row for inline fields in modal */
.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
    min-width: 0;
}

/* ---- Tabs inside a modal ----
   Underline-style tabs (Material/Chrome pattern). Theme-aware: active color
   uses --link-color so it flips deep-blue (light) → amber (dark) for readable
   contrast against either background. */
.modal .tabs-container {
    display: flex;
    background: transparent;
    padding: 0 8px;
    margin: 0;
    gap: 4px;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-shrink: 0;
}
.modal .tabs-container::-webkit-scrollbar { display: none; }

.modal .tab-btn,
.modal .tabs-container .btn {
    flex: 1 0 auto;
    min-width: 0;
    padding: 14px 16px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
    position: relative;
    margin-bottom: -1px;
}

.modal .tab-btn:hover:not(.active),
.modal .tabs-container .btn:hover:not(.active) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal .tab-btn.active,
.modal .tabs-container .btn.active {
    color: var(--link-color);
    background: transparent;
    font-weight: 600;
    border-bottom-color: var(--link-color);
}

/* ---- Mobile (≤640px) ---- centered modal, full available width minus a bit
   of breathing room. Footer stacks with the safe-area inset. */
@media (max-width: 640px) {
    .modal-overlay,
    .modal-backdrop {
        padding: 12px;
    }

    .modal {
        max-width: 100%;
        max-height: calc(100vh - 24px);
        border-radius: var(--radius-lg);
    }

    .modal-header {
        padding: 14px 16px;
    }

    .modal-body {
        padding: 16px;
    }

    .modal-footer {
        padding: 12px 16px max(12px, env(safe-area-inset-bottom));
        flex-direction: column;
        gap: 8px;
    }

    .modal-footer .btn {
        width: 100%;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .form-row .form-group {
        margin-bottom: 16px;
    }
}

@keyframes modal-appear {
    from { transform: scale(0.96) translateY(-6px); opacity: 0; }
    to   { transform: scale(1) translateY(0);       opacity: 1; }
}

/* ============================================
   GRADE CHIPS — used in the school modal to pick which Chilean
   standard grades the transport service covers.
   Toggleable. Active = filled deep blue. Idle = outline.
   ============================================ */
.grade-chip {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 9999px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    transition: all var(--transition-fast);
    font-family: inherit;
    line-height: 1;
    white-space: nowrap;
}

.grade-chip:hover {
    border-color: var(--color-primary);
    color: var(--text-primary);
}

.grade-chip.active {
    background: var(--color-primary);
    color: var(--color-on-primary);
    border-color: var(--color-primary);
    font-weight: 600;
}

.grade-chip.active::before {
    content: '✓ ';
    margin-right: 4px;
}

/* Dropdown */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 200px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md); /* SafeRoute 0.5rem */
    box-shadow: var(--shadow-lg); /* High-level elevation */
    z-index: var(--z-dropdown);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
}

.dropdown.open .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(var(--space-2));
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.dropdown-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: var(--space-2) 0;
}

/* Loading spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--color-primary-500);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-sm {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
}

/* Skeleton loading */
.skeleton {
    background: linear-gradient(90deg,
            var(--bg-tertiary) 25%,
            var(--bg-secondary) 50%,
            var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}