/* ==========================================================================
   Appie Koopjes Monitor - Responsive Modern UI (Light & Dark Mode)
   ========================================================================== */

:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-subtle: #eef3f8;
  --surface-hover: #e6eef7;
  --border: #dde5ef;
  --text: #0f172a;
  --text-muted: #5b687a;

  --ah-blue: #00ade6;
  --ah-blue-dark: #008ec0;
  --ah-blue-soft: rgba(0, 173, 230, 0.12);

  --green: #0f9d58;
  --green-soft: rgba(15, 157, 88, 0.13);
  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.15);
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.11);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 18px;
}

[data-theme="dark"] {
  --bg: #0c1118;
  --surface: #151c26;
  --surface-subtle: #1c2533;
  --surface-hover: #243043;
  --border: #273345;
  --text: #f1f5f9;
  --text-muted: #94a3b8;

  --ah-blue: #18bfff;
  --ah-blue-dark: #00a3e0;
  --ah-blue-soft: rgba(24, 191, 255, 0.16);

  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.16);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.18);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.15);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.42);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

a {
  color: var(--ah-blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 18px;
}

.inline-form {
  display: inline;
  margin: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
  color: var(--text);
  background: var(--surface-subtle);
}

.btn:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--ah-blue);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--ah-blue-dark);
}

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

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-subtle);
  color: var(--text);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.88rem;
  border-radius: 9px;
}

.btn-icon {
  padding: 8px;
  width: 36px;
  height: 36px;
}

.btn-full {
  width: 100%;
}

/* Theme icons */
.icon-sun { display: none; }
.icon-moon { display: block; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* Brand badge */
.brand-badge {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--ah-blue), #0077b6);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 173, 230, 0.32);
}

.brand-badge.small {
  width: 36px;
  height: 36px;
  border-radius: 10px;
}

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 62px;
}

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

.brand-title {
  font-size: 1.12rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.pill-demo {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber);
  vertical-align: middle;
}

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

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 5px;
  border-radius: 999px;
  background: var(--surface-subtle);
  font-size: 0.87rem;
  font-weight: 600;
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--ah-blue);
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
}

.status-dot.ok { background: var(--green); }
.status-dot.warn { background: var(--amber); }
.status-dot.err { background: var(--red); }

/* Store Tabs Bar */
.store-tabs-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.store-tabs {
  display: flex;
  align-items: stretch;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0 0;
  scrollbar-width: thin;
}

.store-tab {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 12px;
  border: 1px solid transparent;
  border-bottom: 3px solid transparent;
  border-radius: 12px 12px 0 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.store-tab:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.store-tab.active {
  background: var(--ah-blue-soft);
  color: var(--text);
  border-bottom-color: var(--ah-blue);
}

.store-tab-text {
  display: flex;
  flex-direction: column;
}

.store-tab-name {
  font-weight: 700;
  font-size: 0.94rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.store-tab-icon {
  flex-shrink: 0;
  opacity: 0.8;
}

.store-tab.active .store-tab-icon {
  color: var(--ah-blue);
  opacity: 1;
}

.store-tab-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.store-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  background: var(--surface-subtle);
  color: var(--text-muted);
}

.store-tab.active .store-tab-count {
  background: var(--ah-blue);
  color: #ffffff;
}

.store-tab-count.has-deals {
  background: var(--green-soft);
  color: var(--green);
}

.store-tab.active .store-tab-count.has-deals {
  background: var(--ah-blue);
  color: #ffffff;
}

.tab-err-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--red);
  display: inline-block;
}

/* Main content */
.main-content {
  padding-top: 20px;
  padding-bottom: 48px;
}

/* Controls Panel */
.controls-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.discount-filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
}

.discount-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-filters-toggle {
  display: none;
  margin-left: auto;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.82rem;
  padding: 6px 10px;
}

.mobile-filters-toggle.active {
  border-color: var(--ah-blue);
  background: var(--ah-blue-soft);
  color: var(--ah-blue);
}

.mini-filter-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ah-blue);
  display: inline-block;
}

.logout-icon {
  display: none;
}

.control-label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
}

.discount-value-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 800;
  background: var(--ah-blue-soft);
  color: var(--ah-blue);
}

.discount-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.preset-btn {
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.14s ease;
}

.preset-btn:hover {
  border-color: var(--ah-blue);
  color: var(--ah-blue);
}

.preset-btn.active {
  background: var(--ah-blue);
  border-color: var(--ah-blue);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 173, 230, 0.28);
}

.discount-slider-wrap {
  flex: 1;
  min-width: 150px;
  max-width: 240px;
  display: flex;
  align-items: center;
}

#discountSlider {
  width: 100%;
  accent-color: var(--ah-blue);
  cursor: pointer;
  height: 6px;
}

.secondary-controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

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

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.search-box input:focus {
  outline: none;
  border-color: var(--ah-blue);
  box-shadow: 0 0 0 3px var(--ah-blue-soft);
}

.controls-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.select-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.toggle-chip input {
  accent-color: var(--ah-blue);
  margin: 0;
}

.view-switch {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px;
}

.view-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 9px;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.view-btn.active {
  background: var(--surface);
  color: var(--ah-blue);
  box-shadow: var(--shadow-sm);
}

.category-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.cat-chip {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.cat-chip.active {
  background: var(--ah-blue-soft);
  border-color: var(--ah-blue);
  color: var(--ah-blue);
}

/* Store Status Bar */
.store-status-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 14px;
}

.store-status-left h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.muted-text {
  margin: 2px 0 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.store-status-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.meta-stats {
  display: flex;
  align-items: center;
  gap: 10px;
}

.count-pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.84rem;
  font-weight: 700;
}

.spinning {
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Error Banner */
.error-banner {
  background: var(--red-soft);
  border: 1px solid rgba(220, 38, 38, 0.35);
  border-left: 5px solid var(--red);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-bottom: 18px;
}

.error-banner-title {
  font-weight: 800;
  color: var(--red);
  margin: 0 0 4px;
  font-size: 0.98rem;
}

.error-banner p {
  margin: 4px 0;
  font-size: 0.9rem;
}

.error-details {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.06);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
  word-break: break-word;
}

[data-theme="dark"] .error-details {
  background: rgba(0, 0, 0, 0.28);
}

/* Product Cards Grid */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(238px, 1fr));
  gap: 16px;
}

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

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

.product-card.sold-out {
  opacity: 0.62;
  filter: grayscale(0.45);
}

/* Crisp white product photo stage so AH packshots pop in both Light and Dark mode */
.product-image-wrap {
  position: relative;
  background: #ffffff;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.product-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform 0.2s ease;
}

.product-card:hover .product-image {
  transform: scale(1.04);
}

.product-placeholder {
  width: 68px;
  height: 68px;
  color: #cbd5e1;
}

.badge-discount {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: -0.01em;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.16);
}

.badge-discount.tier-mega {
  background: linear-gradient(135deg, #f59e0b, #ea580c);
}

.badge-discount.tier-high {
  background: linear-gradient(135deg, #10b981, #059669);
}

.badge-discount.tier-mid {
  background: linear-gradient(135deg, #00ade6, #0284c7);
}

.badge-discount.tier-low {
  background: #64748b;
}

.badge-stock {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  background: rgba(15, 23, 42, 0.78);
  color: #ffffff;
  backdrop-filter: blur(4px);
}

.badge-stock.out {
  background: var(--red);
}

.product-body {
  padding: 13px 14px 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 8px;
}

.product-meta-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.76rem;
  color: var(--text-muted);
  min-width: 0;
}

.product-category {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.store-tag {
  display: inline-block;
  flex-shrink: 0;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--ah-blue-soft);
  color: var(--ah-blue);
  font-weight: 700;
  font-size: 0.73rem;
}

.product-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
  overflow-wrap: anywhere;
}

.product-title a {
  color: inherit;
}

.product-title a:hover {
  color: var(--ah-blue);
}

.product-weight {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.product-price-row {
  margin-top: auto;
  padding-top: 6px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.price-group {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.price-new {
  font-size: 1.32rem;
  font-weight: 900;
  color: var(--green);
  letter-spacing: -0.02em;
}

.price-old {
  font-size: 0.88rem;
  color: var(--text-muted);
  text-decoration: line-through;
}

.price-savings {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--green);
  background: var(--green-soft);
  padding: 2px 7px;
  border-radius: 6px;
}

.product-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.77rem;
  color: var(--text-muted);
}

.exp-pill {
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface-subtle);
  color: var(--text-muted);
}

.exp-pill.today {
  background: var(--amber-soft);
  color: var(--amber);
}

/* Compact List View */
.products-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.products-list .product-card {
  flex-direction: row;
  align-items: center;
  padding: 10px 14px;
  gap: 14px;
}

.products-list .product-image-wrap {
  width: 78px;
  height: 78px;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 6px;
  flex-shrink: 0;
}

.products-list .badge-discount {
  position: static;
  box-shadow: none;
  font-size: 0.8rem;
  padding: 3px 8px;
}

.products-list .badge-stock {
  position: static;
  background: var(--surface-subtle);
  color: var(--text);
}

.products-list .badge-stock.out {
  background: var(--red-soft);
  color: var(--red);
}

.products-list .product-body {
  padding: 0;
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 16px;
}

.products-list .list-main-col {
  flex: 1;
  min-width: 210px;
}

.products-list .product-price-row {
  margin-top: 0;
  padding-top: 0;
}

.products-list .product-footer {
  border-top: none;
  padding-top: 0;
  gap: 10px;
}

/* Empty & Loading states */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 56px 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
}

.empty-state h3 {
  margin: 10px 0 6px;
  color: var(--text);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--ah-blue);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}

/* Login Page */
.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top right, var(--ah-blue-soft), transparent 45%), var(--bg);
}

.login-wrapper {
  width: 100%;
  max-width: 410px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-md);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
}

.login-brand .subtitle {
  margin: 2px 0 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.86rem;
  font-weight: 700;
}

.form-group input {
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.form-group input:focus {
  outline: none;
  border-color: var(--ah-blue);
  box-shadow: 0 0 0 3px var(--ah-blue-soft);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
}

.checkbox-row input {
  accent-color: var(--ah-blue);
}

.alert {
  padding: 10px 13px;
  border-radius: 10px;
  font-size: 0.88rem;
  margin-bottom: 14px;
}

.alert-error {
  background: var(--red-soft);
  color: var(--red);
  border: 1px solid rgba(220, 38, 38, 0.3);
}

.alert-info {
  background: var(--ah-blue-soft);
  color: var(--ah-blue);
  border: 1px solid rgba(0, 173, 230, 0.3);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(3px);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

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

.modal-header h3 {
  margin: 0;
  font-size: 1.08rem;
}

.modal-body {
  padding: 18px 20px 22px;
}

.modal-section h4 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.modal-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.status-box {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-subtle);
  font-size: 0.88rem;
  margin-bottom: 12px;
}

.help-text {
  font-size: 0.86rem;
  color: var(--text-muted);
  margin: 6px 0 10px;
}

.steps-list {
  margin: 0 0 12px;
  padding-left: 18px;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.steps-list li {
  margin-bottom: 5px;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84em;
  background: var(--surface-subtle);
  padding: 2px 5px;
  border-radius: 5px;
}

.inline-action-form {
  display: flex;
  gap: 8px;
}

.inline-action-form input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
}

.lookup-results {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lookup-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  border-radius: 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--text);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
}

.toast.error {
  background: var(--red);
  color: #ffffff;
}

/* Mobile & tablet refinements */
@media (max-width: 768px) {
  .container {
    padding: 0 12px;
  }

  .topbar-inner {
    height: 54px;
    gap: 6px;
  }

  .topbar-brand {
    gap: 8px;
    min-width: 0;
  }

  .topbar-brand > div {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
  }

  .brand-title {
    font-size: 0.96rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .pill-demo {
    margin-left: 2px;
    padding: 1px 5px;
    font-size: 0.62rem;
    flex-shrink: 0;
  }

  .topbar-actions {
    gap: 3px;
    flex-shrink: 0;
  }

  .brand-badge.small {
    width: 30px;
    height: 30px;
  }

  .store-tabs {
    padding: 8px 0;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .store-tabs::-webkit-scrollbar {
    display: none;
  }

  .store-tab {
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg);
    gap: 7px;
    scroll-snap-align: start;
  }

  .store-tab.active {
    background: var(--ah-blue-soft);
    border-color: var(--ah-blue);
    border-bottom-width: 1px;
  }

  .store-tab-sub {
    display: none;
  }

  .store-tab-name {
    font-size: 0.86rem;
  }

  .store-tab-count {
    min-width: 22px;
    height: 20px;
    font-size: 0.74rem;
    padding: 0 6px;
  }

  .main-content {
    padding-top: 12px;
    padding-bottom: calc(36px + env(safe-area-inset-bottom, 0px));
  }

  .controls-panel {
    padding: 12px;
    gap: 10px;
    border-radius: 12px;
  }

  .discount-filter-row {
    gap: 8px;
  }

  .discount-header {
    width: 100%;
    gap: 6px;
    flex-wrap: nowrap;
  }

  .control-label {
    font-size: 0.8rem;
    white-space: nowrap;
  }

  .discount-value-badge {
    min-width: auto;
    padding: 3px 8px;
    font-size: 0.78rem;
    white-space: nowrap;
  }

  .mobile-filters-toggle {
    display: inline-flex;
    white-space: nowrap;
    flex-shrink: 0;
    padding: 5px 10px;
    font-size: 0.8rem;
  }

  .discount-presets {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  .discount-presets::-webkit-scrollbar {
    display: none;
  }

  .preset-btn {
    flex-shrink: 0;
    padding: 7px 12px;
    font-size: 0.82rem;
  }

  .discount-slider-wrap {
    max-width: none;
    width: 100%;
  }

  .secondary-controls-row {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding-top: 10px;
  }

  .secondary-controls-row.is-open {
    display: flex;
  }

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

  /* 16px prevents iOS Safari automatic zoom on input focus */
  .search-box input,
  .select-input,
  .form-group input,
  .inline-action-form input {
    font-size: 16px;
  }

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

  .select-input {
    width: 100%;
    min-width: 0;
    padding: 8px 10px;
  }

  .toggle-chip {
    padding: 8px 10px;
    font-size: 0.82rem;
    white-space: nowrap;
  }

  .category-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-top: 8px;
    padding-bottom: 2px;
  }

  .category-bar::-webkit-scrollbar {
    display: none;
  }

  .cat-chip {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 6px 11px;
    font-size: 0.8rem;
  }

  .store-status-bar {
    margin: 12px 0 10px;
    gap: 8px;
  }

  .store-status-left {
    width: 100%;
  }

  .store-status-left h2 {
    font-size: 1.08rem;
  }

  .store-status-right {
    width: 100%;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 8px;
  }

  .meta-stats {
    gap: 6px;
    flex-wrap: wrap;
    min-width: 0;
  }

  #refreshBtn {
    flex-shrink: 0;
    white-space: nowrap;
  }

  .count-pill {
    font-size: 0.78rem;
    padding: 3px 9px;
  }

  .muted-text {
    font-size: 0.8rem;
  }

  /* Compact list view on mobile */
  .products-list .product-card {
    padding: 10px;
    gap: 10px;
    align-items: flex-start;
  }

  .products-list .product-image-wrap {
    width: 68px;
    height: 68px;
  }

  .products-list .product-body {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    min-width: 0;
  }

  .products-list .list-main-col {
    min-width: 0;
  }

  .products-list .product-price-row {
    justify-content: flex-start;
    gap: 8px;
  }

  .products-list .product-footer {
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px;
  }

  /* Bottom-sheet style modal on mobile */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal-card {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .modal-header {
    padding: 14px 16px;
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 2;
  }

  .modal-body {
    padding: 14px 16px 20px;
  }

  .inline-action-form {
    flex-direction: column;
  }

  .toast-container {
    left: 12px;
    right: 12px;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .toast {
    text-align: center;
  }
}

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

  .logout-icon {
    display: block;
  }

  .logout-btn {
    width: 36px;
    height: 36px;
    padding: 8px;
  }

  .user-chip {
    padding: 3px;
  }

  .products-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .product-image-wrap {
    padding: 10px;
    aspect-ratio: 1 / 1;
  }

  .product-body {
    padding: 9px 10px 10px;
    gap: 5px;
  }

  .product-title {
    font-size: 0.86rem;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .product-weight {
    font-size: 0.76rem;
  }

  .product-price-row {
    padding-top: 4px;
    gap: 4px;
    flex-wrap: wrap;
  }

  .price-group {
    gap: 5px;
    flex-wrap: wrap;
  }

  .price-new {
    font-size: 1.08rem;
  }

  .price-old {
    font-size: 0.78rem;
  }

  .price-savings {
    display: none;
  }

  .badge-discount {
    top: 7px;
    left: 7px;
    font-size: 0.74rem;
    padding: 3px 7px;
  }

  .badge-stock {
    top: 7px;
    right: 7px;
    font-size: 0.7rem;
    padding: 3px 7px;
  }

  .product-footer {
    padding-top: 6px;
    gap: 4px;
    font-size: 0.71rem;
  }

  .exp-pill {
    padding: 2px 6px;
    font-size: 0.7rem;
    white-space: nowrap;
  }

  .time-label {
    white-space: nowrap;
  }

  .login-card {
    padding: 22px 18px;
  }
}

@media (max-width: 340px) {
  .products-grid {
    grid-template-columns: 1fr;
  }
}
