/* ═══════════════════════════════════════════
   Customer Purchase History — v9
   ═══════════════════════════════════════════ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #1a1a1a;
    --card: #262626;
    --border: #3a3a3a;
    --red: #c0392b;
    --red-hover: #a93226;
    --red-light: #e74c3c;
    --text: #e0e0e0;
    --text2: #9ca3af;
    --text3: #6b7280;
    --qoh-red: #e74c3c;
    --qoh-orange: #e67e22;
    --qoh-yellow: #f39c12;
    --qoh-green: #27ae60;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.container { max-width: 540px; margin: 0 auto; padding: 10px 16px; }
.hidden { display: none !important; }

.screen { display: none; animation: fadeIn 0.15s ease; }
.screen.active { display: block; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Shared ── */
.loading-msg { text-align: center; color: var(--text2); padding: 20px 0; font-size: 15px; }
.spinner {
    display: inline-block; width: 16px; height: 16px;
    border: 2px solid #444; border-top-color: var(--red);
    border-radius: 50%; animation: spin 0.6s linear infinite;
    vertical-align: middle; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg { color: var(--red-light); font-size: 15px; margin-top: 10px; text-align: center; min-height: 20px; }

.back-btn {
    background: none; border: none; color: var(--red);
    font-size: 15px; font-weight: 600; cursor: pointer;
    padding: 8px 0; margin-bottom: 8px; min-height: 52px;
    display: flex; align-items: center; transition: opacity 0.15s;
}
.back-btn:active { opacity: 0.7; }

.empty-state { text-align: center; color: var(--text3); padding: 32px 0; font-size: 16px; }
.screen-title { font-size: 18px; font-weight: 700; margin-bottom: 12px; }

.error-banner {
    position: fixed; top: 0; left: 0; right: 0;
    background: var(--red-light); color: #fff;
    text-align: center; padding: 12px 16px;
    font-size: 15px; font-weight: 600; z-index: 2000;
}

/* ═══════════════════════════════════════════
   Login
   ═══════════════════════════════════════════ */
.login-card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 14px; padding: 32px 24px; margin-top: 40px;
}
.login-card h2 { text-align: center; font-size: 20px; font-weight: 700; margin-bottom: 24px; }
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-size: 13px; font-weight: 600; color: var(--text2);
    margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px;
}
.form-group input {
    width: 100%; padding: 14px 16px; background: var(--bg);
    border: 1px solid var(--border); border-radius: 10px;
    color: var(--text); font-size: 17px; outline: none; transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--red); }

.btn-primary {
    width: 100%; padding: 16px; background: var(--red); color: #fff;
    border: none; border-radius: 10px; font-size: 17px; font-weight: 700;
    cursor: pointer; transition: all 0.15s; min-height: 52px; margin-top: 4px;
}
.btn-primary:hover { background: var(--red-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ═══════════════════════════════════════════
   Home
   ═══════════════════════════════════════════ */
.home-header { margin-bottom: 12px; }
.home-header-top {
    display: flex; justify-content: space-between; align-items: center;
    padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.home-header-top h1 { font-size: 17px; font-weight: 700; }
.user-info { font-size: 13px; color: var(--text3); display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.user-info a { color: var(--red); text-decoration: none; font-weight: 600; }

.store-selector-row { display: flex; align-items: center; gap: 8px; padding-top: 8px; }
.store-selector-row label { font-size: 14px; color: var(--text3); font-weight: 600; flex-shrink: 0; }
.store-selector-row select {
    flex: 1; padding: 10px 12px; background: var(--card);
    border: 1px solid var(--border); border-radius: 10px;
    color: var(--text); font-size: 15px; outline: none; cursor: pointer;
    min-height: 48px; transition: border-color 0.2s;
}
.store-selector-row select:focus { border-color: var(--red); }

/* Mode toggle */
.mode-toggle {
    display: flex; gap: 0; margin: 12px 0;
    border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
.mode-btn {
    flex: 1; padding: 12px; background: var(--card); color: var(--text2);
    border: none; font-size: 15px; font-weight: 600; cursor: pointer;
    transition: all 0.15s; min-height: 48px;
}
.mode-btn.active { background: var(--red); color: #fff; }
.mode-btn:not(.active):hover { background: #2e2e2e; }

/* Action bar */
.action-bar { margin-bottom: 12px; }

.btn-scan {
    width: 100%; padding: 14px; background: var(--red); color: #fff;
    border: none; border-radius: 10px; font-size: 17px; font-weight: 700;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    gap: 10px; transition: all 0.15s; margin-bottom: 10px; min-height: 52px;
}
.btn-scan:hover { background: var(--red-hover); }
.btn-scan:active { transform: scale(0.98); }
.btn-scan svg { flex-shrink: 0; }

.manual-entry-row { display: flex; gap: 8px; }
.manual-entry-row input {
    flex: 1; padding: 12px 14px; background: var(--card);
    border: 1px solid var(--border); border-radius: 10px;
    color: var(--text); font-size: 16px; outline: none;
    transition: border-color 0.2s; min-height: 52px;
}
.manual-entry-row input:focus { border-color: var(--red); }
.manual-entry-row input::placeholder { color: #555; }

.btn-go {
    padding: 12px 20px; background: var(--card);
    border: 1px solid var(--border); border-radius: 10px;
    color: var(--text); font-size: 15px; font-weight: 700;
    cursor: pointer; transition: all 0.15s; flex-shrink: 0; min-height: 52px;
}
.btn-go:hover { border-color: var(--red); background: #333; }
.btn-go:active { transform: scale(0.98); }

/* Search results */
.search-results { margin-top: 8px; }
.search-result-card {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--card); border: 1px solid var(--border);
    border-radius: 10px; padding: 14px 16px; margin-bottom: 6px;
    cursor: pointer; transition: border-color 0.15s; min-height: 52px;
}
.search-result-card:hover { border-color: var(--red); }
.search-result-desc { font-size: 15px; font-weight: 500; color: var(--text); }
.search-result-plu { font-size: 12px; color: var(--text3); flex-shrink: 0; margin-left: 10px; font-family: monospace; }

/* ═══════════════════════════════════════════
   Screen 3: Item Customer List
   ═══════════════════════════════════════════ */
.item-header { margin-bottom: 8px; }
.item-header h2 { font-size: 19px; font-weight: 700; line-height: 1.3; }

.item-upc {
    font-size: 13px; color: var(--text3); font-family: monospace;
    margin-top: 2px; letter-spacing: 0.5px;
}

.related-note { font-size: 13px; color: var(--text3); font-style: italic; margin-top: 2px; }

/* Collapsible toggles */
.inv-toggle {
    width: 100%; padding: 10px 14px; background: var(--card);
    border: 1px solid var(--border); border-radius: 10px;
    color: var(--text2); font-size: 14px; font-weight: 700;
    cursor: pointer; text-align: left; transition: border-color 0.15s;
    min-height: 44px;
}
.inv-toggle:hover { border-color: var(--red); }
.inv-toggle::after { content: " \25BC"; font-size: 10px; opacity: 0.6; }
.inv-toggle.open::after { content: " \25B2"; }

/* Deals */
.deals-section { margin-bottom: 8px; }
.deals-content { margin-top: 6px; }

.deal-card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 10px; padding: 16px; margin-bottom: 6px;
}
.deal-card-sm { padding: 12px 16px; }
.deal-card-title {
    font-size: 13px; font-weight: 700; color: var(--text2);
    text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px;
}
.deal-price-row { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.deal-price-main { font-size: 26px; font-weight: 800; color: var(--red); }
.deal-price-per { font-size: 15px; color: var(--text2); font-weight: 500; }
.deal-info { font-size: 13px; color: var(--text3); margin-bottom: 4px; }
.deal-savings {
    display: inline-block; background: rgba(39,174,96,0.15);
    color: var(--qoh-green); font-size: 13px; font-weight: 700;
    padding: 4px 10px; border-radius: 6px; margin-top: 4px;
}
.deal-warning { color: var(--qoh-orange); font-size: 14px; font-weight: 600; margin-top: 4px; }

.zone-badge {
    display: inline-block; font-size: 12px; font-weight: 700;
    padding: 3px 10px; border-radius: 4px; text-transform: uppercase;
}
.zone-green { background: rgba(34,197,94,0.15); color: #22c55e; }
.zone-yellow { background: rgba(234,179,8,0.15); color: #eab308; }
.zone-red { background: rgba(239,68,68,0.15); color: #ef4444; }

.bxgy-badge {
    display: inline-block; background: var(--red); color: #fff;
    font-size: 13px; font-weight: 700; padding: 4px 12px; border-radius: 10px;
}
.loyalty-tag {
    display: inline-block; background: rgba(192,57,43,0.2); color: var(--red);
    font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 4px;
    text-transform: uppercase;
}

.disc-row {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 8px; padding: 12px 14px; margin-bottom: 6px;
}
.disc-row-name { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.disc-row-desc { font-size: 13px; color: var(--text2); }
.disc-row-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.disc-row-price { font-size: 16px; font-weight: 700; color: #fff; }
.disc-row-savings { font-size: 13px; color: var(--qoh-green); font-weight: 600; }
.disc-row-condition { font-size: 12px; color: var(--text2); background: #333; padding: 2px 8px; border-radius: 4px; }

/* Inventory */
.inventory-section { margin-bottom: 8px; }
.inv-table-wrap { margin-top: 6px; }
.inv-table { width: 100%; border-collapse: collapse; font-size: 14px; border-radius: 8px; overflow: hidden; }
.inv-table th {
    text-align: left; padding: 8px 12px; background: #1f1f1f;
    color: var(--text3); font-weight: 700; font-size: 12px;
    text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border);
}
.inv-table th:last-child { text-align: right; }
.inv-table td { padding: 7px 12px; border-bottom: 1px solid #2a2a2a; color: var(--text); font-size: 14px; }
.inv-table td:last-child { text-align: right; font-weight: 700; font-size: 15px; }
.inv-table tr { background: var(--card); }
.inv-table tr.inv-highlight { background: rgba(192,57,43,0.1); }
.inv-qoh-1 { color: var(--qoh-red); }
.inv-qoh-2, .inv-qoh-3 { color: var(--qoh-orange); }
.inv-qoh-4, .inv-qoh-5 { color: var(--qoh-yellow); }
.inv-qoh-6 { color: var(--qoh-green); }

/* Customer count */
.cust-count { font-size: 14px; font-weight: 600; color: var(--text3); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.5px; }

/* Customer cards (used in item-customer list AND customer search results) */
.customer-card {
    background: var(--card); border: 1px solid var(--border);
    border-left: 4px solid var(--red); border-radius: 10px;
    padding: 16px 18px; margin-bottom: 10px; cursor: pointer;
    transition: all 0.15s; box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    min-height: 52px;
}
.customer-card:hover { background: #2c2c2c; }
.customer-card:active { transform: scale(0.99); }
.customer-card .c-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px; }
.customer-card .c-name { font-size: 18px; font-weight: 700; color: #fff; line-height: 1.2; }
.customer-card .c-date { font-size: 13px; color: #d1d5db; flex-shrink: 0; margin-left: 10px; white-space: nowrap; }
.customer-card .c-phone { min-height: 32px; display: flex; align-items: center; }
.customer-card .c-phone .phone-link {
    color: var(--red); text-decoration: none; font-size: 16px; font-weight: 600;
    display: inline-flex; align-items: center; gap: 4px;
    cursor: pointer; min-height: 44px; padding: 4px 0;
}
.customer-card .c-email { font-size: 13px; color: #d1d5db; margin-top: 2px; }

.customer-card-other { border-left-color: #444; }

.store-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    background: rgba(192,57,43,0.2);
    color: var(--red);
    padding: 2px 7px;
    border-radius: 4px;
    margin-left: 8px;
    vertical-align: middle;
    text-transform: uppercase;
}

/* ═══════════════════════════════════════════
   Customer Detail & All Purchases
   ═══════════════════════════════════════════ */
.detail-header { margin-bottom: 10px; }
.detail-header h2 { font-size: 22px; font-weight: 700; color: #fff; line-height: 1.2; }
.detail-item-name { font-size: 15px; color: #d1d5db; margin-top: 2px; }

.detail-contact { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.contact-btn {
    display: flex; align-items: center; justify-content: center; gap: 10px;
    padding: 16px 18px; border-radius: 10px; text-decoration: none;
    font-size: 17px; font-weight: 700; transition: all 0.15s; min-height: 56px;
}
.contact-btn:active { transform: scale(0.98); }
.contact-btn-call { background: var(--red); color: #fff; }
.contact-btn-call:hover { background: var(--red-hover); }
.contact-btn-text { background: #2d5aa0; color: #fff; }
.contact-btn-text:hover { background: #24498a; }
.contact-btn-email { background: #333; color: var(--text); }
.contact-btn-email:hover { background: #3a3a3a; }

/* Purchase rows */
.purchase-row {
    background: var(--card); border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    border-radius: 10px; padding: 14px 16px; margin-bottom: 8px;
}
.purchase-row:nth-child(odd) { border-left-color: #444; }
.purchase-row .row-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.purchase-row .row-date { font-size: 15px; font-weight: 700; color: #fff; }
.badge {
    font-size: 11px; font-weight: 700; padding: 3px 10px;
    border-radius: 10px; text-transform: uppercase; letter-spacing: 0.5px;
}
.badge-scanned { background: var(--red); color: #fff; }
.badge-related { background: #444; color: var(--text2); }
.purchase-row .row-desc { font-size: 14px; color: #ffffff; margin-bottom: 2px; line-height: 1.3; }
.purchase-row .row-upc { font-size: 12px; color: #9ca3af; font-family: monospace; margin-bottom: 4px; }
.purchase-row .row-bottom { display: flex; justify-content: space-between; font-size: 14px; color: #d1d5db; }
.purchase-row .row-bottom .row-store { color: #9ca3af; }

/* Purchase row in all-purchases (tappable) */
.purchase-row.tappable { cursor: pointer; }
.purchase-row.tappable:hover { border-color: var(--red); }

/* Summary bar */
.purchase-summary {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 10px; padding: 16px; margin-top: 12px;
    display: flex; justify-content: space-around; text-align: center;
}
.summary-label { font-size: 11px; color: #9ca3af; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; margin-bottom: 4px; }
.summary-value { font-size: 22px; font-weight: 800; color: #fff; }

/* ═══════════════════════════════════════════
   Phone Call/Text Dropdown
   ═══════════════════════════════════════════ */
.phone-dd-backdrop {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4); z-index: 3000;
}
.phone-dropdown {
    position: fixed; z-index: 3001;
    background: var(--card); border: 1px solid var(--border);
    border-radius: 12px; padding: 6px; min-width: 160px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.phone-dd-option {
    display: block; padding: 14px 18px; color: var(--text);
    text-decoration: none; font-size: 16px; font-weight: 600;
    border-radius: 8px; transition: background 0.1s; min-height: 48px;
    display: flex; align-items: center;
}
.phone-dd-option:hover { background: #333; }

/* ═══════════════════════════════════════════
   Scanner Overlay
   ═══════════════════════════════════════════ */
.scanner-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: #000; z-index: 1000; display: flex; flex-direction: column;
}
.scanner-close {
    position: absolute; top: env(safe-area-inset-top, 12px); right: 12px;
    margin-top: 12px; width: 48px; height: 48px; border: none; border-radius: 50%;
    background: rgba(255,255,255,0.12); color: #fff; font-size: 24px;
    cursor: pointer; z-index: 1001; display: flex; align-items: center; justify-content: center;
}
.scanner-close:active { background: rgba(255,255,255,0.25); }
.scanner-viewport { flex: 1; position: relative; overflow: hidden; }
.scanner-viewport video { width: 100%; height: 100%; object-fit: cover; }
.viewfinder { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 280px; height: 160px; pointer-events: none; }
.viewfinder-border { width: 100%; height: 100%; border: 2px solid rgba(255,255,255,0.5); border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0,0,0,0.55); }
.scan-line { position: absolute; top: 10%; left: 5%; right: 5%; height: 2px; background: var(--red); box-shadow: 0 0 8px var(--red); animation: scanLine 2s ease-in-out infinite; }
@keyframes scanLine { 0%, 100% { top: 10%; } 50% { top: 85%; } }
.scan-flash { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(34,197,94,0.4); opacity: 0; pointer-events: none; transition: opacity 0.15s; }
.scan-flash.active { opacity: 1; }
.scanner-controls { padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 12px; background: rgba(0,0,0,0.7); }
.scan-status { text-align: center; }
.scan-status-text { color: #fff; font-size: 15px; font-weight: 700; text-shadow: 0 1px 4px rgba(0,0,0,0.8); }
.scan-status-dots { display: flex; justify-content: center; gap: 8px; margin-top: 8px; }
.scan-status-dots span { width: 12px; height: 12px; border-radius: 50%; background: rgba(255,255,255,0.2); transition: all 0.15s; }
.scan-status-dots span.lit { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,0.6); }
.torch-btn {
    width: 52px; height: 52px; border: 2px solid rgba(255,255,255,0.25);
    border-radius: 50%; background: rgba(0,0,0,0.4); color: #fff;
    cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.torch-btn:active { border-color: rgba(255,255,255,0.5); }
.torch-btn.active { background: rgba(234,179,8,0.25); border-color: #eab308; color: #eab308; }
.camera-error {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    text-align: center; padding: 28px; background: var(--card);
    border-radius: 14px; border: 1px solid var(--border); max-width: 300px;
}
.camera-error p { color: var(--text2); font-size: 15px; margin-bottom: 8px; }
.camera-error p:first-child { color: var(--text); font-weight: 700; }
.camera-error .btn-primary { margin-top: 12px; width: auto; padding: 12px 28px; }

/* ═══════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════ */
@media (max-width: 360px) {
    .container { padding: 8px 12px; }
    .deal-price-main { font-size: 22px; }
    .summary-value { font-size: 20px; }
    .customer-card .c-name { font-size: 16px; }
}
