:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --primary: #0f766e;
  --primary-hover: #0d5e58;
  --primary-soft: #ecfdf5;
  --primary-text: #065f46;
  --urgent-bg: #fef2f2;
  --urgent-border: #fecaca;
  --urgent-text: #b91c1c;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --warn-text: #b45309;
  --expired-bg: #f1f5f9;
  --expired-text: #64748b;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.07);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #131c31;
  --surface-muted: #1b2742;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --border: #24324d;
  --border-strong: #334669;
  --primary: #14b8a6;
  --primary-hover: #0d9488;
  --primary-soft: rgba(20, 184, 166, 0.14);
  --primary-text: #5eead4;
  --urgent-bg: rgba(239, 68, 68, 0.16);
  --urgent-border: rgba(248, 113, 113, 0.35);
  --urgent-text: #fca5a5;
  --warn-bg: rgba(245, 158, 11, 0.16);
  --warn-border: rgba(251, 191, 36, 0.35);
  --warn-text: #fcd34d;
  --expired-bg: rgba(148, 163, 184, 0.14);
  --expired-text: #94a3b8;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.35);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Tahoma", "Noto Sans Arabic", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--primary);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}

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

.brand-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-subtitle {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.icon-btn {
  height: 36px;
  padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-muted);
  border-color: var(--border-strong);
  text-decoration: none;
}

/* Main container */
.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 16px 40px;
  flex: 1;
}

/* Search & Filter Toolbar */
.controls-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  inset-inline-start: 14px;
  color: var(--text-muted);
  pointer-events: none;
  display: flex;
  align-items: center;
}

.search-input {
  width: 100%;
  height: 46px;
  padding-inline-start: 42px;
  padding-inline-end: 40px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.96rem;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}

.search-clear {
  position: absolute;
  inset-inline-end: 8px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.search-clear:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.search-clear[hidden] {
  display: none;
}

/* Horizontal Store Filter Chips */
.chips-scroll {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.chips-scroll::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  height: 36px;
  padding: 0 13px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.chip:hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.chip-count {
  font-size: 0.74rem;
  opacity: 0.8;
  font-weight: 700;
}

/* Dropdowns row */
.filters-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: center;
}

.select-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.select-input,
.text-input,
.textarea-input {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.select-input:focus,
.text-input:focus,
.textarea-input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}

.textarea-input {
  min-height: 104px;
  resize: vertical;
  line-height: 1.5;
}

/* Summary + expired toggle bar */
.meta-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding: 0 2px;
}

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

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

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.text-link-btn {
  border: none;
  background: none;
  padding: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--primary);
}

.text-link-btn:hover {
  text-decoration: underline;
}

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

@media (min-width: 640px) {
  .offers-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 980px) {
  .offers-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.offer-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 15px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
}

.offer-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.offer-card.is-expired {
  opacity: 0.68;
}

.offer-card.is-urgent {
  border-color: var(--urgent-border);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.badges-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.store-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  background: var(--surface-muted);
  color: var(--text);
}

.store-sameh { background: #e0f2fe; color: #0369a1; }
.store-safeway { background: #fee2e2; color: #b91c1c; }
.store-ctown { background: #fef3c7; color: #92400e; }
.store-hypermax { background: #ede9fe; color: #6d28d9; }
.store-yaser { background: #dcfce7; color: #166534; }
.store-carrefour { background: #dbeafe; color: #1d4ed8; }

[data-theme="dark"] .store-sameh { background: rgba(14, 165, 233, 0.2); color: #7dd3fc; }
[data-theme="dark"] .store-safeway { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
[data-theme="dark"] .store-ctown { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
[data-theme="dark"] .store-hypermax { background: rgba(139, 92, 246, 0.22); color: #c4b5fd; }
[data-theme="dark"] .store-yaser { background: rgba(34, 197, 94, 0.2); color: #86efac; }
[data-theme="dark"] .store-carrefour { background: rgba(59, 130, 246, 0.22); color: #93c5fd; }

.category-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--surface-muted);
  color: var(--text-muted);
}

.expiry-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.73rem;
  font-weight: 700;
  white-space: nowrap;
}

.expiry-normal {
  background: var(--surface-muted);
  color: var(--text-secondary);
}

.expiry-soon {
  background: var(--urgent-bg);
  color: var(--urgent-text);
  border: 1px solid var(--urgent-border);
}

.expiry-expired {
  background: var(--expired-bg);
  color: var(--expired-text);
  text-decoration: line-through;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.product-raw-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text);
  word-break: break-word;
}

.product-en-name {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-secondary);
  line-height: 1.35;
  word-break: break-word;
}

.product-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 3px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.meta-pill {
  background: var(--surface-muted);
  padding: 2px 7px;
  border-radius: 6px;
  font-weight: 600;
}

.card-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.price-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.offer-price {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.price-currency {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-inline-start: 3px;
}

.date-range {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.unit-price-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary-text);
  font-size: 0.82rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* States */
.state-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 20px;
  text-align: center;
  color: var(--text-secondary);
}

.state-box h3 {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 1.05rem;
}

.state-box p {
  margin: 0 0 14px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.skeleton-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.skeleton-line {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-muted) 25%, var(--border) 50%, var(--surface-muted) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite linear;
}

.skeleton-line.w-40 { width: 40%; }
.skeleton-line.w-65 { width: 65%; }
.skeleton-line.w-85 { width: 85%; }
.skeleton-line.h-24 { height: 24px; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Buttons */
.btn {
  min-height: 42px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

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

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

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

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

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-muted);
  border-color: var(--border-strong);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

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

.btn-sm {
  min-height: 34px;
  padding: 0 11px;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
}

/* Admin specific layout */
.admin-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

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

.panel-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 800;
}

.panel-hint {
  margin: 0 0 12px;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.form-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inline-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
}

.inline-row > .text-input {
  flex: 1 1 180px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  font-weight: 700;
  background: var(--surface-muted);
  color: var(--text-secondary);
}

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

.status-pill.err {
  background: var(--urgent-bg);
  color: var(--urgent-text);
}

/* File picker dropzone */
.file-dropzone {
  position: relative;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg);
  padding: 20px 14px;
  text-align: center;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.file-dropzone:hover,
.file-dropzone.drag-over {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.file-dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.dropzone-title {
  font-weight: 700;
  font-size: 0.94rem;
  margin-bottom: 4px;
}

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

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.preview-item {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  aspect-ratio: 3 / 4;
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview-remove {
  position: absolute;
  top: 4px;
  inset-inline-end: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, 0.78);
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Progress box */
.progress-box {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-box[hidden] {
  display: none;
}

.progress-track {
  width: 100%;
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-muted);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: var(--radius-pill);
  transition: width 0.25s ease;
}

.progress-status {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text);
}

.progress-log {
  margin: 0;
  padding-inline-start: 18px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}

.progress-log li.log-error {
  color: var(--urgent-text);
}

.progress-log li.log-ok {
  color: var(--primary-text);
}

/* Admin offer list */
.admin-offers-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-offer-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-offer-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.admin-offer-info {
  min-width: 0;
  flex: 1;
}

.admin-offer-title {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 700;
  word-break: break-word;
}

.admin-offer-sub {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.admin-offer-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  align-items: center;
  font-size: 0.78rem;
}

.admin-offer-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.inline-edit-form {
  border-top: 1px dashed var(--border-strong);
  padding-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.inline-edit-form .span-2 {
  grid-column: 1 / -1;
}

.inline-edit-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.footer-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

/* Toast notification */
.toast-container {
  position: fixed;
  bottom: 18px;
  inset-inline-end: 16px;
  inset-inline-start: 16px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  max-width: 440px;
  text-align: center;
  pointer-events: auto;
}

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

.toast.toast-success {
  background: var(--primary);
  color: #ffffff;
}

@media (max-width: 480px) {
  .filters-row {
    grid-template-columns: 1fr;
  }

  .inline-edit-form {
    grid-template-columns: 1fr;
  }

  .inline-edit-form .span-2 {
    grid-column: auto;
  }

  .inline-edit-actions {
    grid-column: auto;
  }
}
