:root {
    --primary-color: #008C95;
    --primary-dark: #006C73;
    --secondary-color: #F5A623;
    --background-color: #F4F6F8;
    --surface-color: #FFFFFF;
    --text-color: #333333;
    --text-light: #888888;
    --border-color: #EAEAEA;
    --danger-color: #D0021B;
    --warning-color: #f0ad4e;
    --info-color: #5bc0de;
    --success-color: #28a745;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --border-radius: 12px;
    --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    position: relative;
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* === Toast Notification === */
.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0,0,0,0.7);
    color: white;
    padding: 12px 20px;
    border-radius: 20px;
    z-index: 1000;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s, visibility 0.3s;
}
.toast.show {
    visibility: visible;
    opacity: 1;
}


/* === Loader === */
.loader-container { display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100vh; background-color: var(--surface-color); transition: opacity 0.5s ease; }
/* NEW SPIRAL LOADING */
.spinner { 
    width: 50px; 
    height: 50px; 
    border-radius: 50%; 
    background: conic-gradient(#0000 10%, var(--primary-color)); 
    -webkit-mask: radial-gradient(farthest-side,#0000 calc(100% - 8px),#000 0); 
    mask: radial-gradient(farthest-side,#0000 calc(100% - 8px),#000 0); 
    animation: spin 1s infinite linear; 
}
.loader-container p { font-size: 1.5rem; font-weight: 600; color: var(--primary-color); margin-top: 20px; }
.loader-check { font-size: 3rem; color: var(--primary-color); margin-top: -55px; animation: check-pop 0.3s ease-out; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes check-pop { 0% { transform: scale(0); } 80% { transform: scale(1.2); } 100% { transform: scale(1); } }

/* === App Structure === */
.app-container { display: flex; flex-direction: column; height: 100%; width: 100%; max-width: 600px; margin: 0 auto; background-color: var(--surface-color); position: relative; }
.view { display: none; flex-direction: column; width: 100%; height: 100%; overflow-y: auto; }
.view.active { display: flex; }
.page { padding-bottom: 80px; }
.main-content { flex-grow: 1; overflow-y: auto; background-color: var(--background-color); }

/* === Header === */
.app-header {
    background-color: var(--surface-color);
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
}
.app-header h1 {
    font-size: clamp(1.2rem, 4vw, 1.4rem);
    font-weight: 600;
    text-align: center;
    margin: 0 45px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.add-to-homescreen-btn {
    background-color: transparent;
    color: var(--primary-color);
    border: 1.5px solid var(--primary-color);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: clamp(0.7rem, 2vw, 0.8rem);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
}
.menu-btn, .back-btn {
    background: none;
    border: none;
    padding: 4px;
    color: var(--text-color);
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
}

.page-actions-header {
    padding: 12px 20px;
    background-color: var(--background-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 5;
}
.btn-icon-link {
    background: none;
    border: none;
    color: var(--primary-color);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-icon-link:active {
    color: var(--primary-dark);
}

/* === Onboarding & Permissions === */
.onboarding-content { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 30px; text-align: center; height: 100%; }
.onboarding-content h1, .onboarding-content h2 { font-size: clamp(1.5rem, 6vw, 1.8rem); font-weight: 700; margin-bottom: 12px; }
.onboarding-content p { font-size: clamp(0.9rem, 2.5vw, 1rem); color: var(--text-light); margin-bottom: 24px; max-width: 320px; line-height: 1.5; }
.permission-icon { margin-bottom: 20px; color: var(--primary-color); }
.privacy-policy-link {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 20px;
}
.privacy-policy-link a {
    color: var(--primary-color);
    text-decoration: underline;
    font-weight: 600;
}


/* === Forms === */
.form-group { width: 100%; margin-bottom: 20px; text-align: left; }
.form-group label { display: block; font-weight: 600; margin-bottom: 8px; font-size: clamp(0.85rem, 2.5vw, 0.9rem); }
.form-group input, .form-group select { width: 100%; padding: 14px; border: 1px solid var(--border-color); border-radius: var(--border-radius); font-size: 1rem; background-color: #fafafa; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 2px rgba(0, 140, 149, 0.2); }
.form-row { display: flex; gap: 12px; align-items: flex-end; }
.form-row .form-group { flex: 1; }
.source-info {
    font-size: 0.8rem;
    font-style: italic;
    color: var(--text-light);
    text-align: center;
    margin-top: -8px;
    margin-bottom: 16px;
    background-color: var(--background-color);
    padding: 8px;
    border-radius: 8px;
}
.barcode-display {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
    text-align: center;
    margin-bottom: 16px;
    background-color: var(--background-color);
    padding: 12px;
    border-radius: 8px;
    word-break: break-all;
}
.barcode-display.large {
    font-size: 1.5rem;
    padding: 16px;
    font-weight: 700;
}
.wholesaler-only {
    display: none; /* Hidden by default */
}
.scan-new-barcode-btn {
    margin-top: -10px;
    margin-bottom: 10px;
}
.price-group {
    flex: 2;
}
.unit-group {
    flex: 1;
}
#product-form .btn-icon {
    flex: 1;
    margin-bottom: 20px;
}
.stock-group {
    flex: 2;
}

/* NEW STYLES FOR INPUT ICONS (REPLACED EMOJIS) */
.input-wrapper {
    position: relative;
    width: 100%;
}
.input-wrapper input {
    padding-right: 85px; /* Make space for icons */
    letter-spacing: 2px;
    font-weight: 600;
}
.input-icons {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 4px;
}
.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #888;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s, color 0.2s;
}
.icon-btn:hover {
    background-color: rgba(0,0,0,0.05);
}
.icon-btn:active {
    background-color: rgba(0,0,0,0.1);
}
/* Specific copy color */
#copy-login-pin, #copy-create-pin {
    color: var(--primary-color);
}

/* NEW TRIPLE TOGGLE STYLES */
.sale-type-section {
    margin-bottom: 16px;
    padding-top: 12px;
    border-top: 1px dashed var(--border-color);
}
.triple-toggle-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 12px;
}
.toggle-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-light);
    transition: color 0.3s;
}
.toggle-label.active {
    color: var(--text-color); /* Not text-muted */
}
.text-muted {
    color: var(--text-light);
}

.triple-toggle {
    position: relative;
    display: flex;
    width: 108px;
    height: 32px;
    background-color: rgba(0, 0, 0, 0.08); /* slightly darker background to show track */
    border-radius: 16px;
    border: none;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}
.triple-toggle input[type="radio"] {
    flex: 1;
    opacity: 0;
    cursor: pointer;
    z-index: 3;
    margin: 0;
    height: 100%;
}
.triple-toggle::before, .triple-toggle::after {
    content: '';
    position: absolute;
    top: 25%;
    bottom: 25%;
    width: 2px;
    background-color: rgba(0, 0, 0, 0.15); /* Obvious demarcations */
    border-radius: 1px;
    z-index: 1;
    pointer-events: none;
}
.triple-toggle::before {
    left: 35px;
}
.triple-toggle::after {
    right: 35px;
}
.triple-slider {
    position: absolute;
    top: 2px;
    bottom: 2px;
    width: 32px;
    background-color: #adb5bd; /* Default middle */
    border-radius: 14px;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.5, 1), background-color 0.3s;
    z-index: 2;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Positions based on which radio is checked */
.triple-toggle input[value="discount"]:checked ~ .triple-slider {
    transform: translateX(2px);
    background-color: var(--primary-color);
}
.triple-toggle input[value="default"]:checked ~ .triple-slider {
    transform: translateX(38px); /* middle */
    background-color: #adb5bd;
}
.triple-toggle input[value="credit"]:checked ~ .triple-slider {
    transform: translateX(74px); /* right */
    background-color: #ef4444;
}

.discount-input-container {
    margin-top: 12px;
    animation: slideDown 0.3s ease-out;
}
.discount-input-container label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-light);
}

/* Input layout changes */
.input-with-contact-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}
.input-with-contact-wrapper .input-with-prefix {
    flex: 1; /* By default takes all space */
    transition: width 0.3s;
}
.input-with-contact-wrapper.credit-mode .input-with-prefix {
    width: 70%;
    flex: none;
}
.input-with-contact-wrapper.credit-mode #select-contact-btn {
    display: flex !important;
    width: 30%;
    height: 44px; /* match input height */
    justify-content: center;
    align-items: center;
    background-color: rgba(0,0,0,0.02);
    border-radius: var(--border-radius);
    border: 1px dashed var(--border-color);
    transition: background-color 0.2s;
}
.input-with-contact-wrapper.credit-mode #select-contact-btn:hover {
    background-color: rgba(0,0,0,0.06);
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
/* Modern input with prefix */
.input-with-prefix {
    position: relative;
    width: 100%;
}
.currency-prefix {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-weight: 600;
    color: var(--text-light);
    pointer-events: none;
}
/* UPDATED: Modern input styling for discount box */
.input-with-prefix input {
    width: 100%;
    padding: 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    background-color: #fafafa;
    
    padding-left: 32px !important; /* Space for prefix */
    transition: all 0.2s;
}
.input-with-prefix input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 140, 149, 0.2);
}

.discount-mark {
    font-weight: bold;
    color: var(--primary-color);
    font-size: 0.8em;
    margin-left: 2px;
    vertical-align: super;
}


/* === Buttons === */
button:focus { outline: none; }
.btn { padding: 14px 20px; border: none; border-radius: var(--border-radius); font-size: clamp(0.9rem, 2.5vw, 1rem); font-weight: 600; cursor: pointer; width: 100%; transition: background-color 0.2s; min-height: 48px; }
.btn:disabled { background-color: #ccc; cursor: not-allowed; }
.btn-primary { background-color: var(--primary-color); color: white; }
.btn-primary:active { background-color: var(--primary-dark); }
.btn-secondary { background-color: var(--border-color); color: var(--text-color); }
.btn-secondary:active { background-color: #ddd; }
.btn-danger { background-color: var(--danger-color); color: white; }
.btn-icon {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: var(--border-color);
    color: var(--text-color);
    min-height: 48px;
    padding: 8px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}
.btn-icon.success {
    background-color: #eaf6ec;
    color: var(--success-color);
}
.fab { position: fixed; bottom: 90px; right: 20px; width: 60px; height: 60px; border-radius: 50%; background-color: #000; color: white; display: flex; justify-content: center; align-items: center; box-shadow: 0 4px 15px rgba(0,0,0,0.2); border: none; z-index: 100; transition: opacity 0.3s, transform 0.3s; }
.disabled { opacity: 0.6; pointer-events: none; cursor: not-allowed; transform: scale(0.95); }
.input-error-shake {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}
#product-form .input-error-shake {
    border: 1px solid var(--danger-color) !important;
    box-shadow: 0 0 5px rgba(208, 2, 27, 0.5);
}
@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}


/* === Bottom Navigation & Global Actions === */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; max-width: 600px; margin: 0 auto; height: 70px; display: flex; justify-content: space-around; align-items: center; background-color: var(--surface-color); border-top: 1px solid var(--border-color); box-shadow: 0 -2px 10px rgba(0,0,0,0.05); z-index: 200; }
.nav-btn { background: none; border: none; color: var(--text-light); display: flex; flex-direction: column; align-items: center; font-size: 0.75rem; padding: 8px; transition: color 0.2s; }
.nav-btn svg { margin-bottom: 4px; }
.nav-btn.active { color: var(--primary-color); }
.nav-btn-main { background-color: var(--primary-color); border: none; border-radius: 50%; width: 74px; height: 74px; padding-bottom: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: white; box-shadow: 0 4px 15px rgba(0, 140, 149, 0.4); transform: translateY(-20px); transition: opacity 0.3s, transform 0.3s; position: relative; }
.nav-btn-main span { font-size: 0.7rem; margin-top: 2px; }
.nav-btn span { font-size: 0.75rem; margin-top: 4px; font-weight: 500; }

.onboarding-tooltip {
    position: absolute;
    bottom: 80px;
    right: 20px;
    background-color: var(--primary-color);
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    animation: bounce 2s infinite;
    z-index: 1001;
    max-width: 140px;
    text-align: center;
}
.onboarding-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 30px;
    margin-left: -8px;
    border-width: 14px 8px 0 8px;
    border-style: solid;
    border-color: var(--primary-color) transparent transparent transparent;
}
@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-10px); }
    60% { transform: translateY(-5px); }
}.nav-btn-icon { transition: opacity 0.2s ease-in-out; }
.nav-btn-loader {
    position: absolute;
    width: 32px;
    height: 32px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
}
.nav-btn-main.loading .nav-btn-loader { opacity: 1; }
.nav-btn-main.loading .nav-btn-icon { opacity: 0; }
.receipt-actions { position: fixed; bottom: 0; left: 0; right: 0; max-width: 600px; margin: 0 auto; padding: 16px; background: var(--surface-color); box-shadow: 0 -4px 12px rgba(0,0,0,0.1); display: none; gap: 12px; z-index: 201; transform: translateY(100%); transition: transform 0.3s ease-in-out; }
.receipt-actions.visible { display: flex; transform: translateY(0); }

/* Home View / Dashboard Styles */
#home-view, #all-sales-view { user-select: none; -webkit-user-select: none; }
#home-view.page { padding-bottom: 80px; background: linear-gradient(180deg, var(--primary-color) 200px, var(--background-color) 200px); }
.home-header { padding: 24px 20px; color: white; display: flex; justify-content: space-between; align-items: flex-start; }
.home-header p { font-size: clamp(0.85rem, 2.5vw, 0.9rem); opacity: 0.8; }
.home-header h2 { font-size: clamp(1.5rem, 5vw, 1.75rem); font-weight: 700; margin-top: 4px; }

.scan-emoji {
    display: inline-block;
    font-size: 0.75rem;
}
.home-scan-menu-trigger {
    display: flex; align-items: center; gap: 3px; cursor: pointer; padding: 5px 8px; border-radius: 10px; background: rgba(255,255,255,0.15); backdrop-filter: blur(4px); transition: background 0.2s;
}
.home-scan-menu-trigger:active { background: rgba(255,255,255,0.25); }
.home-scan-menu-trigger span#home-scan-count {
    font-size: 0.7rem; font-weight: 400; color: #fff;
}

.home-content { padding: 0 20px; }
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card { background-color: var(--surface-color); border-radius: var(--border-radius); box-shadow: var(--box-shadow); }
.stat-card { padding: 16px; display: flex; flex-direction: column; }
.stat-icon { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-bottom: 12px; color: white; }
.stat-icon.sales { background-color: var(--primary-color); }
.stat-icon.items { background-color: var(--primary-color); }
.stat-card p { font-size: clamp(0.8rem, 2.5vw, 0.9rem); color: var(--text-light); }
.stat-card h3 { font-size: clamp(1.4rem, 5vw, 1.75rem); font-weight: 700; color: var(--text-color); margin-top: 4px; }

/* Recent & All Sales Styles */
.recent-sales-container { margin-top: 24px; }
.recent-sales-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.recent-sales-header h4 { font-size: clamp(1rem, 3vw, 1.1rem); font-weight: 600; }
.selection-hint { font-size: 0.8rem; color: var(--text-light); }
.see-all-container { text-align: center; margin-top: 16px; margin-bottom: 120px; }
.see-all-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-weight: 600;
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    cursor: pointer;
    padding: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.arrow-icon {
    display: inline-block;
    vertical-align: middle;
}
.sale-item { display: flex; align-items: center; background: var(--surface-color); padding: 12px; border-radius: var(--border-radius); margin-bottom: 10px; box-shadow: 0 2px 6px rgba(0,0,0,0.05); transition: background-color 0.2s, transform 0.2s; position: relative; overflow: hidden; cursor: pointer; }
.sale-item.selectable { cursor: pointer; }
.sale-item.selected { background-color: #E0F3F4; transform: scale(1.02); box-shadow: 0 4px 8px rgba(0, 140, 149, 0.3); }
.sale-item.shared-log::before {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 15px 15px 0 0;
    border-color: var(--primary-color) transparent transparent transparent;
    border-top-left-radius: var(--border-radius);
}
.sale-item-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.6);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}
.sale-item.shake-and-show-overlay {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}
.sale-item.shake-and-show-overlay .sale-item-overlay {
    opacity: 1;
}
.sale-item.shake-restricted {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
    border: 1px solid var(--danger-color); 
}
.sale-item img { width: 40px; height: 40px; border-radius: 8px; margin-right: 12px; object-fit: cover; flex-shrink: 0; }
.sale-info { flex-grow: 1; overflow: hidden; }
.sale-info p { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: clamp(0.9rem, 2.5vw, 1rem); }
.sale-info span { font-size: clamp(0.75rem, 2vw, 0.8rem); color: var(--text-light); }
.sale-price { font-weight: 700; font-size: clamp(1rem, 3vw, 1.1rem); margin-left: 8px; }
.all-sales-container { padding: 20px; }
#stock-levels-view .all-sales-container {
    padding: 16px 20px 20px;
}
.sales-group-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding-bottom: 8px;
    margin-bottom: 12px;
    margin-top: 24px;
    border-bottom: 1px solid var(--border-color);
}
.sales-group:first-child .sales-group-header {
    margin-top: 0;
}
.sales-group-header h3 {
    font-size: 1.1rem;
    color: var(--text-color);
    margin: 0;
}
.sales-group-total {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-color);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}
.sales-group-total.acknowledged {
    color: var(--success-color);
}
.sales-group-total .checkmark-icon {
    stroke: var(--success-color);
}
.sales-legend {
    padding: 10px 20px;
    font-size: 0.8rem;
    color: var(--text-light);
    text-align: center;
    background-color: #f9f9f9;
    border-top: 1px solid var(--border-color);
}
.acknowledgement-text {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--success-color);
    background-color: #eaf6ec;
    padding: 8px 12px;
    border-radius: 8px;
    margin: -8px 0 12px;
    text-align: center;
}

/* === Products View === */
.product-header { padding: 16px 20px 0; display: flex; justify-content: space-between; align-items: center; }
.sku-count { text-align: left; font-size: 0.9rem; font-weight: 500; color: var(--text-light); margin: 0; }
.total-value { text-align: right; font-size: 0.9rem; font-weight: 500; color: var(--text-light); margin: 0; }

/* This new wrapper makes the search and filter controls stick together at the top */
.product-controls-sticky-header {
    background-color: var(--background-color);
    position: sticky;
    top: 0;
    z-index: 6;
    border-bottom: 1px solid var(--border-color);
}

/* Container for the search bar, padding adjusted for the new layout */
#product-search-container {
    padding: 8px 20px 0;
}

/* Search input now has a bottom margin to space it from the filters */
#product-search-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    background-color: var(--surface-color);
    margin-bottom: 12px;
}
#product-search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 140, 149, 0.2);
}

/* Filters are no longer sticky on their own and have adjusted padding */
.product-filter-tabs {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 0 20px 12px;
    overflow-x: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.product-filter-tabs::-webkit-scrollbar {
    display: none;
}
.filter-tab-btn {
    padding: 6px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 20px;
    background-color: var(--surface-color);
    color: var(--text-light);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}
.filter-tab-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}
.filter-tab-btn:not(.active):hover {
    background-color: #f0f0f0;
}
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px; padding: 20px; }
.product-card { background-color: var(--surface-color); border-radius: var(--border-radius); box-shadow: var(--box-shadow); display: flex; flex-direction: column; position: relative; aspect-ratio: 3 / 4; overflow: hidden; }
.product-card-image-wrapper { height: 70%; width: 100%; }
.product-card-image-wrapper img { width: 100%; height: 100%; object-fit: cover; }
.out-of-stock-badge, .restock-badge, .setup-badge { position: absolute; top: 8px; right: 8px; color: white; padding: 4px 8px; font-size: 0.7rem; font-weight: 600; border-radius: 6px; z-index: 4; line-height: 1.2; text-align: center; }
.out-of-stock-badge { background-color: var(--danger-color); }
.restock-badge { background-color: var(--warning-color); }
.setup-badge { background-color: var(--info-color); }
.product-card-info { flex-grow: 1; padding: 8px 10px; display: flex; flex-direction: column; justify-content: center; min-height: 30%; }
.product-card-info h4 {
    font-size: clamp(0.85rem, 2.5vw, 0.95rem);
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 2px;
    white-space: normal;
    overflow-wrap: break-word;
    min-height: 1.2em;
}
.product-price { font-size: clamp(0.9rem, 3vw, 1rem); font-weight: 700; color: var(--primary-color); }
.product-stock { font-size: clamp(0.7rem, 2vw, 0.75rem); color: var(--text-light); margin-top: auto; padding-top: 4px; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--text-light); grid-column: 1 / -1; }
.edit-btn-icon { position: absolute; top: 6px; left: 6px; z-index: 3; background: rgba(255, 255, 255, 0.6); backdrop-filter: blur(2px); border: none; border-radius: 50%; width: 30px; height: 30px; padding: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background-color 0.2s; }
.edit-btn-icon:hover { background: rgba(255, 255, 255, 0.8); }
.edit-btn-icon svg { width: 100%; height: 100%; stroke: var(--text-color); }
.out-of-stock-badge + .edit-btn-icon, .restock-badge + .edit-btn-icon, .setup-badge + .edit-btn-icon { left: 6px; top: 42px; }

.selection-mode .product-card { cursor: pointer; border: 2px solid var(--primary-color); }
.selection-mode .product-card:hover { transform: scale(1.03); box-shadow: 0 6px 15px rgba(0,0,0,0.12); }
.selection-mode .edit-btn-icon { display: none !important; }

/* === Wholesaler View Styles === */
#stock-levels-view .page-actions-header {
    justify-content: space-between;
}
#stock-levels-view .product-filter-tabs {
    padding: 0;
    flex-grow: 1;
    justify-content: flex-start;
}
#retailer-stock-view .card, #salespeople-view .card {
    margin-bottom: 16px;
    box-shadow: var(--box-shadow);
}
.retailer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    margin: 0;
    border-bottom: 1px solid var(--border-color);
    background-color: #f9f9f9;
}
.retailer-header h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.retailer-call-btn, .info-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    padding: 4px;
    cursor: pointer;
    line-height: 0;
    margin-left: 8px;
    flex-shrink: 0;
}
.delete-retailer-btn {
    background: none;
    border: none;
    color: var(--danger-color);
    padding: 4px;
    cursor: pointer;
    margin-left: 8px;
}
.delete-retailer-btn svg {
    width: 20px;
    height: 20px;
}
#retailer-stock-view .retailer-product-list {
    padding: 8px 16px;
}
.retailer-product-item {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-color);
    border-radius: 8px;
    margin: 4px 0;
}
.retailer-product-item:last-child {
    border-bottom: none;
}
.retailer-product-item.out-of-stock {
    background-color: #ffebee;
}
.retailer-product-item.restock-now {
    background-color: #fff8e1;
}
/* Salesperson Card Styles */
.salesperson-summary {
    padding: 12px 16px;
}
.sales-section {
    margin-bottom: 16px;
}
.sales-section:last-child {
    margin-bottom: 0;
}
.sales-section h5 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
}
.sales-today-details .sales-day-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-light);
    padding: 4px 0;
}
.sales-today-details .sales-day-item span:first-child {
    font-weight: 500;
    color: var(--text-color);
}
.sales-today-total {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary-color);
    text-align: right;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--border-color);
}
.sales-day {
    background-color: #fdfdfd;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
}
.sales-day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    margin-bottom: 8px;
}
.sales-day-header strong {
    font-weight: 600;
}
.sales-day-header span {
    font-weight: 700;
    color: var(--primary-dark);
}
.sales-day-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #f0f0f0;
}
.sales-day-buttons {
    display: flex;
    gap: 8px;
}
.sales-day-buttons button {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    border: 1.5px solid;
}
.btn-yes {
    background-color: #eaf6ec;
    color: var(--success-color);
    border-color: var(--success-color);
}
.btn-no {
    background-color: #fee;
    color: var(--danger-color);
    border-color: var(--danger-color);
}

.card-footer {
    padding: 8px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

/* Internet Notice on Stock Levels Screen */
.internet-notice {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin: 0 20px 16px;
    background-color: #fffbe6; /* Light yellow */
    color: #8a6d3b; /* Dark yellow text */
    border: 1px solid #ffeeba; /* Yellow border */
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-weight: 500;
}
.internet-notice svg {
    flex-shrink: 0;
    stroke: #8a6d3b;
}

/* Online Status on Retailer Cards */
.retailer-status {
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 2px;
}
.retailer-status.online { color: #28a745; } /* Green */
.retailer-status.away { color: #fd7e14; } /* Orange */
.retailer-status.offline { color: var(--text-light); } /* Grey */


/* === Camera View === */
.camera-container { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: #000; z-index: 200; justify-content: center; align-items: center; }
#camera-feed { width: 100%; height: 100%; object-fit: cover; }
.camera-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; color: white; }
.scan-box { width: 80vw; height: 40vw; max-width: 400px; max-height: 200px; border: 3px solid rgba(255, 255, 255, 0.8); border-radius: var(--border-radius); box-shadow: 0 0 0 2000px rgba(0,0,0,0.5); position: relative; overflow: hidden; }
.scan-box::after { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, transparent, var(--danger-color), transparent); animation: scan 1.5s infinite ease-in-out; }
.scan-box::before { content: ''; position: absolute; bottom: 0; left: 0; height: 5px; width: 0; background-color: var(--primary-color); animation: scan-timer 3s linear forwards; }
@keyframes scan { 0% { top: 0; } 50% { top: calc(100% - 3px); } 100% { top: 0; } }
@keyframes scan-timer { from { width: 0%; } to { width: 100%; } }
#scan-feedback { margin-top: 24px; font-size: 1.2rem; font-weight: 600; text-shadow: 0 1px 3px rgba(0,0,0,0.5); }
.scan-timer-display { font-size: 2.5rem; font-weight: bold; margin-top: 20px; text-shadow: 0 2px 4px rgba(0,0,0,0.5); }
.cancel-scan-btn { position: absolute; bottom: 40px; left: 50%; transform: translateX(-50%); width: auto; padding: 12px 24px; }

/* === Modals === */
.modal-container { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.6); display: flex; justify-content: center; align-items: center; z-index: 300; padding: 20px; }
.modal-content { position: relative; background-color: var(--surface-color); padding: 24px; border-radius: 16px; width: 100%; max-width: 400px; box-shadow: 0 8px 25px rgba(0,0,0,0.15); animation: modal-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); max-height: 90vh; overflow-y: auto; display: flex; flex-direction: column; }
.modal-content h2 { text-align: center; margin-bottom: 16px; font-size: clamp(1.2rem, 4vw, 1.4rem); }
.modal-content p { text-align: center; margin-bottom: 20px; color: var(--text-light); line-height: 1.5; }
.modal-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 24px; }
.modal-actions-inline { display: flex; flex-direction: row; gap: 12px; }
.modal-actions .btn { flex-grow: 1; }
.modal-actions-inline .btn-secondary { flex-basis: 33.33%; }
.modal-actions-inline .btn-primary { flex-basis: 66.67%; }

#confirm-picture-modal img { width: 100%; max-height: 250px; object-fit: contain; border-radius: var(--border-radius); margin-bottom: 10px; }

#confirm-sale-modal {
    padding-bottom: 0;
    justify-content: flex-end;
}

#confirm-sale-modal .modal-scroll-content {
    overflow-y: auto;
    padding: 0 24px;
    margin: 0 -24px;
}

#confirm-sale-modal .sale-item-details { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
#confirm-sale-modal img { width: 60px; height: 60px; border-radius: 8px; object-fit: cover; }
#confirm-sale-modal h3 { font-size: clamp(1.1rem, 3.5vw, 1.2rem); margin: 0; }
#confirm-sale-modal p { color: var(--text-light); margin: 0; }
.sale-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}
.sale-total p { font-size: clamp(0.9rem, 2.5vw, 1rem); color: var(--text-light); }
.sale-total h2 { margin: 0; color: var(--primary-color); font-size: clamp(1.4rem, 4vw, 1.6rem); }

#confirm-sale-modal .modal-actions {
    margin-top: auto;
    padding: 24px;
    margin: 0 -24px;
    background: var(--surface-color);
    border-top: 1px solid var(--border-color);
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 16px;
}
.salesperson-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.7rem;
    color: var(--text-light);
    margin-top: 16px;
}

.salesperson-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
}

#salesperson-label.checked {
    color: var(--danger-color);
    font-size: 0.9rem;
    font-weight: 600;
}

/* --- FIX: Make confirm-log-modal content scrollable --- */
#confirm-log-modal h2 {
    flex-shrink: 0; /* Keep title at top */
}

#confirm-log-content {
    flex-grow: 1; /* Allow content to fill space */
    overflow-y: auto; /* Add scrollbar if content overflows */
    min-height: 0; /* Allow shrinking */
}

#confirm-log-modal .modal-actions {
    margin-top: 16px;
    flex-shrink: 0; /* Keep actions at bottom */
}
/* --- END FIX --- */

.log-accept-notice {
    font-size: 0.75rem;
    color: var(--text-light);
    text-align: center;
    margin-top: 10px;
    margin-bottom: -10px;
}

.delete-btn-icon { position: absolute; top: 16px; right: 16px; z-index: 5; background: #fee; border: 1px solid var(--danger-color); border-radius: 50%; width: 32px; height: 32px; padding: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.delete-btn-icon:hover { background: var(--danger-color); }
.delete-btn-icon svg { stroke: var(--danger-color); transition: stroke 0.2s; }
.delete-btn-icon:hover svg { stroke: white; }
@keyframes modal-pop { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }


@keyframes modal-pop { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Offline notice for modals */
.offline-notice {
    display: none; /* Hidden by default */
    padding: 10px 16px;
    margin-bottom: 16px;
    background-color: #fffbe6; /* Light yellow */
    color: #8a6d3b; /* Dark yellow text */
    border: 1px solid #ffeeba; /* Yellow border */
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}



/* Profile Modal */
.profile-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}
.profile-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}
.profile-item:last-child {
    border-bottom: none;
}
.profile-label {
    font-size: 0.9rem;
    color: var(--text-light);
    font-weight: 500;
}
.profile-value {
    font-size: 1rem;
    font-weight: 600;
    text-align: right;
}
.profile-buttons-inline {
    display: flex;
    gap: 12px;
}
#get-help-btn {
    flex: 2;
    text-decoration: none;
    display: flex;
    justify-content: center;
    align-items: center;
}
#logout-btn {
    flex: 1;
    background-color: transparent;
    border: 1px solid var(--danger-color);
    color: var(--danger-color);
}
#logout-btn:active {
    background-color: #ffebee;
}

/* Scan Tracker in Profile */
.scan-tracker-container {
    background-color: var(--background-color);
    padding: 16px;
    border-radius: var(--border-radius);
    margin-bottom: 24px;
    text-align: center;
}
.scan-tracker-container h3 {
    margin: 0 0 12px 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
}
.scan-progress-bar {
    width: 100%;
    height: 12px;
    background-color: var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 8px;
}
.scan-progress {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #F5A623, #D0021B);
    border-radius: 6px;
    transition: width 0.5s ease-out;
}
.scan-tracker-container p {
    font-size: 0.9rem;
    color: var(--text-light);
    margin: 0;
}
.scan-tracker-container p span {
    font-weight: 700;
    color: var(--text-color);
}
.scan-reward {
    margin-top: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
    animation: reward-pop 0.5s ease-out;
}
@keyframes reward-pop {
    0% { transform: scale(0.5); opacity: 0; }
    80% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* Receipt & Log Modals */
.receipt-modal { 
    max-height: 80vh; 
    /* This ID is on the .modal-content, which is already display: flex, flex-direction: column */
}
.receipt-paper {
    background: #fff;
    padding: clamp(15px, 4vw, 20px);
    font-family: var(--font-family);
    color: #000;
    border: 1px dashed #ccc;
    width: 100%;
    max-width: 320px; /* Modern, portable width */
    margin: 0 auto;

    /* --- FIX: Make receipt content scrollable --- */
    flex-grow: 1; /* Take up available space */
    overflow-y: auto; /* Add scrollbar if content overflows */
    min-height: 0; /* Allow shrinking in flex container */
    /* --- END FIX --- */
}
.receipt-header { text-align: center; margin-bottom: 16px; }
.receipt-header h3 { margin: 0; font-size: clamp(1.1rem, 4.5vw, 1.3rem); }
.receipt-header p { margin: 2px 0; font-size: clamp(0.7rem, 2.5vw, 0.8rem); }
.receipt-items table { width: 100%; border-collapse: collapse; font-size: clamp(0.8rem, 3vw, 0.9rem); }
.receipt-items th, .receipt-items td {
    text-align: left;
    padding: 6px 2px;
    vertical-align: top;
    word-break: break-word;
}
.receipt-items thead tr { border-bottom: 1px solid #000; }
.receipt-items .col-qty, .receipt-items .col-price, .receipt-items .col-total { text-align: right; white-space: nowrap; }
.receipt-items .col-qty { width: 15%; }
.receipt-items .col-price { width: 25%; }
.receipt-items .col-total { width: 30%; }

.receipt-total { margin-top: 16px; border-top: 2px double #000; padding-top: 10px; }
.receipt-total .total-row { display: flex; justify-content: space-between; font-weight: bold; font-size: clamp(1rem, 4vw, 1.2rem); }
.receipt-footer { text-align: center; margin-top: 16px; font-size: clamp(0.7rem, 2.5vw, 0.8rem); }
.receipt-footer p { margin: 2px 0; }

/* --- FIX: Make modal actions sticky --- */
/* Selects the .modal-actions that is a direct child of .receipt-modal */
.receipt-modal > .modal-actions {
    flex-shrink: 0; /* Prevent shrinking */
    margin-top: 16px; /* Add space between content and buttons */
}
/* --- END FIX --- */

#qr-code-modal { text-align: center; }
#qr-canvas { width: 90% !important; height: auto !important; max-width: 300px; margin: 0 auto; }
.qr-help-text { font-size: 0.9rem; color: var(--text-light); margin-top: 16px; }
.log-summary { text-align: left; margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border-color); }
.log-summary p { font-size: 0.9rem; color: var(--text-light); margin: 4px 0; }
.log-summary p strong { color: var(--text-color); }
.log-details-table { font-size: 0.9rem; width: 100%; }
.log-details-row { display: flex; justify-content: space-between; padding: 8px 4px; border-bottom: 1px solid var(--border-color); }
.log-details-row:last-child { border-bottom: none; }
.log-details-row.header { font-weight: 600; color: var(--text-light); padding-bottom: 4px; border-bottom: 2px solid var(--text-color); }
.log-details-row.footer { font-weight: bold; font-size: 1.1rem; color: var(--primary-color); margin-top: 8px; border-top: 2px double var(--text-color); padding-top: 10px; }
.log-details-cell.item { flex-grow: 1; text-align: left; padding-right: 8px; overflow-wrap: break-word; }
.log-details-cell.price { width: 30%; text-align: right; white-space: nowrap; }
.log-details-cell.total { width: 35%; text-align: right; white-space: nowrap; }
.log-details-row.footer .item { color: var(--text-color); }

/* Print Styles */
@media print {
    body > *:not(#modal-container) {
        display: none !important;
    }
    .modal-container, #receipt-modal {
        display: block !important;
        position: static;
        background: white;
        width: 100%;
        height: auto;
        padding: 0;
        overflow: visible;
    }
    #receipt-modal {
        max-width: 100%;
        max-height: none;
        box-shadow: none;
        border: none;
        padding: 0;
    }
    .modal-actions {
        display: none !important;
    }
    .receipt-paper {
        border: none;
        box-shadow: none;
        font-size: 12pt;
        color: black;
    }
    .receipt-paper * {
        color: black;
    }
}


/* Responsiveness Tweaks */
@media (max-width: 360px) {
    .dashboard-grid { grid-template-columns: 1fr 1fr; }
    .product-grid { grid-template-columns: repeat(auto-fill, minmax(125px, 1fr)); gap: 12px; padding: 12px; }
    .page { padding-bottom: 75px; }
    .modal-content { padding: 16px; }
}