/**
 * Estilos Responsivos y UX Mejorada
 * Sistema POS Pupusería
 */

/* ============ VARIABLES CSS ============ */
:root {
    --primary-color: #e74c3c;
    --secondary-color: #c0392b;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --info-color: #3498db;
    --danger-color: #e74c3c;
    --dark-color: #2c3e50;
    --light-color: #ecf0f1;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.2);
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-lg: 16px;
}

/* ============ RESET Y BASE ============ */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none;
}

/* ============ MEJORAS DE INTERACCIÓN TÁCTIL ============ */
button, .btn, a, input, select, textarea {
    touch-action: manipulation;
}

/* Botones más grandes y fáciles de tocar en móvil */
@media (max-width: 768px) {
    .btn {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 1rem;
    }

    .btn-sm {
        min-height: 38px;
        padding: 8px 12px;
    }

    .btn-lg {
        min-height: 52px;
        padding: 14px 24px;
        font-size: 1.1rem;
    }

    .form-control, .form-select {
        min-height: 44px;
        font-size: 16px !important; /* Previene zoom en iOS */
        padding: 10px 14px;
    }

    .form-control-sm, .form-select-sm {
        min-height: 38px;
        font-size: 15px !important;
    }

    .form-control-lg, .form-select-lg {
        min-height: 52px;
        font-size: 18px !important;
    }
}

/* ============ ANIMACIONES SUAVES ============ */
.btn, .card, .nav-link, .list-group-item {
    transition: all var(--transition-fast);
}

.btn:active {
    transform: scale(0.97);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

/* ============ CARDS MEJORADAS ============ */
.card {
    border: none;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    border-bottom: 1px solid rgba(0,0,0,0.08);
    font-weight: 600;
}

/* ============ TABLAS RESPONSIVAS ============ */
.table-responsive {
    border-radius: var(--border-radius-sm);
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    .table {
        font-size: 0.875rem;
    }

    .table th, .table td {
        padding: 0.5rem 0.4rem;
        white-space: nowrap;
    }

    /* Tabla apilable en móvil */
    .table-stack-mobile thead {
        display: none;
    }

    .table-stack-mobile tbody tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #dee2e6;
        border-radius: var(--border-radius-sm);
        padding: 0.5rem;
    }

    .table-stack-mobile tbody td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem;
        border: none;
        border-bottom: 1px solid #f0f0f0;
    }

    .table-stack-mobile tbody td:last-child {
        border-bottom: none;
    }

    .table-stack-mobile tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #666;
    }
}

/* ============ MODALES RESPONSIVOS ============ */
@media (max-width: 576px) {
    .modal-dialog {
        margin: 0.5rem;
        max-height: calc(100vh - 1rem);
    }

    .modal-content {
        border-radius: var(--border-radius-lg);
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-body {
        padding: 1rem;
        max-height: calc(100vh - 200px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-footer {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        flex: 1 1 auto;
        min-width: 120px;
    }

    .modal-lg, .modal-xl {
        max-width: calc(100vw - 1rem);
    }
}

/* ============ NAVEGACIÓN RESPONSIVA ============ */
@media (max-width: 768px) {
    .navbar {
        padding: 0.5rem 1rem;
    }

    .navbar-brand {
        font-size: 1rem;
        max-width: 60%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .navbar-nav {
        padding: 0.5rem 0;
    }

    .nav-link {
        padding: 0.75rem 1rem;
        border-radius: var(--border-radius-sm);
    }

    .nav-link:active {
        background: rgba(0,0,0,0.05);
    }

    /* Dropdown mejorado en móvil */
    .dropdown-menu {
        border-radius: var(--border-radius);
        box-shadow: var(--shadow-lg);
        border: none;
    }

    .dropdown-item {
        padding: 0.75rem 1rem;
    }
}

/* ============ SIDEBAR RESPONSIVO ============ */
@media (max-width: 992px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 1050;
        transition: left var(--transition-normal);
        background: white;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.show {
        left: 0;
    }

    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1040;
        opacity: 0;
        visibility: hidden;
        transition: all var(--transition-normal);
    }

    .sidebar-backdrop.show {
        opacity: 1;
        visibility: visible;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
}

/* ============ GRIDS RESPONSIVOS ============ */
@media (max-width: 576px) {
    .row {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }

    .row > * {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .container, .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* ============ BADGES Y ETIQUETAS ============ */
.badge {
    font-weight: 500;
    padding: 0.4em 0.65em;
    border-radius: 6px;
}

@media (max-width: 576px) {
    .badge {
        font-size: 0.7rem;
        padding: 0.3em 0.5em;
    }
}

/* ============ ALERTAS Y NOTIFICACIONES ============ */
.alert {
    border: none;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
}

.toast {
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
}

@media (max-width: 576px) {
    .toast-container {
        left: 0.5rem !important;
        right: 0.5rem !important;
        bottom: 0.5rem !important;
    }

    .toast {
        width: 100%;
    }
}

/* ============ FORMULARIOS MEJORADOS ============ */
.form-label {
    font-weight: 500;
    margin-bottom: 0.4rem;
    color: #444;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.15);
}

.input-group {
    border-radius: var(--border-radius-sm);
}

.input-group-text {
    border-color: #dee2e6;
    background: #f8f9fa;
}

/* Grupos de botones responsivos */
@media (max-width: 576px) {
    .btn-group {
        flex-wrap: wrap;
    }

    .btn-group .btn {
        flex: 1 1 auto;
    }

    .btn-group-vertical {
        width: 100%;
    }
}

/* ============ LISTAS Y ITEMS ============ */
.list-group-item {
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding: 0.875rem 1rem;
}

.list-group-item:first-child {
    border-top: none;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.list-group-item:last-child {
    border-radius: 0 0 var(--border-radius) var(--border-radius);
}

.list-group-item-action:active {
    background-color: #f0f0f0;
}

/* ============ MESAS/GRID DE PRODUCTOS ============ */
.mesa-grid, .producto-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

@media (max-width: 576px) {
    .mesa-grid, .producto-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
}

@media (min-width: 992px) {
    .mesa-grid, .producto-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

.mesa-card, .producto-card {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-radius: var(--border-radius);
    padding: 1rem;
    user-select: none;
}

.mesa-card:active, .producto-card:active {
    transform: scale(0.95);
}

/* ============ PANELES DE TRABAJO ============ */
.work-panel {
    min-height: calc(100vh - 120px);
}

@media (max-width: 768px) {
    .work-panel {
        min-height: calc(100vh - 100px);
        padding: 0.5rem;
    }
}

/* ============ BOTTOM NAVIGATION (MÓVIL) ============ */
.bottom-nav {
    display: none;
}

@media (max-width: 768px) {
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        z-index: 1030;
        padding: 0.5rem;
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0));
    }

    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 0.5rem;
        color: #666;
        text-decoration: none;
        font-size: 0.75rem;
        border-radius: var(--border-radius-sm);
        transition: all var(--transition-fast);
    }

    .bottom-nav-item i {
        font-size: 1.25rem;
        margin-bottom: 0.25rem;
    }

    .bottom-nav-item.active {
        color: var(--primary-color);
        background: rgba(231, 76, 60, 0.1);
    }

    .bottom-nav-item:active {
        transform: scale(0.95);
    }

    /* Espacio para la navegación inferior */
    body {
        padding-bottom: 70px;
    }
}

/* ============ ESTADOS VACÍOS ============ */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #888;
}

.empty-state i {
    font-size: 4rem;
    opacity: 0.5;
    margin-bottom: 1rem;
}

.empty-state h5 {
    font-weight: 600;
    color: #666;
}

/* ============ LOADING STATES ============ */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--border-radius-sm);
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============ SCROLL MEJORADO ============ */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

@media (max-width: 768px) {
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }
}

/* ============ PULL TO REFRESH INDICATOR ============ */
.pull-indicator {
    position: fixed;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    padding: 1rem;
    border-radius: 50%;
    box-shadow: var(--shadow-md);
    z-index: 9999;
    transition: top var(--transition-normal);
}

.pull-indicator.active {
    top: 20px;
}

/* ============ FAB (FLOATING ACTION BUTTON) ============ */
.fab {
    position: fixed;
    bottom: 90px;
    right: 1rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: var(--shadow-lg);
    z-index: 1020;
    border: none;
    color: white;
    background: var(--primary-color);
    transition: all var(--transition-fast);
}

.fab:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 30px rgba(231, 76, 60, 0.4);
}

.fab:active {
    transform: scale(0.95);
}

@media (min-width: 769px) {
    .fab {
        bottom: 2rem;
        right: 2rem;
    }
}

/* ============ ESTADÍSTICAS / DASHBOARD ============ */
.stat-card {
    text-align: center;
    padding: 1.5rem 1rem;
    border-radius: var(--border-radius);
    color: white;
    transition: all var(--transition-fast);
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-card h3 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.stat-card small {
    opacity: 0.9;
    font-size: 0.85rem;
}

@media (max-width: 576px) {
    .stat-card {
        padding: 1rem 0.75rem;
    }

    .stat-card h3 {
        font-size: 1.25rem;
    }

    .stat-card small {
        font-size: 0.75rem;
    }
}

/* ============ SAFE AREAS (NOTCH/HOME INDICATOR) ============ */
@supports (padding: env(safe-area-inset-bottom)) {
    .navbar {
        padding-top: calc(0.5rem + env(safe-area-inset-top));
    }

    .bottom-nav {
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    }

    .modal-content {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ============ ACCESIBILIDAD ============ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible para navegación con teclado */
:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* ============ MODO OSCURO (OPCIONAL) ============ */
@media (prefers-color-scheme: dark) {
    :root {
        --dark-bg: #1a1a2e;
        --dark-surface: #16213e;
        --dark-text: #eee;
    }

    /* Descomentar para habilitar modo oscuro automático
    body.auto-dark {
        background-color: var(--dark-bg);
        color: var(--dark-text);
    }

    body.auto-dark .card {
        background: var(--dark-surface);
        color: var(--dark-text);
    }
    */
}

/* ============ UTILIDADES ADICIONALES ============ */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.text-truncate-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.sticky-top-mobile {
    position: sticky;
    top: 0;
    z-index: 100;
    background: white;
}

@media (max-width: 768px) {
    .hide-mobile { display: none !important; }
    .show-mobile { display: block !important; }
    .show-mobile-flex { display: flex !important; }
    .show-mobile-inline { display: inline !important; }
}

@media (min-width: 769px) {
    .hide-desktop { display: none !important; }
    .show-desktop { display: block !important; }
    .show-desktop-flex { display: flex !important; }
}

/* Espaciado responsive */
@media (max-width: 576px) {
    .p-responsive { padding: 0.75rem !important; }
    .px-responsive { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
    .py-responsive { padding-top: 0.75rem !important; padding-bottom: 0.75rem !important; }
    .m-responsive { margin: 0.75rem !important; }
    .mb-responsive { margin-bottom: 0.75rem !important; }
    .mt-responsive { margin-top: 0.75rem !important; }
}
