/*
 * ============================================================================
 * POS (Point of Sale) Custom Styles — Metronic-Compatible Refactor
 * ============================================================================
 *
 * IMPORTANT CHANGES (vs. original):
 *
 * 1. SCOPED ALL POS STYLES under the #pos-wrapper parent or POS-specific IDs.
 *    The old file loaded globally via app.blade.php and was overriding:
 *      - body, .app-content backgrounds (with !important)
 *      - .card, .form-control, .form-select (globally — broke every page)
 *      - .bg-body, .text-dark, .text-muted, .text-white (inverted colors everywhere)
 *    These global overrides have been REMOVED. POS pages should add the
 *    `pos-page` class to the <body> tag if they need body-level theming.
 *
 * 2. REMOVED all !important except on #btn-checkout:disabled (required to
 *    override the gradient background).
 *
 * 3. Replaced hardcoded colors with CSS custom properties for maintainability.
 *
 * 4. All Metronic utility classes (.card, .form-control, .form-select, .btn,
 *    .text-dark, .text-muted, etc.) are NO LONGER overridden at root level.
 *
 * POTENTIAL BREAKING CHANGES:
 *
 * - If any non-POS page relied on the dark `.card` background (#1e3a5f),
 *   dark `.form-control`/`.form-select`, or inverted `.text-dark`/`.text-muted`,
 *   those pages will revert to Metronic defaults (which is the correct behavior).
 *
 * - POS pages that previously inherited `body { background: var(--pos-bg) }`
 *   now need the `pos-page` body class for the same effect. Both pos.blade.php
 *   and posAddProducts.blade.php already use #pos-wrapper so all child styles
 *   continue to work without any template changes.
 * ============================================================================
 */


/* ============================================================================
 * 1. POS DESIGN TOKENS (Custom Properties)
 *    Scoped under #pos-wrapper so they don't leak into global Metronic scope.
 * ============================================================================ */
#pos-wrapper {
    --pos-bg: #68738c;
    --pos-surface: #1e293b;
    --pos-card: #1e2d3d;
    --pos-border: #334155;
    --pos-accent: #3b82f6;
    --pos-success: #10b981;
    --pos-danger: #ef4444;
    --pos-warning: #f59e0b;
    --pos-text: #f1f5f9;
    --pos-muted: #94a3b8;
    --pos-input-bg: #0f172a;
}


/* ============================================================================
 * 2. OPTIONAL BODY-LEVEL THEME (opt-in via `pos-page` class on <body>)
 *    Instead of forcing `body !important`, POS views can add this class.
 *    This avoids polluting every page in the app.
 * ============================================================================ */
body.pos-page,
body.pos-page .app-content {
    background: #68738c;
}


/* ============================================================================
 * 3. POS LAYOUT — Grid wrapper
 * ============================================================================ */
#pos-wrapper {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 12px;
    height: 60%;
    max-height: 60%;
}

@media (max-width: 992px) {
    #pos-wrapper {
        grid-template-columns: 1fr;
        height: auto;
    }
    #pos-right {
        order: -1;
    }
}


/* ============================================================================
 * 4. SEARCH BAR
 * ============================================================================ */
#search-wrap {
    background: var(--pos-surface);
    border-radius: 12px;
    padding: 14px 16px;
    border: 1px solid var(--pos-border);
    margin-bottom: 12px;
}

#pos-search {
    background: var(--pos-input-bg);
    border: 2px solid var(--pos-accent);
    border-radius: 8px;
    color: var(--pos-text);
    font-size: 1.25rem;
    padding: 10px 16px;
    width: 100%;
    outline: none;
    transition: border-color 0.15s;
}

#pos-search:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

#pos-search::placeholder {
    color: var(--pos-muted);
}


/* ============================================================================
 * 5. SEARCH RESULTS DROPDOWN
 * ============================================================================ */
#search-results {
    position: absolute;
    z-index: 999;
    background: var(--pos-surface);
    border: 1px solid var(--pos-border);
    border-radius: 8px;
    max-height: 300px;
    overflow-y: auto;
    width: calc(100% - 32px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    display: none;
}

.sr-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--pos-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--pos-text);
    transition: background 0.1s;
}

.sr-item:hover,
.sr-item.active {
    background: rgba(59, 130, 246, 0.2);
}

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

.sr-item .sr-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.sr-item .sr-meta {
    font-size: 0.78rem;
    color: var(--pos-muted);
}

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


/* ============================================================================
 * 6. CART TABLE
 * ============================================================================ */
#cart-wrap {
    background: var(--pos-surface);
    border-radius: 12px;
    border: 1px solid var(--pos-border);
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#cart-wrap h6 {
    padding: 12px 16px;
    margin: 0;
    border-bottom: 1px solid var(--pos-border);
    color: var(--pos-text);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

#cart-table-wrap {
    overflow-y: auto;
    flex: 1;
}

#cart-table {
    width: 100%;
    border-collapse: collapse;
}

#cart-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

#cart-table th {
    background: #0f172a;
    color: var(--pos-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 10px;
    border-bottom: 1px solid var(--pos-border);
}

#cart-table td {
    padding: 8px 10px;
    color: var(--pos-text);
    border-bottom: 1px solid #1a2740;
    vertical-align: middle;
    font-size: 0.9rem;
}

/* Cart row interactions */
.cart-row {
    cursor: pointer;
    transition: background 0.1s;
}

.cart-row:hover {
    background: rgba(59, 130, 246, 0.08);
}

/* KEPT !important: Required to ensure JS-toggled class always wins over :hover */
.cart-row.selected {
    background: rgba(59, 130, 246, 0.18) !important;
}

.cart-row td:first-child {
    max-width: 180px;
}

.prod-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
    display: block;
}

.prod-ref {
    font-size: 0.72rem;
    color: var(--pos-muted);
}


/* ============================================================================
 * 7. QUANTITY CONTROLS (inside cart)
 * ============================================================================ */
.qty-ctrl {
    display: flex;
    align-items: center;
    gap: 4px;
}

.qty-btn {
    background: #1e3a5f;
    border: none;
    color: var(--pos-text);
    border-radius: 5px;
    width: 26px;
    height: 26px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.1s;
}

.qty-btn:hover {
    background: var(--pos-accent);
}

.qty-input {
    width: 52px;
    text-align: center;
    background: var(--pos-input-bg);
    border: 1px solid var(--pos-border);
    border-radius: 5px;
    color: var(--pos-text);
    padding: 2px 4px;
    font-size: 0.9rem;
}

.qty-input:focus {
    outline: none;
    border-color: var(--pos-accent);
}


/* ============================================================================
 * 8. PRICE INPUT (inside cart rows)
 * ============================================================================ */
.price-input {
    width: 80px;
    text-align: right;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
    color: var(--pos-success);
    padding: 2px 4px;
    font-size: 0.9rem;
    font-weight: 700;
}

.price-input:focus {
    outline: none;
    border-color: var(--pos-accent);
    background: var(--pos-input-bg);
}


/* ============================================================================
 * 9. DELETE BUTTON (cart row action)
 * ============================================================================ */
.del-btn {
    background: none;
    border: none;
    color: var(--pos-danger);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.1s;
}

.del-btn:hover {
    background: rgba(239, 68, 68, 0.15);
}


/* ============================================================================
 * 10. RIGHT PANEL
 * ============================================================================ */
#pos-right {
    display: flex;
    flex-direction: column;
    gap: 12px;
}


/* ============================================================================
 * 11. POS CARD (custom card component — NOT Metronic .card)
 *     Original file also overrode `.card` globally. That override has been
 *     REMOVED to prevent breaking Metronic cards on every other page.
 * ============================================================================ */
.pos-card {
    background: var(--pos-surface);
    border-radius: 12px;
    border: 1px solid var(--pos-border);
    padding: 16px;
}

.pos-card h6 {
    color: var(--pos-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 12px;
}


/* ============================================================================
 * 12. CLIENT SELECT (scoped to POS)
 * ============================================================================ */
#client-select-wrap select {
    background: var(--pos-input-bg);
    border: 1px solid var(--pos-border);
    border-radius: 8px;
    color: var(--pos-text);
    padding: 8px 12px;
    width: 100%;
    font-size: 0.9rem;
}

#btn-counter-client {
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid var(--pos-accent);
    color: #93c5fd;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 8px;
    width: 100%;
}

#btn-counter-client:hover {
    background: rgba(59, 130, 246, 0.35);
}


/* ============================================================================
 * 13. DISCOUNT ROW
 * ============================================================================ */
.disc-row {
    display: flex;
    gap: 8px;
    align-items: center;
}


/* ============================================================================
 * 14. POS INPUT (custom input class — NOT Metronic .form-control)
 *     Original file overrode `.form-control` and `.form-select` globally,
 *     which broke Metronic form styling on every non-POS page.
 *     Those overrides have been REMOVED. Use `.pos-input` for POS inputs.
 * ============================================================================ */
.pos-input {
    background: var(--pos-input-bg);
    border: 1px solid var(--pos-border);
    border-radius: 8px;
    color: var(--pos-text);
    padding: 7px 10px;
    font-size: 0.9rem;
    width: 100%;
}

.pos-input:focus {
    outline: none;
    border-color: var(--pos-accent);
}

/*
 * Scoped form-control overrides: only inside #pos-wrapper.
 * This ensures Metronic's default .form-control and .form-select
 * remain untouched outside POS pages.
 */
#pos-wrapper .form-control,
#pos-wrapper .form-select {
    background: var(--pos-input-bg);
    border: 1px solid var(--pos-border);
    border-radius: 8px;
    color: var(--pos-text);
}


/* ============================================================================
 * 15. TOTALS
 * ============================================================================ */
.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    color: var(--pos-text);
    font-size: 0.9rem;
}

.total-row.grand {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--pos-success);
    padding-top: 10px;
    border-top: 1px solid var(--pos-border);
    margin-top: 6px;
}

.total-label {
    color: var(--pos-muted);
}


/* ============================================================================
 * 16. PAYMENT
 * ============================================================================ */
#payment-input {
    font-size: 1.1rem;
    font-weight: 600;
    border-color: var(--pos-success);
}

#payment-input:focus {
    border-color: #34d399;
}

#change-display {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid var(--pos-success);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--pos-success);
    text-align: center;
    margin-top: 8px;
}


/* ============================================================================
 * 17. CHECKOUT BUTTON
 * ============================================================================ */
#btn-checkout {
    width: 100%;
    padding: 14px;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 10px;
    background: linear-gradient(135deg, #10b981, #059669);
    border: none;
    color: white;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    letter-spacing: 0.04em;
}

#btn-checkout:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* KEPT !important: Needed to override the gradient on disabled state */
#btn-checkout:disabled {
    background: #374151 !important;
    cursor: not-allowed;
    transform: none;
    opacity: 0.7;
}


/* ============================================================================
 * 18. PRINT OPTIONS
 * ============================================================================ */
#print-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.print-opt {
    flex: 1;
    min-width: 70px;
    cursor: pointer;
}

.print-opt input[type=radio] {
    display: none;
}

.print-opt label {
    display: block;
    text-align: center;
    padding: 7px 4px;
    border: 1px solid var(--pos-border);
    border-radius: 8px;
    color: var(--pos-muted);
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.15s;
}

.print-opt input[type=radio]:checked + label {
    border-color: var(--pos-accent);
    background: rgba(59, 130, 246, 0.15);
    color: var(--pos-text);
}


/* ============================================================================
 * 19. DRAFT INVOICES
 * ============================================================================ */
#drafts-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 140px;
    overflow-y: auto;
}

.draft-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--pos-card);
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    border: 1px solid var(--pos-border);
    transition: background 0.1s;
}

.draft-item:hover {
    background: rgba(59, 130, 246, 0.1);
}

.draft-info {
    font-size: 0.8rem;
    color: var(--pos-text);
}

.draft-meta {
    font-size: 0.7rem;
    color: var(--pos-muted);
}

.draft-actions {
    display: flex;
    gap: 4px;
}


/* ============================================================================
 * 20. BEEP CANVAS (hidden audio helper)
 * ============================================================================ */
#beep-canvas {
    display: none;
}


/* ============================================================================
 * 21. EMPTY CART
 * ============================================================================ */
#cart-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--pos-muted);
    text-align: center;
}

#cart-empty i {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.4;
}


/* ============================================================================
 * 22. NOTIFICATION TOAST
 * ============================================================================ */
#pos-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--pos-success);
    color: white;
    padding: 10px 22px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    white-space: nowrap;
}

#pos-toast.show {
    opacity: 1;
}


/* ============================================================================
 * 23. SHORTCUT BADGES
 * ============================================================================ */
.shortcut-badge {
    background: #1e3a5f;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.7rem;
    color: #93c5fd;
    margin-left: 4px;
}


/* ============================================================================
 * 24. PRICE INPUT IN CART ROWS
 * ============================================================================ */
.purchase-price {
    opacity: 0.1;
    transition: 0.1s;
}

.purchase-price:hover {
    opacity: 0.2;
}


/* ============================================================================
 * REMOVED — GLOBAL OVERRIDES (these were breaking non-POS Metronic pages)
 * ============================================================================
 *
 * The following rules from the original file have been intentionally REMOVED
 * because they overrode core Metronic classes globally:
 *
 *   body { background: var(--pos-bg) !important; }
 *   .app-content { background: var(--pos-bg) !important; }
 *   .card { background: #1e3a5f; }
 *   .form-control { background / border / color overrides }
 *   .form-select { background / border / color overrides }
 *   .bg-body { background-color: #1e3a5f; }
 *   .text-dark { color: var(--bs-white) !important; }
 *   .text-muted { color: var(--bs-white) !important; }
 *   .text-white { color: var(--bs-text-dark) !important; }  ← was inverted (bug)
 *
 * If your POS page needs dark body styling, add class `pos-page` to <body>.
 * If POS inputs need Metronic's .form-control, they are now scoped under
 * #pos-wrapper .form-control (see section 14).
 * ============================================================================ */
