/* SAPB Intake -- styled after Shopify Polaris (admin layout, cards, badges,
   banners, buttons) with WCAG 2.2 AA contrast and visible focus states.
   Desktop-first; collapses to a single column below 800px. */

:root {
  color-scheme: light;
  --bg: #f1f1f1;
  --surface: #ffffff;
  --surface-subdued: #f7f7f7;
  --surface-hover: #f7f7f7;
  --text: #303030;
  --text-secondary: #616161;
  --border: #e3e3e3;
  --border-input: #8a8a8a;
  --primary: #303030;
  --primary-hover: #1a1a1a;
  --link: #005bd3;
  --focus: #005bd3;
  --topbar: #1a1a1a;
  --sidebar: #ebebeb;

  --success-bg: #cdfee1;  --success-text: #0c5132;  --success-icon: #29845a;
  --info-bg: #e0f0ff;     --info-text: #00527c;     --info-icon: #0094d5;
  --warning-bg: #fff1e3;  --warning-text: #5e4200;  --warning-icon: #b28400;
  --critical-bg: #fee9e8; --critical-text: #8e0b21; --critical-icon: #e51c00;
  --neutral-bg: #e3e3e3;  --neutral-text: #4a4a4a;

  --radius-sm: 8px;
  --radius: 12px;
  --shadow-card: 0 1px 0 rgba(26, 26, 26, 0.07), inset 0 1px 0 rgba(204, 204, 204, 0.5),
                 inset 0 -1px 0 rgba(0, 0, 0, 0.17), inset -1px 0 0 rgba(0, 0, 0, 0.13), inset 1px 0 0 rgba(0, 0, 0, 0.13);
  --shadow-button: 0 -1px 0 0 #b5b5b5 inset, 0 0 0 1px rgba(0, 0, 0, 0.1) inset, 0 0.5px 0 1.5px #fff inset;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "San Francisco", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, "Liberation Mono", monospace;
}

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

html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ---- App frame --------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  height: 56px; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--topbar); color: #e3e3e3;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; color: #fff; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center;
  background: #fff; color: var(--topbar); font-size: 13px; font-weight: 700;
}
.brand-sub { color: #b5b5b5; font-weight: 500; }
.topbar form { margin: 0; }
.topbar-btn {
  font: inherit; font-size: 13px; color: #e3e3e3;
  background: #303030; border: none; border-radius: var(--radius-sm);
  padding: 6px 12px; cursor: pointer;
}
.topbar-btn:hover { background: #4a4a4a; color: #fff; }

.frame { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: calc(100vh - 56px); }

.sidebar { background: var(--sidebar); padding: 12px 8px; border-right: 1px solid var(--border); }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--text); font-weight: 550;
}
.nav-item:hover { background: #fafafa; text-decoration: none; }
.nav-item.active { background: var(--surface); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06); }
.nav-item svg { width: 20px; height: 20px; flex: none; color: #4a4a4a; }

.page { padding: 24px 32px 48px; }
.page-inner { max-width: 1000px; margin: 0 auto; }
.page-inner.narrow { max-width: 760px; }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.page-header h1 { font-size: 20px; line-height: 28px; font-weight: 700; margin: 0; }
.page-header .subtitle { color: var(--text-secondary); margin: 2px 0 0; }
.breadcrumb {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; color: var(--text-secondary); margin-bottom: 4px;
}
.breadcrumb:hover { color: var(--text); }

/* ---- Layout helpers ------------------------------------------------------ */

.layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.stack { display: grid; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.span-2 { grid-column: 1 / -1; }

/* ---- Card ---------------------------------------------------------------- */

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-card); padding: 16px; }
.card + .card { margin-top: 16px; }
.layout .card + .card, .stack .card + .card { margin-top: 0; }
.card-title { font-size: 14px; font-weight: 650; margin: 0 0 12px; }
.card-section { border-top: 1px solid var(--border); margin: 16px -16px 0; padding: 16px 16px 0; }
.card-footer { display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); margin: 16px -16px -16px; padding: 12px 16px; background: var(--surface-subdued); border-radius: 0 0 var(--radius) var(--radius); }

/* ---- Form fields --------------------------------------------------------- */

.field label { display: block; font-weight: 550; margin-bottom: 4px; }
.field .help { color: var(--text-secondary); font-size: 13px; margin-top: 4px; }
.input, .select {
  width: 100%; min-height: 36px;
  font: inherit; color: var(--text);
  background: #fdfdfd;
  border: 1px solid var(--border-input); border-top-color: #898f94;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
}
.input:hover, .select:hover { border-color: #616161; }
.input:focus, .select:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
.input::placeholder { color: #8a8a8a; }
.input.mono { font-family: var(--mono); }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; }
input[type="file"] { font: inherit; }

/* ---- Buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px;
  font: inherit; font-weight: 600; line-height: 20px;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary {
  color: #fff; background: var(--primary);
  box-shadow: 0 -1px 0 1px rgba(0, 0, 0, 0.8) inset, 0 0 0 1px #303030 inset, 0 0.5px 0 1.5px rgba(255, 255, 255, 0.25) inset;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { color: var(--text); background: var(--surface); box-shadow: var(--shadow-button); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-plain { color: var(--link); background: none; padding-left: 0; padding-right: 0; min-height: 0; font-weight: 550; }
.btn-plain:hover { text-decoration: underline; }
.btn svg { width: 16px; height: 16px; }

/* ---- Badges -------------------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 550; line-height: 16px; white-space: nowrap;
  background: var(--neutral-bg); color: var(--neutral-text);
}
.badge.success { background: var(--success-bg); color: var(--success-text); }
.badge.info { background: var(--info-bg); color: var(--info-text); }
.badge.warning { background: var(--warning-bg); color: var(--warning-text); }
.badge.critical { background: var(--critical-bg); color: var(--critical-text); }
.badge.subdued { background: var(--surface-subdued); color: var(--text-secondary); box-shadow: inset 0 0 0 1px var(--border); }

/* ---- Banners (flash messages, results) ------------------------------------ */

.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; margin-bottom: 16px;
  border-radius: var(--radius);
  background: var(--info-bg); color: var(--info-text);
}
.banner svg { width: 20px; height: 20px; flex: none; margin-top: 1px; color: var(--info-icon); }
.banner-title { font-weight: 650; }
.banner p { margin: 2px 0 0; }
.banner.success { background: var(--success-bg); color: var(--success-text); }
.banner.success svg { color: var(--success-icon); }
.banner.warning { background: var(--warning-bg); color: var(--warning-text); }
.banner.warning svg { color: var(--warning-icon); }
.banner.critical, .banner.error { background: var(--critical-bg); color: var(--critical-text); }
.banner.critical svg, .banner.error svg { color: var(--critical-icon); }

/* ---- Description list (item details) -------------------------------------- */

.details { margin: 0; display: grid; grid-template-columns: 140px minmax(0, 1fr); }
.details dt, .details dd { padding: 8px 0; border-bottom: 1px solid var(--border); margin: 0; }
.details dt { color: var(--text-secondary); }
.details dd { font-weight: 550; overflow-wrap: anywhere; }
.details dt:last-of-type, .details dd:last-of-type { border-bottom: none; }

.sku {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px; border-radius: var(--radius-sm);
  background: var(--surface-subdued); box-shadow: inset 0 0 0 1px var(--border);
}
.sku-label { font-size: 12px; color: var(--text-secondary); }
.sku-value { font-family: var(--mono); font-size: 18px; font-weight: 600; }

/* ---- Resource list (what happened) ----------------------------------------- */

.resource-list { list-style: none; margin: 0 -16px; padding: 0; }
.resource-list li {
  display: grid; grid-template-columns: 120px 96px minmax(0, 1fr); gap: 12px; align-items: start;
  padding: 12px 16px; border-top: 1px solid var(--border);
}
.resource-list li:first-child { border-top: none; }
.resource-list .system { font-weight: 600; }
.resource-list .text { color: var(--text-secondary); overflow-wrap: anywhere; }

/* ---- Table (reports) ------------------------------------------------------- */

.table-wrap { margin: 0 -16px -16px; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 16px; border-top: 1px solid var(--border); }
.table th { background: var(--surface-subdued); color: var(--text-secondary); font-weight: 550; font-size: 13px; border-top: none; }
.table tr:hover td { background: var(--surface-hover); }
.table td.num { white-space: nowrap; color: var(--text-secondary); }

/* ---- Misc ------------------------------------------------------------------ */

.muted { color: var(--text-secondary); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.empty { text-align: center; color: var(--text-secondary); padding: 24px 0 8px; }
.log {
  background: #1a1a1a; color: #e3e3e3; font-family: var(--mono); font-size: 12px;
  padding: 12px; border-radius: var(--radius-sm); overflow-x: auto; white-space: pre; margin: 12px 0 0;
}
.progress { height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; margin-top: 12px; }
.progress::after {
  content: ""; display: block; height: 100%; width: 35%;
  background: var(--primary); border-radius: 2px;
  animation: progress 1.4s ease-in-out infinite;
}
@keyframes progress { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
@media (prefers-reduced-motion: reduce) { .progress::after { animation: none; width: 100%; opacity: 0.4; } }

details.disclosure summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; justify-content: space-between; }
details.disclosure summary::-webkit-details-marker { display: none; }
details.disclosure summary::after { content: "Show"; font-weight: 550; color: var(--link); }
details.disclosure[open] summary::after { content: "Hide"; }

/* ---- Sign-in page ------------------------------------------------------------ */

.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; font-weight: 650; }
.auth-brand .brand-mark { background: var(--topbar); color: #fff; }
.auth h1 { font-size: 20px; margin: 0 0 4px; }

/* ---- Narrow screens ---------------------------------------------------------- */

@media (max-width: 800px) {
  .frame { grid-template-columns: 1fr; }
  .sidebar { display: flex; gap: 4px; padding: 8px; border-right: none; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .nav-item { margin: 0; }
  .page { padding: 16px; }
  .layout, .grid-2 { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: stretch; }
  .resource-list li { grid-template-columns: 1fr; gap: 4px; }
  .brand-sub { display: none; }
}
