/* ================================================================
   POS SYSTEM — Master Stylesheet
   Bootstrap 5.3 base + all POS-specific components
   File location: <your-ci4-project>/public/assets/css/pos.css
   ================================================================ */

/* ----------------------------------------------------------------
   CSS VARIABLES
   ---------------------------------------------------------------- */
:root {
    --pos-sidebar-width:    230px;
    --pos-sidebar-bg:       #1a1d23;
    --pos-sidebar-hover:    #2a2e38;
    --pos-sidebar-active:   #0d6efd;
    --pos-navbar-height:    56px;
    --pos-text-muted:       #8b9199;
    --pos-section-label:    #5a6170;
    --pos-border:           #e9ecef;
    --pos-bg-page:          #f4f6f9;
    --pos-bg-white:         #ffffff;
    --pos-bg-light:         #f8fafc;
}

/* ----------------------------------------------------------------
   BASE
   ---------------------------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    background-color: var(--pos-bg-page);
    font-size: 0.875rem;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: #212529;
}

/* ----------------------------------------------------------------
   TOP NAVBAR
   ---------------------------------------------------------------- */
.pos-navbar {
    background: var(--pos-bg-white);
    border-bottom: 1px solid var(--pos-border);
    height: var(--pos-navbar-height);
    z-index: 1030;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

/* ----------------------------------------------------------------
   SIDEBAR
   ---------------------------------------------------------------- */
.pos-sidebar {
    width: var(--pos-sidebar-width);
    min-width: var(--pos-sidebar-width);
    background: var(--pos-sidebar-bg);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform 0.2s ease;
    z-index: 1020;
    flex-shrink: 0;
}

.sidebar-nav {
    padding: 0.5rem 0 2rem;
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* details/summary collapsible group */
.sidebar-group {
    display: block;
    width: 100%;
}

.sidebar-group summary {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.8rem 1.1rem;
    color: #c9ced6;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    background-color: transparent;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
    user-select: none;
    list-style: none;
}

.sidebar-group summary::-webkit-details-marker {
    display: none;
}

.sidebar-group summary::marker {
    display: none;
    content: '';
}

.sidebar-group summary:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.sidebar-group summary i {
    font-size: 1.1rem;
    width: 1.2rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-group summary .toggle-icon {
    margin-left: auto;
    font-size: 0.8rem;
    transition: transform 0.2s ease;
    color: #c9ced6;
}

.sidebar-group[open] summary {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.sidebar-group[open] summary .toggle-icon {
    transform: rotate(90deg);
    color: #ffffff;
}

.sidebar-group-content {
    background: rgba(255, 255, 255, 0.03);
    padding: 0.5rem 0;
    width: 100%;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.6rem 1.1rem;
    color: #c9ced6;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    text-decoration: none;
}

.sidebar-link.active {
    background: rgba(13, 110, 253, 0.15);
    color: #fff;
    border-left-color: #0d6efd;
    font-weight: 600;
}

.sidebar-link i {
    font-size: 1.05rem;
    width: 1.2rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-link .link-badge {
    margin-left: auto;
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.15);
    color: #c9ced6;
    padding: 0.25rem 0.5rem;
    border-radius: 10px;
}
.dashboard-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.7rem 1.1rem;
    margin: 0.3rem 0.6rem 0.5rem;
    color: #fff;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    background: linear-gradient(135deg, #0d6efd, #0a58ca);
    border-radius: 8px;
    transition: background 0.15s, transform 0.15s;
    white-space: nowrap;
    cursor: pointer;
    border: none;
}

.dashboard-link:hover {
    background: linear-gradient(135deg, #0b5ed7, #084298);
    color: #fff;
    text-decoration: none;
    transform: translateX(2px);
}

.dashboard-link i {
    font-size: 1.1rem;
    width: 1.2rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-group-divider {
    height: 1px;
    background: rgba(255,255,255,0.08);
    margin: 0.3rem 1.1rem;
}

.sidebar-group-label {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--pos-section-label);
    padding: 0.5rem 1.1rem 0.2rem;
    text-transform: uppercase;
    user-select: none;
}

/* ----------------------------------------------------------------
   MAIN CONTENT AREA
   ---------------------------------------------------------------- */
.pos-main {
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    min-width: 0;
    flex: 1;
}

/* ----------------------------------------------------------------
   PAGE HEADER
   ---------------------------------------------------------------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--pos-border);
}

.page-header h1 {
    font-size: 1.35rem;
    font-weight: 600;
    color: #2d3748;
    margin: 0;
    line-height: 1.3;
}

/* ----------------------------------------------------------------
   CARDS
   ---------------------------------------------------------------- */
.card {
    border: 1px solid var(--pos-border);
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
    border-radius: 0.5rem;
}

.card-header {
    background: var(--pos-bg-white);
    border-bottom: 1px solid var(--pos-border);
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.85rem 1.1rem;
    color: #374151;
}

.card-footer {
    background: var(--pos-bg-light);
    border-top: 1px solid var(--pos-border);
    padding: 0.6rem 1.1rem;
    font-size: 0.82rem;
}

/* ----------------------------------------------------------------
   STAT / KPI CARDS  (Dashboard & Reports)
   ---------------------------------------------------------------- */
.stat-card {
    border-radius: 0.5rem;
    padding: 1.1rem 1.25rem;
    border: 1px solid transparent;
    height: 100%;
}

.stat-card .stat-value {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1.2;
    margin: 0.15rem 0;
}

.stat-card .stat-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.8;
    margin-bottom: 0.1rem;
}

.stat-card .stat-icon {
    font-size: 2rem;
    opacity: 0.18;
    line-height: 1;
}

/* ----------------------------------------------------------------
   STATUS BADGES
   ---------------------------------------------------------------- */
.status-badge {
    display: inline-block;
    font-size: 0.70rem;
    padding: 0.2rem 0.55rem;
    border-radius: 20px;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
    line-height: 1.4;
}

.badge-completed    { background: #d1fae5; color: #065f46; }
.badge-voided       { background: #fee2e2; color: #991b1b; }
.badge-pending      { background: #fef3c7; color: #92400e; }
.badge-active       { background: #d1fae5; color: #065f46; }
.badge-suspended    { background: #fee2e2; color: #991b1b; }
.badge-in-stock     { background: #d1fae5; color: #065f46; }
.badge-low-stock    { background: #fef3c7; color: #92400e; }
.badge-out-of-stock { background: #fee2e2; color: #991b1b; }
.badge-closed       { background: #e2e8f0; color: #475569; }
.badge-draft        { background: #f1f5f9; color: #64748b; }
.badge-approved     { background: #dbeafe; color: #1e40af; }

/* ----------------------------------------------------------------
   TABLES
   ---------------------------------------------------------------- */
.table-sm td,
.table-sm th {
    vertical-align: middle;
}

.table > :not(caption) > * > * {
    padding: 0.45rem 0.75rem;
}

/* DataTables overrides */
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    padding: 0.3rem 0.65rem;
    font-size: 0.82rem;
    margin-left: 0.4rem;
}

.dataTables_wrapper .dataTables_length select {
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.82rem;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: 0.375rem !important;
    font-size: 0.82rem;
}

/* ----------------------------------------------------------------
   AVATAR
   ---------------------------------------------------------------- */
.avatar-circle-sm {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #0d6efd;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
    user-select: none;
}

/* ----------------------------------------------------------------
   LOGIN PAGE  (standalone — no sidebar)
   ---------------------------------------------------------------- */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1d23 0%, #2d3748 100%);
    padding: 1rem;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 0.75rem;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    padding: 2.5rem;
}

.login-logo {
    text-align: center;
    margin-bottom: 1.75rem;
}

.login-logo i {
    font-size: 2.5rem;
    color: #0d6efd;
}

/* ----------------------------------------------------------------
   POS TERMINAL LAYOUT  (2-column grid)
   ---------------------------------------------------------------- */
.pos-terminal-layout {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 1rem;
    height: calc(100vh - var(--pos-navbar-height) - 2rem);
    min-height: 500px;
}

/* LEFT panel — product search + cart items */
.pos-product-panel {
    background: var(--pos-bg-white);
    border-radius: 0.5rem;
    border: 1px solid var(--pos-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* RIGHT panel — totals + checkout */
.pos-cart-panel {
    background: var(--pos-bg-white);
    border-radius: 0.5rem;
    border: 1px solid var(--pos-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Search bar strip at top of left panel */
.pos-search-bar {
    padding: 0.75rem;
    border-bottom: 1px solid var(--pos-border);
    background: var(--pos-bg-light);
    flex-shrink: 0;
}

/* Cart panel header */
.pos-cart-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--pos-border);
    font-weight: 600;
    font-size: 0.9rem;
    background: var(--pos-bg-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

/* Scrollable cart items area */
.pos-cart-items {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.35rem;
    min-height: 0;
}

/* Individual cart row */
.cart-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 0.4rem;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.82rem;
    transition: background 0.1s;
}

.cart-item:last-child { border-bottom: none; }
.cart-item:hover      { background: #fafbff; }

.cart-item-name {
    flex: 1;
    font-weight: 500;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #1e293b;
}

/* Quantity +/- controls */
.cart-qty-control {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex-shrink: 0;
}

.cart-qty-btn {
    width: 24px;
    height: 24px;
    border: 1px solid #dee2e6;
    background: #f8f9fa;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0;
    line-height: 1;
    color: #374151;
    transition: background 0.1s;
    user-select: none;
}

.cart-qty-btn:hover    { background: #e2e8f0; }
.cart-qty-btn:active   { background: #cbd5e1; }

.cart-qty-input {
    width: 44px;
    height: 24px;
    text-align: center;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 0.82rem;
    padding: 0;
    color: #1e293b;
    background: #fff;
}

.cart-qty-input:focus {
    outline: none;
    border-color: #0d6efd;
    box-shadow: 0 0 0 2px rgba(13,110,253,.15);
}

.cart-item-price {
    font-weight: 600;
    min-width: 72px;
    text-align: right;
    color: #1e293b;
    flex-shrink: 0;
    font-size: 0.83rem;
}

.cart-remove-btn {
    color: #ef4444;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    font-size: 0.9rem;
    opacity: 0.5;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    transition: opacity 0.1s;
}

.cart-remove-btn:hover { opacity: 1; }

/* Cart totals section */
.pos-cart-totals {
    border-top: 2px solid var(--pos-border);
    padding: 0.7rem 1rem;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.pos-cart-totals .total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.12rem 0;
    gap: 0.5rem;
}

.pos-cart-totals .grand-total {
    font-size: 1.15rem;
    font-weight: 700;
    color: #0d6efd;
    border-top: 1px solid var(--pos-border);
    margin-top: 0.4rem;
    padding-top: 0.4rem;
}

/* Checkout / action buttons strip */
.pos-cart-actions {
    padding: 0.65rem;
    border-top: 1px solid var(--pos-border);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    flex-shrink: 0;
}

/* ----------------------------------------------------------------
   PRODUCT SEARCH DROPDOWN
   ---------------------------------------------------------------- */
.product-search-results {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0 0 0.5rem 0.5rem;
    box-shadow: 0 6px 20px rgba(0,0,0,.12);
    max-height: 340px;
    overflow-y: auto;
    z-index: 1050;
}

.product-result-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.9rem;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.82rem;
    transition: background 0.1s;
}

.product-result-item:last-child { border-bottom: none; }
.product-result-item:hover      { background: #eff6ff; }

.product-result-item.out-of-stock {
    opacity: 0.45;
    cursor: not-allowed;
}

.product-result-item .stock-badge {
    font-size: 0.70rem;
    padding: 0.1rem 0.4rem;
    flex-shrink: 0;
}

/* ----------------------------------------------------------------
   SHIFT MANAGEMENT
   ---------------------------------------------------------------- */

/* Denomination count table inputs */
.denom-count {
    width: 90px;
    text-align: center;
}

.denom-subtotal {
    font-weight: 600;
    color: #0f172a;
}

/* Variance colour helpers */
.variance-over   { color: #059669; font-weight: 700; }
.variance-short  { color: #dc2626; font-weight: 700; }
.variance-zero   { color: #6b7280; }

/* ----------------------------------------------------------------
   RECEIPT / PRINT
   ---------------------------------------------------------------- */
.receipt-screen-wrapper {
    max-width: 520px;
    margin: 2rem auto;
}

.receipt-card {
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 4px 20px rgba(0,0,0,.1);
    overflow: hidden;
}

.receipt-top-bar {
    background: #1a1d23;
    color: #fff;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.receipt-body {
    padding: 1.5rem;
}

/* Thermal / monospace receipt styles */
.receipt-thermal {
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    line-height: 1.45;
    color: #000;
}

.receipt-center   { text-align: center; }
.receipt-right    { text-align: right; }
.receipt-bold     { font-weight: 700; }
.receipt-large    { font-size: 16px; font-weight: 700; }

.receipt-divider {
    border-top: 1px dashed #666;
    margin: 0.5rem 0;
}

.receipt-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.1rem;
    gap: 0.5rem;
}

.receipt-row .label { flex: 1; }
.receipt-row .value { text-align: right; min-width: 80px; flex-shrink: 0; }

.item-row          { margin-bottom: 0.3rem; }
.item-row .item-name   { font-weight: 600; word-break: break-word; }
.item-row .item-detail {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #555;
}

.receipt-screen-actions {
    text-align: center;
    margin-top: 1rem;
    padding-bottom: 2rem;
}

.void-stamp {
    color: #dc3545;
    border: 3px solid #dc3545;
    display: inline-block;
    padding: 0.2rem 0.8rem;
    font-weight: 900;
    font-size: 1.4rem;
    transform: rotate(-12deg);
    letter-spacing: 0.1em;
    margin: 0.5rem auto;
}

/* ----------------------------------------------------------------
   STOCK LEVEL SPARKLINE
   ---------------------------------------------------------------- */
#ledgerSparkline {
    display: block;
    width: 100% !important;
    max-height: 40px;
}

/* ----------------------------------------------------------------
   TOGGLE PASSWORD (change password page)
   ---------------------------------------------------------------- */
.toggle-pw { line-height: 1; }

/* Requirement list items on change-password */
#pwRequirements li {
    transition: color 0.2s;
    font-size: 0.8rem;
    padding: 0.05rem 0;
}

/* ----------------------------------------------------------------
   FORMS — General helpers
   ---------------------------------------------------------------- */
.conversion-row {
    animation: fadeInRow 0.15s ease;
}

@keyframes fadeInRow {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Margin preview box on product form */
#marginInfo {
    font-size: 0.78rem;
    transition: background 0.3s, border-color 0.3s;
}

/* ----------------------------------------------------------------
   PRINT — Global rules
   ---------------------------------------------------------------- */
@media print {
    .pos-navbar,
    .pos-sidebar,
    .pos-cart-actions,
    .no-print,
    .btn,
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        display: none !important;
    }

    body         { background: #fff !important; }
    .card        { box-shadow: none !important; border: 1px solid #ccc !important; }
    .pos-main    { overflow: visible !important; }

    /* Shift report print */
    .receipt-wrapper {
        width: 80mm;
        font-size: 12px;
        font-family: 'Courier New', monospace;
    }

    /* Receipt page print — match thermal width */
    .receipt-screen-wrapper { max-width: 100%; margin: 0; }
    .receipt-top-bar        { display: none !important; }
    .receipt-card           { box-shadow: none; border-radius: 0; }
    .receipt-body           { padding: 0.25rem; }
    .receipt-thermal        { font-size: 11px; }
}

/* ----------------------------------------------------------------
   RESPONSIVE — Mobile
   ---------------------------------------------------------------- */
@media (max-width: 991.98px) {
    /* Sidebar becomes an off-canvas drawer */
    .pos-sidebar {
        position: fixed;
        top: var(--pos-navbar-height);
        left: 0;
        height: calc(100vh - var(--pos-navbar-height));
        transform: translateX(-100%);
    }

    .pos-sidebar.show {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,.25);
    }

    /* POS terminal stacks vertically on small screens */
    .pos-terminal-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    .pos-product-panel { min-height: 400px; }
    .pos-cart-panel    { min-height: 300px; }
}

@media (max-width: 767.98px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .stat-card .stat-value { font-size: 1.35rem; }

    .receipt-screen-wrapper { margin: 0.5rem; }
}

@media (max-width: 575.98px) {
    .pos-cart-totals .grand-total { font-size: 1rem; }
    body { font-size: 0.82rem; }
}