/*
 * Salt Bay Labs — shared UI
 *
 * One stylesheet every tool links, so the suite looks like one product. It's
 * plain CSS on purpose: three of these apps are a single static HTML file
 * with no build step, and making them adopt Tailwind would mean giving them a
 * toolchain they don't otherwise need.
 *
 * The values are lifted from the Customer Escalations app (React + Tailwind
 * v4), which is the reference implementation. That app keeps using Tailwind;
 * this file reproduces the same tokens and components for everything else, so
 * the two stay in step as long as the tokens below match.
 *
 * Source of truth: shared/saltbay-ui.css in the saltbaylabs-apps monorepo.
 * Each app holds a *copy* rather than a symlink, because Docker build
 * contexts are per-app and can't reach a sibling directory. Run
 * `shared/sync-shared.sh` after editing this file to push the copies out, and
 * don't edit the copies directly — the script overwrites them.
 */

:root {
  color-scheme: light;

  /* Brand */
  --sb-navy: #1e3a5f;
  --sb-navy-dark: #162c48;
  --sb-amber: #f0b429;

  /* Surfaces */
  --sb-bg: #f4f5f7;
  --sb-surface: #ffffff;
  --sb-surface-sunken: #fafafa;
  --sb-border: #e5e7eb;
  --sb-border-strong: #d4d4d8;

  /* Ink */
  --sb-text: #1a1c23;
  --sb-text-muted: #64748b;
  --sb-text-faint: #9ca3af;

  /* Status. Reserved for state, never reused as chart series colours. */
  --sb-good: #047857;
  --sb-good-bg: #ecfdf5;
  --sb-good-border: #a7f3d0;
  --sb-warn: #b45309;
  --sb-warn-bg: #fffbeb;
  --sb-warn-border: #fde68a;
  --sb-bad: #be123c;
  --sb-bad-bg: #fff1f2;
  --sb-bad-border: #fecdd3;
  --sb-info: #0369a1;
  --sb-info-bg: #f0f9ff;
  --sb-info-border: #bae6fd;

  /* Chart series — the first three slots of the validated categorical
     palette, in order. Don't cycle past three; fold the tail into "Other". */
  --sb-series-1: #2a78d6;
  --sb-series-2: #eb6834;
  --sb-series-3: #1baf7a;

  --sb-radius: 12px;
  --sb-radius-sm: 8px;
  --sb-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
  --sb-shadow-md: 0 4px 14px rgb(0 0 0 / 0.07);

  --sb-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --sb-font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ------------------------------------------------------------------ base */

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

body.sb {
  margin: 0;
  min-height: 100%;
  font-family: var(--sb-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--sb-text);
  background: var(--sb-bg);
  -webkit-font-smoothing: antialiased;
}

body.sb h1 { font-size: 1.125rem; font-weight: 600; margin: 0; }
body.sb h2 { font-size: 0.875rem; font-weight: 600; margin: 0; }
body.sb a { color: var(--sb-navy); }

.sb ::-webkit-scrollbar { width: 10px; height: 10px; }
.sb ::-webkit-scrollbar-thumb { background: #cbd0d9; border-radius: 6px; }
.sb ::-webkit-scrollbar-track { background: transparent; }

/* --------------------------------------------------------------- topbar */
/* Matches the Customer Escalations header, including the behaviour of
   dropping labels at phone width where icons and names collided. */

.sb-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--sb-navy);
  color: #fff;
  box-shadow: var(--sb-shadow);
  /* The bar is injected as the first child of whatever <body> already is.
     One of these pages centres its content with `display:flex` on the body,
     which shrank the bar to the width of its own text - so it states its
     full width and refuses to be shrunk or stretched by a host's flex or
     grid layout. */
  width: 100%;
  align-self: stretch;
  justify-self: stretch;
  grid-column: 1 / -1;
  flex: 0 0 auto;
  box-sizing: border-box;
}

.sb-topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
}

/* The topbar is injected into pages that already have their own stylesheet,
   several of which style bare `a` and `span` elements globally. Those rules
   were winning here and painting the brand navy-on-navy. Everything inside
   the bar therefore states its own colour rather than inheriting, and the
   selectors are specific enough to beat a host page's element rules. */
.sb-topbar,
.sb-topbar * {
  color: #fff;
}

.sb-topbar .sb-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  text-decoration: none;
  flex-shrink: 0;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.sb-topbar .sb-brand:hover { color: #fff; }

.sb-brand svg { width: 28px; height: 28px; }

.sb-brand-sep {
  width: 1px;
  height: 20px;
  background: rgb(255 255 255 / 0.2);
  flex-shrink: 0;
}

.sb-topbar .sb-tool-name {
  font-weight: 500;
  font-size: 0.875rem;
  color: rgb(255 255 255 / 0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-topbar-spacer { flex: 1; }

.sb-topbar a.sb-topbar-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--sb-radius-sm);
  font-size: 0.875rem;
  color: rgb(255 255 255 / 0.7);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.sb-topbar a.sb-topbar-link:hover {
  color: #fff;
  background: rgb(255 255 255 / 0.1);
}

/* A host page that sets a global margin on headings or paragraphs shouldn't
   be able to push the bar's contents around either. */
.sb-topbar :is(h1, h2, h3, p, span, a) { margin: 0; }

@media (max-width: 640px) {
  .sb-brand span.sb-brand-text { display: none; }
  .sb-topbar-link .sb-topbar-link-text { display: none; }
}

/* ----------------------------------------------------------------- page */

.sb-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 16px;
}

.sb-main--narrow { max-width: 1100px; }

.sb-page-title { margin-bottom: 16px; }
.sb-page-title h1 { color: var(--sb-text); }
.sb-page-title p {
  margin: 2px 0 0;
  font-size: 0.875rem;
  color: var(--sb-text-muted);
}

/* ---------------------------------------------------------------- cards */

.sb-card {
  background: var(--sb-surface);
  border: 1px solid var(--sb-border);
  border-radius: var(--sb-radius);
  box-shadow: var(--sb-shadow);
}

.sb-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px 8px;
}

.sb-card-head p {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--sb-text-muted);
}

.sb-card-body { padding: 4px 16px 16px; }

/* Used where a card is the whole content and needs no header. */
.sb-card--pad { padding: 16px; }

.sb-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

/* ------------------------------------------------------------- controls */

.sb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--sb-radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

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

.sb-btn--primary { background: var(--sb-navy); color: #fff; }
.sb-btn--primary:hover:not(:disabled) { background: var(--sb-navy-dark); }

.sb-btn--secondary {
  background: var(--sb-surface);
  color: #374151;
  border-color: var(--sb-border-strong);
}
.sb-btn--secondary:hover:not(:disabled) { background: var(--sb-surface-sunken); }

.sb-btn--ghost { background: transparent; color: #4b5563; }
.sb-btn--ghost:hover:not(:disabled) { background: #f3f4f6; }

.sb-btn--danger { background: #e11d48; color: #fff; }
.sb-btn--danger:hover:not(:disabled) { background: #be123c; }

.sb-input,
.sb-select,
.sb-textarea {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--sb-border-strong);
  border-radius: var(--sb-radius-sm);
  background: var(--sb-surface);
  font: inherit;
  font-size: 0.875rem;
  color: var(--sb-text);
}

.sb-input::placeholder,
.sb-textarea::placeholder { color: var(--sb-text-faint); }

.sb-input:focus,
.sb-select:focus,
.sb-textarea:focus {
  outline: none;
  border-color: var(--sb-navy);
  box-shadow: 0 0 0 3px rgb(30 58 95 / 0.15);
}

.sb-input:disabled,
.sb-select:disabled,
.sb-textarea:disabled {
  background: var(--sb-surface-sunken);
  color: var(--sb-text-faint);
}

.sb-textarea { line-height: 1.6; resize: vertical; }

.sb-field { display: block; margin-bottom: 12px; }
.sb-field > span.sb-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 4px;
}
.sb-field > span.sb-hint {
  display: block;
  font-size: 0.6875rem;
  color: var(--sb-text-faint);
  margin-top: 4px;
  line-height: 1.4;
}

/* A file drop zone — GTIN, NDC and PDF Compress are all upload-first tools,
   so this is a shared component rather than three different ones. */
.sb-dropzone {
  border: 2px dashed var(--sb-border-strong);
  border-radius: var(--sb-radius);
  background: var(--sb-surface);
  padding: 28px 16px;
  text-align: center;
  color: var(--sb-text-muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.sb-dropzone:hover,
.sb-dropzone.sb-dropzone--active {
  border-color: var(--sb-navy);
  background: #f8fafc;
}

/* ---------------------------------------------------------------- chips */

.sb-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border: 1px solid var(--sb-border);
  border-radius: 6px;
  background: #f3f4f6;
  color: #4b5563;
  font-size: 0.6875rem;
  font-weight: 500;
  white-space: nowrap;
}

.sb-chip--navy {
  background: rgb(30 58 95 / 0.08);
  color: var(--sb-navy);
  border-color: rgb(30 58 95 / 0.2);
}
.sb-chip--good { background: var(--sb-good-bg); color: var(--sb-good); border-color: var(--sb-good-border); }
.sb-chip--warn { background: var(--sb-warn-bg); color: var(--sb-warn); border-color: var(--sb-warn-border); }
.sb-chip--bad  { background: var(--sb-bad-bg);  color: var(--sb-bad);  border-color: var(--sb-bad-border); }

/* --------------------------------------------------------------- tables */

.sb-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

.sb-table thead th {
  text-align: left;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
  color: var(--sb-text-muted);
  background: var(--sb-surface-sunken);
  padding: 8px 12px;
  border-bottom: 1px solid var(--sb-border);
}

.sb-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: top;
}

.sb-table tbody tr:last-child td { border-bottom: 0; }
.sb-table tbody tr:hover { background: #fafafa; }
.sb-table .sb-num { text-align: right; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- banner */

.sb-banner {
  padding: 8px 12px;
  border-radius: var(--sb-radius-sm);
  border: 1px solid;
  font-size: 0.875rem;
  margin-bottom: 12px;
}

.sb-banner--info { background: var(--sb-info-bg); border-color: var(--sb-info-border); color: #075985; }
.sb-banner--good { background: var(--sb-good-bg); border-color: var(--sb-good-border); color: #065f46; }
.sb-banner--warn { background: var(--sb-warn-bg); border-color: var(--sb-warn-border); color: #92400e; }
.sb-banner--bad  { background: var(--sb-bad-bg);  border-color: var(--sb-bad-border);  color: #9f1239; }

/* ------------------------------------------------------------------ kpi */

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

.sb-kpi-label {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
  color: var(--sb-text-muted);
}

.sb-kpi-value {
  font-size: 1.5rem;
  font-weight: 600;
  margin-top: 4px;
  color: var(--sb-navy);
  font-variant-numeric: tabular-nums;
}

.sb-kpi-hint {
  font-size: 0.6875rem;
  color: var(--sb-text-faint);
  margin-top: 2px;
  line-height: 1.3;
}

/* -------------------------------------------------------------- utility */

.sb-muted { color: var(--sb-text-muted); }
.sb-faint { color: var(--sb-text-faint); }
.sb-mono  { font-family: var(--sb-font-mono); }
.sb-nums  { font-variant-numeric: tabular-nums; }
.sb-row   { display: flex; align-items: center; gap: 8px; }
.sb-wrap  { flex-wrap: wrap; }
.sb-stack > * + * { margin-top: 12px; }
.sb-hidden { display: none !important; }

.sb-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: sb-spin 0.7s linear infinite;
}

@keyframes sb-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .sb-spinner { animation-duration: 2s; }
  * { transition-duration: 0.01ms !important; }
}
