:root {
  --ink: #142033;
  --muted: #5b6b82;
  --line: #d7deea;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --surface: #ffffff;
  --panel: #e8eef6;
  --panel-soft: #f0f7ff;
  --brand: #1f4b99;
  --brand-hover: #183d7c;
  --critical: #b42318;
  --warning: #b98900;
  --success: #0f7a4a;
  --soon: #c05717;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}
.app-header, main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 0;
}
.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  margin-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}
.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
h1 {
  margin: 0;
  font-size: 1.7rem;
  font-weight: 700;
  color: #0f172a;
  letter-spacing: -0.02em;
}
.lede {
  margin: 0.35rem 0 0;
  color: #64748b;
  max-width: 46rem;
  line-height: 1.45;
}
.header-meta {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: flex-end;
}
.shop-pill, .plan-pill {
  margin: 0;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--brand);
  font-size: 0.8rem;
  font-weight: 600;
}
.install-card, .billing-card, .legal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.15rem 1.25rem;
  margin: 1rem 0;
  box-shadow: var(--shadow);
}
.billing-card {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}
.install-card h2, .billing-card h2, .legal h2, .lookup-head h2, .addon-summary h2, .table-toolbar h2 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--brand);
}
.install-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin-top: 0.75rem;
}
.install-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  min-width: 16rem;
  flex: 1;
}
.hint {
  margin: 0.75rem 0 0;
  color: #64748b;
  font-size: 0.88rem;
}
.legal h3 { margin-top: 1.25rem; color: #0f172a; }
.legal ul { padding-left: 1.2rem; }
.legal-nav {
  margin: 0.65rem 0 0;
  font-size: 0.9rem;
}
.legal-nav a {
  font-weight: 700;
  color: var(--brand);
}
.settings,
.tiles,
.table-card,
.banner,
.lookup-card,
.sumtracker-card,
.addon-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem 1rem;
  padding: 1.15rem 1.25rem;
  margin: 1rem 0;
  align-items: end;
  background:
    linear-gradient(180deg, var(--panel-soft) 0, var(--panel-soft) 2.6rem, var(--surface) 2.6rem);
}
.settings label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}
.location-fields {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}
.field-hint {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.35;
}
.field-label-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.sales-location-field.is-locked {
  opacity: 0.72;
}
.settings .check {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
  font-weight: 600;
  padding-top: 1.15rem;
}
input, select, button, .button {
  font: inherit;
}
input, select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  color: var(--ink);
  background: #fff;
}
input:focus, select:focus {
  outline: 2px solid #93c5fd;
  outline-offset: 1px;
}
.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.settings-toolbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem 1rem;
  align-items: end;
}
.settings-toolbar .check {
  padding-top: 0;
  min-height: 2.45rem;
}
.settings-main-actions {
  display: contents;
}
.settings-main-actions .button {
  width: 100%;
  min-width: 0;
  min-height: 2.45rem;
  justify-content: center;
}
.sumtracker-setup-btn {
  min-width: 0;
}
@media (max-width: 820px) {
  .settings-toolbar {
    grid-template-columns: 1fr 1fr;
  }
}
.lookup-card,
.sumtracker-card,
.addon-card {
  padding: 1.15rem 1.25rem 1.1rem;
  margin: 0 0 1rem;
}
.addon-card {
  border-style: dashed;
  background:
    linear-gradient(180deg, rgba(31, 75, 153, 0.04), transparent 4.5rem),
    var(--surface);
}
.addon-card.is-locked {
  opacity: 0.98;
}
.addon-summary {
  list-style: none;
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  justify-content: space-between;
  cursor: pointer;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  font: inherit;
  color: inherit;
}
.addon-summary-text { min-width: 0; }
.addon-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.45rem;
}
.addon-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px solid var(--border);
}
.addon-badge-pro {
  color: #1f4b99;
  background: #e8f0ff;
  border-color: #c5d7f5;
}
.addon-summary h2 {
  margin: 0 0 0.3rem;
  font-size: 1.05rem;
}
.addon-summary .hint {
  margin: 0;
  max-width: 40rem;
}
.addon-chevron {
  flex: 0 0 auto;
  width: 1.6rem;
  height: 1.6rem;
  margin-top: 0.15rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  position: relative;
}
.addon-chevron::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 45%;
  width: 0.4rem;
  height: 0.4rem;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  transform: translate(-50%, -50%) rotate(45deg);
  transition: transform 0.15s ease;
}
.addon-card.is-open .addon-chevron::before {
  top: 55%;
  transform: translate(-50%, -50%) rotate(225deg);
}
.addon-body {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.addon-body[hidden] {
  display: none !important;
}
.addon-upsell {
  display: grid;
  gap: 0.75rem;
  justify-items: start;
  max-width: 36rem;
}
.addon-upsell p {
  margin: 0;
  color: var(--ink);
  line-height: 1.45;
}
.lookup-head {
  margin-bottom: 0.85rem;
}
.lookup-head h2 {
  margin: 0 0 0.35rem;
}
.lookup-head .hint {
  margin: 0;
  max-width: 42rem;
}
.lookup-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}
.lookup-search-wrap {
  position: relative;
  max-width: 32rem;
}
.lookup-results {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0.25rem 0;
  position: absolute;
  left: 0;
  right: 0;
  z-index: 15;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  max-height: 18rem;
  overflow: auto;
}
.lookup-results li button {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  color: var(--ink);
  font: inherit;
}
.lookup-results li button:hover,
.lookup-results li button:focus {
  background: var(--panel-soft);
  outline: none;
}
.lookup-results .thumb,
.lookup-detail .thumb {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  background: #f1f5f9;
  flex: 0 0 auto;
}
.lookup-results .thumb-empty,
.lookup-detail .thumb-empty {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #f1f5f9;
  flex: 0 0 auto;
  display: inline-block;
}
.lookup-status {
  margin: 0.5rem 0 0;
  min-height: 1.1em;
}
.lookup-status.is-error { color: var(--critical); }
.lookup-detail {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.lookup-detail-top {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  margin-bottom: 0.9rem;
}
.lookup-detail-top h3 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  color: #0f172a;
}
.lookup-detail-top .hint { margin: 0; }
.lookup-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
  gap: 0.65rem;
}
.lookup-metric {
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-soft);
}
.lookup-metric .label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.lookup-metric .value {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}
.sumtracker-head {
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.85rem;
}
.sumtracker-head .hint {
  margin: 0;
  max-width: 42rem;
}
.sumtracker-fields {
  display: grid;
  gap: 0.85rem;
}
.sumtracker-fields label,
.sumtracker-key {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}
.sumtracker-key {
  max-width: none;
}
.sumtracker-key-row {
  display: grid;
  grid-template-columns: minmax(16rem, 1fr) auto;
  gap: 0.85rem 1rem;
  align-items: end;
  max-width: 48rem;
}
.sumtracker-key-actions {
  padding-bottom: 0.05rem;
}
.api-key-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.02em;
}
.sumtracker-warehouse-row {
  display: grid;
  grid-template-columns: minmax(16rem, 1fr) auto;
  gap: 0.85rem 1rem;
  align-items: end;
  max-width: none;
}
.sumtracker-warehouse-row select {
  width: 100%;
  min-width: 0;
}
.sumtracker-actions {
  padding-bottom: 0.05rem;
  flex-wrap: wrap;
}
.sumtracker-status { margin: 0.65rem 0 0; min-height: 1.1em; font-weight: 600; }
.sumtracker-status.is-error { color: var(--critical); }
.sumtracker-status.is-ok { color: var(--success); }
.help-bubble {
  position: relative;
  flex: 0 0 auto;
}
.help-bubble > summary {
  list-style: none;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--brand);
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.7rem;
  text-align: center;
  cursor: pointer;
  user-select: none;
}
.help-bubble > summary::-webkit-details-marker { display: none; }
.help-bubble > summary:hover,
.help-bubble[open] > summary {
  border-color: var(--brand);
  background: var(--panel-soft);
  color: var(--brand);
}
.help-bubble-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 20;
  width: min(22rem, calc(100vw - 2.5rem));
  padding: 0.85rem 1rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  color: var(--ink);
  font-size: 0.86rem;
  line-height: 1.45;
}
.help-bubble-panel p { margin: 0 0 0.55rem; }
.help-bubble-panel p:last-child { margin-bottom: 0; }
.help-bubble-panel ol {
  margin: 0 0 0.65rem;
  padding-left: 1.15rem;
}
.help-bubble-panel li { margin: 0.2rem 0; }
@media (max-width: 820px) {
  .sumtracker-key-row,
  .sumtracker-warehouse-row {
    grid-template-columns: 1fr;
  }
  .help-bubble-panel {
    right: auto;
    left: 0;
  }
}
.button, button.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s ease, filter 0.12s ease, transform 0.08s ease;
}
.button:hover, button.button:hover {
  background: var(--brand-hover);
  filter: brightness(1.06);
}
.button:active, button.button:active,
#refresh.is-pressed {
  transform: translateY(1px) scale(0.98);
  background: #122f61;
  box-shadow: inset 0 2px 8px rgba(8, 15, 30, 0.35);
  filter: none;
}
#refresh {
  min-width: 10.2rem;
}
#refresh.is-busy {
  background: var(--brand-hover);
  box-shadow: inset 0 2px 8px rgba(8, 15, 30, 0.22);
}
.button.secondary {
  background: #fff;
  color: var(--brand);
  border: 1px solid var(--line);
}
.button.secondary:hover {
  background: var(--panel-soft);
  filter: none;
}
.button[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}
button:disabled { opacity: 0.55; cursor: wait; }
button:focus-visible, .button:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}
#banners { display: grid; gap: 0.6rem; }
.banner { padding: 0.75rem 1rem; font-size: 0.92rem; }
.banner.error { border-color: #f1b3ab; background: #fff4f4; color: var(--critical); }
.banner.warn { border-color: #f1d4a3; background: #fff7ea; color: #92400e; }
.banner.notice { border-color: #bfdbfe; background: var(--panel-soft); color: var(--brand); }
.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  overflow: hidden;
  margin: 1rem 0;
}
.tile {
  padding: 1.1rem 1.2rem;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, var(--panel-soft), var(--surface));
}
.tile:last-child { border-right: 0; }
.tile-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}
.tile-value {
  margin: 0.2rem 0 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #0f172a;
}
@media (max-width: 700px) {
  .tiles { grid-template-columns: 1fr; }
  .tile { border-right: 0; border-bottom: 1px solid var(--border); }
  .tile:last-child { border-bottom: 0; }
}
.table-card { margin-bottom: 2rem; overflow: hidden; }
.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.95rem 1.15rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel-soft);
}
.table-toolbar h2 {
  margin: 0;
  font-size: 1.05rem;
}
.table-wrap {
  max-height: calc(100dvh - 8.5rem);
  overflow: auto;
  overscroll-behavior: contain;
}
#productsTable {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.92rem;
}
#productsTable thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f8fafc;
  box-shadow: 0 1px 0 var(--border);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
th, td {
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--brand);
  background: #f8fafc;
  font-weight: 700;
}
.num { font-variant-numeric: tabular-nums; }
#productsTable th,
#productsTable td,
#productsTable thead th,
#productsTable thead th.num,
#productsTable td.num,
#productsTable thead th.col-image,
#productsTable td.col-image {
  text-align: center;
}
#productsTable thead th[data-sort] {
  padding: 0.3rem 0.35rem;
}
.sort-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  width: 100%;
  margin: 0;
  padding: 0.4rem 0.3rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  letter-spacing: inherit;
  text-transform: inherit;
  line-height: 1.2;
  white-space: normal;
  text-align: center;
  cursor: pointer;
}
.sort-btn:hover,
.sort-btn:focus-visible {
  background: #e8eef6;
  outline: none;
}
.sort-btn.is-active {
  color: var(--brand);
  background: #e8eef6;
}
.sort-ind {
  min-width: 0.7rem;
  font-size: 0.72rem;
  line-height: 1;
}
.col-image { width: 56px; }
td img, .thumb-empty {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  background: #f1f5f9;
  display: block;
  margin-left: auto;
  margin-right: auto;
}
.thumb-empty { border: 1px solid var(--border); }
td a,
.product-link {
  color: var(--brand);
  font-weight: 600;
  text-decoration: none;
}
td a:hover,
.product-link:hover { text-decoration: underline; }
.product-thumb-link {
  display: block;
  width: 40px;
  margin-left: auto;
  margin-right: auto;
  line-height: 0;
}
.product-thumb-link:hover { text-decoration: none; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: currentColor;
}
.badge-out_of_stock { color: var(--critical); background: #fef2f2; }
.badge-reorder_now { color: #c05717; background: #fff7ed; }
.badge-order_soon { color: var(--warning); background: #fffbeb; }
.badge-healthy { color: var(--success); background: #ecfdf5; }
.badge-sufficiently_ordered { color: var(--success); background: #ecfdf5; }
.badge-not_stocked { color: var(--muted); background: #f1f5f9; white-space: normal; text-align: center; }
.badge-not_stocked::before { display: none; }
.missing-code {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: normal;
  line-height: 1.25;
}
.order-more-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  color: #fff;
  background: #c05717;
  border: 1px solid #9a4310;
  text-decoration: none;
  cursor: pointer;
}
a.order-more-btn:hover {
  background: #9a4310;
  text-decoration: none;
  color: #fff;
}
.table-state {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}
.loading {
  position: fixed;
  inset: 0;
  background: rgba(248, 250, 252, 0.82);
  display: grid;
  place-items: center;
  z-index: 20;
}
.loading[hidden] { display: none; }
.loading-card {
  width: min(26rem, calc(100vw - 2rem));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.35rem 1.4rem 1.2rem;
  box-shadow: var(--shadow-md);
  text-align: center;
}
.loading-ring {
  width: 2.2rem;
  height: 2.2rem;
  margin: 0 auto 0.8rem;
  border-radius: 999px;
  border: 3px solid #d7deea;
  border-top-color: var(--brand);
  animation: loading-spin 0.8s linear infinite;
}
@keyframes loading-spin {
  to { transform: rotate(360deg); }
}
.loading-title {
  margin: 0 0 0.25rem;
  font-weight: 700;
  color: var(--brand);
}
.loading-stage {
  margin: 0 0 0.9rem;
  color: var(--muted);
  font-size: 0.92rem;
}
.loading-progress {
  height: 0.45rem;
  border-radius: 999px;
  background: #e8eef6;
  overflow: hidden;
}
.loading-bar {
  display: block;
  height: 100%;
  width: 8%;
  border-radius: inherit;
  background: var(--brand);
  transition: width 0.6s ease;
}
.loading-time {
  margin: 0.7rem 0 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #0f172a;
}
.spinner {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  font-weight: 600;
  color: var(--brand);
  box-shadow: var(--shadow-md);
}
code { font-size: 0.86em; color: var(--brand); }
.app-footer {
  max-width: 1280px;
  margin: 0 auto 1.5rem;
  padding: 1.25rem 1.25rem 2rem;
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}
.app-footer a { color: var(--brand); font-weight: 600; }