:root {
  --cream: #f3efe6;
  --paper: #fffcf7;
  --ink: #1a1916;
  --blue: #2c64ba;
  --blue-deep: #1e4f96;
  --blue-navy: #0f2f5b;
  --blue-mist: #e8f1fb;
  --mint: #e4f6f2;
  --terracotta: #c45c3c;
  --sand: #e8dccb;
  --muted: #6b6560;
  --line: #e4d9c8;
  --good: #0f2f5b;
  --warn: #b45309;
  --bad: #b42318;
  --shadow: 0 1px 2px rgba(26, 25, 22, 0.06), 0 8px 24px rgba(26, 25, 22, 0.05);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "Segoe UI", "Helvetica Neue", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(1200px 400px at 10% -10%, #e8f1fb 0%, transparent 55%),
    var(--cream);
}

a { color: var(--blue); }
a:hover { color: var(--blue-deep); }

h1, h2, h3 {
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: var(--ink);
}
h1 { font-size: 1.75rem; margin: 0 0 0.35rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.85rem; }
h3 { font-size: 1rem; }

p { margin: 0 0 0.75rem; }

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.85rem 1.25rem;
  flex-wrap: wrap;
  padding: 0.7rem 1.4rem;
  background: rgba(44, 100, 186, 0.96);
  color: var(--paper);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--mint);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: 1.05rem;
}
.brand:hover { color: var(--mint); }
.brand .mark {
  display: block;
  width: 1.7rem;
  height: 1.7rem;
}

.top nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
}
.top nav a {
  color: rgba(255, 252, 247, 0.82);
  text-decoration: none;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.92rem;
}
.top nav a:hover,
.top nav a.is-active {
  color: var(--paper);
  background: rgba(255, 255, 255, 0.12);
}

.top .logout { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }
.hh-switch { margin-left: auto; }
.hh-switch + .logout { margin-left: 0; }
.hh-switch select {
  background: rgba(0, 0, 0, 0.2);
  color: var(--paper);
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  font: inherit;
  font-size: 0.88rem;
}
.logout a,
.logout button,
.top button {
  background: transparent;
  color: var(--paper);
  border: 1px solid rgba(255, 255, 255, 0.22);
  padding: 0.32rem 0.75rem;
  border-radius: 999px;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}
.logout a { text-decoration: none; }
.logout a:hover,
.logout button:hover { background: rgba(255, 255, 255, 0.1); color: var(--paper); }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.messages {
  list-style: none;
  max-width: 1080px;
  margin: 0.9rem auto 0;
  padding: 0 1.4rem;
}
.messages li {
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.4rem;
  font-size: 0.95rem;
}
.messages .success { background: var(--blue-mist); color: var(--blue-navy); }
.messages .error,
.messages .warning { background: #fbe8e1; color: #7a271a; }

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.6rem 1.4rem 3rem;
}

main > h1 + p { margin-top: 0; }
main > h1 + p.muted { margin-bottom: 1.1rem; }

.muted { color: var(--muted); }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem 1.3rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.card > h1:first-child,
.card > h2:first-child { margin-top: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.score {
  font-size: 2.75rem;
  font-weight: 720;
  letter-spacing: -0.05em;
  line-height: 1.05;
  color: var(--blue-navy);
  margin: 0.15rem 0 0.25rem;
}

.bar {
  height: 8px;
  background: var(--sand);
  border-radius: 99px;
  overflow: hidden;
  margin: 0.25rem 0 0.9rem;
}
.bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--blue-navy), var(--blue-deep));
  border-radius: 99px;
}

.babs-row {
  display: grid;
  grid-template-columns: 7.5rem 3.2rem 1fr;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.55rem;
}
.babs-row p { margin: 0; font-size: 0.92rem; }
.babs-row .pct {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  color: var(--blue-navy);
  text-align: right;
}
.babs-row .bar { margin: 0; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 1.15rem;
}
.filters a {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.75rem;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.88rem;
}
.filters a:hover {
  border-color: var(--blue-deep);
  color: var(--blue-navy);
}
.filters a.is-active {
  background: var(--blue-navy);
  border-color: var(--blue-navy);
  color: var(--paper);
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.85rem 0 1rem;
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: var(--blue-navy);
  color: var(--paper);
  border: 1px solid var(--blue-navy);
  padding: 0.52rem 0.95rem;
  border-radius: 999px;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
}
button:hover,
.btn:hover { background: var(--blue-deep); color: var(--paper); border-color: var(--blue-deep); }

.btn.secondary { background: var(--terracotta); border-color: var(--terracotta); }
.btn.ghost,
button.ghost {
  background: transparent;
  color: var(--blue-navy);
  border: 1px solid var(--line);
}
.btn.ghost:hover,
button.ghost:hover {
  background: var(--blue-mist);
  border-color: var(--blue-deep);
  color: var(--blue-navy);
}
.btn.ghost.danger {
  color: var(--bad);
  border-color: #f0c4b8;
}
.btn.ghost.danger:hover {
  background: #fef2f2;
  border-color: var(--bad);
  color: var(--bad);
}

label { display: block; margin: 0.7rem 0 0.3rem; font-size: 0.9rem; font-weight: 600; color: var(--ink); }

input, select, textarea {
  font: inherit;
  width: 100%;
  max-width: 28rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(15, 47, 91, 0.28);
  outline-offset: 1px;
  border-color: var(--blue-deep);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
th, td {
  text-align: left;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 650;
  background: #f7f3ea;
}
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #faf7f1; }

.expired { color: var(--bad); font-weight: 700; }
.soon { color: var(--warn); font-weight: 600; }

.formset td input,
.formset td select { max-width: 12rem; }

.thumb {
  width: 64px;
  height: 64px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  flex-shrink: 0;
}
.thumb-empty { display: inline-block; background: var(--cream); }

.product-hit {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: inherit;
}
.product-hit:last-child { border-bottom: 0; }
a.product-hit:hover { color: inherit; }
a.product-hit:hover strong { color: var(--blue-navy); }

.facts {
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0.2rem 0 0;
}
.facts p { margin: 0.15rem 0 0; }
.facts strong { color: var(--ink); font-weight: 650; }

main > ul {
  list-style: none;
  padding: 0;
  margin: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
main > ul > li {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}
main > ul > li:last-child { border-bottom: 0; }

.card ul { padding-left: 1.1rem; }

.auth main {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 9rem);
  padding-top: 1.5rem;
}
.auth .card {
  width: min(28rem, 100%);
  padding: 1.6rem 1.5rem 1.4rem;
}

footer {
  text-align: center;
  color: var(--muted);
  padding: 0 1.4rem 2.4rem;
  font-size: 0.85rem;
}

@media (max-width: 720px) {
  .hh-switch { margin-left: 0; }
  .babs-row { grid-template-columns: 1fr auto; }
  .babs-row .bar { grid-column: 1 / -1; }
  .score { font-size: 2.3rem; }
  th, td { padding: 0.6rem 0.55rem; }
}

.stock-group { margin-bottom: 1rem; }
.stock-group table { box-shadow: none; }
.stock-head {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}
.stock-head h2 { margin: 0 0 0.2rem; font-size: 1.15rem; }
.lot-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.lot-actions .btn {
  padding: 0.28rem 0.7rem;
  font-size: 0.82rem;
}
.chip {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  background: var(--blue-mist);
  color: var(--blue-navy);
  font-size: 0.8rem;
  font-weight: 650;
}

body.system-health-page main { max-width: 1180px; }

.system-health { display: flex; flex-direction: column; gap: 1rem; }
.system-health-hero { overflow: hidden; }
.system-health-hero--ok { border-color: #b7d4c2; }
.system-health-hero--warning { border-color: #f0d9a8; background: linear-gradient(135deg, #fffbeb 0%, var(--paper) 60%); }
.system-health-hero--error { border-color: #f0c4b8; background: linear-gradient(135deg, #fef2f2 0%, var(--paper) 60%); }
.system-health-hero__layout {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.25rem;
  flex-wrap: wrap;
}
.system-health-hero__lead { display: flex; align-items: flex-start; gap: 0.85rem; }
.system-health-hero__title { margin: 0; font-size: 1.5rem; }
.system-health-hero__meta { margin: 0.35rem 0 0; font-size: 0.92rem; color: var(--muted); }
.system-health-hero__hint { margin: 0.5rem 0 0; max-width: 42rem; }
.system-health-hero__pulse {
  width: 0.85rem;
  height: 0.85rem;
  margin-top: 0.45rem;
  border-radius: 50%;
  background: #16a34a;
  box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.45);
  animation: system-health-pulse 2s ease-out infinite;
  flex-shrink: 0;
}
.system-health-hero--warning .system-health-hero__pulse { background: var(--warn); box-shadow: none; animation: none; }
.system-health-hero--error .system-health-hero__pulse { background: var(--bad); box-shadow: none; animation: none; }
@keyframes system-health-pulse {
  0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.45); }
  70% { box-shadow: 0 0 0 0.55rem rgba(22, 163, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}
.system-health-hero__status-block { display: flex; flex-direction: column; align-items: flex-end; gap: 0.35rem; }
.system-health-warnings {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  background: #fffbeb;
  border: 1px solid #f0d9a8;
}
.system-health-warnings__title { margin: 0 0 0.45rem; font-size: 0.85rem; font-weight: 700; color: #92400e; }
.system-health-warnings__list { margin: 0; padding-left: 1.15rem; color: #78350f; font-size: 0.9rem; }
.system-health-warnings__list li + li { margin-top: 0.25rem; }
.system-health-overview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.system-health-overview__chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: inherit;
  text-decoration: none;
  font-size: 0.82rem;
}
.system-health-overview__chip:hover { color: inherit; border-color: var(--blue); }
.system-health-overview__chip--warning { border-color: #f0d9a8; }
.system-health-overview__chip--error { border-color: #f0c4b8; }
.system-health-overview__dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #16a34a;
  flex-shrink: 0;
}
.system-health-overview__chip--warning .system-health-overview__dot { background: var(--warn); }
.system-health-overview__chip--error .system-health-overview__dot { background: var(--bad); }
.system-health-overview__name { font-weight: 600; color: var(--ink); }
.system-health-overview__state { color: var(--muted); }
.system-health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr));
  gap: 1rem;
}
.system-health-card { margin-bottom: 0; scroll-margin-top: 4.5rem; }
.system-health-card--ok { border-top: 3px solid #16a34a; }
.system-health-card--warning { border-top: 3px solid var(--warn); }
.system-health-card--error { border-top: 3px solid var(--bad); }
.system-health-card__header { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; }
.system-health-card__title { margin: 0; font-size: 1.05rem; }
.system-health-card__summary { margin: 0.75rem 0 0; color: var(--muted); font-size: 0.92rem; }
.system-health-status {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}
.system-health-status--lg { padding: 0.35rem 0.85rem; font-size: 0.95rem; }
.system-health-status--ok { background: #ecfdf5; color: #047857; border: 1px solid #86efac; }
.system-health-status--warning { background: #fffbeb; color: var(--warn); border: 1px solid #f0d9a8; }
.system-health-status--error { background: #fef2f2; color: var(--bad); border: 1px solid #f0c4b8; }
.system-health-metrics { display: grid; gap: 0.45rem; margin: 0.95rem 0 0; }
.system-health-metrics__row {
  display: grid;
  grid-template-columns: minmax(7rem, 38%) 1fr;
  gap: 0.65rem;
  padding: 0.45rem 0.55rem;
  border-radius: var(--radius-sm);
  background: var(--cream);
}
.system-health-metrics__row dt { margin: 0; font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.system-health-metrics__row dd { margin: 0; font-size: 0.88rem; overflow-wrap: anywhere; }
.system-health-metrics__value--mono { font-family: var(--mono); font-size: 0.8rem; }
.system-health-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.85rem 0 1.1rem;
  font-size: 0.92rem;
}
.system-health-table th,
.system-health-table td {
  text-align: left;
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.system-health-table th { color: var(--muted); font-size: 0.82rem; }
.system-health-table .is-inactive td { color: var(--muted); }
.system-health-table form { display: inline; margin: 0; }
.system-health-table .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.two-factor-qr-wrap { text-align: center; margin: 1rem 0; }
.two-factor-qr { width: 180px; height: 180px; image-rendering: pixelated; }
.two-factor-secret { font-family: var(--mono); word-break: break-all; }
.two-factor-backup { list-style: none; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem 1rem; }
.two-factor-backup code { font-family: var(--mono); font-size: 0.95rem; }
@media (max-width: 640px) {
  .system-health-hero__status-block { align-items: flex-start; width: 100%; }
}
