/* ============================================================
   css/base.css — Reset y estilos base
   ============================================================ */

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    overflow-x: clip;   /* previene scroll horizontal a nivel de página */
}

body {
    background: var(--bg-base);
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: 1.6;
    min-height: 100vh;
    /* Prevenir selección accidental en mobile */
    -webkit-tap-highlight-color: transparent;
}

/* Scrollbar personalizada */
::-webkit-scrollbar        { width: 4px; height: 4px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--border-active); border-radius: var(--radius-full); }

/* Links */
a {
    color: var(--blue);
    text-decoration: none;
    transition: var(--transition-fast);
}
a:hover { color: var(--text); }

/* Imágenes */
img { max-width: 100%; display: block; }

/* ── TIPOGRAFÍA BASE ─────────────────────────────────────── */

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    font-weight: 700;
    line-height: 1.2;
    color: var(--text);
}

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

p { line-height: 1.65; }

.text-xs    { font-size: var(--text-xs); }
.text-sm    { font-size: var(--text-sm); }
.text-base  { font-size: var(--text-base); }
.text-lg    { font-size: var(--text-lg); }
.text-xl    { font-size: var(--text-xl); }

.text-muted  { color: var(--text-muted); }
.text-faint  { color: var(--text-faint); }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-blue   { color: var(--blue); }
.text-purple { color: var(--purple); }
.text-teal   { color: var(--teal); }
.text-orange { color: var(--orange); }

.font-mono    { font-family: var(--font-mono); }
.font-display { font-family: var(--font-display); }

.font-medium  { font-weight: 500; }
.font-semibold{ font-weight: 600; }
.font-bold    { font-weight: 700; }

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

.uppercase   { text-transform: uppercase; letter-spacing: .06em; }

/* ── INPUTS Y FORMULARIOS ────────────────────────────────── */

input, select, textarea {
    background: var(--bg-overlay);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-size: var(--text-base);
    font-family: var(--font-body);
    width: 100%;
    transition: var(--transition-fast);
    outline: none;
    touch-action: manipulation;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--blue);
    background: var(--bg-elevated);
}
input::placeholder, textarea::placeholder {
    color: var(--text-faint);
}

/* ── BOTONES ─────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    border: none;
    transition: var(--transition-fast);
    white-space: nowrap;
    text-decoration: none;
    line-height: 1;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--blue);
    color: var(--text-inverse);
}
.btn-primary:hover { background: #93c5fd; color: var(--text-inverse); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-active); }

.btn-danger {
    background: var(--red-dim);
    color: var(--red);
    border: 1px solid rgba(248,113,113,.2);
}
.btn-danger:hover { background: rgba(248,113,113,.2); }

.btn-success {
    background: var(--green-dim);
    color: var(--green);
    border: 1px solid rgba(74,222,128,.2);
}

.btn-sm   { padding: 5px 10px; font-size: var(--text-xs); }
.btn-lg   { padding: 11px 22px; font-size: var(--text-md); }
.btn-full { width: 100%; }
.btn-icon { padding: 7px; }

/* ── BADGES ──────────────────────────────────────────────── */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 600;
    font-family: var(--font-mono);
    white-space: nowrap;
}

.badge-blue   { background: var(--blue-dim);   color: var(--blue); }
.badge-green  { background: var(--green-dim);  color: var(--green); }
.badge-red    { background: var(--red-dim);    color: var(--red); }
.badge-yellow { background: var(--yellow-dim); color: var(--yellow); }
.badge-purple { background: var(--purple-dim); color: var(--purple); }
.badge-teal   { background: var(--teal-dim);   color: var(--teal); }
.badge-orange { background: var(--orange-dim); color: var(--orange); }

/* ── CARDS ───────────────────────────────────────────────── */

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
}

.card-elevated {
    background: var(--bg-elevated);
    border-color: var(--border-active);
    box-shadow: var(--shadow);
}

.card-title {
    font-family: var(--font-display);
    font-size: var(--text-md);
    font-weight: 700;
    margin-bottom: var(--space-4);
}

/* ── PROGRESS BAR ────────────────────────────────────────── */

.progress-wrap {
    background: var(--bg-overlay);
    border-radius: var(--radius-full);
    height: 6px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width .5s ease;
}
.progress-green  { background: var(--green); }
.progress-blue   { background: var(--blue); }
.progress-yellow { background: var(--yellow); }
.progress-red    { background: var(--red); }
.progress-purple { background: var(--purple); }

/* ── SEPARADORES ─────────────────────────────────────────── */

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

/* ── ESTADO VACÍO ────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: var(--space-8);
    color: var(--text-muted);
    font-size: var(--text-sm);
}
.empty-state-icon {
    font-size: 32px;
    display: block;
    margin-bottom: var(--space-3);
    opacity: .5;
}

/* ── TOAST ───────────────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--space-4));
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--bg-elevated);
    border: 1px solid var(--border-active);
    border-radius: var(--radius);
    padding: 10px 18px;
    font-size: var(--text-sm);
    font-family: var(--font-mono);
    z-index: 9999;
    opacity: 0;
    transition: var(--transition);
    pointer-events: none;
    white-space: nowrap;
    box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok  { border-color: var(--green); color: var(--green); }
.toast.err { border-color: var(--red);   color: var(--red); }

@media (min-width: 768px) {
    .toast {
        bottom: var(--space-5);
        right: var(--space-5);
        left: auto;
        transform: translateY(10px);
    }
    .toast.show { transform: translateY(0); }
}

/* ── OVERLAY Y MODALES ───────────────────────────────────── */

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.75);
    z-index: 500;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}
.overlay.open { display: flex; }

.modal {
    background: var(--bg-elevated);
    border: 1px solid var(--border-active);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    width: 500px;
    max-width: 96vw;
    max-height: 90vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: var(--shadow-xl);
    animation: modalIn .2s ease;
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(.96) translateY(8px); }
    to   { opacity: 1; transform: none; }
}

/* Modal en pantalla completa en mobile — bottom sheet */
@media (max-width: 640px) {
    .overlay { align-items: flex-end; }
    .modal {
        width: 100%;
        max-width: 100%;
        max-height: 92dvh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
    }
    @keyframes modalIn {
        from { opacity: 0; transform: translateY(48px); }
        to   { opacity: 1; transform: translateY(0); }
    }
    .modal-footer {
        flex-direction: column-reverse;
        gap: var(--space-3);
        padding-top: var(--space-5);
    }
    .modal-footer .btn { width: 100%; min-height: var(--touch-target); }
}

.modal-title {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 700;
    margin-bottom: var(--space-5);
}
.modal-footer {
    display: flex;
    gap: var(--space-2);
    justify-content: flex-end;
    margin-top: var(--space-5);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
}

/* ── FORM GROUP ──────────────────────────────────────────── */

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin-bottom: var(--space-4);
}
.form-group label {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
}
@media (max-width: 640px) {
    .form-row { grid-template-columns: 1fr; gap: var(--space-2); }
}

/* ── TABLA ───────────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; }
th {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 0 12px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border-soft);
    font-size: var(--text-sm);
    vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.015); }

/* ── UTILIDADES ──────────────────────────────────────────── */

.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }

.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.mb-6 { margin-bottom: var(--space-6); }

.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.flex         { display: flex; }
.flex-col     { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1       { flex: 1; }
.flex-wrap    { flex-wrap: wrap; }

.hidden  { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* Animaciones de entrada de página */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}
.page-enter { animation: fadeIn .2s ease; }

/* ── MOBILE — OPTIMIZACIONES TÁCTILES ───────────────────────
   Breakpoint 900px coincide con el colapso del sidebar.
   ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    /* font-size 16px en inputs evita el zoom automático en iOS/Android */
    input, select, textarea {
        font-size: 16px;
        min-height: var(--touch-target);
        padding: 12px 14px;
    }
    textarea { min-height: calc(var(--touch-target) * 2); }

    /* Botones: target táctil mínimo de 44px */
    .btn     { min-height: var(--touch-target); padding: 10px 18px; }
    .btn-sm  { min-height: 36px; padding: 8px 12px; font-size: var(--text-sm); }
    .btn-icon { min-width: var(--touch-target); min-height: var(--touch-target); }
    .btn-lg  { min-height: 52px; }

    /* Cards: scroll horizontal para tablas internas */
    .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .card table { min-width: max-content; }

    /* Tabla: padding más cómodo para el dedo */
    td { padding: 13px 12px; }
}

/* Respetar preferencia del SO para reducir movimiento */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}
