:root {
    --primary: #0f172a;
    --primary-light: #1e293b;
    --accent: #3b82f6;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #334155;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 4px;
    --sidebar-width: 210px;
}

body.theme-dark {
    --primary: #1e293b;
    --primary-light: #334155;
    --accent: #60a5fa;
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
}

body.theme-nord {
    --primary: #2e3440;
    --primary-light: #3b4252;
    --accent: #88c0d0;
    --bg: #eceff4;
    --surface: #ffffff;
    --text: #2e3440;
    --text-muted: #4c566a;
    --border: #d8dee9;
}

body.theme-dracula {
    --primary: #282a36;
    --primary-light: #44475a;
    --accent: #bd93f9;
    --bg: #1e1f29;
    --surface: #282a36;
    --text: #f8f8f2;
    --text-muted: #6272a4;
    --border: #44475a;
}

body.theme-citrus {
    --primary: #365314;
    --primary-light: #4d7c0f;
    --accent: #84cc16;
    --bg: #f7fee7;
    --surface: #ffffff;
    --text: #1a2e05;
    --text-muted: #65a30d;
    --border: #ecfccb;
}

body.theme-ocean {
    --primary: #083344;
    --primary-light: #164e63;
    --accent: #06b6d4;
    --bg: #ecfeff;
    --surface: #ffffff;
    --text: #164e63;
    --text-muted: #67e8f9;
    --border: #cffafe;
}

body.theme-forest {
    --primary: #064e3b;
    --primary-light: #065f46;
    --accent: #10b981;
    --bg: #f0fdf4;
    --surface: #ffffff;
    --text: #064e3b;
    --text-muted: #34d399;
    --border: #dcfce7;
}

body.theme-sunset {
    --primary: #451a03;
    --primary-light: #78350f;
    --accent: #f59e0b;
    --bg: #fffbeb;
    --surface: #ffffff;
    --text: #451a03;
    --text-muted: #fbbf24;
    --border: #fef3c7;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    overflow-x: hidden;
}

[dir="rtl"] {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background-color: #0f172a; /* Updated to match system primary dark blue */
    color: white;
    position: fixed;
    top: 0;
    transition: all 0.3s;
    z-index: 1000;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Custom scrollbar for sidebar */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Base positioning for desktop */
@media (min-width: 1200px) {
    [dir="ltr"] .sidebar { left: 0 !important; right: auto !important; }
    [dir="rtl"] .sidebar { right: 0 !important; left: auto !important; }
    
    [dir="ltr"] .main-content { margin-left: var(--sidebar-width) !important; margin-right: 0 !important; }
    [dir="rtl"] .main-content { margin-left: 0 !important; margin-right: var(--sidebar-width) !important; }
}

.sidebar-header {
    padding: 1rem;
    font-size: 1.15rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1); /* Lighter border for blue bg */
}

.nav-link {
    font-weight: 400; /* Normal font for sub items */
    color: rgba(255, 255, 255, 0.9); /* Lighter text for blue bg */
    padding: 0.6rem 1rem;
    display: flex;
    align-items: center;
    text-decoration: none;
    transition: background 0.2s;
}

.nav-link:hover, .nav-link.active {
    background-color: rgba(255, 255, 255, 0.1); /* Subtle hover for blue bg */
    color: white;
}

.nav-link i {
    width: 20px;
    margin-right: 8px;
}

.nav-section-title {
    font-size: 0.85rem;
    font-weight: 700 !important; /* Bold for main category */
    color: #38bdf8 !important; /* Sky Blue for distinction */
    letter-spacing: 0.05em;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-section-title:hover {
    color: white !important;
}

.nav-section-title i.chevron {
    transition: transform 0.2s;
    font-size: 0.6rem;
}

.nav-section-title.collapsed i.chevron {
    transform: rotate(-90deg);
}

.nav-section-title .group-icon {
    width: 18px;
    margin-right: 10px;
}

[dir="rtl"] .nav-section-title .group-icon {
    margin-right: 0;
    margin-left: 10px;
}

/* POS Styles */
.pos-container {
    display: flex;
    height: calc(100vh - 120px);
    gap: 20px;
}
.pos-products {
    flex: 1;
    overflow-y: auto;
    padding-right: 10px;
}
.pos-cart {
    width: 400px;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    height: 100%;
}
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 15px;
}
.product-card {
    background: var(--surface);
    border-radius: 10px;
    border: 1px solid var(--border);
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.05);
    border-color: var(--accent);
}
.product-card img {
    width: 100%;
    height: 120px;
    object-fit: contain;
    margin-bottom: 10px;
    border-radius: 8px;
}
.product-card .price {
    font-weight: 700;
    color: var(--text);
}
.cart-items {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}
.cart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border);
}
.cart-total {
    padding: 20px;
    background: var(--bg);
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
}
.qty-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}
.qty-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
}
.qty-btn:hover {
    background: var(--bg);
}

[dir="rtl"] .nav-link i {
    margin-right: 0;
    margin-left: 8px;
}

/* Main Content */
.main-content {
    padding: 2rem;
    transition: all 0.3s;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Desktop margins handled in the top @media block */

@media (max-width: 1199.98px) {
    [dir="ltr"] .sidebar {
        left: calc(-1 * var(--sidebar-width)) !important;
    }
    [dir="ltr"] .sidebar.show {
        left: 0 !important;
        box-shadow: 0 0 50px rgba(0,0,0,0.3) !important;
    }
    [dir="rtl"] .sidebar {
        right: calc(-1 * var(--sidebar-width)) !important;
        left: auto !important;
    }
    [dir="rtl"] .sidebar.show {
        right: 0 !important;
        left: auto !important;
        box-shadow: 0 0 50px rgba(0,0,0,0.3) !important;
    }
    .main-content {
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100% !important;
    }
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}
.sidebar-overlay.show {
    display: block;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    margin: -2rem -2rem 2rem -2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

/* UI Components */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.btn-primary {
    background-color: var(--accent);
    border: none;
    border-radius: var(--radius);
}

.table {
    color: var(--text);
}

.table th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border);
}

.op-50 {
    opacity: 0.5;
}

.main-footer {
    background: transparent;
    color: var(--text-muted);
    margin-top: auto;
    flex-shrink: 0;
}

.main-footer .border-top {
    border-color: var(--border) !important;
}

/* RTL Adjustments */
/* Theme Compatibility Overrides */
body.theme-dark, body.theme-dracula {
    color-scheme: dark;
}

body:not(.theme-default) .text-dark {
    color: var(--text) !important;
}

body:not(.theme-default) .bg-light,
body:not(.theme-default) .bg-white {
    background-color: var(--surface) !important;
}

body:not(.theme-default) .border-dark {
    border-color: var(--border) !important;
}

body:not(.theme-default) .list-group-item {
    background-color: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

body:not(.theme-default) .list-group-item-action:hover {
    background-color: var(--bg);
    color: var(--accent);
}

body:not(.theme-default) .dropdown-menu {
    background-color: var(--surface);
    border-color: var(--border);
}

body:not(.theme-default) .dropdown-item {
    color: var(--text);
}

body:not(.theme-default) .dropdown-item:hover {
    background-color: var(--primary-light);
    color: #fff;
}

body:not(.theme-default) .alert-warning {
    background-color: var(--primary-light);
    border-color: var(--accent);
    color: var(--text);
}

body:not(.theme-default) .modal-content {
    background-color: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

body:not(.theme-default) .form-control,
body:not(.theme-default) .form-select {
    background-color: var(--bg);
    border-color: var(--border);
    color: var(--text);
}

body:not(.theme-default) .form-control:focus,
body:not(.theme-default) .form-select:focus {
    background-color: var(--bg);
    border-color: var(--accent);
    color: var(--text);
}

[dir="rtl"] .ms-auto {
    margin-right: auto !important;
    margin-left: 0 !important;
}

[dir="rtl"] .text-end {
    text-align: left !important;
}

[dir="rtl"] .text-start {
    text-align: right !important;
}

[dir="rtl"] .me-3 {
    margin-right: 0 !important;
    margin-left: 1rem !important;
}

[dir="rtl"] .me-2 {
    margin-right: 0 !important;
    margin-left: 0.5rem !important;
}

[dir="rtl"] .ms-2 {
    margin-left: 0 !important;
    margin-right: 0.5rem !important;
}

/* Thermal Receipt Styles */
.thermal-receipt {
    width: 80mm;
    margin: 0 auto;
    padding: 10px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    line-height: 1.4;
    background: #fff;
    color: #000;
    break-inside: avoid;
    page-break-inside: avoid;
}
.thermal-receipt.rtl {
    direction: rtl;
    text-align: right;
}
.thermal-receipt .center {
    text-align: center;
}
.thermal-receipt .separator {
    border-top: 1px dashed #000;
    margin: 10px 0;
}
.thermal-receipt table {
    width: 100%;
}
.thermal-receipt table th {
    text-align: left;
    border-bottom: 1px dashed #000;
    font-size: 10px;
}
.thermal-receipt.rtl table th {
    text-align: right;
}
.thermal-receipt table td {
    padding: 5px 0;
    font-size: 11px;
}
.thermal-receipt .total-row {
    font-weight: bold;
    font-size: 14px;
}

@media print {
    .thermal-receipt-print {
        width: 80mm !important;
        margin: 0 !important;
        padding: 5mm !important;
    }
    body.printing-receipt * {
        visibility: hidden;
    }
    body.printing-receipt .thermal-receipt-print, 
    body.printing-receipt .thermal-receipt-print * {
        visibility: visible !important;
    }
    body.printing-receipt #posPrintArea {
        visibility: visible !important;
        display: block !important;
    }
    body.printing-receipt .thermal-receipt-print {
        position: absolute;
        left: 0;
        top: 0;
        display: block !important;
    }
}

/* Payment Modal Styles */
.payment-methods-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}
.payment-method-btn {
    border: 2px solid #e2e8f0;
    background: #fff;
    padding: 15px 10px;
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}
.payment-method-btn.active {
    border-color: #3b82f6;
    background: #eff6ff;
    color: #3b82f6;
}
.payment-method-btn i {
    font-size: 1.5rem;
    display: block;
    margin-bottom: 5px;
}

.quick-pay-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    margin-top: 10px;
}
.quick-pay-btn {
    padding: 10px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    border-radius: 6px;
    text-align: center;
    cursor: pointer;
    font-weight: 600;
}
.quick-pay-btn:hover {
    background: #edf2f7;
}

.amount-due-box {
    background: #f1f5f9;
    padding: 15px;
    border-radius: 10px;
    text-align: center;
    margin-bottom: 20px;
}
.amount-due-box .label {
    font-size: 0.75rem;
    color: #64748b;
    text-transform: uppercase;
    font-weight: 600;
}
.amount-due-box .value {
    font-size: 1.25rem;
    font-weight: 800;
    color: #0f172a;
}
.payment-line {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #e9ecef;
}
.payment-line .method {
    font-weight: 600;
    text-transform: capitalize;
}
.payment-line .amount {
    font-weight: 700;
}
.payment-summary {
    border-top: 2px dashed #dee2e6;
    margin-top: 15px;
    padding-top: 15px;
}

/* Styled Modal Headers */
.modal-header, .card-header {
    background-color: var(--accent);
    color: white;
    border-bottom: 1px solid var(--border);
}
.modal-title, .card-title {
    color: white !important;
}
.modal-header .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* 3-Column Form Grid */
.form-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

@media (max-width: 992px) {
    .form-grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (max-width: 768px) {
    .form-grid-3 {
        grid-template-columns: 1fr;
    }
}

.form-grid-3 > div {
    width: 100% !important; /* Override bootstrap cols if present */
    max-width: 100% !important;
    flex: none !important;
}

/* Helpers to span columns in grid */
.form-grid-3 > .span-2 { grid-column: span 2; }
.form-grid-3 > .span-3 { grid-column: span 3; }
.form-grid-3 > .full-width { grid-column: 1 / -1; }

/* Handle existing bootstrap classes in grid */
.form-grid-3 > .col-12, 
.form-grid-3 > .col-md-12 {
    grid-column: 1 / -1;
}

.form-grid-3 > .col-md-8 {
    grid-column: span 2;
}

/* Ensure form controls take full width of their grid cell */
.form-grid-3 .form-control, 
.form-grid-3 .form-select, 
.form-grid-3 .input-group {
    width: 100%;
}
