/* ============================================================
   GestorPimacs — Estilos
   Estética: Industrial / Utilitaria / Señalización de taller
   ============================================================ */

:root {
    /* Paleta principal */
    --bg:             #1a1d23;
    --bg-panel:       #22262e;
    --bg-elevated:    #2a2f38;
    --bg-input:       #181b20;

    --text-primary:   #e8eaed;
    --text-secondary: #9aa0ab;
    --text-muted:     #636975;

    /* Señalización */
    --verde:          #22c55e;
    --verde-bg:       rgba(34, 197, 94, 0.12);
    --rojo:           #ef4444;
    --rojo-bg:        rgba(239, 68, 68, 0.12);
    --amarillo:       #f59e0b;
    --amarillo-bg:    rgba(245, 158, 11, 0.12);
    --azul:           #3b82f6;
    --azul-bg:        rgba(59, 130, 246, 0.12);

    /* Acentos */
    --accent:         #f59e0b;
    --accent-hover:   #d97706;

    /* Bordes */
    --borde:          #333842;
    --borde-hover:    #4a5060;

    /* Tipografía */
    --font-body:      'DM Sans', system-ui, -apple-system, sans-serif;
    --font-mono:      'JetBrains Mono', 'Courier New', monospace;

    /* Radios */
    --radius:         10px;
    --radius-sm:      6px;
    --radius-lg:      16px;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ============================================================
   PANTALLAS
   ============================================================ */
.pantalla {
    display: none;
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    padding: 24px 20px;
    min-height: 100vh;
    animation: fadeIn 0.2s ease;
}
.pantalla.activa { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   PANTALLA INICIO
   ============================================================ */
.inicio-header {
    text-align: center;
    padding: 40px 0 20px;
}

.logo {
    width: 100px;
    height: 100px;
    margin-bottom: 16px;
    filter: drop-shadow(0 0 20px rgba(245, 158, 11, 0.25));
}

.inicio-header h1 {
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.subtitulo {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-weight: 500;
}

/* Scanner */
.scanner-area {
    background: var(--bg-panel);
    border: 2px solid var(--borde);
    border-radius: var(--radius-lg);
    padding: 40px 24px;
    text-align: center;
    margin: 28px 0;
    transition: border-color 0.3s;
}
.scanner-area:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}

.scanner-icono {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    color: var(--accent);
    animation: pulse-glow 2.5s ease-in-out infinite;
}
.scanner-icono--usuario { color: var(--azul); }

@keyframes pulse-glow {
    0%, 100% { opacity: 0.7; transform: scale(1); }
    50%      { opacity: 1;   transform: scale(1.05); }
}

.scanner-texto {
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.input-qr {
    width: 100%;
    max-width: 420px;
    padding: 14px 20px;
    font-family: var(--font-mono);
    font-size: 1.3rem;
    font-weight: 500;
    text-align: center;
    background: var(--bg-input);
    color: var(--accent);
    border: 2px solid var(--borde);
    border-radius: var(--radius);
    outline: none;
    letter-spacing: 0.08em;
    transition: border-color 0.2s;
}
.input-qr:focus {
    border-color: var(--accent);
}
.input-qr::placeholder {
    color: var(--text-muted);
    font-size: 0.95rem;
    letter-spacing: 0;
}

/* Botones inicio */
.opciones-inicio {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 8px;
}

/* ============================================================
   BOTONES
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    border: 2px solid var(--borde);
    border-radius: var(--radius);
    background: var(--bg-elevated);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    line-height: 1.3;
}
.btn:hover {
    border-color: var(--borde-hover);
    background: #323843;
    transform: translateY(-1px);
}
.btn:active {
    transform: translateY(0);
}

.btn-icono { font-size: 1.4rem; }

.btn-historial {
    flex-direction: column;
    padding: 20px 12px;
    font-size: 0.95rem;
}

/* Acciones coloreadas */
.btn-accion--retirar    { border-color: var(--amarillo); color: var(--amarillo); background: var(--amarillo-bg); }
.btn-accion--devolver   { border-color: var(--verde);    color: var(--verde);    background: var(--verde-bg); }
.btn-accion--abonar     { border-color: var(--azul);     color: var(--azul);     background: var(--azul-bg); }
.btn-accion--defectuoso { border-color: var(--rojo);     color: var(--rojo);     background: var(--rojo-bg); }
.btn-accion--error      { border-color: var(--rojo);     color: var(--rojo);     background: var(--rojo-bg); }
.btn-accion--baja       { border-color: #888;            color: #aaa;            background: rgba(150,150,150,0.1); }

.btn-accion--retirar:hover    { background: rgba(245, 158, 11, 0.22); }
.btn-accion--devolver:hover   { background: rgba(34, 197, 94, 0.22); }
.btn-accion--abonar:hover     { background: rgba(59, 130, 246, 0.22); }
.btn-accion--defectuoso:hover,
.btn-accion--error:hover      { background: rgba(239, 68, 68, 0.22); }

.btn-confirmar-alta {
    width: 100%;
    padding: 16px;
    font-size: 1.15rem;
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(245, 158, 11, 0.1);
}
.btn-confirmar-alta:hover { background: rgba(245, 158, 11, 0.2); }

.btn-filtrar {
    background: var(--azul-bg);
    border-color: var(--azul);
    color: var(--azul);
}
.btn-exportar {
    background: var(--verde-bg);
    border-color: var(--verde);
    color: var(--verde);
}

.btn-volver-inicio {
    margin-top: 24px;
    padding: 16px 40px;
    font-size: 1.15rem;
    border-color: var(--accent);
    color: var(--accent);
}

.btn-admin {
    flex: 1;
}

.btn-danger {
    border-color: var(--rojo);
    color: var(--rojo);
    background: var(--rojo-bg);
}

/* ============================================================
   HEADER DE PANTALLAS
   ============================================================ */
.pantalla-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.btn-volver {
    padding: 10px 16px;
    font-family: var(--font-body);
    font-size: 0.95rem;
    font-weight: 600;
    border: 2px solid var(--borde);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}
.btn-volver:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

/* Timeout */
.timeout-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
    min-width: 100px;
}
.timeout-progress {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    width: 100%;
    transition: width 1s linear, background-color 0.5s;
}
.timeout-progress.warning { background: var(--rojo); }

.timeout-texto {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-muted);
    min-width: 32px;
}

/* ============================================================
   INFO DE ÍTEM
   ============================================================ */
.item-info {
    background: var(--bg-panel);
    border: 2px solid var(--borde);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
}
.item-info-codigo {
    font-family: var(--font-mono);
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}
.item-info-desc {
    font-size: 1.2rem;
    color: var(--text-primary);
    margin-bottom: 12px;
}
.item-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px 16px;
}
.item-info-campo {
    display: flex;
    gap: 6px;
    font-size: 0.9rem;
}
.item-info-label {
    color: var(--text-muted);
    white-space: nowrap;
}
.item-info-valor {
    color: var(--text-secondary);
    font-weight: 500;
}

.item-estado {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.estado-Disponible        { background: var(--verde-bg);    color: var(--verde); }
.estado-Retirado          { background: var(--amarillo-bg); color: var(--amarillo); }
.estado-Ocupada           { background: var(--amarillo-bg); color: var(--amarillo); }
.estado-Para_abonar       { background: var(--azul-bg);     color: var(--azul); }
.estado-Defectuoso,
.estado-Defectuosa        { background: var(--rojo-bg);     color: var(--rojo); }
.estado-Error_en_comanda  { background: var(--rojo-bg);     color: var(--rojo); }
.estado-Dado_de_baja      { background: rgba(150,150,150,0.15); color: #999; }
.estado-activo            { background: var(--verde-bg);    color: var(--verde); }
.estado-baja              { background: rgba(150,150,150,0.15); color: #999; }

/* Lista acciones */
.acciones-lista {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.acciones-lista .btn {
    padding: 20px;
    font-size: 1.15rem;
}

/* ============================================================
   CONFIRMAR
   ============================================================ */
.confirmar-area { text-align: center; }

.confirmar-resumen {
    background: var(--bg-panel);
    border: 2px solid var(--borde);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    font-size: 1.1rem;
}
.confirmar-resumen strong {
    color: var(--accent);
}

.scanner-area--confirmar {
    border-color: var(--azul);
}
.scanner-area--confirmar:focus-within {
    border-color: var(--azul);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* ============================================================
   FORMULARIO ALTA
   ============================================================ */
.alta-contenido { max-width: 680px; margin: 0 auto; }

.alta-codigo {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 20px;
    text-align: center;
}

.form-alta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-grupo {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.form-grupo--full { grid-column: 1 / -1; }

.form-grupo label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.form-grupo input,
.form-grupo select,
.form-grupo textarea {
    padding: 10px 14px;
    font-family: var(--font-body);
    font-size: 1rem;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 2px solid var(--borde);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.2s;
}
.form-grupo input:focus,
.form-grupo select:focus,
.form-grupo textarea:focus {
    border-color: var(--accent);
}

.form-grupo textarea { resize: vertical; min-height: 80px; }
.form-grupo select { cursor: pointer; }

.alta-acciones { margin-top: 20px; }

/* ============================================================
   HISTORIAL
   ============================================================ */
.historial-titulo {
    font-size: 1.4rem;
    color: var(--text-primary);
}

.historial-filtros {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    background: var(--bg-panel);
    border: 2px solid var(--borde);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
    align-items: flex-end;
}

.filtro-grupo {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 130px;
}
.filtro-grupo label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.filtro-grupo input,
.filtro-grupo select {
    padding: 8px 10px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 2px solid var(--borde);
    border-radius: var(--radius-sm);
    outline: none;
}
.filtro-grupo input:focus,
.filtro-grupo select:focus {
    border-color: var(--accent);
}

.filtro-botones {
    flex-direction: row;
    gap: 8px;
    align-items: stretch;
}
.filtro-botones .btn {
    padding: 8px 14px;
    font-size: 0.85rem;
}

/* Tabla */
.historial-tabla-wrapper {
    overflow-x: auto;
    border: 2px solid var(--borde);
    border-radius: var(--radius);
}

.historial-tabla {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.historial-tabla th {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    padding: 12px 14px;
    text-align: left;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    border-bottom: 2px solid var(--borde);
    position: sticky;
    top: 0;
}
.historial-tabla td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--borde);
    color: var(--text-primary);
}
.historial-tabla tbody tr:hover {
    background: rgba(245, 158, 11, 0.04);
}
.historial-tabla .mono {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent);
}

/* Paginación */
.historial-paginacion {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 16px;
}
.historial-paginacion button {
    padding: 8px 14px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    border: 2px solid var(--borde);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}
.historial-paginacion button:hover { border-color: var(--accent); color: var(--accent); }
.historial-paginacion button.activa {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
}

/* ============================================================
   ADMINISTRACIÓN
   ============================================================ */
.admin-secciones {
    display: flex;
    flex-direction: column;
    gap: 24px;
}
.admin-seccion {
    background: var(--bg-panel);
    border: 2px solid var(--borde);
    border-radius: var(--radius-lg);
    padding: 24px;
}
.admin-seccion h3 {
    font-size: 1.15rem;
    margin-bottom: 12px;
    color: var(--text-primary);
}
.admin-instruccion {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}
.admin-acciones-grupo {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}
.admin-contenido { margin-top: 16px; }

/* Tabla usuarios admin */
.admin-tabla {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.admin-tabla th {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--borde);
}
.admin-tabla td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--borde);
}

/* Formulario admin alta usuario */
.admin-form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}
.admin-form .form-grupo { min-width: 180px; flex: 1; }
.admin-form .btn { align-self: flex-end; }

/* Formulario editar ítem admin */
.admin-editar-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 16px;
}
.admin-editar-form .form-grupo--full { grid-column: 1 / -1; }

/* ============================================================
   RESULTADO
   ============================================================ */
.resultado-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    text-align: center;
    padding: 40px;
}

.resultado-icono {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    font-size: 3rem;
}
.resultado-icono--ok  { background: var(--verde-bg);  color: var(--verde); }
.resultado-icono--err { background: var(--rojo-bg);   color: var(--rojo); }

.resultado-mensaje {
    font-size: 1.5rem;
    font-weight: 600;
    max-width: 500px;
    line-height: 1.4;
}

/* ============================================================
   OVERLAY
   ============================================================ */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 1000;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--borde);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 700px) {
    .opciones-inicio {
        grid-template-columns: 1fr;
    }
    .acciones-lista {
        grid-template-columns: 1fr;
    }
    .form-alta {
        grid-template-columns: 1fr;
    }
    .historial-filtros {
        flex-direction: column;
    }
    .admin-editar-form {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   TOASTS
   ============================================================ */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.95rem;
    max-width: 420px;
    opacity: 0;
    transform: translateX(40px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: auto;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.toast--visible {
    opacity: 1;
    transform: translateX(0);
}

.toast--ok {
    background: var(--bg-panel);
    color: var(--verde);
    border: 2px solid var(--verde);
    border-left: 6px solid var(--verde);
}

.toast--error {
    background: var(--bg-panel);
    color: var(--rojo);
    border: 2px solid var(--rojo);
    border-left: 6px solid var(--rojo);
}

.toast--warning {
    background: var(--bg-panel);
    color: var(--amarillo);
    border: 2px solid var(--amarillo);
    border-left: 6px solid var(--amarillo);
}

.toast--info {
    background: var(--bg-panel);
    color: var(--azul);
    border: 2px solid var(--azul);
    border-left: 6px solid var(--azul);
}

@media (max-width: 500px) {
    #toast-container {
        left: 12px;
        right: 12px;
    }
    .toast { max-width: 100%; }
}
