@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: rgba(30, 30, 50, 0.7);
  --bg-card-hover: rgba(40, 40, 65, 0.8);
  --border-color: rgba(255, 255, 255, 0.08);
  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #555570;
  --accent-blue: #4f8fff;
  --accent-purple: #8b5cf6;
  --accent-green: #22c55e;
  --accent-red: #ef4444;
  --accent-orange: #f59e0b;
  --accent-cyan: #06b6d4;
  --gradient-blue: linear-gradient(135deg, #1e3a6d, #2d5aa0);
  --gradient-purple: linear-gradient(135deg, #3b1d6e, #6b3fa0);
  --gradient-green: linear-gradient(135deg, #14532d, #22c55e40);
  --gradient-red: linear-gradient(135deg, #7f1d1d, #ef444440);
  --gradient-orange: linear-gradient(135deg, #78350f, #f59e0b40);
  --sidebar-width: 190px;
  --mobile-sidebar-width: min(82vw, var(--sidebar-width));
  --app-visual-height: 100vh;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  height: 100%;
  background: var(--bg-primary);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  width: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.app-layout {
  display: flex;
  height: 100vh;
  min-width: 0;
}

.app-layout[hidden] { display: none; }

.auth-checking {
  background: var(--bg-primary);
}

.login-page {
  min-height: 100vh;
  width: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(79, 143, 255, 0.16), transparent 34%),
    radial-gradient(circle at bottom right, rgba(6, 182, 212, 0.12), transparent 30%),
    var(--bg-primary);
}

@supports (min-height: 100dvh) {
  .login-page { min-height: 100dvh; }
}

.login-panel {
  width: min(100%, 420px);
  padding: 28px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(14px);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.login-brand-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: rgba(79, 143, 255, 0.16);
  border: 1px solid rgba(79, 143, 255, 0.28);
  font-size: 24px;
  flex: 0 0 auto;
}

.login-brand h1 {
  font-size: 22px;
  line-height: 1.2;
  margin-bottom: 4px;
}

.login-brand p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.login-form {
  display: grid;
  gap: 16px;
}

.password-input-wrap {
  display: flex;
  gap: 6px;
}

.password-input-wrap .form-input {
  flex: 1;
}

.password-toggle {
  flex: 0 0 auto;
}

.login-error {
  display: none;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(239, 68, 68, 0.28);
  background: rgba(239, 68, 68, 0.1);
  color: var(--accent-red);
  font-size: 13px;
  line-height: 1.4;
}

.login-error.active {
  display: block;
}

.login-submit {
  justify-content: center;
  width: 100%;
  min-height: 44px;
}

@supports (height: 100dvh) {
  body { min-height: 100dvh; }
  .app-layout { height: 100dvh; }
}

@supports not (height: 100dvh) {
  html { height: -webkit-fill-available; }
  body { min-height: -webkit-fill-available; }
  .app-layout { height: -webkit-fill-available; }
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-header .subtitle { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.nav-list {
  flex: 1;
  padding: 12px 8px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.055);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 600;
  transition: all var(--transition);
  margin-bottom: 8px;
  user-select: none;
}

.nav-item:hover {
  background: rgba(255,255,255,0.07);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
}
.nav-item.active {
  background: rgba(79,143,255,0.16);
  border-color: rgba(79,143,255,0.42);
  color: var(--accent-blue);
}
.nav-icon { font-size: 20px; width: 24px; text-align: center; }

.auth-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: auto 12px 0;
  padding: 12px 0;
  border-top: 1px solid var(--border-color);
}

.auth-user {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
}

.auth-user span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-user-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.12);
  flex: 0 0 auto;
}

.theme-toggle-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 12px 12px;
  padding: 12px 6px 0;
  border-top: 1px solid var(--border-color);
}

.theme-toggle-wrap span {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.top-bar {
  display: none;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  align-items: center;
  gap: 12px;
}

#menuToggle {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 22px;
  cursor: pointer;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}

.main-content::-webkit-scrollbar { width: 6px; }
.main-content::-webkit-scrollbar-track { background: transparent; }
.main-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

/* Glass Card */
.glass-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(10px);
  transition: transform var(--transition), box-shadow var(--transition);
  margin-bottom: 16px;
}

.glass-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.2); }

/* Page Header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(79, 143, 255, 0.08), rgba(255, 255, 255, 0.035));
}

.page-header h2 { font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.page-icon { font-size: 24px; }
.page-desc { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.header-actions { display: flex; gap: 8px; }

/* Stats Grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 12px; }
.stats-grid-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  min-height: 96px;
  height: 96px;
  margin-bottom: 0;
}

.stat-card.gradient-blue { background: linear-gradient(135deg, rgba(79,143,255,0.18), rgba(79,143,255,0.08)); border-color: rgba(79,143,255,0.2); }
.stat-card.gradient-purple { background: linear-gradient(135deg, rgba(139,92,246,0.18), rgba(139,92,246,0.08)); border-color: rgba(139,92,246,0.2); }
.stat-card.gradient-green { background: linear-gradient(135deg, rgba(34,197,94,0.18), rgba(34,197,94,0.08)); border-color: rgba(34,197,94,0.2); }
.stat-card.gradient-red { background: linear-gradient(135deg, rgba(239,68,68,0.18), rgba(239,68,68,0.08)); border-color: rgba(239,68,68,0.2); }
.stat-card.gradient-orange { background: linear-gradient(135deg, rgba(245,158,11,0.18), rgba(245,158,11,0.08)); border-color: rgba(245,158,11,0.2); }

.stat-icon { font-size: 28px; }
.stat-value { font-size: 20px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; line-height: 1.35; }

/* Section Grid */
.section-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-bottom: 16px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-header h3 { font-size: 15px; font-weight: 600; }

/* Badges */
.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 20px;
  background: rgba(79,143,255,0.15);
  color: var(--accent-blue);
  font-weight: 600;
}

.badge-danger { background: rgba(239,68,68,0.15); color: var(--accent-red); }

/* Tags */
.tag {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

.tag-machine { background: rgba(79,143,255,0.12); color: var(--accent-blue); }
.tag-category { background: rgba(139,92,246,0.12); color: var(--accent-purple); }
.tag-source { background: rgba(245,158,11,0.12); color: var(--accent-orange); }
.tag-daily { background: rgba(34,197,94,0.12); color: var(--accent-green); }
.tag-refund { background: rgba(239,68,68,0.12); color: var(--accent-red); }
.tag-monthly { background: rgba(6,182,212,0.12); color: var(--accent-cyan); }

/* Machine Card Products (non-table context) */
.product-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 13px;
  line-height: 1.35;
}

.product-row:last-child { border-bottom: none; }
.product-name { min-width: 0; }
.product-row-extra { display: none; }
.machine-products.expanded .product-row-extra { display: flex; }

/* Product rows inside data-table: use normal table row display */
.data-table .product-row {
  display: table-row;
}
.product-stock { font-weight: 600; }
.product-stock.low-stock { color: var(--accent-red); }
.empty-hint { font-size: 13px; color: var(--text-muted); }
.more-hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.machine-expand-btn {
  width: 100%;
  margin-top: 12px;
  padding: 9px 12px;
  border: 1px solid rgba(79,143,255,0.18);
  border-radius: var(--radius-sm);
  background: rgba(79,143,255,0.08);
  color: var(--accent-blue);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.machine-expand-btn:hover {
  background: rgba(79,143,255,0.13);
  border-color: rgba(79,143,255,0.28);
}
.machine-products.expanded .expand-text,
.machine-expand-btn .collapse-text {
  display: none;
}
.machine-products.expanded .collapse-text {
  display: inline;
}

/* Warning Card */
.warning-card { border-color: rgba(239,68,68,0.2); }
.warning-list { display: flex; flex-direction: column; gap: 6px; }

.warning-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(239,68,68,0.06);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.warning-name { flex: 1; font-weight: 500; }
.warning-machine { color: var(--text-secondary); font-size: 12px; }
.warning-stock { color: var(--accent-red); font-weight: 700; }

/* Mini Chart */
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 160px; padding: 10px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.bar-value { font-size: 10px; color: var(--text-secondary); margin-bottom: 4px; white-space: nowrap; }

.bar {
  width: 100%;
  max-width: 40px;
  background: linear-gradient(180deg, var(--accent-blue), var(--accent-purple));
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: height 0.5s ease;
}

.bar-label { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

.chart-card {
  margin-bottom: 16px;
}

/* Sparkline Chart */
.sparkline-chart { display: flex; align-items: flex-end; gap: 3px; height: 20px; width: 100%; margin-top: 2px; }
.sparkline-bar-wrapper { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; cursor: pointer; }
.sparkline-bar { width: 100%; background: var(--accent-green); border-radius: 2px 2px 0 0; min-height: 2px; opacity: 0.6; transition: all 0.2s ease; }
.sparkline-label { font-size: 8px; color: var(--text-muted); margin-top: 2px; line-height: 1; transform: scale(0.9); transform-origin: top center; text-align: center; }
.sparkline-bar-wrapper:hover .sparkline-bar { opacity: 1; background: var(--accent-blue); }
.product-sales-cell {
  display: flex;
  flex-direction: column;
  width: 100%;
}
.product-sales-summary {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
}
.product-sales-label {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  line-height: 1.1;
  white-space: nowrap;
}
.product-sales-value {
  font-size: 11px;
  line-height: 1.1;
  white-space: nowrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  white-space: nowrap;
}

.btn-primary { background: var(--accent-blue); color: #fff; }
.btn-primary:hover { background: #3d7ae8; transform: translateY(-1px); }

.btn-accent { background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple)); color: #fff; }
.btn-accent:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-ai-gradient { background: linear-gradient(135deg, var(--accent-purple), var(--accent-blue)); color: #fff; }
.btn-ai-gradient:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-danger { background: var(--accent-red); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border-color); }
.btn-ghost:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }

.btn-danger-ghost { background: transparent; color: var(--text-muted); border: none; padding: 4px 8px; }
.btn-danger-ghost:hover { color: var(--accent-red); }

.btn-icon { padding: 6px 8px; min-width: auto; }
.product-action-btn {
  display: inline-grid;
  place-items: center;
  gap: 0;
  width: 28px;
  min-width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: rgba(79, 143, 255, 0.1);
  color: var(--accent-blue);
  line-height: 1;
}
.product-action-btn:hover {
  background: rgba(79, 143, 255, 0.16);
  color: var(--accent-blue);
}
.product-action-btn.btn-danger-ghost {
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-muted);
}
.product-action-btn.btn-danger-ghost:hover {
  background: rgba(239, 68, 68, 0.12);
  color: var(--accent-red);
}
.action-icon {
  width: 15px;
  height: 15px;
  display: block;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 14px; }
.btn-icon-left { font-size: 16px; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full-width { grid-column: 1 / -1; }
.flex-1 { flex: 1; }

.form-group label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.required { color: var(--accent-red); }

.form-input, .form-select {
  padding: 9px 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  transition: border-color var(--transition);
  width: 100%;
}

.form-select option {
  background-color: var(--bg-card);
  color: var(--text-primary);
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(79,143,255,0.1);
}

.form-input-sm, .form-select-sm { padding: 6px 10px; font-size: 12px; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.align-center { align-items: center; }

.api-key-input-wrap { display: flex; gap: 6px; }
.api-key-input-wrap .form-input { flex: 1; }
.btn-toggle-key { font-size: 16px; }

/* Filter Bar */
.filter-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 14px 18px; margin-bottom: 16px; }
.filter-group { display: flex; align-items: center; gap: 6px; }
.filter-group label { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.filter-inline { display: flex; gap: 8px; }

/* Products Grid */
.products-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }

.product-card { transition: transform var(--transition), box-shadow var(--transition); cursor: pointer; }
.product-card:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(0,0,0,0.3); }

.product-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.product-card-title h4 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.product-tags { display: flex; gap: 6px; }
.product-card-actions { display: flex; gap: 2px; }

.product-card-body { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.product-metric { display: flex; flex-direction: column; gap: 2px; }
.metric-label { font-size: 11px; color: var(--text-muted); }
.metric-value { font-size: 14px; font-weight: 600; }

.product-card-footer {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
}

.text-green { color: var(--accent-green); }
.text-red { color: var(--accent-red); }
.text-bold { font-weight: 600; }

/* Products Dual Panel */
.products-panels {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.product-panel { display: none; }
.product-panel.panel-active { display: block; }
.panel-machine-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
  font-weight: 600;
}

@media (min-width: 1400px) {
  .products-panels { grid-template-columns: 1fr 1fr; }
  .product-panel { display: block !important; }
  .product-machine-filter-group { display: none !important; }
}

/* Data Table */
.table-responsive { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; padding: 12px 14px; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border-color); font-weight: 600; white-space: nowrap; }
.data-table td { padding: 12px 14px; border-bottom: 1px solid rgba(255,255,255,0.03); vertical-align: middle; }
.data-table tbody tr:hover { background: rgba(255,255,255,0.02); }

/* Sortable Headers */
.th-sortable {
  cursor: pointer;
  user-select: none;
  transition: color var(--transition), background var(--transition);
}
.th-sortable:hover {
  color: var(--accent-blue);
  background: rgba(79,143,255,0.06);
}
.th-sortable.sort-asc,
.th-sortable.sort-desc {
  color: var(--accent-blue);
}
.sort-arrow {
  font-size: 11px;
  font-weight: 700;
}

/* Purchase Summary */
.purchase-summary {
  margin-top: 16px;
  padding: 14px;
  background: rgba(79,143,255,0.06);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(79,143,255,0.1);
}

.summary-item { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.summary-value { font-weight: 600; color: var(--accent-blue); }

/* Sale Items */
.sale-items-section { margin-top: 16px; border-top: 1px solid var(--border-color); padding-top: 14px; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.section-header h4 { font-size: 13px; }
.sale-items-hidden { display: none; }

.sale-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  font-size: 13px;
}

.sale-item-name { flex: 1; }
.sale-item-name small { color: var(--text-muted); }
.sale-item-input { display: flex; align-items: center; gap: 6px; }
.sale-item-input .form-input { width: 70px; text-align: center; }
.sale-item-input span { font-size: 12px; color: var(--text-muted); }

/* Edit Info */
.edit-info { margin-top: 14px; padding: 12px; background: rgba(139,92,246,0.06); border-radius: var(--radius-sm); }
.edit-info p { font-size: 12px; color: var(--text-secondary); padding: 3px 0; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.2s;
  padding: 20px;
}

.modal-overlay.modal-active { opacity: 1; }

.modal-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform 0.2s;
}

.modal-active .modal-dialog { transform: scale(1); }
.modal-wide { max-width: 600px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 { font-size: 16px; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 20px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
}

/* Confirm Dialog */
.confirm-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  max-width: 380px;
  width: 100%;
  transform: scale(0.95);
  transition: transform 0.2s;
}

.modal-active .confirm-dialog { transform: scale(1); }
.confirm-icon { font-size: 36px; margin-bottom: 12px; }
.confirm-message { font-size: 14px; color: var(--text-secondary); margin-bottom: 20px; line-height: 1.5; }
.confirm-message { white-space: pre-line; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; }

/* Toast */
.toast-message {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 2000;
  opacity: 0;
  transition: all 0.3s;
  white-space: nowrap;
}

.toast-show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { background: var(--accent-green); color: #fff; }
.toast-error { background: var(--accent-red); color: #fff; }
.toast-info { background: var(--accent-blue); color: #fff; }
.toast-icon { font-size: 16px; }

/* Empty States */
.empty-state, .empty-state-sm {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-sub { font-size: 12px; margin-top: 6px; }
.empty-state-sm { padding: 24px; }

/* AI Page */
.ai-config-card { margin-bottom: 16px; }
.config-header { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.config-icon { font-size: 20px; }
.config-hint { font-size: 12px; color: var(--text-muted); margin-top: 10px; }

.ai-action-card { margin-bottom: 20px; }

.ai-loading { text-align: center; padding: 40px; }
.ai-loading p { color: var(--text-secondary); margin-top: 12px; font-size: 13px; }

.pulse-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-blue);
  margin: 0 auto;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.8); opacity: 0.3; }
}

.ai-empty-state { text-align: center; padding: 40px; }
.ai-empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.ai-empty-state p { color: var(--text-secondary); font-size: 14px; }
.ai-empty-state .empty-sub { font-size: 12px; color: var(--text-muted); }

.ai-result-card.success { text-align: center; border-color: rgba(34,197,94,0.2); }
.ai-result-card .result-icon { font-size: 40px; margin-bottom: 10px; }
.result-time { font-size: 11px; color: var(--text-muted); }

.ai-result-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.ai-result-header h3 { font-size: 16px; }
.restock-list { display: flex; flex-direction: column; gap: 10px; }

.restock-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
}

.restock-item.urgent { border-color: rgba(239,68,68,0.3); background: rgba(239,68,68,0.05); }
.restock-info { flex: 1; }
.restock-name { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.restock-detail { font-size: 12px; color: var(--text-secondary); }
.restock-reason { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.restock-action { text-align: center; min-width: 80px; }
.restock-qty { font-size: 24px; font-weight: 700; color: var(--accent-blue); }
.restock-label { font-size: 11px; color: var(--text-muted); }

.urgency-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  display: inline-block;
  margin-bottom: 6px;
}

.urgency-紧急 { background: rgba(239,68,68,0.15); color: var(--accent-red); }
.urgency-一般 { background: rgba(245,158,11,0.15); color: var(--accent-orange); }
.urgency-充足 { background: rgba(34,197,94,0.15); color: var(--accent-green); }

/* Settings */
.settings-section { margin-bottom: 16px; }
.settings-section h3 { font-size: 16px; margin-bottom: 14px; }
.settings-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 14px; }
.settings-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.security-warning {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(245, 158, 11, 0.26);
  background: rgba(245, 158, 11, 0.1);
  color: var(--accent-orange);
  font-size: 13px;
  line-height: 1.45;
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Loading */
.page-loading { opacity: 0.5; pointer-events: none; transition: opacity 0.15s; }

/* Error */
.error-state { text-align: center; padding: 40px; }
.error-state h3 { color: var(--accent-red); margin-bottom: 8px; }

/* Sale Detail Text */
.sale-detail-text { font-size: 11px; color: var(--text-muted); max-width: 200px; line-height: 1.4; }
.text-muted { color: var(--text-muted); }

/* AI Order Recognition */
.upload-area {
  border: 2px dashed rgba(79,143,255,0.3);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: rgba(79,143,255,0.03);
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--accent-blue);
  background: rgba(79,143,255,0.08);
}
.upload-icon { font-size: 48px; margin-bottom: 12px; }
.upload-area p { color: var(--text-secondary); font-size: 14px; }
.upload-hint { font-size: 12px !important; color: var(--text-muted) !important; margin-top: 6px; }

.preview-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px; font-size: 13px; font-weight: 600;
}
.order-preview-img {
  max-width: 100%; max-height: 200px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-color); object-fit: contain;
  display: block; margin: 0 auto;
}

.ai-result-form h4 { font-size: 15px; font-weight: 600; margin-bottom: 14px; color: var(--accent-green); }
.ai-result-form h4 small { font-weight: 400; font-size: 12px; }
.ai-error-box {
  padding: 20px; text-align: center; color: var(--accent-red);
  background: rgba(239,68,68,0.06); border-radius: var(--radius-sm);
}
.ai-error-box p { margin-bottom: 12px; }

/* AI Multi-Item Results */
.ai-items-list { display: flex; flex-direction: column; gap: 12px; }
.ai-item-row {
  padding: 12px; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.03); border: 1px solid var(--border-color);
}
.ai-item-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px; font-size: 13px; font-weight: 600;
}
.ai-item-badge {
  background: var(--accent-blue); color: #fff; font-size: 11px;
  padding: 2px 8px; border-radius: 10px; font-weight: 700;
}
.ai-item-name { color: var(--text-secondary); }
.ai-item-row .form-grid { gap: 8px; }
.ai-item-row .form-group label { font-size: 11px; margin-bottom: 2px; }
.ai-item-row .form-input { padding: 6px 8px; font-size: 13px; }
.ai-match-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; margin-bottom: 10px;
  background: rgba(46,204,113,0.08); border: 1px solid rgba(46,204,113,0.2);
  border-radius: var(--radius-sm); font-size: 12px; color: #2ecc71;
}
.ai-match-badge .match-icon { font-size: 14px; }
.ai-match-badge strong { color: var(--text-primary); }
.ai-match-badge .btn { font-size: 11px; padding: 2px 8px; color: var(--text-muted); margin-left: auto; }
.match-tag {
  font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; margin-left: auto;
}
.match-ok { background: rgba(34,197,94,0.15); color: var(--accent-green); }
.match-warn { background: rgba(245,158,11,0.15); color: #f59e0b; }

.warning-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(245, 158, 11, 0.22);
  background: rgba(245, 158, 11, 0.08);
  color: var(--accent-orange);
  font-size: 12px;
  line-height: 1.45;
}

.warning-box strong {
  display: block;
  margin-bottom: 6px;
  color: var(--accent-orange);
}

.warning-box ul {
  margin: 0;
  padding-left: 18px;
}

.warning-box li + li {
  margin-top: 4px;
}

/* Product Merge UI */
.merge-group { margin-bottom: 12px; }
.merge-group-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.merge-items { display: flex; flex-direction: column; gap: 6px; }
.merge-item {
  padding: 8px 12px; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.02); border: 1px solid var(--border-color);
  transition: all var(--transition);
}
.merge-item:has(input:checked) {
  border-color: rgba(79,143,255,0.4); background: rgba(79,143,255,0.06);
}
.merge-radio-label {
  display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13px;
}
.merge-radio-label input[type="radio"] {
  accent-color: var(--accent-blue); width: 16px; height: 16px; flex-shrink: 0;
}
.merge-item-info { display: flex; flex-direction: column; gap: 3px; }
.merge-item-info strong { font-size: 14px; }
.merge-recommend {
  margin-top: 10px; padding: 8px 12px; font-size: 12px;
  background: rgba(245,158,11,0.06); border-radius: var(--radius-sm);
  color: var(--accent-orange); border: 1px solid rgba(245,158,11,0.15);
}

/* Profit Rate */
.profit-rate { color: var(--accent-green); }

/* Responsive */
@media (max-width: 768px) {
  .app-layout {
    height: var(--app-visual-height);
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: auto;
    width: var(--mobile-sidebar-width);
    height: var(--app-visual-height);
    max-height: 100dvh;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    transform: translateX(calc(-100% - 16px));
    transition: transform 0.3s;
    will-change: transform;
    box-shadow: 4px 0 20px rgba(0,0,0,0.4);
  }

  .sidebar.sidebar-open { transform: translateX(0); }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    height: var(--app-visual-height);
    background: rgba(0,0,0,0.5);
    z-index: 99;
  }
  .sidebar-overlay.active { display: block; }
  .top-bar {
    display: flex;
    padding-top: calc(12px + env(safe-area-inset-top));
    flex-shrink: 0;
  }
  .main-content {
    padding: 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
  }
  .stat-card {
    align-items: center;
    gap: 10px;
    min-height: 80px;
    height: 86px;
    padding: 14px 12px;
    border-radius: var(--radius-sm);
  }
  .stat-icon {
    width: 28px;
    flex: 0 0 28px;
    text-align: center;
    font-size: 22px;
    line-height: 1;
  }
  .stat-content {
    min-width: 0;
  }
  .stat-value {
    font-size: 17px;
    line-height: 1.2;
  }
  .stat-label {
    font-size: 11px;
    line-height: 1.25;
  }
  .stats-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .stats-grid-3 .stat-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 10px 8px;
  }
  .stats-grid-3 .stat-icon {
    font-size: 18px;
    line-height: 1;
  }
  .stats-grid-3 .stat-value {
    font-size: 15px;
    line-height: 1.15;
  }
  .stats-grid-3 .stat-label {
    font-size: 10px;
    line-height: 1.25;
  }
  .products-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }
  .login-page { padding: 16px; }
  .login-panel { padding: 22px; }
  .login-brand { align-items: flex-start; }
  .login-brand h1 { font-size: 20px; }
  .form-row.align-center { align-items: stretch; }
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 12px;
    margin-bottom: 12px;
  }
  .filter-bar .filter-group {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
  }
  .filter-bar .filter-group label {
    text-align: right;
  }
  .filter-bar .filter-search {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
  }
  .filter-bar .filter-search .form-input {
    grid-column: 2;
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 12px;
    padding: 12px 14px;
  }
  .page-header h2 {
    font-size: 21px;
  }
  .page-desc {
    margin-top: 2px;
  }
  .header-actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }
  .header-actions .btn {
    flex: 1 1 140px;
    justify-content: center;
  }
  .section-grid { grid-template-columns: 1fr; }

  .chart-card,
  .machine-card {
    padding: 16px 18px;
    border-radius: var(--radius-sm);
  }

  .chart-card .card-header,
  .machine-card .card-header {
    margin-bottom: 12px;
  }

  .modal-overlay {
    align-items: stretch;
    padding: 10px;
  }

  .modal-dialog {
    max-height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    align-self: center;
  }

  .modal-wide {
    max-width: 100%;
  }

  .modal-footer {
    position: sticky;
    bottom: 0;
    background: var(--bg-secondary);
  }

  .ai-item-header,
  .ai-match-badge {
    flex-wrap: wrap;
  }

  .ai-match-badge .btn,
  .match-tag {
    margin-left: 0;
  }

  .sale-item-row {
    align-items: flex-start;
    gap: 8px;
  }

  .sale-item-name {
    min-width: 0;
    line-height: 1.35;
    word-break: break-word;
  }

  #purchaseTableWrap {
    overflow-x: visible;
    padding: 0;
  }

  .purchase-record-card {
    padding: 12px;
  }

  .purchase-record-card .card-header {
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
  }

  .purchase-record-card .card-header h3 {
    flex-shrink: 0;
    font-size: 15px;
  }

  .purchase-record-card .filter-inline {
    flex: 1;
    min-width: 0;
    gap: 6px;
  }

  .purchase-record-card .filter-inline .form-input {
    flex: 1;
    width: auto !important;
    min-width: 0;
  }

  .purchase-record-card .filter-inline .form-select {
    width: 92px;
    flex: 0 0 92px;
  }

  #purchaseTableWrap .data-table,
  #purchaseTableWrap .data-table thead,
  #purchaseTableWrap .data-table tbody,
  #purchaseTableWrap .data-table tr,
  #purchaseTableWrap .data-table td {
    display: block;
    width: 100%;
  }

  #purchaseTableWrap .data-table thead {
    display: none;
  }

  #purchaseTableWrap .data-table tbody {
    padding: 0;
  }

  #purchaseTableWrap .data-table tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px 8px;
    position: relative;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
  }

  #purchaseTableWrap .data-table tbody tr:last-child {
    border-bottom: none;
  }

  #purchaseTableWrap .data-table td {
    padding: 0;
    border: none;
    min-width: 0;
  }

  #purchaseTableWrap .data-table td:not(:last-child) {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 34px;
    padding: 6px 8px;
    background: rgba(148, 163, 184, 0.06);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 7px;
    color: var(--text-primary);
    text-align: left;
    font-size: 12px;
  }

  #purchaseTableWrap .data-table td:nth-child(1) {
    position: absolute;
    top: 11px;
    right: 0;
    width: auto;
    min-height: 0;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.2;
  }

  #purchaseTableWrap .data-table td:nth-child(2) {
    grid-column: 1 / -1;
    min-height: 30px;
    padding: 0 122px 3px 0;
    background: transparent;
    border: none;
    justify-content: flex-start;
    text-align: left;
  }

  #purchaseTableWrap .data-table td:nth-child(1)::before,
  #purchaseTableWrap .data-table td:nth-child(2)::before {
    content: none;
  }

  #purchaseTableWrap .data-table td:nth-child(3)::before { content: "售货机"; }
  #purchaseTableWrap .data-table td:nth-child(4)::before { content: "数量"; }
  #purchaseTableWrap .data-table td:nth-child(5)::before { content: "单价"; }
  #purchaseTableWrap .data-table td:nth-child(6)::before { content: "总价"; }
  #purchaseTableWrap .data-table td:nth-child(7)::before { content: "来源"; }

  #purchaseTableWrap .data-table td:not(:last-child)::before {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    line-height: 1.15;
    flex: 0 0 auto;
  }

  #purchaseTableWrap .data-table td:nth-child(2) strong {
    display: block;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.35;
    font-size: 14px;
  }

  #purchaseTableWrap .data-table td:nth-child(3) {
    grid-column: 1 / 2;
  }

  #purchaseTableWrap .data-table td:nth-child(4) {
    grid-column: 2 / 3;
  }

  #purchaseTableWrap .data-table td:nth-child(5) {
    grid-column: 1 / 2;
  }

  #purchaseTableWrap .data-table td:nth-child(6) {
    grid-column: 2 / 3;
  }

  #purchaseTableWrap .data-table td:nth-child(7) {
    grid-column: 1 / 2;
  }

  #purchaseTableWrap .data-table td:last-child {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    grid-column: 2 / 3;
    gap: 4px;
    min-height: 34px;
    padding: 0;
  }

  #purchaseTableWrap .data-table td:last-child .btn {
    width: 28px;
    min-width: 28px;
    height: 28px;
    padding: 0;
    margin-right: 0 !important;
    justify-content: center;
  }

  .products-panels .table-responsive {
    overflow-x: visible !important;
    padding: 0 !important;
  }

  .products-panels .data-table,
  .products-panels .data-table thead,
  .products-panels .data-table tbody,
  .products-panels .data-table tr,
  .products-panels .data-table td {
    display: block;
    width: 100%;
  }

  .products-panels .data-table {
    border-collapse: separate;
  }

  .products-panels .data-table thead {
    display: none;
  }

  .products-panels .data-table tbody {
    padding: 4px 8px 10px;
  }

  .products-panels .data-table .product-row {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 5px;
    width: 100%;
    min-width: 0;
    padding: 10px 10px 9px;
    border-bottom: 1px solid var(--border-color);
  }

  .products-panels .data-table .product-row:last-child {
    border-bottom: none;
  }

  .products-panels .data-table td {
    padding: 0;
    border: none;
    min-width: 0;
    height: auto;
    vertical-align: initial;
  }

  .products-panels .data-table .product-row td:first-child {
    grid-column: 1 / 6;
    grid-row: 1;
    min-height: 34px;
    padding-right: 6px;
  }

  .products-panels .data-table .product-row td:first-child > div:first-child {
    font-size: 14px !important;
    line-height: 1.3;
    margin-bottom: 5px !important;
  }

  .products-panels .data-table .product-row td:first-child > div:last-child {
    flex-wrap: wrap;
    gap: 4px !important;
  }

  .products-panels .data-table .product-row td:not(:first-child):not(:last-child) {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 38px;
    padding: 5px 4px;
    background: rgba(148, 163, 184, 0.06);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 6px;
    color: var(--text-primary);
    text-align: center;
    font-size: 12px;
    line-height: 1.2;
  }

  .products-panels .data-table .product-row td:nth-child(7) {
    grid-column: 1 / -1;
    order: 2;
    display: flex;
    min-height: 46px;
    height: 46px;
    max-height: 46px;
    padding: 5px 8px;
    overflow: hidden;
    -webkit-transform: translateZ(0);
  }

  .products-panels .data-table .product-row td:nth-child(8) {
    order: 1;
  }

  .products-panels .data-table .product-row td:nth-child(2)::before { content: "零售价"; }
  .products-panels .data-table .product-row td:nth-child(3)::before { content: "进货均价"; }
  .products-panels .data-table .product-row td:nth-child(4)::before { content: "单品利润"; }
  .products-panels .data-table .product-row td:nth-child(5)::before { content: "利润率"; }
  .products-panels .data-table .product-row td:nth-child(6)::before { content: "库存"; }
  .products-panels .data-table .product-row td:nth-child(7)::before { content: none; }
  .products-panels .data-table .product-row td:nth-child(8)::before { content: "累计进货"; }

  .products-panels .data-table .product-row td:not(:first-child):not(:last-child)::before {
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    line-height: 1.1;
  }

  .products-panels .data-table .product-row td:nth-child(7) > div {
    width: 100% !important;
    height: 100%;
    min-width: 0;
    justify-content: center;
    gap: 2px;
  }

  .products-panels .data-table .product-row td:nth-child(7) > div > span {
    align-self: center;
    margin-bottom: 0 !important;
    font-size: 11px !important;
    line-height: 1.1;
  }

  .products-panels .data-table .product-row td:nth-child(7) .sparkline-chart {
    flex: 0 0 22px;
    height: 22px;
    max-height: 22px;
    min-height: 22px;
    gap: 4px;
    margin-top: 0 !important;
    overflow: hidden;
  }

  .products-panels .data-table .product-row td:nth-child(7) .sparkline-bar-wrapper {
    height: 22px;
    min-height: 0;
    overflow: hidden;
  }

  .products-panels .data-table .product-row td:nth-child(7) .sparkline-bar {
    flex: 0 0 auto;
  }

  .products-panels .data-table .product-row td:last-child {
    grid-column: 6 / 7;
    grid-row: 1;
    display: flex;
    align-self: start;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    width: auto;
    min-height: 30px;
    padding-top: 0;
    pointer-events: none;
    z-index: 1;
  }

  .products-panels .data-table .product-row td:last-child .btn {
    pointer-events: auto;
    width: 28px;
    min-width: 28px;
    height: 28px;
    padding: 0;
    display: inline-grid;
    place-items: center;
  }
}

@media (max-width: 480px) {
  .stat-card { padding: 14px; }
  .stat-value { font-size: 17px; }
  .bar-chart { height: 120px; }
  #purchaseTableWrap .data-table tbody tr {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #purchaseTableWrap .data-table td:nth-child(2) {
    grid-column: 1 / -1;
  }
  #purchaseTableWrap .data-table td:nth-child(3) {
    grid-column: 1 / 2;
  }
  #purchaseTableWrap .data-table td:nth-child(4) {
    grid-column: 2 / 3;
  }
  #purchaseTableWrap .data-table td:nth-child(5) {
    grid-column: 1 / 2;
  }
  #purchaseTableWrap .data-table td:nth-child(6) {
    grid-column: 2 / 3;
  }
  #purchaseTableWrap .data-table td:nth-child(7) {
    grid-column: 1 / 2;
  }
  #purchaseTableWrap .data-table td:last-child {
    grid-column: 2 / 3;
    min-height: 34px;
    margin-top: 0;
  }
  .products-panels .data-table .product-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .products-panels .data-table .product-row td:first-child {
    grid-column: 1 / 3;
  }
  .products-panels .data-table .product-row td:last-child {
    grid-column: 3 / 4;
  }
  .products-panels .data-table .product-row td:nth-child(7) {
    grid-column: 1 / -1;
  }
  .products-panels .data-table .product-row td:nth-child(7) {
    min-height: 46px;
    height: 46px;
    max-height: 46px;
  }
  .products-panels .data-table .product-row td:nth-child(7) > div {
    width: 100% !important;
    flex-basis: auto;
  }
}

@media (max-width: 768px) {
  body.browser-ios-safari {
    --mobile-sidebar-width: min(72vw, 168px);
  }

  body.browser-ios-safari .sidebar {
    height: var(--app-visual-height);
    max-height: var(--app-visual-height);
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }

  body.browser-ios-safari .nav-list {
    padding-top: 10px;
  }

  body.browser-ios-safari .nav-item {
    gap: 8px;
    padding: 11px 12px;
    font-size: 14px;
  }

  body.browser-ios-safari .nav-icon {
    width: 22px;
    font-size: 19px;
  }

  body.browser-ios-safari .sidebar-overlay {
    height: var(--app-visual-height);
  }
}

@media (max-width: 768px) {
  body.light-mode #purchaseTableWrap .data-table td:not(:last-child) {
    background: #f8fafc;
    border-color: #e2e8f0;
  }

  body.light-mode .products-panels .data-table .product-row td:not(:first-child):not(:last-child) {
    background: #f8fafc;
    border-color: #e2e8f0;
  }
}


/* Light Mode Variables */
body.light-mode {
  --bg-primary: #f3f4f6;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-card-hover: #f9fafb;
  --border-color: rgba(0, 0, 0, 0.08);
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  --accent-blue: #3b82f6;
  --accent-purple: #8b5cf6;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-orange: #f59e0b;
  --accent-cyan: #0891b2;
  
  --gradient-blue: linear-gradient(135deg, #dbeafe, #bfdbfe);
  --gradient-purple: linear-gradient(135deg, #f3e8ff, #e9d5ff);
  --gradient-green: linear-gradient(135deg, #dcfce7, #bbf7d0);
  --gradient-red: linear-gradient(135deg, #fee2e2, #fecaca);
  --gradient-orange: linear-gradient(135deg, #fef3c7, #fde68a);
}

body.light-mode .stat-card.gradient-blue,
body.light-mode .stat-card.gradient-purple,
body.light-mode .stat-card.gradient-green,
body.light-mode .stat-card.gradient-red,
body.light-mode .stat-card.gradient-orange {
  color: var(--text-primary);
}

body.light-mode .page-header {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(255, 255, 255, 0.82));
}

body.light-mode .stat-card.gradient-blue { background: linear-gradient(135deg, #dbeafe, #eff6ff); }
body.light-mode .stat-card.gradient-purple { background: linear-gradient(135deg, #ede9fe, #f5f3ff); }
body.light-mode .stat-card.gradient-green { background: linear-gradient(135deg, #dcfce7, #f0fdf4); }
body.light-mode .stat-card.gradient-red { background: linear-gradient(135deg, #fee2e2, #fff1f2); }
body.light-mode .stat-card.gradient-orange { background: linear-gradient(135deg, #fef3c7, #fffbeb); }

body.light-mode .stat-card.gradient-blue .stat-label,
body.light-mode .stat-card.gradient-purple .stat-label,
body.light-mode .stat-card.gradient-green .stat-label,
body.light-mode .stat-card.gradient-red .stat-label,
body.light-mode .stat-card.gradient-orange .stat-label {
  color: var(--text-secondary);
}

body.light-mode .sidebar-header h1 {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

body.light-mode .nav-item {
  background: #f8fafc;
  border-color: #e2e8f0;
}

body.light-mode .nav-item:hover {
  background: #eff6ff;
  border-color: #bfdbfe;
}

body.light-mode .nav-item.active {
  background: #dbeafe;
  border-color: #93c5fd;
}

/* Checkbox Custom Styles */
.checkbox-container {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
}

.checkbox-container input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-blue);
  cursor: pointer;
}

.checkbox-label {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
}

/* ========== Sales Card Layout ========== */
.sales-record-card {
  padding: 18px;
}

.sales-record-header {
  align-items: flex-start;
  gap: 12px;
}

.sales-record-filters {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.sales-search-input {
  width: 220px;
}

.sales-month-filter {
  width: 132px;
}

.sales-day-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Day group */
.sales-day-group {
  border-radius: var(--radius);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.018);
  border: 1px solid var(--border-color);
}

.sales-day-header {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto auto 20px;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(79,143,255,0.08), rgba(255,255,255,0.035));
  border-bottom: 1px solid var(--border-color);
  border-radius: 0;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s;
}

.sales-day-header:hover {
  background: linear-gradient(135deg, rgba(79,143,255,0.12), rgba(255,255,255,0.05));
}

.sales-day-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sales-day-date {
  font-size: 14px;
  font-weight: 600;
}

.sales-day-count {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(79, 143, 255, 0.12);
  color: var(--accent-blue);
  font-weight: 600;
}

.sales-day-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(76px, auto));
  gap: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

.sales-day-stats span {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  line-height: 1.15;
}

.sales-day-stats small {
  color: var(--text-muted);
  font-size: 10px;
}

.sales-day-stats span b {
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.sales-day-stats span b.text-green { color: var(--accent-green); }
.sales-day-stats span b.text-red { color: var(--accent-red); }

.sales-day-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.sales-day-action-set {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.sales-day-action-time {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  margin-right: 2px;
  font-variant-numeric: tabular-nums;
}

.sales-day-chevron {
  font-size: 12px;
  color: var(--text-muted);
  transition: transform 0.25s;
}

.sales-day-group.collapsed .sales-day-chevron {
  transform: rotate(-90deg);
}

.sales-day-body {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
}

.sales-day-group.collapsed .sales-day-body {
  display: none;
}

.sales-day-group.collapsed .sales-day-header {
  border-bottom: none;
}

/* Individual sale card */
.sale-card {
  display: flex;
  align-items: stretch;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.055);
  border-radius: 0;
  overflow: hidden;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.sale-card:last-child {
  border-bottom: none;
}

.sale-card:hover {
  background: rgba(255, 255, 255, 0.04);
}

.sale-card-accent {
  width: 3px;
  flex-shrink: 0;
  background: var(--accent-green);
}

.sale-card-accent.refund { background: var(--accent-red); }
.sale-card-accent.loss { background: var(--accent-orange); }

.sale-card-body {
  flex: 1;
  display: block;
  padding: 12px 14px;
  min-width: 0;
}

.sale-card-main {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.sale-card-topline {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  min-width: 0;
}

.sale-card-time {
  font-size: 13px;
  color: var(--text-primary);
  min-width: 44px;
  flex-shrink: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sale-machine-tag,
.sale-type-tag {
  font-size: 10px;
}

.tag-loss {
  background: rgba(245, 158, 11, 0.14);
  color: var(--accent-orange);
}

.tag-test {
  background: rgba(85, 85, 112, 0.22);
  color: var(--text-secondary);
}

.sale-card-item-count {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.sale-card-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 6px 8px;
  padding: 0;
  min-width: 0;
}

.sale-item-chip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  font-size: 12px;
  padding: 7px 9px;
  background: rgba(79, 143, 255, 0.07);
  border: 1px solid rgba(79, 143, 255, 0.13);
  border-radius: 6px;
  color: var(--text-secondary);
  line-height: 1.25;
  min-width: 0;
}

.sale-item-chip:nth-child(2n) {
  background: rgba(6, 182, 212, 0.06);
  border-color: rgba(6, 182, 212, 0.12);
}

.sale-item-chip:nth-child(3n) {
  background: rgba(139, 92, 246, 0.06);
  border-color: rgba(139, 92, 246, 0.12);
}

.sale-item-chip:hover {
  background: rgba(79, 143, 255, 0.12);
  border-color: rgba(79, 143, 255, 0.22);
}

.sale-item-name-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sale-item-qty {
  color: var(--accent-blue);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: rgba(79, 143, 255, 0.16);
  border-radius: 999px;
  padding: 1px 6px;
}

.sale-card-note {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Mobile adjustments */
@media (max-width: 900px) {
  .sales-day-header {
    grid-template-columns: minmax(150px, 1fr) auto 20px;
  }

  .sales-day-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  .sales-record-card {
    padding: 14px;
  }

  .sales-record-header {
    align-items: stretch;
  }

  .sales-record-filters {
    width: 100%;
  }

  .sales-search-input,
  .sales-month-filter {
    width: 100%;
  }

  .sales-day-header {
    grid-template-columns: 1fr 18px;
    gap: 8px;
    padding: 10px 14px;
  }

  .sales-day-chevron {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }

  .sales-day-stats {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
  }

  .sales-day-stats span {
    align-items: flex-start;
  }

  .sale-card-body {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
  }

  .sale-card-side {
    grid-template-columns: repeat(2, 1fr);
    justify-content: stretch;
    text-align: left;
    padding-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.05);
  }

  .sale-card-items {
    gap: 5px;
  }

  .sale-card-time {
    font-size: 12px;
  }
}
