:root {
  --p-bg: #f1f2f4;
  --p-surface: #ffffff;
  --p-surface-subdued: #f8fafc;
  --p-border: #dde0e4;
  --p-text: #1a1c1d;
  --p-muted: #5c5f62;
  --p-primary: #111827;
  --p-accent: #008060;
  --p-accent-hover: #006e52;
  --p-success-bg: #dcfce7;
  --p-success-fg: #14532d;
  --p-warn-bg: #fef3c7;
  --p-warn-fg: #78350f;
  --p-crit-bg: #fee2e2;
  --p-crit-fg: #7f1d1d;
  --p-info-bg: #e0f2fe;
  --p-info-fg: #0c4a6e;
  --p-radius: 12px;
  --p-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--p-bg);
  color: var(--p-text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.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;
}

.app-frame {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--p-surface);
  border-bottom: 1px solid var(--p-border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--p-accent);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-subtitle {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--p-muted);
}

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

.shop-pill {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--p-surface-subdued);
  border: 1px solid var(--p-border);
  color: var(--p-muted);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background 0.14s ease, border-color 0.14s ease;
  white-space: nowrap;
}

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

.btn-primary:hover {
  background: #1f2937;
}

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

.btn-accent:hover {
  background: var(--p-accent-hover);
}

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

.btn-secondary:hover {
  background: #f6f6f7;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.main-container {
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px 24px 44px;
  display: grid;
  gap: 18px;
}

/* KPI Strip */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius);
  padding: 16px 18px;
  box-shadow: var(--p-shadow);
}

.kpi-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--p-muted);
  margin-bottom: 8px;
}

.kpi-value-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.kpi-value {
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.kpi-foot {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--p-muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.pill-success {
  background: var(--p-success-bg);
  color: var(--p-success-fg);
}

.pill-warn {
  background: var(--p-warn-bg);
  color: var(--p-warn-fg);
}

.pill-crit {
  background: var(--p-crit-bg);
  color: var(--p-crit-fg);
}

.pill-info {
  background: var(--p-info-bg);
  color: var(--p-info-fg);
}

.pill-neutral {
  background: #eef1f4;
  color: #334155;
}

/* Bulk Rule Bar */
.bulk-rule-bar {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius);
  padding: 16px 20px;
  box-shadow: var(--p-shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.bulk-rule-copy {
  flex: 1 1 320px;
  min-width: 0;
}

.section-heading {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
}

.muted-text {
  margin: 0;
  font-size: 13px;
  color: var(--p-muted);
}

.bulk-rule-controls {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  max-width: 100%;
}

.field-inline {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
}

.sr-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--p-muted);
}

.input-select,
.input-text,
.input-textarea {
  width: 100%;
  max-width: 100%;
  padding: 8px 11px;
  border: 1px solid #c9cccf;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #ffffff;
  color: var(--p-text);
}

.input-select {
  min-width: 260px;
}

/* Catalog Table Card */
.catalog-card {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius);
  box-shadow: var(--p-shadow);
  overflow: hidden;
}

.catalog-toolbar {
  padding: 14px 18px;
  border-bottom: 1px solid var(--p-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-pill {
  border: 1px solid transparent;
  background: transparent;
  color: var(--p-muted);
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.filter-pill:hover {
  background: #f3f4f6;
  color: var(--p-text);
}

.filter-pill.active {
  background: #e8f5f0;
  color: var(--p-accent);
  border-color: #b5e1d2;
}

.search-box {
  flex: 0 1 290px;
  min-width: 0;
  width: 100%;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

.polaris-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.polaris-table th {
  padding: 11px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--p-muted);
  background: var(--p-surface-subdued);
  border-bottom: 1px solid var(--p-border);
}

.polaris-table td {
  padding: 14px 16px;
  border-bottom: 1px solid #eef0f3;
  vertical-align: top;
}

.polaris-table tr:last-child td {
  border-bottom: none;
}

.sku-title {
  font-weight: 600;
  color: var(--p-text);
  display: block;
  margin-bottom: 3px;
}

.sku-meta {
  font-size: 12px;
  color: var(--p-muted);
}

.score-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.score-track {
  width: 80px;
  height: 7px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
}

.score-fill {
  height: 100%;
  border-radius: 999px;
}

.issue-list {
  margin: 5px 0 0;
  padding: 0;
  list-style: none;
  font-size: 11.5px;
  color: #991b1b;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Drawers */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  z-index: 40;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(560px, 100vw);
  height: 100vh;
  background: var(--p-surface);
  z-index: 50;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 28px rgba(15, 23, 42, 0.16);
}

.drawer[hidden],
.drawer-backdrop[hidden],
.toast-banner[hidden] {
  display: none !important;
}

.drawer-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--p-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow-tag {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--p-accent);
  margin-bottom: 3px;
}

.drawer-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--p-border);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--p-muted);
}

.drawer-body {
  padding: 18px 20px 28px;
  overflow-y: auto;
  flex: 1;
}

.form-stack {
  display: grid;
  gap: 14px;
}

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

.form-row-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-field label {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}

.form-group-box {
  border: 1px solid var(--p-border);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0;
  display: grid;
  gap: 10px;
}

.form-group-box legend {
  padding: 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--p-text);
}

.checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 4px;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  cursor: pointer;
}

.drawer-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 8px;
}

/* Preview Card inside Drawer */
.dpp-preview-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--p-border);
  border-radius: 12px;
  background: var(--p-surface-subdued);
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.qr-preview-box {
  width: 118px;
  height: 118px;
  padding: 8px;
  background: #ffffff;
  border: 1px solid var(--p-border);
  border-radius: 10px;
  flex-shrink: 0;
}

.qr-preview-box svg {
  width: 100%;
  height: 100%;
  display: block;
}

.preview-section {
  border: 1px solid var(--p-border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.preview-section h3 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--p-muted);
}

.code-chip {
  display: inline-block;
  padding: 3px 7px;
  background: #eef2f6;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  word-break: break-all;
}

.toast-banner {
  position: fixed;
  bottom: 20px;
  right: 20px;
  max-width: min(420px, calc(100vw - 32px));
  background: #0f172a;
  color: #ffffff;
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.22);
  z-index: 60;
}

.app-footer {
  width: 100%;
  max-width: 1360px;
  margin: auto auto 0;
  padding: 16px 24px 28px;
  border-top: 1px solid var(--p-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  color: var(--p-muted);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.footer-links a {
  color: var(--p-muted);
  text-decoration: none;
  font-weight: 600;
}

.footer-links a:hover {
  color: var(--p-text);
  text-decoration: underline;
}

.footer-disclaimer {
  margin: 0;
  font-size: 11.5px;
  color: var(--p-muted);
}

/* Mobile Responsive Polish (375x812) — strictly 0px horizontal overflow */
@media (max-width: 900px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 12px 14px;
  }

  .main-container {
    padding: 14px 12px 36px;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .bulk-rule-bar {
    padding: 14px;
  }

  .input-select {
    min-width: 0;
  }

  .bulk-rule-controls {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    flex: 1 1 100%;
  }

  .polaris-table thead {
    display: none;
  }

  .polaris-table,
  .polaris-table tbody,
  .polaris-table tr,
  .polaris-table td {
    display: block;
    width: 100%;
  }

  .polaris-table tr {
    padding: 12px 14px;
    border-bottom: 1px solid var(--p-border);
  }

  .polaris-table td {
    padding: 5px 0;
    border: none;
  }

  .form-row-2,
  .form-row-3 {
    grid-template-columns: 1fr;
  }
}

/* === Apple HIG & Emil Kowalski Micro-Interaction Craft === */
:root {
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}
button, .btn, .p-btn, a.btn, [role="button"] {
  transition: transform 140ms var(--ease-out-expo), background-color 160ms var(--ease-out-expo), border-color 160ms var(--ease-out-expo), box-shadow 160ms var(--ease-out-expo);
}
button:active:not(:disabled), .btn:active:not(:disabled), .p-btn:active:not(:disabled), [role="button"]:active {
  transform: scale(0.97);
}
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid #008060;
  outline-offset: 2px;
}
.kpi-val, .metric-val, td, th, .stat-num, .badge {
  font-variant-numeric: tabular-nums;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* === UI/UX Pro Max + Emil Kowalski Surface Elevation Pass === */
body {
  background: radial-gradient(circle at 50% 0%, #eef2f7 0%, #f4f6fa 52%, #f1f3f7 100%);
}
.topbar, header.topbar, .app-header {
  background: linear-gradient(180deg, #181a1f 0%, #111318 100%) !important;
  color: #ffffff !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12);
}
.topbar h1, .topbar .brand-name, .topbar .brand-title, header.topbar h1 {
  color: #ffffff !important;
  letter-spacing: -0.025em;
}
.topbar p, .topbar .brand-sub, header.topbar p {
  color: #94a3b8 !important;
}
.topbar .pill, .topbar .shop-pill, .topbar .plan-pill, .topbar .btn-outline, .topbar .btn-secondary {
  background: rgba(255, 255, 255, 0.08) !important;
  color: #f8fafc !important;
  border-color: rgba(255, 255, 255, 0.16) !important;
}
.topbar .btn-primary, .topbar button.primary {
  background: linear-gradient(180deg, #00946f 0%, #007a5b 100%) !important;
  color: #ffffff !important;
  border: 1px solid rgba(255, 255, 255, 0.18) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 2px 6px rgba(0, 128, 96, 0.28);
}
.card, .kpi-card, .panel, .rule-bar, .table-card {
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 1px 2px rgba(15, 23, 42, 0.04), 0 6px 18px rgba(15, 23, 42, 0.03);
  transition: transform 180ms var(--ease-out-expo), box-shadow 180ms var(--ease-out-expo), border-color 180ms var(--ease-out-expo);
}
.kpi-card:hover {
  transform: translateY(-1px);
  border-color: rgba(0, 128, 96, 0.25);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.05), 0 10px 24px rgba(15, 23, 42, 0.05);
}
.kpi-value, .kpi-val, .metric-val {
  letter-spacing: -0.03em;
  font-weight: 700;
}
tbody tr {
  transition: background-color 140ms var(--ease-out-expo);
}
tbody tr:hover {
  background-color: #f8fafc;
}
input:focus, select:focus, textarea:focus {
  border-color: #008060 !important;
  box-shadow: 0 0 0 3px rgba(0, 128, 96, 0.14) !important;
  outline: none;
}
