:root {
  --bg-primary: #09090b;
  --bg-secondary: #121217;
  --bg-card: #16161d;
  --bg-card-hover: #1d1d26;
  --bg-elevated: #22222d;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(99, 102, 241, 0.45);
  --text-primary: #f4f4f6;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-soft: rgba(99, 102, 241, 0.15);

  --status-active-bg: rgba(16, 185, 129, 0.14);
  --status-active-text: #34d399;
  --status-active-border: rgba(16, 185, 129, 0.35);

  --status-warn-bg: rgba(245, 158, 11, 0.15);
  --status-warn-text: #fbbf24;
  --status-warn-border: rgba(245, 158, 11, 0.4);

  --status-urgent-bg: rgba(249, 115, 22, 0.18);
  --status-urgent-text: #fb923c;
  --status-urgent-border: rgba(249, 115, 22, 0.45);

  --status-upcoming-bg: rgba(59, 130, 246, 0.15);
  --status-upcoming-text: #60a5fa;
  --status-upcoming-border: rgba(59, 130, 246, 0.38);

  --status-expired-bg: rgba(239, 68, 68, 0.13);
  --status-expired-text: #f87171;
  --status-expired-border: rgba(239, 68, 68, 0.32);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-card: 0 4px 14px -4px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-elevated: #e2e8f0;
  --border-color: #e2e8f0;
  --border-highlight: rgba(79, 70, 229, 0.4);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.1);

  --status-active-bg: #ecfdf5;
  --status-active-text: #059669;
  --status-active-border: #a7f3d0;

  --status-warn-bg: #fffbeb;
  --status-warn-text: #d97706;
  --status-warn-border: #fde68a;

  --status-urgent-bg: #fff7ed;
  --status-urgent-text: #ea580c;
  --status-urgent-border: #fed7aa;

  --status-upcoming-bg: #eff6ff;
  --status-upcoming-text: #2563eb;
  --status-upcoming-border: #bfdbfe;

  --status-expired-bg: #fef2f2;
  --status-expired-text: #dc2626;
  --status-expired-border: #fecaca;

  --shadow-card: 0 2px 10px -2px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.38;
  min-height: 100vh;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
}

/* Sticky Topbar - Ultra Compact on iOS */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(9, 9, 11, 0.9);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border-color);
  padding-top: env(safe-area-inset-top, 0px);
}

[data-theme="light"] .topbar {
  background: rgba(255, 255, 255, 0.92);
}

.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}

.brand-text {
  min-width: 0;
  flex: 1;
}

.brand-title-line {
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-text h1 {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.row-count-pill {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  border: 1px solid var(--border-highlight);
  white-space: nowrap;
}

.brand-sub {
  font-size: 0.68rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.14s ease;
  white-space: nowrap;
}

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

.btn-compact {
  padding: 6px 9px;
  font-size: 0.75rem;
}

.btn-icon {
  padding: 6px 8px;
  font-size: 0.75rem;
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: #fff;
  border-color: transparent;
}

/* Search + Scan + Filter Bar */
.search-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.search-box {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  font-size: 0.85rem;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 7px 30px 7px 30px;
  border-radius: 9px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.84rem;
  outline: none;
}

.search-input:focus {
  border-color: var(--accent);
}

.search-clear {
  position: absolute;
  right: 6px;
  background: var(--bg-elevated);
  border: none;
  color: var(--text-secondary);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-scan {
  background: var(--status-active-bg);
  color: var(--status-active-text);
  border-color: var(--status-active-border);
  padding: 7px 10px;
  border-radius: 9px;
}

.btn-filter-toggle {
  position: relative;
  padding: 7px 10px;
  border-radius: 9px;
}

.btn-filter-toggle.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-hover);
}

.filter-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 999px;
}

/* Horizontal Quick Strips (Months + Statuses) */
.QuickStrip {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.sheet-tabs,
.status-pills {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.sheet-tabs::-webkit-scrollbar,
.status-pills::-webkit-scrollbar {
  display: none;
}

.sheet-tab {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 600;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.sheet-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.sheet-tab .count {
  font-size: 0.65rem;
  opacity: 0.85;
}

.status-pill {
  padding: 4px 9px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.status-pill b {
  font-size: 0.75rem;
  color: var(--text-primary);
}

.status-pill.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text-primary);
}

.pill-active b,
.pill-valid b {
  color: var(--status-active-text);
}
.pill-warn b {
  color: var(--status-warn-text);
}
.pill-urgent b {
  color: var(--status-urgent-text);
}
.pill-upcoming b {
  color: var(--status-upcoming-text);
}
.pill-expired b {
  color: var(--status-expired-text);
}
.pill-conflict {
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
}
.pill-conflict b {
  color: #f87171;
}
.pill-conflict.active {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}
.pill-conflict.active b {
  color: #fff;
}

/* Conflict Sub-Toolbar */
.conflict-toolbar {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.32);
  border-radius: var(--radius-md);
  padding: 7px 9px;
}
.conflict-toolbar[hidden] {
  display: none !important;
}
.conflict-toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

/* Conflict Warning Banner & Comparison Entries */
.conflict-alert-strip {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #f87171;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  cursor: pointer;
}
[data-theme="light"] .conflict-alert-strip {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fecaca;
}

.conflict-entry-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.conflict-entry-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-left: 3px solid #ef4444;
  border-radius: 7px;
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.74rem;
}

.conflict-entry-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

/* Main Container */
.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Collapsible Filters Panel */
.filters-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-card);
}

.filters-panel[hidden] {
  display: none !important;
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 7px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.filter-field label {
  font-size: 0.67rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

.filter-select {
  width: 100%;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.78rem;
  outline: none;
}

.toolbar-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border-color);
}

.view-switches {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 7px;
  padding: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 5px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--accent);
  color: #fff;
}

/* Summary Bar */
.summary-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
  padding: 2px 2px;
}

.results-summary {
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.active-chips {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.active-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent-hover);
  border: 1px solid var(--border-highlight);
  cursor: pointer;
}

/* Compact Promotion Cards Grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 8px;
}

.promo-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 11px;
  padding: 10px 11px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-card);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.badge-group {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  flex-wrap: nowrap;
  overflow: hidden;
}

.ctkm-pill {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  border: 1px solid var(--border-highlight);
  cursor: pointer;
  flex-shrink: 0;
}

.meta-inline-tag {
  font-size: 0.68rem;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-badge {
  font-size: 0.67rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid transparent;
  flex-shrink: 0;
}

.status-CON_HAN {
  background: var(--status-active-bg);
  color: var(--status-active-text);
  border-color: var(--status-active-border);
}
.status-SAP_HET_HAN {
  background: var(--status-warn-bg);
  color: var(--status-warn-text);
  border-color: var(--status-warn-border);
}
.status-HET_HAN_HOM_NAY {
  background: var(--status-urgent-bg);
  color: var(--status-urgent-text);
  border-color: var(--status-urgent-border);
}
.status-CHUA_BAT_DAU {
  background: var(--status-upcoming-bg);
  color: var(--status-upcoming-text);
  border-color: var(--status-upcoming-border);
}
.status-HET_HAN {
  background: var(--status-expired-bg);
  color: var(--status-expired-text);
  border-color: var(--status-expired-border);
}

.product-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}

/* Compact Promo Box */
.promo-highlight-box {
  background: rgba(99, 102, 241, 0.08);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
}

.promo-badge-line {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-hover);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.promo-detail-line {
  font-size: 0.73rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Single-line Compact Card Footer (Barcode + Date + POS Button) */
.card-footer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px dashed var(--border-color);
  font-size: 0.72rem;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: wrap;
}

.barcode-chip {
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 2px 7px;
  border-radius: 5px;
  cursor: pointer;
}

.date-chip {
  font-size: 0.7rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.footer-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.mini-btn {
  padding: 3px 7px;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 5px;
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
}

.note-banner {
  background: rgba(245, 158, 11, 0.11);
  border: 1px solid rgba(245, 158, 11, 0.28);
  color: var(--status-warn-text);
  padding: 4px 7px;
  border-radius: 5px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sample SKU list inside CTKM Group Card */
.sample-sku-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--bg-secondary);
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  max-height: 120px;
  overflow-y: auto;
}

.sample-sku-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.72rem;
  padding: 2px 0;
  border-bottom: 1px solid var(--border-color);
}

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

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 0;
}

.page-info-text {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Modals (iOS Bottom Sheet on Mobile) */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 580px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.6);
}

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

.modal-header h3 {
  font-size: 0.92rem;
  font-weight: 700;
}

.modal-close {
  background: var(--bg-elevated);
  border: none;
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
}

.modal-body {
  padding: 12px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.upload-dropzone {
  border: 2px dashed var(--border-highlight);
  background: var(--accent-soft);
  border-radius: var(--radius-md);
  padding: 18px 12px;
  text-align: center;
  cursor: pointer;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 0.74rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.barcode-stage {
  background: #ffffff;
  padding: 14px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #000;
}

.toast {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: #10b981;
  color: #fff;
  padding: 8px 15px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}

.toast[hidden] {
  display: none !important;
}

@media (max-width: 640px) {
  .hide-mobile {
    display: none;
  }
  .cards-grid {
    grid-template-columns: 1fr;
    gap: 7px;
  }
  .filters-grid {
    grid-template-columns: 1fr 1fr;
  }
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal-card {
    border-radius: 18px 18px 0 0;
    max-height: 88vh;
  }
}

@media (max-width: 390px) {
  .hide-xs {
    display: none;
  }
}
