/* NutriLabel application styles (10_UI_AND_WORKFLOWS.md section 4).
   Pico CSS provides the classless defaults; this file holds the design tokens
   and the few components Pico lacks. Inter is bundled locally. */

@font-face {
  font-family: "Inter";
  src: url("/static/fonts/inter-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("/static/fonts/inter-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("/static/fonts/inter-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("/static/fonts/inter-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --nl-bg: #f5f7f7;
  --nl-surface: #ffffff;
  --nl-ink: #1f2a2e;
  --nl-muted: #5d6b70;
  --nl-line: #dfe5e6;
  --nl-line-strong: #c6d0d2;
  --nl-accent: #267a78;
  --nl-accent-dark: #1c5f5d;
  --nl-accent-soft: #e4f1f0;
  --nl-amber-bg: #fff4dc;
  --nl-amber-ink: #855400;
  --nl-green-bg: #e1f3e7;
  --nl-green-ink: #1f6a3c;
  --nl-blue-bg: #e5eefb;
  --nl-blue-ink: #24538f;
  --nl-red-bg: #fbe5e3;
  --nl-red-ink: #9b2c24;
  --nl-grey-bg: #eceff0;
  --nl-grey-ink: #536166;
  --nl-slate-bg: #e6e9ee;
  --nl-slate-ink: #394252;
  --nl-radius: 10px;
  --nl-space: 1rem;
  --nl-sidebar: 236px;
  --pico-font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --pico-font-size: 100%;
  --pico-border-radius: 8px;
  --pico-primary: var(--nl-accent);
  --pico-primary-background: var(--nl-accent);
  --pico-primary-border: var(--nl-accent);
  --pico-primary-hover: var(--nl-accent-dark);
  --pico-primary-hover-background: var(--nl-accent-dark);
  --pico-primary-hover-border: var(--nl-accent-dark);
  --pico-primary-focus: rgba(38, 122, 120, 0.16);
  --pico-primary-inverse: #ffffff;
  --pico-primary-underline: transparent;
  --pico-primary-hover-underline: underline;
  --pico-form-element-focus-color: rgba(38, 122, 120, 0.22);
  --pico-color: var(--nl-ink);
  --pico-muted-color: var(--nl-muted);
  --pico-card-background-color: var(--nl-surface);
  --pico-card-border-color: var(--nl-line);
}

/* Pico defines its palette under :root:not([data-theme=dark]); this selector
   has the same specificity and comes later, so the app's muted teal wins. */
:root:not([data-theme=dark]) {
  --pico-primary: var(--nl-accent);
  --pico-primary-background: var(--nl-accent);
  --pico-primary-border: var(--nl-accent);
  --pico-primary-hover: var(--nl-accent-dark);
  --pico-primary-hover-background: var(--nl-accent-dark);
  --pico-primary-hover-border: var(--nl-accent-dark);
  --pico-primary-focus: rgba(38, 122, 120, 0.16);
  --pico-primary-inverse: #ffffff;
}

html { font-size: 16px; }

body {
  margin: 0;
  background: var(--nl-bg);
  color: var(--nl-ink);
  font-family: var(--pico-font-family);
}

a { color: var(--nl-accent-dark); }
a:hover { color: var(--nl-accent); }
:focus-visible { outline: 3px solid rgba(38, 122, 120, 0.35); outline-offset: 2px; }

.layout { min-height: 100vh; display: flex; }
.sidebar {
  width: var(--nl-sidebar);
  flex: 0 0 var(--nl-sidebar);
  background: #13282a;
  color: #dbe7e6;
  padding: 1.25rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  /* Review F19: a sticky 100vh sidebar stopped at the viewport height in a
     full-page screenshot (and on a long page). It now stretches with the
     layout so the dark surface covers the whole page. */
  position: static;
  height: auto;
  min-height: 100vh;
  box-sizing: border-box;
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: #fff;
  font-weight: 700;
  font-size: 1.06rem;
  letter-spacing: -0.01em;
  padding: 0.25rem 0.55rem 1.1rem;
}
.sidebar .brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--nl-accent); color: #fff;
  display: grid; place-items: center; font-size: 0.8rem; font-weight: 700;
}
.sidebar nav { display: flex; flex-direction: column; gap: 0.15rem; }
.sidebar nav a {
  color: #c9d8d7;
  text-decoration: none;
  padding: 0.58rem 0.65rem;
  border-radius: 8px;
  font-size: 0.94rem;
  font-weight: 500;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar nav a.active { background: rgba(38,122,120,0.35); color: #fff; }
.sidebar .sidebar-foot {
  margin-top: auto; font-size: 0.76rem; color: #8fa6a4; padding: 0.8rem 0.65rem;
}

.main { flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; background: var(--nl-surface); border-bottom: 1px solid var(--nl-line);
  padding: 0.7rem 1.6rem; position: sticky; top: 0; z-index: 5;
}
.topbar .context { font-size: 0.86rem; color: var(--nl-muted); }
.topbar .context strong { color: var(--nl-ink); font-weight: 600; }
.topbar .who { display: flex; align-items: center; gap: 0.7rem; font-size: 0.86rem; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--nl-accent-soft);
  color: var(--nl-accent-dark); display: grid; place-items: center; font-weight: 700;
  font-size: 0.8rem;
}
.content { max-width: 1180px; margin: 0 auto; padding: 1.6rem 1.6rem 3rem; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; }
.page-head h1 { margin: 0 0 0.25rem; font-size: 1.55rem; letter-spacing: -0.02em; }
.page-head p { margin: 0; color: var(--nl-muted); }

.card {
  background: var(--nl-surface); border: 1px solid var(--nl-line);
  border-radius: var(--nl-radius); padding: 1.2rem;
}
.card + .card { margin-top: 1rem; }
.card h2 { font-size: 1.05rem; margin: 0 0 0.8rem; }
.card > h2:first-child, .card > .spread:first-child { margin-top: 0; }
.card h3 { font-size: 0.95rem; margin: 0 0 0.5rem; }
.stack { display: grid; gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: stretch; }
.grid-2 > .card, .grid-3 > .card { margin-top: 0; align-self: stretch; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.search-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; gap: 1rem; align-items: end; }
.row { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; }
form.row { display: flex; align-items: center; gap: 0.35rem; }
form.row select, form.row button { width: auto; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; }
.muted { color: var(--nl-muted); }
.small { font-size: 0.82rem; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.nowrap { white-space: nowrap; }

.hero-search {
  background: linear-gradient(120deg, #ffffff 0%, #eef5f4 100%);
  border: 1px solid var(--nl-line); border-radius: 14px; padding: 1.4rem;
}
.hero-search h1 { margin: 0 0 0.3rem; font-size: 1.6rem; letter-spacing: -0.02em; }
.hero-search p { margin: 0 0 1rem; color: var(--nl-muted); }
.searchbar { display: flex; gap: 0.5rem; }
.searchbar input { margin: 0; }
.searchbar button { white-space: nowrap; }
.search-help { margin-top: 0.7rem; }

.status-pill {
  display: inline-flex; align-items: center; gap: 0.3rem; white-space: nowrap;
  border-radius: 999px; padding: 0.2rem 0.55rem; font-size: 0.74rem;
  font-weight: 600; letter-spacing: 0.01em; border: 1px solid transparent;
}
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-estimate { background: var(--nl-amber-bg); color: var(--nl-amber-ink); }
.status-lab_verified { background: var(--nl-green-bg); color: var(--nl-green-ink); }
.status-mixed { background: var(--nl-blue-bg); color: var(--nl-blue-ink); }
.status-error { background: var(--nl-red-bg); color: var(--nl-red-ink); }
.status-superseded { background: var(--nl-grey-bg); color: var(--nl-grey-ink); }
.status-draft { background: var(--nl-grey-bg); color: var(--nl-grey-ink); }


table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.88rem; }
table.data thead th {
  position: sticky; top: 0; background: #f9fbfb; z-index: 2;
  text-align: left; font-weight: 600; color: var(--nl-muted);
  border-bottom: 1px solid var(--nl-line-strong); padding: 0.6rem 0.65rem;
  font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em;
}
table.data td { padding: 0.62rem 0.65rem; border-bottom: 1px solid var(--nl-line); vertical-align: middle; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: #f7faf9; }
table.data tbody tr:last-child td { border-bottom: 0; }
.table-wrap { overflow: auto; border: 1px solid var(--nl-line); border-radius: var(--nl-radius); background: var(--nl-surface); }
.table-wrap table.data thead th:first-child { border-top-left-radius: var(--nl-radius); }
.table-wrap table.data thead th:last-child { border-top-right-radius: var(--nl-radius); }

form .field { margin-bottom: 0.9rem; }
form label { font-weight: 600; font-size: 0.88rem; display: block; margin-bottom: 0.25rem; }
form .help { color: var(--nl-muted); font-size: 0.78rem; margin-top: 0.2rem; }
form .field-error { color: var(--nl-red-ink); font-size: 0.8rem; margin-top: 0.2rem; }
.role-select { width: auto; min-width: 7.5rem; padding: 0.2rem 1.9rem 0.2rem 0.45rem; font-size: 0.8rem; }
.form-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }
.form-actions > button, .form-actions > a[role="button"] { width: auto; }
input[type="number"], input[type="text"], input[type="email"], input[type="password"], select, textarea { margin-bottom: 0; }
summary { cursor: pointer; }

.finding-panel { border: 1px solid var(--nl-line); border-radius: var(--nl-radius); overflow: hidden; }
.finding { padding: 0.75rem 0.9rem; border-bottom: 1px solid var(--nl-line); background: #fff; font-size: 0.86rem; }
.finding:last-child { border-bottom: 0; }
.finding.error { border-left: 3px solid var(--nl-red-ink); background: #fffafa; }
.finding.warning { border-left: 3px solid #c18514; background: #fffdf6; }
.finding.note { border-left: 3px solid var(--nl-accent); }
.finding strong { display: block; margin-bottom: 0.15rem; }

.empty-state {
  text-align: center; padding: 2.2rem 1rem; color: var(--nl-muted);
  border: 1px dashed var(--nl-line-strong); border-radius: var(--nl-radius);
  background: #fbfcfc;
}
.empty-state h3 { color: var(--nl-ink); margin: 0 0 0.3rem; }
.empty-state p { margin: 0 0 1rem; }

.tabs { display: flex; gap: 0.2rem; border-bottom: 1px solid var(--nl-line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: 0.55rem 0.85rem; text-decoration: none; color: var(--nl-muted); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--nl-accent-dark); border-bottom-color: var(--nl-accent); }
.tabs a:hover { color: var(--nl-ink); }

.builder { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.9fr); gap: 1.2rem; align-items: start; }
.builder .preview { position: static; }
.diff-col { background: #fffdf5; }
.badge { display: inline-block; padding: 0.12rem 0.45rem; border-radius: 6px; background: var(--nl-accent-soft); color: var(--nl-accent-dark); font-size: 0.72rem; font-weight: 600; }
.badge.neutral { background: var(--nl-grey-bg); color: var(--nl-grey-ink); }
.badge.warn { background: var(--nl-amber-bg); color: var(--nl-amber-ink); }
.badge.info { background: var(--nl-blue-bg); color: var(--nl-blue-ink); }
.badge.ok { background: var(--nl-green-bg); color: var(--nl-green-ink); }
.badge.error { background: var(--nl-red-bg); color: var(--nl-red-ink); }
.notice { border-radius: 8px; padding: 0.7rem 0.9rem; margin-bottom: 1rem; font-size: 0.88rem; background: var(--nl-green-bg); color: var(--nl-green-ink); border: 1px solid #c8e6d2; }
.notice.error { background: var(--nl-red-bg); color: var(--nl-red-ink); border-color: #f0c9c5; }
.notice.info { background: var(--nl-blue-bg); color: var(--nl-blue-ink); border-color: #cddcf4; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(circle at 15% 10%, #e9f3f2 0, #f5f7f7 42%, #f5f7f7 100%); }
.login-card { width: min(420px, 100%); background: #fff; border: 1px solid var(--nl-line); border-radius: 16px; padding: 2rem; box-shadow: 0 16px 40px rgba(27, 60, 62, 0.08); }
.login-card h1 { font-size: 1.4rem; margin: 0.8rem 0 0.2rem; letter-spacing: -0.02em; }
.login-card .brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 700; }
.login-card .brand .brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--nl-accent); color: #fff; display: grid; place-items: center; font-size: 0.85rem; }
.login-card label { font-size: 0.85rem; }
.login-card .login-actions { margin-top: 1.2rem; }
.login-card button { width: 100%; }
.auth-note { margin-top: 1.2rem; font-size: 0.78rem; color: var(--nl-muted); }

.per-100-table input { width: 100%; text-align: right; padding: 0.35rem 0.45rem; font-size: 0.82rem; }
.per-100-table td { padding: 0.3rem 0.4rem; }
.units-header { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--nl-muted); }

@media (max-width: 1024px) {
  .builder { grid-template-columns: 1fr; }
  .builder .preview { position: static; }
}
@media (max-width: 860px) {
  .layout { display: block; }
  /* Below 860 px the sidebar becomes a top bar, so the full-page height from
     the wide layout must not apply (review F19, checked on the 820 px capture). */
  .sidebar { width: auto; height: auto; min-height: 0; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 0.75rem; }
  .sidebar .brand { padding: 0 0.8rem 0 0; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar .sidebar-foot { display: none; }
  .content { padding: 1.1rem; }
  .topbar { padding: 0.6rem 1.1rem; }
  .grid-2, .grid-3, .search-grid { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
}

/* Regulatory label fonts for the inline SVG preview. The label itself names
   Nimbus Sans and Libre Franklin in rules_data/us/formats.yaml and in every
   snapshot; these faces mirror the files bundled in app/render/fonts so the
   browser preview uses the same metrics as PNG/PDF (10_UI_AND_WORKFLOWS.md
   section 4: the rendered label never uses the application font). */
@font-face {
  font-family: "Nimbus Sans";
  src: url("/static/fonts/label/NimbusSans-Regular.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Nimbus Sans";
  src: url("/static/fonts/label/NimbusSans-Bold.otf") format("opentype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Nimbus Sans";
  src: url("/static/fonts/label/NimbusSans-Italic.otf") format("opentype");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Nimbus Sans";
  src: url("/static/fonts/label/NimbusSans-BoldItalic.otf") format("opentype");
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Libre Franklin";
  src: url("/static/fonts/label/LibreFranklin-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Libre Franklin";
  src: url("/static/fonts/label/LibreFranklin-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Libre Franklin";
  src: url("/static/fonts/label/LibreFranklin-Italic.ttf") format("truetype");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

/* ---- Label builder (W3) and published label page ---- */
/* Workflow states are neutral so a colour never doubles as the quality stamp
   (estimate amber, lab-verified green, mixed blue) — 10_UI section 4. */
.status-review { background: var(--nl-slate-bg); color: var(--nl-slate-ink); }
.status-published { background: var(--nl-ink); color: #ffffff; }
.status-error { background: var(--nl-red-bg); color: var(--nl-red-ink); }
.builder-right { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.builder .preview { position: static; }
.label-preview { background: #fff; border: 1px solid var(--nl-line); border-radius: 4px; padding: 0.6rem; overflow-x: auto; }
.label-preview svg { display: block; width: 100%; height: auto; max-width: 100%; }
.finding-group { border-top: 1px solid var(--nl-line); }
.finding-group:first-of-type { border-top: 0; }
.finding-group-title { margin: 0; padding: 0.55rem 0.9rem 0.3rem; font-size: 0.76rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--nl-muted); display: flex; align-items: center; gap: 0.45rem; }
.finding-group-title.finding-errors { color: var(--nl-red-ink); }
.finding-group-title.finding-warnings { color: #8a5a00; }
.finding a, a.finding { display: block; text-decoration: none; color: inherit; }
a.finding:hover { background: #f6f8f8; }
a.finding strong { font-size: 0.78rem; letter-spacing: 0.01em; }
a.finding span { display: block; color: var(--nl-muted); }
.notice.warning { background: var(--nl-amber-bg); color: var(--nl-amber-ink); border-color: #efd39a; }
.checkline { display: flex; gap: 0.5rem; align-items: flex-start; margin: 0.55rem 0; font-size: 0.9rem; }
.checkline input { margin-top: 0.2rem; }
.download-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
.download-grid a[role="button"] { margin: 0; text-align: center; }
.snapshot-list { display: grid; grid-template-columns: minmax(7rem, 34%) 1fr; gap: 0.35rem 0.8rem; margin: 0; }
.snapshot-list dt { margin: 0; }
.snapshot-list dd { margin: 0; overflow-wrap: anywhere; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
@media (max-width: 1024px) {
  .builder { grid-template-columns: 1fr; }
  .builder .preview { position: static; }
}

/* ---- Phase 5: diff column, audit detail, allergen inputs, exports ---- */
.diff-table td { font-variant-numeric: tabular-nums; }
.diff-table tr.diff-changed { background: #fff4dc; }
.diff-table tr.diff-changed td:first-child { font-weight: 600; }
.audit-json {
  margin: 0.2rem 0 0;
  max-height: 15rem;
  overflow: auto;
  background: #f6f8f8;
  border: 1px solid var(--nl-line);
  border-radius: 6px;
  padding: 0.45rem;
  font-size: 0.72rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.allergen-inputs { border: 1px solid var(--nl-line); border-radius: var(--nl-radius); padding: 0.8rem; margin: 0.8rem 0; }
.allergen-inputs legend { font-weight: 600; padding: 0 0.35rem; }
.spec-card-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; }
.spec-card-actions a[role="button"] { margin: 0; text-align: center; }
@media (max-width: 640px) {
  /* Review F19 / W4 step 2: the three spec-sheet actions stay side by side at
     820 px and only stack on a phone-width screen. */
  .spec-card-actions { grid-template-columns: 1fr; }
}
