/* Import Outfit and Noto Sans Devanagari (Hindi) Fonts */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Devanagari:wght@400;500;700&family=Outfit:wght@300;400;500;600;700&display=swap');

/* Dynamic CSS Custom Variables System */
:root {
  --font-sans: 'Outfit', 'Noto Sans Devanagari', -apple-system, BlinkMacSystemFont, sans-serif;
  
  /* Primary HSL Tokens (Controlled dynamically via JS class theme triggers) */
  --primary-h: 162; /* Default: Kirana Green */
  --primary-s: 84%;
  --primary-l: 38%;
  --primary: hsl(var(--primary-h), var(--primary-s), var(--primary-l));
  --primary-light: hsl(var(--primary-h), var(--primary-s), 95%);
  --primary-dark: hsl(var(--primary-h), var(--primary-s), 28%);
  --primary-glow: hsla(var(--primary-h), var(--primary-s), var(--primary-l), 0.15);

  /* Light Theme Color System */
  --bg-app: #f4f6f8;
  --bg-card: #ffffff;
  --bg-hover: #f9fafb;
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --text-inverse: #ffffff;
  --border: #e5e7eb;
  --border-focus: hsl(var(--primary-h), var(--primary-s), 50%);

  /* UI Semantics */
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --info: #3b82f6;

  /* Sizing and Styling Radii */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 18px -2px rgba(0, 0, 0, 0.08), 0 2px 6px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 30px -5px rgba(0, 0, 0, 0.1), 0 8px 12px -6px rgba(0, 0, 0, 0.05);
  --shadow-primary: 0 8px 20px -4px hsla(var(--primary-h), var(--primary-s), var(--primary-l), 0.25);

  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --safe-bottom: 72px; /* Bottom spacing to clear mobile nav bar */
}

/* Theme Variant Tweaks */
.theme-medical {
  --primary-h: 200; /* Bright Blue */
  --primary-s: 95%;
  --primary-l: 45%;
}
.theme-wholesale {
  --primary-h: 262; /* Royal Purple */
  --primary-s: 80%;
  --primary-l: 55%;
}
.theme-retail {
  --primary-h: 345; /* Energetic Rose Coral */
  --primary-s: 85%;
  --primary-l: 52%;
}

/* Dark Mode Overrides */
[data-theme="dark"] {
  --bg-app: #0b0f17;
  --bg-card: #151d2a;
  --bg-hover: #1e293b;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --border: #223044;
  --primary-light: hsl(var(--primary-h), var(--primary-s), 15%);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 35px rgba(0, 0, 0, 0.4);
}

/* Core Settings & Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Top Navigation Header */
.top-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  height: 56px;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-badge {
  background-color: var(--primary);
  color: var(--text-inverse);
  font-weight: 700;
  font-size: 16px;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-primary);
  letter-spacing: 0.5px;
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

.logo-text span {
  color: var(--primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Language Toggle Button */
.lang-btn {
  background-color: var(--primary-light);
  border: 1px solid transparent;
  color: var(--primary);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
}

.lang-btn:hover {
  background-color: var(--primary);
  color: var(--text-inverse);
}

/* Theme Toggle Button */
.theme-toggle-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.theme-toggle-btn:hover {
  background-color: var(--bg-app);
  color: var(--text-main);
}

/* App Main Container Layout */
.app-container {
  max-width: 600px; /* Force optimized mobile viewport */
  margin: 0 auto;
  min-height: calc(100vh - 56px);
  padding: 16px 16px var(--safe-bottom) 16px;
  position: relative;
}

/* Card Styling */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-title {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-main);
}

/* Dynamic Grid */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Bottom Navigation Bar for Mobile-First experience */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  background-color: var(--bg-card);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 8px 4px 10px 4px;
  z-index: 1000;
  box-shadow: 0 -4px 20px -6px rgba(0, 0, 0, 0.12);
  border-radius: 16px 16px 0 0;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  gap: 4px;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

.nav-item svg {
  width: 22px;
  height: 22px;
  transition: var(--transition);
}

.nav-item:hover, .nav-item.active {
  color: var(--primary);
}

.nav-item.active svg {
  transform: scale(1.1);
  stroke: var(--primary);
  fill: var(--primary-glow);
}

/* High Visibility Floating Action POS billing button */
.nav-item-pos {
  position: relative;
  top: -14px;
  background-color: var(--primary) !important;
  color: var(--text-inverse) !important;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-primary);
  margin: 0 auto;
}

.nav-item-pos svg {
  width: 24px;
  height: 24px;
  stroke: var(--text-inverse);
}

.nav-item-pos:hover {
  transform: scale(1.05);
}

/* Large Tactile Form Controls */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 12px 14px;
  font-size: 15px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: var(--transition);
}

.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px;
  padding-right: 40px;
}

/* Big Buttons with tactile feedback */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
  min-height: 48px;
  user-select: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: var(--primary);
  color: var(--text-inverse);
  box-shadow: var(--shadow-primary);
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-secondary {
  background-color: var(--bg-app);
  border-color: var(--border);
  color: var(--text-main);
}

.btn-secondary:hover {
  background-color: var(--border);
}

.btn-danger {
  background-color: var(--danger);
  color: var(--text-inverse);
}

.btn-success {
  background-color: var(--success);
  color: var(--text-inverse);
}

/* Alerts and Status Banners */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-warning {
  background-color: var(--warning-light);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.15);
}

.alert-danger {
  background-color: var(--danger-light);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.15);
}

.alert-success {
  background-color: var(--success-light);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.15);
}

/* Section Header (Page Level) */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
}

/* SPA Page Toggle Manager */
.app-page {
  display: none;
  animation: pageFadeIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-page.active {
  display: block;
}

@keyframes pageFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Search bar and filters row */
.search-row {
  position: relative;
  margin-bottom: 12px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 18px;
  height: 18px;
}

.search-control {
  padding-left: 42px !important;
}

/* Inventory List Items styling */
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.list-item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.list-item-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text-main);
}

.list-item-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  text-transform: uppercase;
}

.badge-low-stock {
  background-color: var(--danger-light);
  color: var(--danger);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}

.list-item-price {
  text-align: right;
  font-weight: 700;
  font-size: 16px;
  color: var(--text-main);
}

.list-item-stock {
  font-size: 12px;
  color: var(--text-muted);
}

/* Dynamic Interactive Shopping Cart (POS checkout) */
.cart-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--bg-app);
}

.cart-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

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

.cart-item-info {
  flex: 1;
}

.cart-item-name {
  font-weight: 600;
  font-size: 14px;
}

.cart-item-math {
  font-size: 11px;
  color: var(--text-muted);
}

.cart-item-qty-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.qty-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background-color: var(--bg-card);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}

.qty-btn:active {
  background-color: var(--border);
}

.qty-val {
  font-weight: 600;
  font-size: 14px;
}

.cart-summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.cart-total-row {
  display: flex;
  justify-content: space-between;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  border-top: 1px dashed var(--border);
  padding-top: 8px;
  margin-top: 8px;
  margin-bottom: 16px;
}

/* Theme picker chips */
.theme-picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.theme-chip {
  height: 50px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 12px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  transition: var(--transition);
}

.theme-chip-kirana { background-color: #059669; }
.theme-chip-medical { background-color: #0284c7; }
.theme-chip-wholesale { background-color: #7c3aed; }
.theme-chip-retail { background-color: #e11d48; }

.theme-chip.active {
  border-color: var(--text-main);
  transform: scale(1.05);
}

/* Ledgers & Balance Sheet indicators */
.balance-sheet {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.balance-card {
  flex: 1;
  text-align: center;
  padding: 12px;
  border-radius: var(--radius-sm);
}

.balance-card-due {
  background-color: var(--danger-light);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.1);
}

.balance-card-adv {
  background-color: var(--success-light);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.1);
}

/* Modal Popup standard overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background-color: var(--bg-card);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 480px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  animation: modalSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
}

/* Dynamic Charts Styles using bare-metal CSS grid & flex */
.chart-container {
  height: 180px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 20px 0 10px 0;
  border-bottom: 1px solid var(--border);
}

.chart-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.chart-bar {
  width: 100%;
  max-width: 24px;
  background-color: var(--primary);
  border-radius: var(--radius-xs) var(--radius-xs) 0 0;
  min-height: 2px;
  transition: height 0.6s ease;
  position: relative;
}

.chart-bar-value {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 700;
  color: var(--text-main);
}

.chart-bar-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: center;
}

/* POS Invoice Printing Container Layout */
#print-receipt-section {
  display: none;
  background-color: #fff;
  color: #000;
  padding: 20px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
  width: 80mm; /* standard thermal receipt size */
  margin: 0 auto;
  border: 1px solid #ccc;
}

.receipt-header {
  text-align: center;
  border-bottom: 1px dashed #000;
  padding-bottom: 10px;
  margin-bottom: 10px;
}

.receipt-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.receipt-info {
  margin-bottom: 4px;
  line-height: 1.3;
}

.receipt-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
}

.receipt-items-table th, .receipt-items-table td {
  text-align: left;
  padding: 4px 0;
  font-size: 12px;
}

.receipt-items-table th:last-child, .receipt-items-table td:last-child {
  text-align: right;
}

.receipt-divider {
  border-top: 1px dashed #000;
  margin: 8px 0;
}

.receipt-totals {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.receipt-grand-total {
  font-size: 15px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  border-top: 1px solid #000;
  border-bottom: 1px solid #000;
  padding: 6px 0;
  margin-top: 6px;
}

.receipt-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 11px;
}

/* Print Overrides for standard browsers */
@media print {
  body * {
    visibility: hidden;
  }
  #print-receipt-section, #print-receipt-section * {
    visibility: visible;
  }
  #print-receipt-section {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    border: none;
  }
}

/* Real Barcode Camera Scanner Styling */
#reader video {
  width: 100% !important;
  height: auto !important;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

#reader {
  border: none !important;
}

#reader img {
  display: none !important; /* Hide the QR code logo/instruction from html5-qrcode */
}
