/* ============================================
   POS Ultra Simple - Estilos
   Mobile-first, minimalista, alto contraste
   ============================================ */

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

:root {
    --primary: #2563EB;
    --primary-dark: #1D4ED8;
    --primary-light: #DBEAFE;
    --success: #16A34A;
    --success-dark: #15803D;
    --danger: #DC2626;
    --danger-dark: #B91C1C;
    --warning: #F59E0B;
    --bg: #F5F5F7;
    --bg-card: #FFFFFF;
    --text: #1E293B;
    --text-secondary: #64748B;
    --text-muted: #94A3B8;
    --border: #E2E8F0;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --nav-height: 64px;
    --header-height: 60px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Views --- */
.view {
    display: none;
    padding: 0 16px 16px;
    padding-bottom: calc(var(--nav-height) + 16px);
    min-height: 100vh;
    min-height: 100dvh;
}

.view.active {
    display: block;
}

/* --- Header --- */
.view-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}

.view-header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text);
}

/* --- Botones --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:active {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:active {
    background: var(--success-dark);
}

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:active {
    background: var(--danger-dark);
}

.btn-outline {
    background: transparent;
    color: var(--text);
    border: 2px solid var(--border);
}
.btn-outline:active {
    background: var(--border);
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn-lg {
    padding: 14px 24px;
    font-size: 1.05rem;
    min-height: 52px;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    padding: 10px;
    width: 46px;
    height: 46px;
    flex-shrink: 0;
}

.btn-scan-header {
    padding: 8px 14px;
    font-size: 0.9rem;
}

/* --- Inputs --- */
input[type="text"],
input[type="number"],
input[type="date"] {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 1rem;
    color: var(--text);
    background: var(--bg-card);
    transition: border-color 0.15s;
    appearance: none;
    -webkit-appearance: none;
}

input:focus {
    outline: none;
    border-color: var(--primary);
}

.input-search {
    background: var(--bg-card);
    padding-left: 14px;
}

.input-with-btn {
    display: flex;
    gap: 8px;
}
.input-with-btn input {
    flex: 1;
}

/* --- Formulario --- */
.form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.error-text {
    color: var(--danger);
    font-size: 0.8rem;
}

/* --- Búsqueda --- */
.search-container {
    margin-bottom: 12px;
}

.quick-search-container {
    position: relative;
    padding: 0 0 8px;
}

.search-results-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 20;
    background: var(--bg-card);
    border: 2px solid var(--primary);
    border-radius: var(--radius-sm);
    max-height: 200px;
    overflow-y: auto;
    list-style: none;
    box-shadow: var(--shadow-md);
}

.search-results-dropdown li {
    padding: 12px 14px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
}

.search-results-dropdown li:last-child {
    border-bottom: none;
}

.search-results-dropdown li:active {
    background: var(--primary-light);
}

.search-results-dropdown li .product-price {
    font-weight: 700;
    color: var(--success);
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 1rem;
    margin-bottom: 4px;
}

.empty-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* --- Carrito --- */
#cart-container {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 8px;
}

.cart-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cart-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.cart-item-info {
    flex: 1;
    min-width: 0;
}

.cart-item-name {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cart-item-price {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.cart-item-subtotal {
    font-weight: 700;
    color: var(--primary);
    font-size: 1rem;
    white-space: nowrap;
    min-width: 70px;
    text-align: right;
}

.cart-item-qty {
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-qty {
    width: 36px;
    height: 36px;
    border: 2px solid var(--border);
    border-radius: 50%;
    background: var(--bg-card);
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    touch-action: manipulation;
    transition: all 0.15s;
}

.btn-qty:active {
    background: var(--primary-light);
    border-color: var(--primary);
}

.qty-value {
    font-weight: 700;
    font-size: 1.05rem;
    min-width: 28px;
    text-align: center;
}

.btn-remove-item {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: #FEE2E2;
    color: var(--danger);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    flex-shrink: 0;
}

.btn-remove-item:active {
    background: var(--danger);
    color: white;
}

/* --- Cart Footer --- */
.cart-footer {
    position: fixed;
    bottom: var(--nav-height);
    left: 0;
    right: 0;
    background: var(--bg-card);
    padding: 12px 16px;
    border-top: 2px solid var(--border);
    box-shadow: 0 -4px 16px rgba(0,0,0,0.06);
    z-index: 9;
}

.cart-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.cart-total span:first-child {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
}

.total-amount {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text);
}

/* --- Lista de Productos --- */
.product-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.product-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.product-item-info {
    flex: 1;
    min-width: 0;
}

.product-item-name {
    font-weight: 600;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-item-barcode {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: monospace;
}

.product-item-price {
    font-weight: 700;
    color: var(--success);
    font-size: 1.1rem;
    white-space: nowrap;
}

.product-item-actions {
    display: flex;
    gap: 6px;
}

.btn-edit, .btn-delete {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

.btn-edit {
    background: var(--primary-light);
    color: var(--primary);
}
.btn-edit:active {
    background: var(--primary);
    color: white;
}

.btn-delete {
    background: #FEE2E2;
    color: var(--danger);
}
.btn-delete:active {
    background: var(--danger);
    color: white;
}

/* --- Historial de Ventas --- */
.filter-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.filter-container label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.input-date {
    flex: 1;
    max-width: 180px;
}

.history-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px;
    cursor: pointer;
    touch-action: manipulation;
}

.history-item-header:active {
    background: var(--bg);
}

.history-date {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.history-total {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
}

.history-detail {
    display: none;
    padding: 0 14px 14px;
    border-top: 1px solid var(--border);
}

.history-detail.open {
    display: block;
}

.history-detail-list {
    list-style: none;
    padding: 8px 0 0;
}

.history-detail-item {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
}

.history-detail-item:last-child {
    border-bottom: none;
}

.history-detail-item .item-name {
    flex: 1;
    color: var(--text);
}

.history-detail-item .item-qty {
    color: var(--text-secondary);
    margin: 0 8px;
}

.history-detail-item .item-subtotal {
    font-weight: 600;
    color: var(--text);
}

/* --- Modales --- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn 0.15s ease;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-card);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    max-height: 90dvh;
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 20px;
    overflow-y: auto;
    animation: slideUp 0.2s ease;
}

.modal-small {
    max-height: auto;
}

.modal-scanner-content {
    padding-bottom: 24px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
}

.btn-close {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: var(--bg);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}
.modal-actions .btn {
    flex: 1;
}

.confirm-body {
    text-align: center;
    padding: 8px 0;
}

.confirm-body p {
    font-size: 1rem;
    margin-bottom: 8px;
}

.confirm-items {
    color: var(--text-secondary);
}

.confirm-total {
    font-size: 1.3rem;
}

.text-muted {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* --- Scanner --- */
#scanner-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background: #000;
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 12px;
}

#scanner-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scanner-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.scanner-line {
    width: 80%;
    height: 3px;
    background: var(--danger);
    box-shadow: 0 0 12px rgba(220,38,38,0.6);
    animation: scanLine 2s ease-in-out infinite;
}

.scanner-feedback {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--success);
    color: white;
    text-align: center;
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 8px;
    animation: feedbackPop 0.3s ease;
}

.scanner-feedback.hidden {
    display: none;
}

.scanner-hint {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 80px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 12px 24px;
    border-radius: 28px;
    font-size: 0.95rem;
    font-weight: 500;
    z-index: 200;
    box-shadow: var(--shadow-md);
    animation: toastIn 0.3s ease;
    white-space: nowrap;
}

.toast.hidden {
    display: none;
}

/* --- Barra de Navegación Inferior --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--bg-card);
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid var(--border);
    z-index: 50;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    transition: color 0.15s;
    position: relative;
}

.nav-btn.active {
    color: var(--primary);
}

.nav-btn.active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 3px;
    background: var(--primary);
    border-radius: 0 0 3px 3px;
}

.nav-btn svg {
    width: 24px;
    height: 24px;
}

/* --- Utilidades --- */
.hidden {
    display: none !important;
}

/* --- Animaciones --- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

@keyframes scanLine {
    0%, 100% { transform: translateY(-40px); opacity: 0.6; }
    50% { transform: translateY(40px); opacity: 1; }
}

@keyframes feedbackPop {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes toastIn {
    0% { transform: translateX(-50%) translateY(20px); opacity: 0; }
    100% { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* --- Media queries para pantallas más grandes --- */
@media (min-width: 480px) {
    .view {
        max-width: 480px;
        margin: 0 auto;
    }
    .cart-footer {
        max-width: 480px;
        left: 50%;
        transform: translateX(-50%);
    }
    .bottom-nav {
        max-width: 480px;
        left: 50%;
        transform: translateX(-50%);
    }
    .modal-content {
        border-radius: var(--radius);
        margin-bottom: 20px;
    }
}
