/* ==============================================================================
   POS — LA MAMÁ DE LOS POLLITOS (LIGHT MODE)
   Diseño limpio, minimalista y luminoso
   ============================================================================== */

/* --- Design Tokens --- */
:root {
    --bg-0:           #f3f4f6;
    --bg-1:           #ffffff;
    --bg-2:           #f9fafb;
    --bg-3:           #f3f4f6;
    --bg-4:           #e5e7eb;
    --border:         #e5e7eb;

    --brand:          #ff5e00;
    --brand-alt:      #ea580c;
    --gold:           #eab308;
    --green:          #16a34a;
    --green-glow:     rgba(22,163,74,0.1);
    --red:            #dc2626;
    --blue:           #2563eb;
    --purple:         #9333ea;

    --text-1:         #111827;
    --text-2:         #4b5563;
    --text-3:         #9ca3af;

    --radius-sm:      6px;
    --radius-md:      12px;
    --radius-lg:      16px;
    --radius-xl:      24px;

    --shadow-sm:      0 1px 2px rgba(0,0,0,0.05);
    --shadow-md:      0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg:      0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);

    --glow-brand:     0 4px 14px rgba(255,94,0,0.25);
    --t-fast:         all 0.15s ease;
    --t-med:          all 0.25s cubic-bezier(0.4,0,0.2,1);
    --font-title:     'Outfit', sans-serif;
    --font-body:      'Plus Jakarta Sans', sans-serif;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; background: var(--bg-0); color: var(--text-1); font-family: var(--font-body); }
body { min-height: 100vh; overflow-x: hidden; line-height: 1.5; }
h1,h2,h3,h4,h5 { font-family: var(--font-title); font-weight: 800; letter-spacing: -0.02em; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, select, textarea { font-family: inherit; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

/* ============================================================
   SHARED UTILITIES
   ============================================================ */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 18px; border-radius: var(--radius-md);
    font-weight: 600; font-size: 0.9rem;
    transition: var(--t-fast); cursor: pointer;
}
.btn-primary {
    background: var(--brand); color: #fff;
    box-shadow: var(--glow-brand);
}
.btn-primary:hover { background: var(--brand-alt); transform: translateY(-1px); box-shadow: 0 6px 20px rgba(255,94,0,0.35); }
.btn-primary:active { transform: translateY(0); }
.btn-full { width: 100%; justify-content: center; padding: 14px; font-size: 1rem; }
.btn-ghost {
    background: transparent; color: var(--text-2);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-3); color: var(--text-1); }
.btn-sm { padding: 6px 10px; font-size: 0.8rem; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-export {
    background: var(--bg-1); border: 1px solid var(--border);
    color: var(--text-1); padding: 9px 16px;
}
.btn-export:hover { background: var(--bg-2); border-color: var(--brand); }
.btn-logout {
    background: transparent; border: 1px solid var(--border);
    color: var(--text-2); font-size: 0.8rem; padding: 7px 12px;
    border-radius: var(--radius-md); gap: 5px; display: inline-flex; align-items: center;
}
.btn-logout svg { width: 14px; height: 14px; }
.btn-logout:hover { border-color: var(--red); color: var(--red); background: #fef2f2; }

.spinner {
    display: inline-block; width: 16px; height: 16px;
    border: 2px solid rgba(0,0,0,0.1);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-screen {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: radial-gradient(ellipse at 20% 50%, rgba(255,94,0,0.05) 0%, transparent 60%), var(--bg-0);
    padding: 24px;
}
.login-card {
    width: 100%; max-width: 420px;
    background: var(--bg-1); border: 1px solid var(--border);
    border-radius: var(--radius-xl); padding: 40px 36px;
    box-shadow: var(--shadow-lg); animation: slideUp 0.4s ease;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
.login-brand { text-align: center; margin-bottom: 32px; }
.login-logo { font-size: 3rem; margin-bottom: 12px; animation: pulse 2s ease infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.login-title { font-size: 1.5rem; color: var(--text-1); }
.login-subtitle { font-size: 0.85rem; color: var(--text-2); margin-top: 4px; }
.login-error {
    background: #fef2f2; border: 1px solid #fecaca;
    border-radius: var(--radius-md); padding: 10px 14px;
    font-size: 0.85rem; color: var(--red); margin-bottom: 20px;
}
.login-form { display: flex; flex-direction: column; gap: 18px; }
.login-footer-note { text-align: center; font-size: 0.75rem; color: var(--text-3); margin-top: 20px; }

/* ============================================================
   APP HEADER
   ============================================================ */
.app-header {
    position: sticky; top: 0; z-index: 100;
    display: flex; align-items: center; gap: 0;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 0 16px; height: 56px;
}
.header-brand { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.header-logo { font-size: 1.4rem; }
.header-title { font-family: var(--font-title); font-size: 1rem; font-weight: 800; color: var(--text-1); }

.app-tabs { display: flex; flex: 1; justify-content: center; gap: 4px; }
.app-tabs .tab-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: var(--radius-md);
    font-size: 0.85rem; font-weight: 600; color: var(--text-2);
    transition: var(--t-fast); min-height: 40px;
}
.app-tabs .tab-btn svg { width: 16px; height: 16px; }
.app-tabs .tab-btn:hover { color: var(--text-1); background: var(--bg-2); }
.app-tabs .tab-btn.active { color: var(--brand); background: rgba(255,94,0,0.1); }

.header-user { display: flex; align-items: center; gap: 10px; min-width: 160px; justify-content: flex-end; }
.user-email-tag { font-size: 0.75rem; color: var(--text-3); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================================================
   POS / CAJA LAYOUT
   ============================================================ */
.pos-layout {
    display: grid; grid-template-columns: 1fr 380px;
    height: calc(100vh - 56px);
    overflow: hidden;
}

/* --- CATALOG PANEL --- */
.catalog-panel {
    display: flex; flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
    padding: 16px;
    gap: 12px;
    background: var(--bg-2);
}
.catalog-search-bar { position: relative; }
.catalog-search-bar .search-icon {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    width: 16px; height: 16px; color: var(--text-3); pointer-events: none;
}
#productSearch {
    width: 100%; background: var(--bg-1); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 10px 14px 10px 38px;
    color: var(--text-1); font-size: 0.9rem;
    box-shadow: var(--shadow-sm);
}
#productSearch:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(255,94,0,0.1); }
#productSearch::placeholder { color: var(--text-3); }

.catalog-categories { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.cat-btn {
    padding: 8px 14px; border-radius: var(--radius-md);
    font-size: 0.82rem; font-weight: 600;
    background: var(--bg-1); border: 1px solid var(--border);
    color: var(--text-2); transition: var(--t-fast);
    box-shadow: var(--shadow-sm);
    min-height: 36px;
}
.cat-btn:hover { background: var(--bg-2); color: var(--text-1); }
.cat-btn.active { background: rgba(255,94,0,0.1); border-color: rgba(255,94,0,0.4); color: var(--brand); }

/* ── PRODUCT GRID ──────────────────────────────────────────── */
/* Always a fixed 4-column grid so cards are uniform regardless
   of how many items are visible after filtering.              */
.product-grid {
    flex: 1; overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    align-content: start;          /* cards don't stretch vertically */
    gap: 12px;
    padding-right: 4px; padding-bottom: 20px;
}
.product-grid::-webkit-scrollbar { width: 4px; }
.product-grid::-webkit-scrollbar-track { background: transparent; }
.product-grid::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 2px; }

/* ── PRODUCT CARD ──────────────────────────────────────────── */
.product-card {
    background: var(--bg-1); border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex; flex-direction: column;
    cursor: pointer; transition: var(--t-fast);
    user-select: none; -webkit-tap-highlight-color: transparent;
    position: relative; overflow: hidden;
    box-shadow: var(--shadow-sm);
    /* Fixed height so all cards are the same size */
    height: 230px;
}
.product-card:hover { border-color: rgba(255,94,0,0.3); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.product-card:active { transform: scale(0.97); }
.product-card.dragging { opacity: 0.5; }

.product-card-img-wrapper {
    width: 100%; height: 110px; flex-shrink: 0;
    background: var(--bg-2);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden; border-bottom: 1px solid var(--border);
}
.product-card-img { width: 100%; height: 100%; object-fit: cover; }

.product-card-content {
    padding: 8px 10px;
    display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: hidden;
}
.product-card-name {
    font-size: 0.78rem; font-weight: 700; color: var(--text-1);
    line-height: 1.2;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
}
.product-card-cat { font-size: 0.68rem; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.05em; }
.product-card-price {
    font-family: var(--font-title); font-size: 1rem; font-weight: 800;
    color: var(--brand); margin-top: auto;
}
.product-card-add {
    position: absolute; top: 8px; right: 8px;
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--brand); color: #fff;
    font-size: 1rem; display: flex; align-items: center; justify-content: center;
    opacity: 0; transform: scale(0.7); transition: var(--t-fast);
    box-shadow: var(--shadow-md); pointer-events: none;
}
.product-card:hover .product-card-add { opacity: 1; transform: scale(1); }
/* Touch: always show add button */
@media (hover: none) {
    .product-card-add { opacity: 0.85; transform: scale(1); }
}

.edit-price-btn {
    position: absolute; bottom: 6px; right: 6px;
    background: rgba(255,255,255,0.9); border: 1px solid var(--border);
    border-radius: 6px; padding: 2px 6px; font-size: 0.75rem;
    color: var(--text-2); opacity: 0; transition: var(--t-fast);
    z-index: 2;
}
.product-card:hover .edit-price-btn { opacity: 1; }
@media (hover: none) { .edit-price-btn { opacity: 1; } }

.product-no-results {
    grid-column: 1/-1; text-align: center; padding: 40px 20px;
    color: var(--text-3); font-size: 0.9rem;
}

/* --- ORDER PANEL --- */
.order-panel {
    display: flex; flex-direction: column;
    background: var(--bg-1); overflow: hidden;
    padding: 16px; gap: 12px;
}
.order-header { display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.order-title {
    display: flex; align-items: center; gap: 8px;
    font-size: 1.1rem; font-weight: 800;
}
.order-title svg { width: 18px; height: 18px; color: var(--brand); }

.order-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
    gap: 12px;
    padding-right: 2px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
.order-content::-webkit-scrollbar { width: 3px; }
.order-content::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 2px; }

.order-items { display: flex; flex-direction: column; gap: 6px; }

.order-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--text-3); }
.empty-icon { font-size: 2.5rem; opacity: 0.4; }

.order-item {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg-1); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 10px 12px;
    animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: translateX(0); } }
.order-item-info { flex: 1; min-width: 0; }
.order-item-name { font-size: 0.85rem; font-weight: 600; color: var(--text-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-item-subtotal { font-size: 0.78rem; color: var(--text-2); }
.order-item-qty { display: flex; align-items: center; gap: 4px; }
.qty-btn {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--bg-2); border: 1px solid var(--border);
    color: var(--text-1); font-size: 1rem; display: flex; align-items: center; justify-content: center;
    transition: var(--t-fast);
}
.qty-btn:hover { background: var(--bg-4); }
.qty-btn:active { transform: scale(0.9); }
.qty-num { font-weight: 700; font-size: 0.9rem; min-width: 20px; text-align: center; }

.order-item-remove {
    width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    color: var(--text-3); transition: var(--t-fast); background: transparent;
}
.order-item-remove:hover { background: #fef2f2; color: var(--red); }

.order-summary {
    background: var(--bg-2); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 12px 14px;
    display: flex; flex-direction: column; gap: 6px;
}
.summary-row { display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; color: var(--text-2); }
.summary-total { padding-top: 8px; border-top: 1px solid var(--border); font-size: 1.1rem; font-weight: 800; color: var(--text-1); }
.summary-total strong { font-family: var(--font-title); font-size: 1.3rem; color: var(--text-1); }

/* --- PAYMENT SECTION --- */
.payment-section { display: flex; flex-direction: column; gap: 10px; }
.payment-title { font-size: 0.82rem; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }
.payment-methods { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.pay-method-btn {
    padding: 10px 6px; border-radius: var(--radius-md);
    background: var(--bg-1); border: 1px solid var(--border);
    color: var(--text-2); font-size: 0.82rem; font-weight: 600;
    transition: var(--t-fast); text-align: center; box-shadow: var(--shadow-sm);
    min-height: 44px;
}
.pay-method-btn:hover { background: var(--bg-2); color: var(--text-1); }
.pay-method-btn.active { background: rgba(255,94,0,0.05); border-color: var(--brand); color: var(--brand); box-shadow: none; }

.cash-section {
    background: var(--bg-2); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 12px 14px;
    display: flex; flex-direction: column; gap: 8px;
    animation: fadeIn 0.2s ease;
}
.cash-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 0.9rem; }
.cash-row label { color: var(--text-2); font-weight: 600; white-space: nowrap; }
#cashReceived {
    flex: 1; background: var(--bg-1); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 8px 10px;
    color: var(--text-1); font-size: 0.95rem; text-align: right;
    max-width: 120px;
}
#cashReceived:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 2px rgba(255,94,0,0.1); }
.cash-change { font-weight: 700; color: var(--text-1); }
.change-value { font-family: var(--font-title); font-size: 1.1rem; color: var(--green); }

.btn-charge {
    width: 100%; padding: 16px; border-radius: var(--radius-lg);
    background: var(--green);
    color: #fff; font-size: 1.1rem; font-weight: 800; font-family: var(--font-title);
    display: flex; align-items: center; justify-content: center; gap: 10px;
    box-shadow: 0 4px 15px rgba(22,163,74,0.3);
    transition: var(--t-fast);
    letter-spacing: 0.02em;
    min-height: 56px; flex-shrink: 0;
}
.btn-charge:not(:disabled):hover { background: #15803d; box-shadow: 0 6px 20px rgba(22,163,74,0.4); transform: translateY(-2px); }
.btn-charge:not(:disabled):active { transform: translateY(0); }
.btn-charge:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.btn-charge svg { width: 20px; height: 20px; }

/* ============================================================
   DASHBOARD
   ============================================================ */
.tab-panel { overflow-y: auto; height: calc(100vh - 56px); }
.dashboard-layout { padding: 24px; display: flex; flex-direction: column; gap: 24px; max-width: 1200px; margin: 0 auto; }
.dashboard-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.section-title { font-family: var(--font-title); font-size: 1.4rem; color: var(--text-1); }

.dash-period-selector { display: flex; gap: 6px; flex-wrap: wrap; }
.period-btn {
    padding: 8px 14px; border-radius: var(--radius-md);
    font-size: 0.83rem; font-weight: 600;
    background: var(--bg-1); border: 1px solid var(--border); color: var(--text-2);
    transition: var(--t-fast); box-shadow: var(--shadow-sm); min-height: 36px;
}
.period-btn:hover { background: var(--bg-2); color: var(--text-1); }
.period-btn.active { background: rgba(255,94,0,0.05); border-color: var(--brand); color: var(--brand); box-shadow: none; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.kpi-card {
    background: var(--bg-1); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 20px;
    display: flex; align-items: center; gap: 16px;
    transition: var(--t-fast); box-shadow: var(--shadow-sm);
}
.kpi-card:hover { border-color: rgba(255,94,0,0.2); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-icon { font-size: 2rem; line-height: 1; }
.kpi-label { font-size: 0.78rem; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.kpi-value { font-family: var(--font-title); font-size: 1.6rem; font-weight: 800; color: var(--text-1); display: block; margin-top: 2px; }

.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-card {
    background: var(--bg-1); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm);
}
.chart-title { font-size: 0.95rem; font-weight: 700; color: var(--text-1); margin-bottom: 16px; }
.top-products-card { grid-column: 1 / -1; }

.donut-svg { width: 160px; height: 160px; display: block; margin: 0 auto; }
.chart-donut-area { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }

/* ============================================================
   HISTORIAL
   ============================================================ */
.historial-layout { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.historial-header { display: flex; align-items: center; justify-content: space-between; }
.historial-table-wrapper { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); background: var(--bg-1); box-shadow: var(--shadow-sm); }
.historial-table { width: 100%; border-collapse: collapse; }
.historial-table thead { background: var(--bg-2); border-bottom: 1px solid var(--border); }
.historial-table th {
    padding: 12px 14px; text-align: left;
    font-size: 0.78rem; font-weight: 700; color: var(--text-2);
    text-transform: uppercase; letter-spacing: 0.05em;
    white-space: nowrap;
}
.historial-table td {
    padding: 12px 14px; font-size: 0.85rem; color: var(--text-1);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.historial-table tr:last-child td { border-bottom: none; }
.historial-table tbody tr { transition: background 0.1s; }
.historial-table tbody tr:hover { background: var(--bg-2); }
.historial-table tbody tr.voided { opacity: 0.5; background: var(--bg-3); }
.historial-table tbody tr.cancelled td { color: var(--red); }
.historial-table tbody tr.test td { color: var(--text-3); font-style: italic; }
.historial-empty { text-align: center; padding: 32px; color: var(--text-3); }

.badge-method {
    display: inline-block; padding: 3px 8px; border-radius: 99px;
    font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
}
.badge-efectivo  { background: rgba(22,163,74,0.1);  color: var(--green);  border: 1px solid rgba(22,163,74,0.2); }
.badge-tarjeta   { background: rgba(37,99,235,0.1);  color: var(--blue);   border: 1px solid rgba(37,99,235,0.2); }
.badge-transferencia { background: rgba(147,51,234,0.1); color: var(--purple); border: 1px solid rgba(147,51,234,0.2); }

.badge-status {
    display: inline-block; padding: 3px 8px; border-radius: 99px;
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em;
    cursor: pointer; transition: var(--t-fast);
}
.badge-creado      { background: rgba(22,163,74,0.1);  color: var(--green);  border: 1px solid rgba(22,163,74,0.2); }
.badge-cancelada   { background: #fef2f2;               color: var(--red);   border: 1px solid #fecaca; }
.badge-test        { background: rgba(147,51,234,0.1);  color: var(--purple); border: 1px solid rgba(147,51,234,0.2); }

/* Historial Batch Actions & Row */
.historial-batch-actions {
    display: flex; gap: 8px; align-items: center;
    background: var(--bg-2); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 8px 12px;
    margin-bottom: 12px; opacity: 0.5; pointer-events: none; transition: var(--t-fast);
}
.historial-batch-actions.active { opacity: 1; pointer-events: auto; }
.historial-table tbody tr { cursor: pointer; }
.historial-table tbody tr.selected { background: rgba(255,94,0,0.05); }
.historial-table input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* Transaction Details Modal */
.tx-detail-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.tx-detail-row:last-child { border-bottom: none; }
.tx-detail-label { color: var(--text-2); font-weight: 600; }
.tx-detail-val { color: var(--text-1); text-align: right; }
.tx-items-list { margin-top: 12px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px; }
.tx-item-row { display: flex; justify-content: space-between; font-size: 0.85rem; padding: 4px 0; }

/* ============================================================
   TOAST & MODALS
   ============================================================ */
.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: var(--bg-1); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 12px 22px;
    font-size: 0.9rem; font-weight: 600; color: var(--text-1);
    box-shadow: var(--shadow-lg); z-index: 9999;
    animation: toastIn 0.3s ease; white-space: nowrap;
    pointer-events: none;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(16px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
.toast.success { border-left: 4px solid var(--green); }
.toast.error   { border-left: 4px solid var(--red); }

.modal-overlay {
    position: fixed; inset: 0; z-index: 9000;
    background: rgba(0,0,0,0.45); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    /* Block ALL touch events going to background */
    touch-action: none;
    overscroll-behavior: contain;
}
.modal-card {
    background: var(--bg-1); border: 1px solid var(--border);
    border-radius: var(--radius-xl); padding: 28px;
    max-width: 460px; width: 100%;
    max-height: 90dvh; overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.25s ease;
    position: relative;
    /* Allow scroll inside modal card but block it leaking out */
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
.modal-title { font-size: 1.2rem; margin-bottom: 16px; color: var(--text-1); }
.modal-body { font-size: 0.9rem; color: var(--text-2); line-height: 1.5; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.modal-close-x {
    position: absolute; top: 14px; right: 14px;
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-3); font-size: 1.2rem; transition: var(--t-fast);
    background: transparent;
}
.modal-close-x:hover { background: var(--bg-3); color: var(--text-1); }

.input-styled {
    width: 100%; background: var(--bg-1); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 10px 14px;
    color: var(--text-1); font-size: 0.95rem; margin-bottom: 12px;
    transition: border-color 0.15s;
    min-height: 44px;
}
.input-styled:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 2px rgba(255,94,0,0.1); }
label.field-label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }

/* Product edit modal preview */
.prod-img-preview {
    width: 100%; height: 140px; object-fit: cover;
    border-radius: var(--radius-md); border: 1px solid var(--border);
    margin-bottom: 12px; background: var(--bg-2);
}

/* Mobile close cart hidden by default */
.mobile-close-cart { display: none !important; }

/* Backdrop */
.cart-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    z-index: 998; backdrop-filter: blur(3px);
    opacity: 0; pointer-events: none; transition: opacity 0.25s ease;
}
.cart-backdrop.show { opacity: 1; pointer-events: auto; }

/* Banner */
.mobile-cart-banner {
    position: fixed; bottom: 16px; left: 16px; right: 16px;
    background: var(--bg-1); border: 1px solid var(--border);
    border-radius: var(--radius-xl); padding: 12px 20px;
    display: none; /* Hidden by default */
    align-items: center; justify-content: space-between;
    box-shadow: var(--shadow-lg); z-index: 997;
    animation: slideUp 0.3s cubic-bezier(0.4,0,0.2,1);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    background: rgba(255, 255, 255, 0.95);
}
.cart-banner-info { display: flex; align-items: center; gap: 8px; font-size: 0.95rem; color: var(--text-1); }
.cart-banner-icon { font-size: 1.2rem; }
.cart-banner-divider { color: var(--text-3); }

/* Responsive adjustments */
@media (max-width: 860px) {
    .pos-layout { grid-template-columns: 1fr; height: calc(100vh - 56px); overflow: hidden; }
    .catalog-panel { height: 100%; border-right: none; overflow: hidden; }
    /* Contain scroll only inside product grid */
    .product-grid { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
    .header-brand .header-title { display: none; }
    .user-email-tag { display: none; }
    .header-brand, .header-user { min-width: auto; }
    
    .mobile-cart-banner.active {
        display: flex;
    }

    /* Order panel becomes a bottom drawer */
    .order-panel {
        position: fixed; bottom: 0;
        left: 0; right: 0;
        width: 100%;
        height: 72dvh; max-height: 72dvh;
        z-index: 999; background: var(--bg-1);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        box-shadow: 0 -10px 25px rgba(0,0,0,0.15);
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding: 16px;
        display: flex; flex-direction: column;
        gap: 12px; overflow: hidden !important;
    }
    
    /* Shrink the drawer when keyboard is open */
    .order-panel.keyboard-active {
        height: 46dvh !important;
        max-height: 46dvh !important;
    }
    
    .order-panel.open {
        transform: translateY(0);
    }
    .mobile-close-cart { display: flex !important; align-items: center; justify-content: center; }
}

/* On wider tablets, center the drawer nicely */
@media (min-width: 601px) and (max-width: 860px) {
    .order-panel {
        left: 50% !important;
        right: auto !important;
        width: min(92%, 500px) !important;
        transform: translateX(-50%) translateY(100%) !important;
    }
    .order-panel.open {
        transform: translateX(-50%) translateY(0) !important;
    }
}

@media (max-width: 600px) {
    .product-grid { grid-template-columns: repeat(2, 1fr); }
    .charts-grid { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .app-tabs .tab-btn span { display: none; }
    .app-tabs .tab-btn svg { width: 20px; height: 20px; }
    
    .order-item { flex-wrap: wrap; position: relative; padding-right: 40px; }
    .order-item-info { width: 100%; flex: none; }
    .order-item-qty { width: 100%; justify-content: flex-start; margin-top: 6px; }
    .order-item-remove { position: absolute; right: 8px; top: 8px; }
}

/* Scroll lock when modal/drawer is open */
body.modal-open {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden !important;
    touch-action: none;
    -webkit-overflow-scrolling: none;
}

/* Hide tests toggle */
.historial-table.hide-tests tr.test { display: none !important; }
