/* =========================================
   1. GLOBAL & TYPOGRAPHY
   ========================================= */
body {
  background-color: #f5f7fa; /* Professional Light Blue-Gray */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #334155;
  min-height: 100vh;
}

/* Helper Text Utilities */
.small-muted { font-size: .85rem; color: #64748b; }
.ls-1 { letter-spacing: 0.05em; } /* For uppercase labels */
.fw-medium { font-weight: 500; }

.kbd-like { 
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; 
  background: rgba(0,0,0,0.04);
  padding: 2px 6px;
  border-radius: 4px;
  color: #d63384;
}

/* =========================================
   2. PROFESSIONAL COMPONENTS (Soft UI)
   ========================================= */
/* Soft Cards*/
.card-soft {
  border: none;
  background: #ffffff;
  border-radius: 16px; 
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

.card-soft .card-body {
  padding: 1.25rem;
}

/* Modern Inputs */
.form-control, .form-select {
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  padding: 10px 12px;
  min-height: 42px;
  font-size: 0.95rem;
  background-color: #fff;
}

.form-control:focus, .form-select:focus {
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
  border-color: #3b82f6;
}

/* Buttons */
.btn {
  font-weight: 500;
  border-radius: 10px;
  padding: 0.5rem 1rem;
  transition: all 0.2s;
  min-height: 40px; /* Better tap target */
  touch-action: manipulation; /* Faster touch response */
}
.btn-rounded { border-radius: 999px; }


/* =========================================
   3. CLEAN DATA TABLES
   ========================================= */
.table {
  --bs-table-bg: transparent;
  margin-bottom: 0;
}

.table thead th {
  background-color: #f8fafc;
  color: #64748b;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #e2e8f0;
  border-top: 0;
  padding: 12px 16px;
  vertical-align: middle;
}

.table tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.9rem;
  vertical-align: middle;
}

.table-hover tbody tr:hover {
  background-color: #f8fafc;
}

/* POS Specific Table Styles */
.qty-pill { min-width: 62px; text-align: center; }


/* =========================================
   4. REPORT DASHBOARD WIDGETS
   ========================================= */
/* Circular Icons for KPI Cards */
.icon-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}


/* =========================================
   5. INVOICE / PAPER RECEIPT (A4)
   ========================================= */

/* ១. កំណត់ឱ្យ Invoice ត្រូវតែជា A4 ជានិច្ច (ហាមបង្រួម) */
.invoiceA4 {
    width: 21cm !important;
    min-width: 21cm !important;
    max-width: 21cm !important;
    margin: 0 auto;
    padding: 40px !important;
    background: white;
    box-sizing: border-box; 
    /* បើលើទូរស័ព្ទ វាអាចនឹងធំជាងអេក្រង់ តែយើងនឹងដាក់ Scroll */
}

/* ២. បង្ខំឱ្យប្រអប់ Payment និង Invoice នៅទន្ទឹមគ្នា (ហាមធ្លាក់ចុះក្រោម) */
.invoiceA4 .row {
    display: flex !important;
    flex-wrap: nowrap !important; /* ហាមបត់ */
}

.invoiceA4 .col-md-6 {
    width: 50% !important;
    flex: 0 0 50% !important;
    max-width: 50% !important;
}

/* ៣. បង្ខំឱ្យបង្ហាញគ្រប់កន្លែងក្នុងតារាង (ហាមលាក់ Qty, Price...) */
.invoiceA4 .d-none, 
.invoiceA4 .d-md-block,
.invoiceA4 .d-md-table-cell {
    display: table-cell !important; /* បង្ខំឱ្យបង្ហាញ */
}

.invoiceA4 th, 
.invoiceA4 td {
    white-space: nowrap; /* ហាមអក្សរធ្លាក់បន្ទាត់ */
}

/* ៤. សម្រាប់ទូរស័ព្ទ៖ ដាក់ Scroll ឱ្យអូសឆ្វេងស្តាំបាន */
@media (max-width: 991px) {
    /* យើងត្រូវមាន Wrapper មួយនៅក្រៅ Invoice ដើម្បីអាច Scroll បាន */
    .invoice-container-scroll {
        overflow-x: auto !important;
        width: 100%;
        padding-bottom: 20px;
    }
}

/* ៥. សម្រាប់ Print & PDF (ធានាថាចេញពេញស្អាត) */
@media print {
    @page {
        size: A4;
        margin: 0;
    }
    body {
        min-width: 1024px !important; /* បន្លំថាជាកុំព្យូទ័រ */
    }
    .invoiceA4 {
        width: 100% !important; /* ពេញក្រដាស */
        box-shadow: none !important;
        margin: 0 !important;
    }
    /* លាក់ប៊ូតុង និងរបស់របរផ្សេងទៀត */
    .navbar, .btn, .no-print, #scanModal, form { 
        display: none !important; 
    }
}

/* =========================================
   6. NAVBAR STYLES
   ========================================= */
/* Sticky checkout bar for mobile */
.sticky-checkout {
  position: sticky;
  bottom: 0;
  z-index: 1020;
  background: #fff;
  border-top: 1px solid rgba(0,0,0,.08);
  padding: 12px;
  box-shadow: 0 -4px 10px rgba(0,0,0,0.03);
}

/* Navbar Hover Effects */
.navbar .nav-link {
  border-radius: 14px;
  padding: .45rem .75rem;
  margin: 0 .15rem;
  position: relative;
}
.navbar .nav-link:hover { background: rgba(255,255,255,.12); }
.navbar .nav-link.active { background: rgba(255,255,255,.20); }

/* Underline Animation */
.navbar .nav-link::after {
  content: "";
  position: absolute;
  left: 12px; right: 12px; bottom: 6px; height: 2px;
  background: rgba(255,255,255,.55);
  border-radius: 2px;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .15s ease;
  opacity: .75;
}
.navbar .nav-link:hover::after,
.navbar .nav-link.active::after {
  transform: scaleX(1);
}

/* Navbar Widgets (Branch/Offline Pills) */
.nav-pill {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .35rem .65rem; border-radius: 999px;
  background: rgba(255,255,255,.12); color: #fff;
  font-size: .9rem; border: 1px solid rgba(255,255,255,.22);
}
.nav-pill strong { font-weight: 700; }

/* Navbar Select */
.navbar .form-select-sm {
  min-width: 210px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,.28);
  background-color: rgba(255,255,255,.12); color: #fff;
}
.navbar .form-select-sm:focus {
  box-shadow: 0 0 0 .2rem rgba(255,255,255,.18);
  border-color: rgba(255,255,255,.45);
}
.navbar .form-select-sm option { color: #000; }


/* =========================================
   7. SPECIFIC NAVBAR OVERRIDES (DF-Nav)
   ========================================= */
.df-nav .nav-link { 
  margin: 0 !important; padding: .55rem .85rem !important; 
  border-radius: 14px !important; position: static !important; 
}
.df-nav .nav-link::after { display:none !important; }

.df-nav .df-nav-links .nav-link {
  display:inline-flex; align-items:center; gap:.55rem;
  color: rgba(255,255,255,.92) !important;
  transition: background-color .15s ease, opacity .15s ease;
  opacity: .92;
}
.df-nav .df-nav-links .nav-link:hover { background: rgba(255,255,255,.14) !important; opacity: 1; }
.df-nav .df-nav-links .nav-link.active { background: rgba(255,255,255,.22) !important; opacity: 1; }

.df-user {
  display:inline-flex; align-items:center; gap:.55rem;
  padding:.35rem .6rem; border-radius: 999px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.22);
  color:#fff;
}
.df-avatar {
  width:34px; height:34px; border-radius: 999px;
  display:flex; align-items:center; justify-content:center;
  background: rgba(255,255,255,.22);
  font-weight:700; letter-spacing:.02em;
}


/* =========================================
   8. RIGHT PANEL & UTILITIES
   ========================================= */
.df-right-panel { width: 360px; }
.df-right-panel .offcanvas-header { border-bottom: 1px solid #f1f5f9; }

/* Panel Cards */
.df-panel-card {
  border: 1px solid #e2e8f0;
  border-radius: 16px; padding: 14px; background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.df-panel-title { font-weight: 700; display:flex; align-items:center; margin-bottom: 6px; color: #334155; }
.df-panel-value { font-size: 1.1rem; color: #0f172a; }

.df-avatar-lg {
  width:44px; height:44px; border-radius:999px;
  display:flex; align-items:center; justify-content:center;
  background: rgba(13,110,253,.12); color: #0d6efd; font-weight: 800;
}

/* Floating Toggle & Circle Buttons */
.df-right-toggle {
  position: fixed; top: 72px; right: 14px; z-index: 1055;
  width: 44px; height: 44px; border-radius: 14px;
  border: 1px solid rgba(0,0,0,.10); background: #fff;
  box-shadow: 0 10px 25px rgba(0,0,0,.10);
  display:inline-flex; align-items:center; justify-content:center;
}

.df-btn-circle {
  width: 44px; height: 44px; padding: 0 !important; border-radius: 999px !important;
  display: inline-flex !important; align-items: center; justify-content: center;
}
.df-btn-circle i { font-size: 1.15rem; line-height: 1; }

button.df-btn-circle.btn, button.df-btn-circle.btn-sm {
  width: 44px !important; height: 44px !important; min-height: 44px !important;
  padding: 0 !important; border-radius: 999px !important;
}


/* =========================================
   9. IMAGE PREVIEWS & ANIMATION
   ========================================= */
.img-box {
  width: 100%; border: 1px dashed #cbd5e1;
  border-radius: 16px; background: #f8fafc;
  overflow: hidden; display: flex; align-items: center; justify-content: center;
  padding: 10px; min-height: 220px;
}
.img-preview { 
  width: 100%; max-height: 320px; object-fit: contain; 
  border-radius: 14px; background: #fff; 
}
.img-placeholder {
  width: 100%; min-height: 220px; display: flex; 
  align-items: center; justify-content: center; border-radius: 14px;
}

/* Hover Scale & Border Animation */
.hover-scale { position: relative; }
.hover-scale:hover { transform: none !important; }
.hover-scale::after {
  content: ""; position: absolute; inset: -2px; z-index: 10;
  pointer-events: none; border-radius: 18px; 
  background: linear-gradient(60deg, #0d6efd, #0dcaf0, #6610f2, #d63384, #0d6efd);
  background-size: 300% 300%;
  animation: borderRun 3s linear infinite;
  opacity: 0; transition: opacity 0.3s ease-in-out;
  padding: 2px; 
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}
.hover-scale:hover::after { opacity: 1; }

@keyframes borderRun {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}


/* =========================================
   10. RESPONSIVE & MOBILE FIXES
   ========================================= */

/* --- B. Right Panel (Offcanvas) & Navbar on Mobile --- */
@media (max-width: 576px) {
  .df-right-panel { width: 100% !important; }
  .card-soft .card-body { padding: 1rem; }
  
  .df-right-toggle {
    top: auto; bottom: 20px; right: 20px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.15);
  }

  .navbar .navbar-brand { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
  .navbar .nav-link { padding: .35rem .7rem; margin: .1rem .1rem; }
  .df-nav .df-nav-links .nav-link { width:100%; justify-content:flex-start; }
  
  .img-box { min-height: 180px; }
  .img-preview { max-height: 220px; }
  .img-placeholder { min-height: 180px; }
}

/* --- C. POS Layout Fixes for Mobile --- */
@media (max-width: 991px) {
  /* Allow scrolling on mobile */
  body, html { overflow: auto !important; height: auto !important; }
  .main-content { height: auto !important; padding-bottom: 80px !important; }
  
  /* Reset grid heights */
  .col-lg-8, .col-xl-8, .col-lg-4, .col-xl-4 { height: auto !important; overflow: visible !important; }

  /* Product List Height */
  #product-scroll-area { max-height: 50vh; min-height: 300px; }
  
  /* Cart Height */
  #cart-items-container { max-height: 40vh; }
  
  /* Hide scrollbars for cleaner UI */
  #product-scroll-area::-webkit-scrollbar,
  #cart-items-container::-webkit-scrollbar { display: none; }

  /* Adjust buttons & text size */
  .btn { padding: 0.4rem 0.8rem; font-size: 0.9rem; }
  .card-body { padding: 0.8rem !important; }
  h5, .h5 { font-size: 1.1rem; }
}

/* --- D. Table Responsiveness --- */
@media (max-width: 768px) {
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table thead th { white-space: nowrap; font-size: 0.7rem; padding: 10px; }
  .table tbody td { padding: 10px; font-size: 0.85rem; }
}

/* --- E. General Touch Improvements --- */
/* Fast click, no double-tap zoom */
button, a, input, .btn { touch-action: manipulation; }

/* Ensure Modals appear on top */
.modal-backdrop { z-index: 1040 !important; }
.modal { z-index: 1050 !important; }


/* =========================================
   11. KHMER FONT SUPPORT
   ========================================= */
.cursor-pointer { cursor: pointer; }
.dropdown-item:active { background-color: #e9ecef; color: #000; }

html[lang="km"] body {
    font-family: 'Kantumruy Pro', sans-serif;
    font-weight: 400; line-height: 1.6;
}

/* Navbar Font */
html[lang="km"] .navbar, 
html[lang="km"] .dropdown-menu {
    font-family: 'Kantumruy Pro', sans-serif;
    font-weight: 600; font-size: 0.95rem;
}

/* Headers Font (Moul) */
html[lang="km"] h1, html[lang="km"] h2, html[lang="km"] h3, 
html[lang="km"] h4, html[lang="km"] h5, html[lang="km"] h6,
html[lang="km"] .h1, html[lang="km"] .h2, html[lang="km"] .h3, 
html[lang="km"] .card-title {
    font-family: 'Moul', serif;
    font-weight: 300; line-height: 1.8; color: #2c3e50;
}

html[lang="km"] .btn {
    font-family: 'Kantumruy Pro', sans-serif; font-weight: 500;
}

/* Mobile adjustments for Khmer */
@media (max-width: 576px) {
  html[lang="km"] body { line-height: 1.5; }
  html[lang="km"] h1, html[lang="km"] .h1,
  html[lang="km"] h2, html[lang="km"] .h2 { font-size: 1.5rem; }
  html[lang="km"] h5, html[lang="km"] .h5 { font-size: 1.1rem; line-height: 1.6; }
}


/* =========================================
   12. PRINT STYLES (A4 & RECEIPT)
   ========================================= */
@media print {
  .navbar, .btn, .no-print, #scanModal, form, .sticky-checkout, .df-right-toggle { 
    display: none !important; 
  }
  
  body, .main-content {
    background: white !important; padding: 0 !important; margin: 0 !important; 
    overflow: visible !important; height: auto !important;
  }


  /* Force Print Colors */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}