/* ==========================================================================
   Thungmakham Beach POS & Sales Analytics Design System
   Aesthetic: Deep Coastal Modern Dark / Light Mode with Thermal Slip Fidelity
   ========================================================================== */

:root {
  /* Color Palette - Midnight Coastal */
  --bg-primary: #0a0f1d;
  --bg-secondary: #10192e;
  --bg-tertiary: #17233f;
  --bg-card: rgba(19, 30, 54, 0.75);
  --bg-card-hover: rgba(26, 41, 74, 0.85);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-active: rgba(6, 182, 212, 0.4);
  
  /* Brand Accents */
  --accent-cyan: #06b6d4;
  --accent-cyan-glow: rgba(6, 182, 212, 0.25);
  --accent-amber: #f59e0b;
  --accent-amber-glow: rgba(245, 158, 11, 0.2);
  --accent-emerald: #10b981;
  --accent-emerald-glow: rgba(16, 185, 129, 0.2);
  --accent-rose: #f43f5e;
  --accent-indigo: #6366f1;

  /* Typography Colors */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #0f172a;

  /* Fonts */
  --font-sans: 'Prompt', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;
  --font-receipt: 'Sarabun', 'Courier New', Courier, monospace;

  /* Layout & Elevations */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 25px var(--accent-cyan-glow);

  /* Receipt Thermal Width Defaults */
  --receipt-width-80mm: 360px;
  --receipt-width-58mm: 270px;

  /* Safe Area Insets & Mobile Navigation */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --bottom-nav-height: 62px;
}

[data-theme="light"] {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e2e8f0;
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-card-hover: #f8fafc;
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-active: rgba(8, 145, 178, 0.5);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.12);
}

/* Reset & Global */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(6, 182, 212, 0.06) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(245, 158, 11, 0.04) 0%, transparent 40%);
  background-attachment: fixed;
}

/* App Shell Container */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar Navigation */
.sidebar {
  width: 270px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
  transition: all 0.3s ease;
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: #ffffff;
  padding: 3px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.brand-info {
  overflow: hidden;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--accent-cyan);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 5px;
}

.brand-sub .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
}

.sidebar-menu {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  overflow-y: auto;
}

.menu-category {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 12px 12px 6px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  border: 1px solid transparent;
}

.nav-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  transform: translateX(3px);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.15) 0%, rgba(99, 102, 241, 0.12) 100%);
  color: var(--accent-cyan);
  font-weight: 600;
  border-color: var(--border-active);
  box-shadow: 0 2px 12px rgba(6, 182, 212, 0.12);
}

.nav-item .icon {
  font-size: 1.25rem;
  width: 24px;
  text-align: center;
}

.nav-badge {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.nav-item.active .nav-badge {
  background: var(--accent-cyan);
  color: #000;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.15);
}

.excel-status-card {
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  font-size: 0.75rem;
}

.excel-status-title {
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.excel-file-name {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
}

/* Main Content Area */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Top App Bar */
.topbar {
  height: 70px;
  background: rgba(16, 25, 46, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.page-breadcrumb {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid transparent;
  outline: none;
  text-decoration: none;
}

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

.btn-primary {
  background: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%);
  color: #041017;
  font-weight: 700;
  box-shadow: 0 2px 10px rgba(6, 182, 212, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #22d3ee 0%, #06b6d4 100%);
  box-shadow: 0 4px 16px rgba(6, 182, 212, 0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--border-active);
}

.btn-amber {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #1a0e00;
  font-weight: 700;
}

.btn-amber:hover {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  box-shadow: 0 4px 16px var(--accent-amber-glow);
}

.btn-install-app {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.15) 0%, rgba(99, 102, 241, 0.12) 100%);
  border-color: var(--border-active);
  color: var(--accent-cyan);
}

.btn-install-app:hover {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.25) 0%, rgba(99, 102, 241, 0.2) 100%);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 14px var(--accent-cyan-glow);
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
}

/* Content Container */
.content-area {
  padding: 28px;
  flex: 1;
}

.view-section {
  display: none;
  animation: fadeIn 0.25s ease-out forwards;
}

.view-section.active {
  display: block;
}

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

/* Quick KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-top: 2px solid var(--accent-cyan);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  position: relative;
  overflow: hidden;
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  box-shadow: var(--shadow-sm);
}

.kpi-card:hover {
  border-color: var(--border-active);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-card.amber { border-top-color: var(--accent-amber); }
.kpi-card.emerald { border-top-color: var(--accent-emerald); }
.kpi-card.indigo { border-top-color: var(--accent-indigo); }

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

.kpi-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.kpi-icon-badge {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  background: rgba(6, 182, 212, 0.12);
  color: var(--accent-cyan);
}

.kpi-card.amber .kpi-icon-badge {
  background: rgba(245, 158, 11, 0.12);
  color: var(--accent-amber);
}
.kpi-card.emerald .kpi-icon-badge {
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-emerald);
}
.kpi-card.indigo .kpi-icon-badge {
  background: rgba(99, 102, 241, 0.12);
  color: var(--accent-indigo);
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}

.kpi-footer {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.kpi-footer .badge-tag {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.72rem;
}

/* Charts and Panels Layout */
.dashboard-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
  margin-bottom: 28px;
}

.panel-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

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

.panel-title {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.chart-wrapper {
  position: relative;
  height: 280px;
  width: 100%;
}

/* Best Sellers List */
.best-sellers-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  max-height: 380px;
  padding-right: 4px;
}

.best-seller-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  transition: all 0.2s ease;
}

.best-seller-item:hover {
  border-color: var(--border-active);
  background: var(--bg-card-hover);
}

.item-rank {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.best-seller-item:nth-child(1) .item-rank {
  background: #f59e0b;
  color: #000;
}
.best-seller-item:nth-child(2) .item-rank {
  background: #94a3b8;
  color: #000;
}
.best-seller-item:nth-child(3) .item-rank {
  background: #d97706;
  color: #fff;
}

.item-details {
  flex: 1;
  margin-left: 12px;
}

.item-name {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-primary);
}

.item-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.item-sales-figure {
  text-align: right;
}

.item-revenue {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-cyan);
  font-size: 0.95rem;
}

.item-qty-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Filter & Search Bar */
.filter-toolbar {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 260px;
}

.search-input {
  width: 100%;
  padding: 10px 16px 10px 42px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  outline: none;
  transition: all 0.2s ease;
}

.search-input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 12px var(--accent-cyan-glow);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1.1rem;
}

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

.select-filter {
  padding: 9px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  outline: none;
  cursor: pointer;
}

.select-filter:focus {
  border-color: var(--accent-cyan);
}

/* Receipts Table */
.table-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.pos-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.pos-table th {
  background: var(--bg-tertiary);
  padding: 14px 18px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.pos-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.9rem;
  color: var(--text-primary);
  vertical-align: middle;
}

.pos-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.receipt-no-tag {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.1);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  display: inline-block;
}

.order-no-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.price-total {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-primary);
  font-size: 1rem;
}

.badge-channel {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  display: inline-block;
}

/* ==========================================================================
   MODAL DIALOGS
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(3, 7, 18, 0.8);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
}

.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 650px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.modal-backdrop.open .modal-dialog {
  transform: scale(1);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  line-height: 1;
}

.modal-close-btn:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background: rgba(0, 0, 0, 0.1);
}

/* ==========================================================================
   AUTHENTIC THERMAL RECEIPT SLIP STYLING
   ========================================================================== */
.receipt-preview-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #0f172a;
  padding: 28px 20px;
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

.thermal-paper {
  background: #ffffff;
  color: #111111;
  font-family: var(--font-receipt);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  border-radius: 4px;
  position: relative;
  padding: 20px 14px 28px;
  width: var(--receipt-width-80mm);
  box-sizing: border-box;
  font-size: 13px;
  line-height: 1.35;
}

.thermal-paper.size-58mm {
  width: var(--receipt-width-58mm);
  padding: 14px 8px 20px;
  font-size: 11px;
}

/* Zigzag paper tear edges top & bottom */
.thermal-paper::after {
  content: "";
  position: absolute;
  bottom: -10px;
  left: 0;
  right: 0;
  height: 10px;
  background: radial-gradient(circle, transparent, transparent 50%, #ffffff 50%, #ffffff 100%);
  background-size: 14px 14px;
}

/* Header layout matching user request: Logo on TOP, centered, text on single line each */
.receipt-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px dashed #333;
  width: 100%;
}

.thermal-paper.size-58mm .receipt-header {
  margin-bottom: 6px;
  padding-bottom: 6px;
}

.receipt-logo-wrap {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.receipt-logo {
  max-width: 80px;
  max-height: 80px;
  object-fit: contain;
  filter: contrast(150%) grayscale(100%);
}

.thermal-paper.size-58mm .receipt-logo {
  max-width: 58px;
  max-height: 58px;
}

.receipt-title-box {
  width: 100%;
  text-align: center;
  overflow: hidden;
}

.receipt-store-name {
  font-size: 11px;
  font-weight: 800;
  line-height: 1.3;
  color: #000;
  margin-bottom: 3px;
  white-space: nowrap;
  letter-spacing: -0.2px;
}

.thermal-paper.size-58mm .receipt-store-name {
  font-size: 8.2px;
  letter-spacing: -0.35px;
}

.receipt-doc-type {
  font-size: 13px;
  font-weight: 800;
  color: #000;
  margin-bottom: 3px;
  white-space: nowrap;
  letter-spacing: -0.1px;
}

.thermal-paper.size-58mm .receipt-doc-type {
  font-size: 10px;
}

.receipt-dept {
  font-size: 11.5px;
  font-weight: 700;
  color: #111;
  margin-bottom: 3px;
  white-space: nowrap;
}

.thermal-paper.size-58mm .receipt-dept {
  font-size: 9.2px;
}

.receipt-tax-id {
  font-size: 11px;
  font-weight: 700;
  color: #000;
  margin-bottom: 3px;
  white-space: nowrap;
  font-family: var(--font-mono);
  letter-spacing: -0.2px;
}

.thermal-paper.size-58mm .receipt-tax-id {
  font-size: 8.5px;
  letter-spacing: -0.2px;
}

.receipt-contact {
  font-size: 9.8px;
  color: #333;
  line-height: 1.25;
  white-space: nowrap;
  letter-spacing: -0.2px;
}

.thermal-paper.size-58mm .receipt-contact {
  font-size: 7.8px;
  letter-spacing: -0.25px;
}

/* Order Meta Grid */
.receipt-meta {
  margin: 10px 0;
  font-size: 11.5px;
  color: #222;
}

.thermal-paper.size-58mm .receipt-meta {
  font-size: 10px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 3px;
}

.meta-bold {
  font-weight: 700;
  color: #000;
}

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

.receipt-divider.double {
  border-top: 2px solid #000;
}

/* Items Table */
.receipt-items-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12px;
}

.thermal-paper.size-58mm .receipt-items-table {
  font-size: 10.5px;
}

.receipt-items-table th {
  padding: 4px 0;
  text-align: left;
  border-bottom: 1px dashed #333;
  font-weight: 700;
}

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

.receipt-items-table th.text-center,
.receipt-items-table td.text-center {
  text-align: center;
}

.receipt-items-table td {
  padding: 4px 0;
  vertical-align: top;
}

.item-line-name {
  word-break: break-word;
  font-weight: 600;
}

/* Calculations & Totals */
.receipt-totals {
  margin: 10px 0;
  font-size: 12px;
}

.thermal-paper.size-58mm .receipt-totals {
  font-size: 10.5px;
}

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

.totals-row.grand-total {
  font-size: 15px;
  font-weight: 900;
  padding: 6px 0;
  border-top: 1px solid #000;
  border-bottom: 2px solid #000;
  margin: 6px 0;
}

.thermal-paper.size-58mm .totals-row.grand-total {
  font-size: 13px;
}

/* Footer Section */
.receipt-footer {
  text-align: center;
  margin-top: 14px;
  padding-top: 8px;
  font-size: 11px;
}

.receipt-footer-text {
  font-weight: 600;
  margin-bottom: 8px;
}

.receipt-barcode-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 8px 0;
}

.receipt-barcode {
  height: 40px;
  width: 80%;
  background: repeating-linear-gradient(
    90deg,
    #000 0px,
    #000 2px,
    #fff 2px,
    #fff 4px,
    #000 4px,
    #000 7px,
    #fff 7px,
    #fff 9px
  );
  margin-bottom: 3px;
}

.receipt-barcode-num {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 2px;
}

/* Drag & Drop Upload Zone */
.dropzone-card {
  border: 2px dashed var(--border-active);
  background: rgba(6, 182, 212, 0.04);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s ease;
  margin-bottom: 24px;
}

.dropzone-card:hover,
.dropzone-card.dragover {
  background: rgba(6, 182, 212, 0.1);
  border-color: var(--accent-cyan);
  transform: scale(1.01);
}

.dropzone-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  display: inline-block;
  color: var(--accent-cyan);
}

.dropzone-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.dropzone-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Settings Form Controls */
.form-group {
  margin-bottom: 18px;
}

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

.form-input, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  outline: none;
  transition: all 0.2s ease;
}

.form-input:focus, .form-textarea:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan-glow);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Notification Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border-active);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideInRight 0.3s ease-out forwards;
}

.toast.success { border-color: rgba(16, 185, 129, 0.4); box-shadow: 0 4px 20px rgba(16, 185, 129, 0.15); }
.toast.error { border-color: rgba(244, 63, 94, 0.4); box-shadow: 0 4px 20px rgba(244, 63, 94, 0.15); }

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ==========================================================================
   PRINT MEDIA STYLES - ZERO BLEED THERMAL ESC/POS (พิมพ์เฉพาะใบเสร็จอย่างเดียว)
   ========================================================================== */
@media print {
  @page {
    margin: 0 !important;
    size: auto;
  }

  html, body {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
    font-size: 12pt !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Completely hide the entire application UI and all background elements */
  .app-shell,
  .sidebar,
  .topbar,
  .main-content,
  .view-section,
  .kpi-grid,
  .dashboard-row,
  .filter-toolbar,
  .table-card,
  .panel-card,
  .dropzone-card,
  .mobile-bottom-nav,
  .sidebar-overlay,
  .toast-container,
  .modal-backdrop:not(.open),
  #newBillModal,
  #consolidatedModal,
  #pwaInstallModal,
  .modal-header,
  .modal-footer,
  .modal-close-btn,
  .paper-size-switcher,
  .btn,
  .print-hide {
    display: none !important;
  }

  /* Reset modal backdrop so ONLY the white receipt slip is output */
  .modal-backdrop.open {
    position: static !important;
    display: block !important;
    background: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    width: 100% !important;
    height: auto !important;
    opacity: 1 !important;
    visibility: visible !important;
    overflow: visible !important;
  }

  .modal-dialog {
    position: static !important;
    display: block !important;
    border: none !important;
    box-shadow: none !important;
    max-width: 100% !important;
    width: 100% !important;
    max-height: none !important;
    height: auto !important;
    background: transparent !important;
    transform: none !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  .modal-body {
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    background: transparent !important;
    display: block !important;
  }

  .receipt-preview-container {
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
    border: none !important;
    box-shadow: none !important;
  }

  /* PURE THERMAL RECEIPT SLIP ONLY (SUNMI D3 80mm SEIKO HEAD: 72mm PRINTABLE DOTS) */
  .thermal-paper {
    position: relative !important;
    box-shadow: none !important;
    margin: 0 auto !important;
    padding: 2mm 1mm !important;
    width: 72mm !important;
    max-width: 72mm !important;
    border-radius: 0 !important;
    border: none !important;
    background: #ffffff !important;
    color: #000000 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    page-break-after: avoid !important;
    page-break-before: avoid !important;
    break-after: avoid !important;
    break-before: avoid !important;
  }

  .thermal-paper.size-58mm {
    width: 48mm !important;
    max-width: 48mm !important;
    padding: 1mm 0.5mm !important;
  }

  .thermal-paper::after {
    display: none !important;
  }

  .receipt-logo {
    filter: grayscale(100%) contrast(200%) !important;
  }

  /* Keep all item rows and totals continuous without splitting or cutting */
  .receipt-items-table tr,
  .totals-row,
  .receipt-header,
  .receipt-meta,
  .receipt-footer {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
}

/* ==========================================================================
   RESPONSIVE DESIGN & MOBILE/TABLET OPTIMIZATIONS (100% PC, IPAD, MOBILE)
   ========================================================================== */

/* Component Base UI for Mobile Elements */
.mobile-menu-toggle {
  display: none;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.mobile-menu-toggle:active {
  transform: scale(0.92);
  background: var(--bg-card-hover);
}

.sidebar-close-btn {
  display: none;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: all 0.2s ease;
}

.sidebar-close-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.16);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.sidebar-overlay.open {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

/* Mobile Bottom Navigation Bar */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-nav-height) + var(--safe-bottom));
  background: rgba(13, 20, 38, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-subtle);
  box-shadow: 0 -4px 25px rgba(0, 0, 0, 0.45);
  z-index: 90;
  padding: 6px 12px calc(6px + var(--safe-bottom)) 12px;
  align-items: center;
  justify-content: space-around;
}

.mobile-nav-btn {
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
  min-width: 54px;
  outline: none;
}

.mobile-nav-btn:active {
  transform: scale(0.92);
}

.mobile-nav-btn .mobile-nav-icon {
  font-size: 1.25rem;
  line-height: 1;
  transition: transform 0.2s ease;
}

.mobile-nav-btn.active {
  color: var(--accent-cyan);
  font-weight: 700;
}

.mobile-nav-btn.active .mobile-nav-icon {
  transform: translateY(-2px);
  filter: drop-shadow(0 0 8px var(--accent-cyan-glow));
}

.mobile-nav-badge {
  position: absolute;
  top: 0px;
  right: 4px;
  background: var(--accent-cyan);
  color: #000;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 10px;
  line-height: 1.2;
}

.mobile-nav-btn.highlight-btn {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.2) 0%, rgba(99, 102, 241, 0.15) 100%);
  border: 1px solid var(--border-active);
  color: var(--accent-cyan);
  border-radius: var(--radius-md);
}

.mobile-nav-btn.highlight-amber {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, rgba(217, 119, 6, 0.15) 100%);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: var(--accent-amber);
  border-radius: var(--radius-md);
}

/* Topbar Components */
.topbar-title-wrap {
  display: flex;
  flex-direction: column;
}

.topbar-month-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-active);
  flex-shrink: 0;
}

.topbar-month-selector .select-filter {
  background: transparent;
  border: none;
  font-weight: 700;
  color: var(--text-primary);
  padding: 2px 4px;
  cursor: pointer;
  outline: none;
}

.topbar-actions-desktop {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* --------------------------------------------------------------------------
   TABLET & IPAD (768px - 1024px)
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .app-layout {
    position: relative;
  }

  /* Sidebar becomes an off-canvas drawer */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 290px;
    height: 100vh;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
    border-right: 1px solid var(--border-active);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-header {
    justify-content: space-between;
    padding: 20px 20px 16px;
  }

  .sidebar-close-btn {
    display: inline-flex;
  }

  .mobile-menu-toggle {
    display: inline-flex;
  }

  /* Topbar adjusts smoothly */
  .topbar {
    min-height: 64px;
    height: auto;
    padding: 10px 20px;
    gap: 12px;
  }

  .topbar-actions-desktop {
    display: none;
  }

  /* Bottom Navigation becomes active for easy tablet/phone access */
  .mobile-bottom-nav {
    display: flex;
  }

  .content-area {
    padding: 20px 20px calc(var(--bottom-nav-height) + var(--safe-bottom) + 20px) 20px;
  }

  /* Grid adaptations */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 22px;
  }

  .dashboard-row {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .chart-wrapper {
    height: 250px;
  }

  .best-sellers-list {
    max-height: 320px;
  }
}

/* --------------------------------------------------------------------------
   MOBILE PHONES (max-width: 767px)
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
  .topbar {
    padding: 8px 14px;
    gap: 8px;
  }

  .topbar-left {
    gap: 10px;
  }

  .page-title {
    font-size: 1.02rem;
    line-height: 1.25;
  }

  .page-breadcrumb {
    display: none;
  }

  .month-label {
    display: none;
  }

  .topbar-month-selector {
    padding: 4px 8px;
  }

  .topbar-month-selector .select-filter {
    font-size: 0.8rem;
    max-width: 130px;
  }

  .btn-refresh .btn-refresh-text {
    display: none;
  }

  .btn-refresh {
    padding: 8px 10px;
  }

  .content-area {
    padding: 14px 12px calc(var(--bottom-nav-height) + var(--safe-bottom) + 16px) 12px;
  }

  /* 2-Column Dense KPI Grid on Mobile */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
  }

  .kpi-card {
    padding: 12px 12px 10px 14px;
    border-radius: var(--radius-md);
  }

  .kpi-header {
    margin-bottom: 6px;
  }

  .kpi-label {
    font-size: 0.74rem;
    line-height: 1.2;
  }

  .kpi-icon-badge {
    width: 28px;
    height: 28px;
    font-size: 0.95rem;
    border-radius: 6px;
  }

  .kpi-value {
    font-size: 1.25rem;
    margin-bottom: 4px;
    letter-spacing: -0.5px;
  }

  .kpi-footer {
    font-size: 0.68rem;
    flex-wrap: wrap;
    gap: 4px;
  }

  /* Filter Toolbar */
  .filter-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 14px 12px;
  }

  .search-box {
    min-width: 100%;
    width: 100%;
  }

  .filter-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .filter-actions .select-filter {
    width: 100%;
  }

  /* Panels & Cards */
  .panel-card {
    padding: 16px 14px;
    border-radius: var(--radius-md);
    margin-bottom: 18px;
  }

  .panel-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 14px;
  }

  .panel-title {
    font-size: 0.96rem;
  }

  .chart-wrapper {
    height: 210px;
  }

  /* POS Table for Mobile */
  .pos-table th, .pos-table td {
    padding: 10px 10px;
    font-size: 0.82rem;
  }

  .receipt-no-tag {
    font-size: 0.78rem;
  }

  /* Modals on Mobile */
  .modal-backdrop {
    padding: 6px;
    align-items: flex-end;
  }

  .modal-dialog {
    max-width: 100%;
    width: 100%;
    max-height: 94vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(20px);
  }

  .modal-backdrop.open .modal-dialog {
    transform: translateY(0);
  }

  .modal-header {
    padding: 14px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .modal-title {
    font-size: 0.98rem;
  }

  .modal-body {
    padding: 14px 10px;
  }

  .modal-footer {
    padding: 12px 16px calc(12px + var(--safe-bottom)) 16px;
    flex-direction: column;
    gap: 8px;
  }

  .modal-footer .btn {
    width: 100%;
  }

  /* Receipt Slip Container on Mobile */
  .receipt-preview-container {
    padding: 14px 4px;
  }

  .thermal-paper {
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
    padding: 16px 10px 22px;
  }

  .thermal-paper.size-58mm {
    max-width: 270px;
    margin: 0 auto;
  }

  /* Form controls: 16px font-size prevents iOS zoom */
  .form-input, .form-textarea, .select-filter {
    font-size: 16px !important;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

/* --------------------------------------------------------------------------
   SMALL MOBILE PHONES (max-width: 380px)
   -------------------------------------------------------------------------- */
@media (max-width: 380px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  
  .topbar-month-selector .select-filter {
    max-width: 100px;
    font-size: 0.75rem;
  }

  .mobile-nav-btn {
    min-width: 48px;
    font-size: 0.68rem;
  }

  .mobile-nav-btn .mobile-nav-icon {
    font-size: 1.15rem;
  }
}

/* ==========================================================================
   SUNMI D3 15.6" (1920x1080 FULL HD) & COUNTERTOP TOUCH POS TERMINAL
   ========================================================================== */
@media (min-width: 1200px) {
  :root {
    --sidebar-width: 270px;
    --touch-target-min: 48px;
  }

  /* Touch buttons on Sunmi D3 countertop */
  .btn {
    min-height: 46px;
    padding: 10px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    touch-action: manipulation;
  }

  .btn-sm {
    min-height: 40px;
    padding: 8px 16px;
    font-size: 0.9rem;
    touch-action: manipulation;
  }

  .btn-primary {
    box-shadow: 0 4px 16px rgba(6, 182, 212, 0.35);
  }

  /* Receipts table touch rows on 15.6" screen */
  .pos-table th {
    padding: 16px 18px;
    font-size: 0.95rem;
  }

  .pos-table td {
    padding: 16px 18px;
    font-size: 0.96rem;
  }

  .pos-table tr {
    transition: background 0.15s ease;
  }

  .pos-table tr:hover {
    background: rgba(255, 255, 255, 0.04);
  }

  .pos-table tr:active {
    background: rgba(6, 182, 212, 0.12);
  }

  .receipt-no-tag {
    font-size: 0.95rem;
    padding: 6px 12px;
  }

  /* KPI cards on 15.6" widescreen */
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
  }

  .kpi-card {
    padding: 22px;
    border-radius: var(--radius-lg);
  }

  .kpi-value {
    font-size: 1.95rem;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
  }

  .kpi-label {
    font-size: 0.88rem;
  }

  .kpi-icon-badge {
    width: 44px;
    height: 44px;
    font-size: 1.35rem;
  }

  /* Receipt Modal on Sunmi D3 15.6" (1920x1080) */
  #receiptModal .modal-dialog {
    max-width: 580px;
    width: 580px;
    border-radius: 20px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7);
  }

  #receiptModal .modal-body {
    max-height: 75vh;
    padding: 18px 24px;
  }

  #receiptModal .receipt-preview-container {
    padding: 24px;
    background: #0f172a;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
  }

  /* Large tactile print button in modal footer for Sunmi D3 cashiers */
  #receiptModal .modal-footer {
    padding: 16px 24px;
    gap: 16px;
  }

  #receiptModal .modal-footer .btn-primary {
    min-height: 52px;
    padding: 14px 28px;
    font-size: 1.12rem;
    font-weight: 800;
    letter-spacing: 0.3px;
    border-radius: 12px;
    background: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%);
    box-shadow: 0 6px 24px rgba(6, 182, 212, 0.45);
  }

  #receiptModal .modal-footer .btn-secondary {
    min-height: 52px;
    padding: 14px 22px;
    font-size: 1rem;
    border-radius: 12px;
  }

  /* Paper size switcher on Sunmi D3 */
  .paper-size-switcher {
    gap: 8px;
  }

  .paper-size-switcher .size-btn {
    min-height: 38px;
    padding: 6px 16px;
    font-size: 0.95rem;
    font-weight: 700;
    border-radius: 10px;
  }

  /* Quick POS new bill modal on 15.6" */
  #newBillModal .modal-dialog {
    max-width: 720px;
    border-radius: 20px;
  }

  #consolidatedModal .modal-dialog {
    max-width: 680px;
    border-radius: 20px;
  }
}
