/* ═══════════════════════════════════════════════════════════════════════════
   Comment Shop admin UI
   Design system: 8px spacing scale, token-driven radius/shadow/color,
   WCAG AA color pairs. All component class names are a public contract
   consumed by inline scripts and public/js/* — do not rename.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── 1. Design tokens ── */
:root {
  /* Brand */
  --primary: #0f766e;
  --primary-dark: #0b5d56;
  --primary-soft: #e6f4f1;

  /* Surfaces */
  --sidebar-bg: #ffffff;
  --sidebar-text: #47525e;
  --sidebar-active: #0f766e;
  --card-bg: #ffffff;
  --body-bg: #f6f8fa;
  --surface-sunken: #f8fafc;

  /* Ink — all pairs ≥ 4.5:1 on white */
  --text: #101828;
  --text-muted: #5d6b7a;
  --border: #e3e8ee;
  --border-strong: #c9d2dc;

  /* Semantic — AA against white for text and for white-on-fill buttons */
  --success: #15803d;
  --danger: #b93448;
  --warning: #935e0b;
  --info: #2563a6;

  /* Focus ring */
  --focus: rgba(15, 118, 110, 0.25);

  /* 8px spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Radius scale */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Elevation */
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.10);
  --shadow-lg: 0 20px 48px rgba(16, 24, 40, 0.16);

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI Variable Text', 'Segoe UI', Inter, system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'Cascadia Mono', Consolas, monospace;
}

/* ── 2. Base ── */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: var(--body-bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

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

svg { display: block; }
button, input, select, textarea { font: inherit; }

h1, h2, h3 { letter-spacing: -0.01em; }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: #f1f5f9;
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 5px;
}

/* Native hidden state must win over layout declarations on async screens. */
[hidden] { display: none !important; }

/* ── 3. Sidebar ── */
.sidebar {
  width: 252px;
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  border-right: 1px solid var(--border);
  transition: transform 0.2s ease;
}

.sidebar-brand {
  min-height: 72px;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-brand h2 {
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.sidebar-brand span.emoji { font-size: 20px; }

.brand-link { display: flex; align-items: center; gap: var(--space-3); min-width: 0; color: var(--text); text-decoration: none; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; flex: 0 0 36px; background: var(--primary); color: #fff; border-radius: var(--radius-md); }
.brand-mark svg { width: 20px; height: 20px; }
.brand-copy { min-width: 0; display: flex; flex-direction: column; }
.brand-copy strong { font-size: 14px; line-height: 1.3; }
.brand-copy small { margin-top: 2px; color: var(--text-muted); font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }

.sidebar-nav { flex: 1; padding: var(--space-4) var(--space-3); overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 38px;
  padding: var(--space-2) var(--space-3);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  border-radius: var(--radius-sm);
}
.nav-item + .nav-item { margin-top: 2px; }
.nav-item:hover { background: var(--surface-sunken); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.nav-item .nav-icon { width: 20px; height: 20px; display: grid; place-items: center; flex: 0 0 20px; }
.nav-item .nav-icon svg { width: 17px; height: 17px; }

.nav-group + .nav-group { margin-top: var(--space-5); }
.nav-group-label {
  padding: 0 var(--space-3) var(--space-2);
  color: #8a95a1;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.nav-group:first-child .nav-group-label { display: none; }

.sidebar-bottom { margin-top: auto; }
.language-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-1);
  margin: 0 var(--space-3) var(--space-3);
  padding: 3px;
  background: #eef1f4;
  border-radius: var(--radius-sm);
}
.language-button {
  min-height: 28px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.language-button.active { background: #fff; color: var(--text); box-shadow: var(--shadow-xs); }

.sidebar-footer {
  padding: var(--space-3);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
}
.sidebar-user-name { color: var(--text); font-size: 12px; font-weight: 700; }
.sidebar-user-email { margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-user { display: grid; grid-template-columns: 34px minmax(0, 1fr) 32px; align-items: center; gap: var(--space-2); }
.user-avatar {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 700;
}
.user-copy { min-width: 0; display: flex; flex-direction: column; text-align: left; }
.user-copy strong, .user-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-copy strong { color: var(--text); font-size: 12.5px; font-weight: 600; }
.user-copy small { color: var(--text-muted); font-size: 11px; }
.sidebar-user-skeleton { height: 34px; border-radius: var(--radius-sm); background: #eef1f4; }

.sidebar-logout { width: 32px; margin-top: 0; border: 0; background: transparent; color: var(--text-muted); }
.sidebar-logout:hover { border: 0; background: var(--surface-sunken); color: var(--text); }

.sidebar-backdrop { display: none; }
.sidebar-close, .mobile-menu-button { display: none; }

/* ── 4. Main layout ── */
.main {
  margin-left: 252px;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(1.4) blur(6px);
  border-bottom: 1px solid var(--border);
  min-height: 72px;
  padding: var(--space-3) clamp(20px, 3vw, 32px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar h1 { font-size: 18px; font-weight: 650; color: var(--text); line-height: 1.25; }
.topbar-actions { display: flex; gap: var(--space-2); align-items: center; flex-shrink: 0; }
.topbar-actions .badge { min-height: 26px; }

.page-heading { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.page-heading-icon {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  flex: 0 0 38px;
  border-radius: var(--radius-md);
  background: var(--primary-soft);
  color: var(--primary-dark);
}
.page-heading-icon svg { width: 19px; height: 19px; }
.page-heading p { margin-top: 2px; color: var(--text-muted); font-size: 12.5px; }

.content {
  width: 100%;
  max-width: 1480px;
  min-width: 0;
  padding: var(--space-5) clamp(20px, 3vw, 32px) var(--space-7);
  flex: 1;
}

/* ── 5. Cards ── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  min-width: 0;
}
.card-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--space-4);
}
.card-title svg { width: 16px; height: 16px; color: var(--primary); }

/* ── 6. Stats ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.stats-grid-fixed { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)) !important; }
.inventory-stats { margin-bottom: var(--space-5); }

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  padding: var(--space-4) var(--space-4) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}
.stat-card .stat-icon {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  color: var(--text-muted);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.stat-card .stat-icon svg { width: 17px; height: 17px; }
.stat-card .stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-card .stat-label { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }

.stat-card.primary .stat-value { color: var(--primary); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.primary .stat-icon { background: var(--primary-soft); border-color: transparent; color: var(--primary-dark); }
.stat-card.success .stat-icon { background: #e7f6ed; border-color: transparent; color: var(--success); }
.stat-card.warning .stat-icon { background: #fdf3e1; border-color: transparent; color: var(--warning); }
.stat-card.danger .stat-icon { background: #fdecee; border-color: transparent; color: var(--danger); }

/* ── 7. Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-xs); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #116632; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #9c2739; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover:not(:disabled) { background: #7a4d08; }
.btn-outline { background: #fff; border-color: var(--border-strong); color: var(--text); box-shadow: var(--shadow-xs); }
.btn-outline:hover:not(:disabled) { background: var(--surface-sunken); border-color: #aeb9c4; }

.btn-sm { min-height: 32px; padding: var(--space-1) var(--space-3); font-size: 12.5px; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: var(--radius-md); justify-content: center; }

.icon-button {
  width: 34px; height: 34px;
  display: inline-grid; place-items: center;
  flex: 0 0 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.icon-button:hover { background: var(--surface-sunken); color: var(--text); }
.icon-button svg { width: 16px; height: 16px; }
.danger-icon { color: var(--danger); }

/* ── 8. Tables ── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
}
.table-wrap:focus-visible { outline-offset: 3px; }
.table-wrap-loading { position: relative; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  background: var(--surface-sunken);
  padding: 10px var(--space-4);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--surface-sunken); }
tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}
tbody tr:last-child td { border-bottom: none; }

.table-actions { display: inline-flex; align-items: center; gap: var(--space-1); white-space: nowrap; }
.bulk-actions { margin-bottom: var(--space-3); flex-wrap: wrap; }
.bulk-action-select { max-width: 220px; }
.cell-note { display: block; margin-top: 3px; color: var(--text-muted); font-size: 12px; }
.cell-primary { font-weight: 600; }
.cell-centered { text-align: center; }
.cell-truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-muted { color: var(--text-muted); }

.table-link { color: var(--text); font-weight: 600; text-decoration: none; }
.table-link:hover { color: var(--primary); text-decoration: underline; text-underline-offset: 2px; }
.order-number-link { text-decoration: none; }
.order-number-link code { transition: border-color 0.12s, color 0.12s; }
.order-number-link:hover code { border-color: var(--primary); color: var(--primary-dark); }
.order-row-click { cursor: pointer; }

.stock-success { color: var(--success); }
.stock-warning { color: var(--warning); }
.stock-danger { color: var(--danger); }

/* Pagination (both class contracts in use) */
.pagination-bar, .pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  min-height: 48px;
  padding-top: var(--space-3);
  color: var(--text-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* ── 9. Badges, chips, status ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
.badge::before {
  content: '';
  width: 6px; height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

/* Amber — waiting / in progress */
.badge-pending, .badge-processing, .badge-waiting_stock { background: #fdf3d7; color: #7c5308; }
/* Sky — acknowledged */
.badge-confirmed, .badge-matched, .badge-received { background: #e0f2fe; color: #075985; }
/* Green — done / money in */
.badge-paid, .badge-delivered, .badge-completed, .badge-active, .badge-converted { background: #dcf5e5; color: #146433; }
/* Blue — moving */
.badge-shipped, .badge-order_created { background: #dbeafe; color: #1e40af; }
/* Teal — held stock */
.badge-allocated, .badge-reserved { background: #d3f2ec; color: #0d5c53; }
/* Violet — waiting on customer */
.badge-awaiting_customer { background: #ede9fe; color: #5b21b6; }
/* Red — stopped */
.badge-cancelled, .badge-out_of_stock, .badge-inactive { background: #fde5e8; color: #93213a; }
/* Gray — neutral / archived */
.badge-no_match, .badge-ignored, .badge-expired { background: #eef2f6; color: #46536b; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px 8px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text);
  font-weight: 600;
}

.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; vertical-align: 1px; }
.status-dot.tone-success { background: #16a34a; }
.status-dot.tone-danger { background: #dc2626; }
.status-dot.tone-neutral { background: #94a3b8; }

/* ── 10. Forms ── */
.form-group { margin-bottom: var(--space-4); }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.form-control {
  width: 100%;
  min-height: 36px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color 0.12s, box-shadow 0.12s;
  outline: none;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.form-control.is-invalid { border-color: var(--danger); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px rgba(185, 52, 72, 0.18); }
select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%235d6b7a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: var(--space-1); }
.form-grid { gap: 14px; }
.admin-user-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.account-replace-option {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
  color: var(--text-secondary);
  font-size: 14px;
}
.account-replace-option input { margin-top: 2px; }
.inline-error { color: var(--danger); font-size: 12px; margin-top: 5px; }

/* ── 11. Toolbar / filter bars ── */
.toolbar {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.toolbar .form-control { width: auto; min-width: 160px; }

.search-box { position: relative; flex: 1; min-width: 200px; }
.search-box input {
  width: 100%;
  min-height: 36px;
  padding: var(--space-2) var(--space-3) var(--space-2) 36px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 14px;
  outline: none;
  background: #fff;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.search-box input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.search-box .search-icon {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  line-height: 1;
  pointer-events: none;
}
.search-box .search-icon svg { width: 16px; height: 16px; }

/* Filter bar variant used on Customers / Reservations */
.filter-bar {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}
.search-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  min-width: 220px;
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--text-muted);
  cursor: text;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.search-field:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
.search-field svg { width: 16px; height: 16px; flex: 0 0 16px; }
.search-field input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  padding: var(--space-2) 0;
  font-size: 14px;
  color: var(--text);
  background: transparent;
}
.filter-bar > select {
  min-height: 36px;
  padding: var(--space-2) 32px var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%235d6b7a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E") no-repeat right 12px center;
  appearance: none;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.filter-bar > select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }

/* ── 12. Modals ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.55);
  backdrop-filter: blur(2px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--space-5);
  position: relative;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.18s ease;
}
.modal-wide { max-width: 1120px; }
.modal-narrow { max-width: 380px; }
.modal-log { max-width: 580px; }
@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-5); }
.modal-header p { margin-top: 4px; color: var(--text-muted); font-size: 13px; }
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  width: 34px; height: 34px;
  display: inline-grid; place-items: center;
  flex: 0 0 34px;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  transition: background 0.12s, color 0.12s;
}
.modal-close:hover { background: var(--surface-sunken); color: var(--text); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}
.modal-context { margin: -8px 0 var(--space-4); color: var(--text-muted); font-size: 13px; }

.confirm-dialog { max-width: 420px; text-align: center; }
.confirm-icon {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  margin: 0 auto var(--space-4);
  border-radius: 50%;
  background: #fdecee;
  color: var(--danger);
}
.confirm-icon svg { width: 22px; height: 22px; }
.confirm-dialog p { margin-top: var(--space-2); color: var(--text-muted); font-size: 14px; }
.confirm-dialog .modal-footer { justify-content: center; }

/* ── 13. Alerts, notices, toasts ── */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid;
  font-size: 13.5px;
  margin-bottom: var(--space-3);
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.alert-success { background: #f0faf4; color: #146433; border-color: #bfe8cf; }
.alert-danger  { background: #fdf1f3; color: #93213a; border-color: #f3c2cb; }
.alert-info    { background: #f0f7fe; color: #175a96; border-color: #bcd9f3; }
.alert-warning { background: #fdf6e7; color: #7c5308; border-color: #ecd9a8; }

.notice {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid;
  margin-bottom: var(--space-3);
  font-size: 13px;
}
.success-notice { background: #f0faf4; border-color: #bfe8cf; color: #146433; }
.error-notice { background: #fdf1f3; border-color: #f3c2cb; color: #93213a; }
.error-list { margin: 0 0 14px 20px; color: var(--danger); font-size: 13px; }
.csv-result { margin: var(--space-1) 0 var(--space-2); }

#toast-container {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  background: #fff;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  min-width: 260px;
  max-width: 380px;
  box-shadow: var(--shadow-md);
  animation: slideInRight 0.25s ease;
}
@keyframes slideInRight {
  from { transform: translateX(24px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
.toast::before {
  content: '';
  width: 8px; height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
}
.toast.success { border-left-color: var(--success); }
.toast.success::before { background: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.error::before { background: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.warning::before { background: var(--warning); }
.toast.info { border-left-color: var(--info); }
.toast.info::before { background: var(--info); }

/* ── 14. Empty & loading states ── */
.empty-state {
  text-align: center;
  padding: var(--space-7) var(--space-4);
  color: var(--text-muted);
}
.empty-state .empty-icon {
  width: 48px; height: 48px;
  margin: 0 auto var(--space-3);
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.empty-state .empty-icon svg { width: 22px; height: 22px; }
.empty-state h3 { font-size: 15px; font-weight: 600; margin-bottom: var(--space-1); color: var(--text); }
.empty-state p { font-size: 13.5px; max-width: 380px; margin: 0 auto; }
.data-table-state { min-height: 150px; display: grid; place-items: center; align-content: center; gap: var(--space-2); }
.data-table-state-loading { min-height: 104px; }
.data-table-state-error .empty-icon { color: var(--danger); background: #fdf1f3; border-color: #f3c2cb; }

.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2.5px solid rgba(16, 24, 40, 0.12);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  z-index: 10;
}

/* ── 15. Switch toggle ── */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0;
  background: #cbd5e1;
  border-radius: 24px;
  cursor: pointer;
  transition: 0.2s;
}
.slider:before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; bottom: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-xs);
  transition: 0.2s;
}
input:checked + .slider { background: var(--primary); }
input:checked + .slider:before { transform: translateX(18px); }

/* ── 16. Authentication ── */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-5);
  background: var(--body-bg);
}
.auth-shell { width: min(100%, 420px); }
.auth-brand { margin-bottom: var(--space-5); text-align: center; }
.auth-brand-mark { display: inline-flex; align-items: center; gap: var(--space-2); font-size: 24px; font-weight: 800; color: var(--text); letter-spacing: -0.02em; }
.auth-brand-mark svg { width: 25px; height: 25px; }
.auth-brand-subtitle { margin-top: var(--space-1); font-size: 13px; color: var(--text-muted); }
.auth-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-5);
  box-shadow: var(--shadow-md);
}
.auth-panel h1 { font-size: 20px; margin-bottom: var(--space-1); }
.auth-panel-intro { color: var(--text-muted); font-size: 14px; margin-bottom: var(--space-5); }
.auth-submit { width: 100%; justify-content: center; min-height: 42px; }
.auth-error { display: none; margin-bottom: var(--space-4); }
.auth-error.visible { display: flex; }

/* ── 17. Section headings & product editor ── */
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin: var(--space-2) 0 var(--space-4);
}
.section-heading h3, .section-heading h2 { font-size: 15px; color: var(--text); }
.section-heading p, .page-section-heading p { margin-top: 3px; color: var(--text-muted); font-size: 13px; }
.page-section-heading { margin: 0 0 var(--space-4); }
.compact-heading { margin: 0 0 var(--space-3); }
.section-heading-actions { display: inline-flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; justify-content: flex-end; }

.variant-list { display: grid; gap: var(--space-2); }
.variant-generator {
  margin-bottom: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
}
.variant-generator-grid { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) 120px 120px; gap: var(--space-2); }
.variant-generator-grid .form-group { margin-bottom: 0; }
.variant-row {
  display: grid;
  grid-template-columns: 28px minmax(96px, .85fr) minmax(90px, 1fr) minmax(74px, .75fr) minmax(120px, 1.2fr) 90px 90px 110px 34px;
  gap: var(--space-2);
  align-items: end;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
}
.variant-row .form-group { margin-bottom: 0; }
.variant-index { padding-bottom: 10px; color: var(--text-muted); font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; }
.variant-summary { display: flex; align-items: center; gap: 7px; margin: 3px 0; font-size: 12px; }
.variant-summary code { color: var(--primary-dark); font-weight: 700; }
.variant-summary .badge { font-size: 10px; padding: 1px 7px; }

/* ── 18. Facebook pages integration ── */
.facebook-pages-content { display: grid; gap: var(--space-5); }
.integration-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  padding: var(--space-5);
  color: #fff;
  background: #101828;
  border: 1px solid #1f2a3c;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.integration-summary h2 { margin: 4px 0 var(--space-2); font-size: 19px; }
.integration-summary p { margin: 0; max-width: 620px; color: #cbd5e1; font-size: 13.5px; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: #7dd3c8; }
.integration-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  min-width: 340px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.05);
}
.integration-metrics div { padding: 14px; text-align: center; border-left: 1px solid rgba(255, 255, 255, 0.12); }
.integration-metrics div:first-child { border-left: 0; }
.integration-metrics strong, .integration-metrics span { display: block; }
.integration-metrics strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.integration-metrics span { margin-top: 3px; color: #cbd5e1; font-size: 11.5px; }

.facebook-page-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 390px), 1fr)); gap: var(--space-4); }
.facebook-page-card {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.facebook-page-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4); border-bottom: 1px solid var(--border); }
.facebook-page-avatar { width: 48px; height: 48px; flex: 0 0 48px; object-fit: cover; border-radius: 50%; background: #e0e7ff; }
.facebook-page-fallback { display: grid; place-items: center; color: #1d4ed8; font-size: 18px; font-weight: 700; }
.facebook-page-title { min-width: 0; flex: 1; }
.facebook-page-title h3 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.facebook-page-title p { margin: 4px 0 0; color: var(--text-muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.integration-badge { display: inline-flex; padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 650; white-space: nowrap; }
.tone-success { color: #146433; background: #dcf5e5; }
.tone-danger { color: #93213a; background: #fde5e8; }
.tone-neutral { color: #46536b; background: #eef2f6; }
.facebook-page-details { display: grid; gap: 0; margin: 0; padding: var(--space-1) var(--space-4); }
.facebook-page-details > div { display: grid; grid-template-columns: 112px 1fr; gap: var(--space-3); align-items: center; padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
.facebook-page-details > div:last-child { border: 0; }
.facebook-page-details dt { display: flex; align-items: center; gap: 7px; color: var(--text-muted); font-size: 12.5px; }
.facebook-page-details dt svg { width: 15px; height: 15px; }
.facebook-page-details dd { margin: 0; font-size: 13px; font-weight: 600; }
.facebook-page-details dd small { display: block; margin: 3px 0 0 15px; color: var(--text-muted); font-weight: 400; }
.facebook-page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: auto;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-sunken);
  border-top: 1px solid var(--border);
}
.facebook-page-actions .btn { min-height: 34px; padding: 6px 10px; font-size: 12px; }

.page-state .data-state {
  min-height: 260px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: var(--space-2);
  padding: var(--space-6);
  text-align: center;
  background: var(--card-bg);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}
.data-state.compact { min-height: 160px; }
.data-state h3, .data-state p { margin: 0; }
.data-state p { color: var(--text-muted); }
.loading-spinner { width: 30px; height: 30px; border: 3px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: page-spin .8s linear infinite; }
@keyframes page-spin { to { transform: rotate(360deg); } }
.security-note {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  padding: var(--space-3);
  color: #175a96;
  background: #f0f7fe;
  border: 1px solid #bcd9f3;
  border-radius: var(--radius-md);
  font-size: 12.5px;
}
.security-note svg { flex: 0 0 18px; width: 18px; }

.managed-page-options { display: grid; gap: var(--space-2); max-height: 320px; overflow-y: auto; margin-bottom: var(--space-4); }
.managed-page-option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.managed-page-option:hover { background: var(--surface-sunken); }
.managed-page-option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.managed-page-option input[type="checkbox"] { accent-color: var(--primary); width: 16px; height: 16px; flex: 0 0 16px; }
.managed-page-option .facebook-page-avatar { width: 36px; height: 36px; flex: 0 0 36px; font-size: 14px; }

/* ── 19. Misc components ── */
.reply-variations {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
}

.log-detail-grid { display: grid; gap: var(--space-3); margin-bottom: var(--space-4); }
.raw-payload { max-height: 220px; overflow: auto; padding: var(--space-3); border-radius: var(--radius-md); background: #111827; color: #dbeafe; font: 11px/1.55 var(--font-mono); }
.log-detail-time { margin-top: var(--space-2); color: var(--text-muted); font-size: 12px; }

.setup-steps {
  margin: 0 0 var(--space-4);
  padding-left: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: 14px;
}
.setup-steps li::marker { color: var(--primary); font-weight: 700; font-variant-numeric: tabular-nums; }
.setup-steps a { color: var(--primary); font-weight: 600; }

.responsive-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }

input[type="checkbox"] { accent-color: var(--primary); }

/* ── 20. Responsive ── */
@media (max-width: 1100px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-md); }
  .main { margin-left: 0; }
  .mobile-menu-button, .sidebar-close { display: inline-grid; }
  .sidebar-open { overflow: hidden; }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 90; border: 0; background: rgba(16, 24, 40, 0.45); cursor: default; }
  .sidebar-open .sidebar-backdrop { display: block; }
  .topbar { gap: var(--space-3); }
  .topbar .mobile-menu-button { order: -1; }
  .page-heading { margin-right: auto; }
}

@media (max-width: 768px) {
  .responsive-settings-grid { grid-template-columns: 1fr !important; }
  .admin-user-form-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content { padding: var(--space-4) 14px var(--space-6); }
  .integration-summary { align-items: stretch; flex-direction: column; }
  .integration-metrics { min-width: 0; width: 100%; }
  .facebook-page-actions .btn { flex: 1 1 130px; }
}

@media (max-width: 760px) {
  .sidebar { width: min(88vw, 300px); }
  .topbar { min-height: 64px; padding: 10px 14px; flex-wrap: wrap; }
  .page-heading-icon { display: none; }
  .page-heading h1 { font-size: 17px; }
  .page-heading p { display: none; }
  .topbar-actions { margin-left: auto; }
  .topbar-actions .btn:not(.btn-primary) { font-size: 0; width: 36px; padding: 0; }
  .topbar-actions .btn:not(.btn-primary) svg { margin: 0; }
  .stats-grid, .stats-grid-fixed { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: var(--space-2); }
  .stat-card { padding: var(--space-3); }
  .stat-card .stat-value { font-size: 21px; }
  .card { padding: var(--space-4); margin-bottom: var(--space-3); }
  .toolbar { align-items: stretch; }
  .search-box { flex-basis: 100%; }
  .toolbar .form-control { flex: 1; min-width: 0; width: 100% !important; }
  .filter-bar { align-items: stretch; }
  .search-field { flex-basis: 100%; }
  .filter-bar > select, .filter-bar > .btn { flex: 1; }
  .responsive-grid { grid-template-columns: 1fr !important; }
  .compact-heading { align-items: flex-start; flex-direction: column; }
  .section-heading-actions { width: 100%; justify-content: stretch; }
  .section-heading-actions .btn { flex: 1; }
  .variant-generator-grid { grid-template-columns: 1fr 1fr; }
  .variant-row { grid-template-columns: 28px 1fr 1fr 34px; }
  .variant-row .form-group:nth-of-type(4) { grid-column: 2 / span 2; }
  .pagination-bar, .pagination { align-items: flex-start; flex-direction: column; padding: 10px 0; }
  .modal-overlay { align-items: flex-end; padding: 32px 0 0; }
  .modal { max-width: none !important; max-height: calc(100vh - 32px); border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: var(--space-4); }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer .btn { flex: 1; }
  #toast-container { left: 14px; right: 14px; bottom: 14px; }
  .toast { min-width: 0; max-width: none; width: 100%; }
  .reply-variations { grid-template-columns: 1fr; }
  .integration-summary { padding: var(--space-4); }
}

@media (max-width: 480px) {
  .integration-metrics { grid-template-columns: 1fr; }
  .integration-metrics div { border-left: 0; border-top: 1px solid rgba(255, 255, 255, 0.12); }
  .integration-metrics div:first-child { border-top: 0; }
  .facebook-page-head { align-items: flex-start; flex-wrap: wrap; }
  .integration-badge { margin-left: 60px; }
  .facebook-page-details > div { grid-template-columns: 1fr; gap: 5px; }
  .facebook-page-details dd small { margin-left: 0; }
}

@media (max-width: 420px) {
  .stats-grid, .stats-grid-fixed { grid-template-columns: 1fr 1fr !important; }
  .stat-card .stat-icon { width: 28px; height: 28px; }
  .topbar-actions .btn-primary { padding-inline: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
