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

:root {
  --bg:      #f5f6f8;
  --surface: #ffffff;
  --border:  #e2e5ea;
  --text:    #1a1d23;
  --muted:   #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger:  #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #d97706;
  --radius:  6px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
}

/* NAV */
nav {
  background: var(--text);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0;
  height: 52px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}
nav .brand {
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  text-decoration: none;
  margin-right: 32px;
}
nav a {
  color: #9ca3af;
  text-decoration: none;
  padding: 0 12px;
  height: 52px;
  display: flex;
  align-items: center;
  font-size: 13px;
  font-weight: 500;
  transition: color 0.15s;
}
nav a:hover, nav a.active { color: #fff; }

/* PAGE */
.page { max-width: 1200px; margin: 0 auto; padding: 28px 24px; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 20px; font-weight: 700; }
.page-header .actions { display: flex; gap: 8px; }

/* CARDS */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 16px;
}

/* FLASH */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; font-size: 13px; }
.flash.notice { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash.alert  { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* TABLES */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: #f9fafb;
}
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f9fafb; }
.td-actions { display: flex; gap: 6px; white-space: nowrap; }

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s;
  line-height: 1;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* BADGES */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-green   { background: #dcfce7; color: #166534; }
.badge-red     { background: #fee2e2; color: #991b1b; }
.badge-yellow  { background: #fef9c3; color: #854d0e; }
.badge-blue    { background: #dbeafe; color: #1e40af; }
.badge-gray    { background: #f3f4f6; color: #374151; }

/* FORMS */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
input[type="text"],
input[type="url"],
input[type="number"],
input[type="password"],
input[type="email"],
select,
textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11px; color: var(--muted); margin-top: 2px; }
.form-check { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.form-check input[type="checkbox"] { width: auto; }
.field-errors { background: #fee2e2; border: 1px solid #fecaca; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.field-errors ul { list-style: none; color: #991b1b; font-size: 13px; }
.form-actions { display: flex; gap: 8px; padding-top: 8px; }

/* DETAIL LISTS */
dl.detail { display: grid; grid-template-columns: 160px 1fr; gap: 10px 16px; }
dl.detail dt { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; padding-top: 2px; }
dl.detail dd { font-size: 13px; word-break: break-word; }

/* IMAGES GRID */
.images-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.image-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  position: relative;
}
.image-card img { width: 100%; aspect-ratio: 1; object-fit: contain; padding: 8px; background: #f9fafb; display: block; }
.image-card .image-footer { padding: 8px; border-top: 1px solid var(--border); display: flex; gap: 4px; flex-wrap: wrap; }
.image-card .primary-badge { position: absolute; top: 6px; left: 6px; }

/* COLUMN MAPPINGS */
.mappings-grid { display: grid; grid-template-columns: 120px 1fr; gap: 8px; align-items: center; }
.mappings-grid .mapping-label { font-size: 12px; font-weight: 600; color: var(--muted); font-family: monospace; }

/* MISC */
.text-muted  { color: var(--muted); }
.text-danger { color: var(--danger); }
.mono { font-family: monospace; font-size: 12px; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state p { margin-bottom: 12px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.back-link { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.back-link:hover { color: var(--text); text-decoration: none; }
.stat-row { display: flex; gap: 24px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .value { font-size: 24px; font-weight: 700; }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* PROGRESS BARS */
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.4s ease;
}
.progress-bar-fill.indeterminate {
  width: 40% !important;
  animation: indeterminate 1.4s ease-in-out infinite;
}
@keyframes indeterminate {
  0%   { transform: translateX(-150%); }
  100% { transform: translateX(350%); }
}

/* SERVICE PANELS */
.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.service-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.service-panel--running {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px #dbeafe;
}
.service-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.service-panel-name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  margin-bottom: 2px;
}
.service-panel-class { font-size: 11px; }
.service-panel-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* SERVICE LOG */
.service-log {
  background: #0f172a;
  border-radius: 4px;
  padding: 10px 12px;
  margin-top: 10px;
  font-family: monospace;
  font-size: 11px;
  line-height: 1.6;
  max-height: 120px;
  overflow-y: auto;
  color: #94a3b8;
}
.service-log .log-line { white-space: pre-wrap; word-break: break-all; }
.service-log .log-line:last-child { color: #e2e8f0; }

/* TOGGLE SWITCH */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
  flex-shrink: 0;
}
.toggle-input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 24px;
  transition: background 0.2s;
}
.toggle-slider::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-input:checked + .toggle-slider { background: var(--success); }
.toggle-input:checked + .toggle-slider::after { transform: translateX(20px); }
.toggle--disabled { opacity: 0.4; cursor: not-allowed; }

/* CHANNEL ICONS */
.channel-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
}
.channel-icon--website  { background: #6366f1; }
.channel-icon--ebay     { background: #e53e3e; }
.channel-icon--amazon   { background: #dd6b20; }
.channel-icon--onbuy    { background: #2b6cb0; }
.channel-icon--bq       { background: #276749; }
.channel-icon--manomano { background: #6b46c1; }

/* CHANNEL TABLE (product listings edit) */
.channel-table tbody tr { transition: background 0.15s; }
.channel-row--active td:first-child { border-left: 3px solid var(--success); }
.channel-row--disabled { opacity: 0.5; }
.price-input { width: 120px !important; font-family: monospace; }

/* CHANNEL SUMMARY (product show) */
.channel-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.channel-summary-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f9fafb;
  transition: border-color 0.15s, background 0.15s;
}
.channel-summary-item--on {
  background: #f0fdf4;
  border-color: #86efac;
}
.channel-summary-info { flex: 1; min-width: 0; }
.channel-summary-name { font-weight: 600; font-size: 13px; }
.channel-summary-status { font-size: 12px; margin-top: 1px; }
.channel-summary-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot--on  { background: var(--success); }
.dot--off { background: #d1d5db; }

/* DASHBOARD */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.stat-cards--secondary {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.15s, border-color 0.15s;
}
a.stat-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(37,99,235,0.1);
  text-decoration: none;
}
.stat-card--success { border-left: 3px solid var(--success); }
.stat-card--danger  { border-left: 3px solid var(--danger); }
.stat-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}
.stat-card-icon--blue   { background: #dbeafe; color: #1d4ed8; }
.stat-card-icon--purple { background: #ede9fe; color: #7c3aed; }
.stat-card-icon--green  { background: #dcfce7; color: #16a34a; }
.stat-card-icon--red    { background: #fee2e2; color: #dc2626; }
.stat-card-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
}
.stat-card-value--sm { font-size: 24px; }
.stat-card-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.stat-card-sub {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.stat-card--sm { padding: 16px; }
.dashboard-links { display: flex; gap: 8px; flex-wrap: wrap; }

/* TABS */
.tabs__nav {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.tabs__tab {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: var(--radius) var(--radius) 0 0;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.tabs__tab:hover { color: var(--text); background: var(--bg); }
.tabs__tab--active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* Pagy pagination */
.pagination {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
}
.pagy nav { display: flex; gap: 4px; align-items: center; }
.pagy a, .pagy span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  text-decoration: none;
  color: var(--text);
  background: white;
}
.pagy a:hover { background: var(--bg); }
.pagy span.current {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  font-weight: 600;
}
.pagy span.gap, .pagy span.prev.disabled, .pagy span.next.disabled {
  color: var(--muted);
  background: var(--bg);
}
