/* Plant traceability app — design tokens */
:root {
  --ink: #12324a;        /* harbour navy: sidebar, headings */
  --ink-deep: #0c2435;
  --paper: #f4f7f7;      /* cool page background */
  --surface: #ffffff;
  --line: #dce3e6;
  --line-strong: #c3cdd2;
  --text: #1e2a32;
  --muted: #5b6b76;
  --buoy: #d9952b;       /* buoy ochre: the one accent */
  --buoy-soft: #fbf1df;
  --pass: #2e7d5b;
  --pass-soft: #e3f2ea;
  --fail: #b4432f;
  --fail-soft: #f8e5e1;
  --focus: #2b7fd1;
  --r-sm: 6px;
  --r: 10px;
  --font: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sidebar: 256px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5;
  color: var(--text); background: var(--paper);
  font-variant-numeric: tabular-nums;
}
a { color: var(--ink); }
img { max-width: 100%; }
h1, h2, h3 { font-stretch: 88%; color: var(--ink); line-height: 1.2; margin: 0; }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 12px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--ink); color: #d6e1e8; position: sticky; top: 0; height: 100vh;
  overflow-y: auto; display: flex; flex-direction: column; padding: 18px 14px 24px;
}
.brand-tile {
  background: var(--surface); border-radius: var(--r); padding: 12px; display: flex; gap: 10px;
  align-items: center; color: var(--ink); text-decoration: none; margin-bottom: 18px;
}
.brand-tile img { width: 44px; height: 44px; object-fit: contain; }
.brand-tile.logo-only { justify-content: center; padding: 14px 12px; min-height: 92px; }
.brand-tile.logo-only img { width: 100%; height: 64px; object-fit: contain; object-position: center; }
.brand-tile .mono {
  width: 44px; height: 44px; border-radius: 8px; background: var(--buoy); color: var(--ink-deep);
  display: grid; place-items: center; font-weight: 800; font-size: 16px; flex: none;
}
.brand-tile strong { display: block; font-size: 14px; line-height: 1.25; font-stretch: 90%; }
.brand-tile span { font-size: 12px; color: var(--muted); }
.nav a, .nav summary {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: #d6e1e8; text-decoration: none; font-size: 14px; cursor: pointer;
}
.nav a:hover, .nav summary:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; box-shadow: inset 3px 0 0 var(--buoy); }
.nav .group-label { font-size: 12px; color: #8fa5b4; margin: 18px 10px 6px; }
.nav details summary { list-style: none; justify-content: space-between; }
.nav details summary::-webkit-details-marker { display: none; }
.nav details summary::after { content: "+"; color: #8fa5b4; font-size: 16px; }
.nav details[open] summary::after { content: "–"; }
.nav details a { padding-left: 22px; font-size: 13.5px; }
.nav .ico { width: 18px; height: 18px; flex: none; opacity: .85; }
.sidebar-foot { margin-top: auto; padding-top: 20px; font-size: 12px; color: #8fa5b4; padding-left: 10px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 32px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.menu-btn { display: none; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font: inherit; }
.user-chip { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--ink); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none;
}
.user-chip small { display: block; color: var(--muted); font-size: 12px; line-height: 1.2; }
.user-chip b { display: block; font-size: 14px; font-weight: 600; line-height: 1.2; }
.topbar form { margin: 0; }
.acting-bar {
  background: var(--buoy-soft); border-bottom: 1px solid #efd5a8; padding: 8px 32px; font-size: 14px;
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
}
.content { padding: 28px 32px 48px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 6px 0 0; color: var(--muted); max-width: 70ch; }
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumb a { color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600;
  font-size: 14px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-deep); }
.btn-accent { background: var(--buoy); border-color: var(--buoy); color: var(--ink-deep); }
.btn-danger { color: var(--fail); border-color: #e3b9b0; }
.btn-danger:hover { border-color: var(--fail); background: var(--fail-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--ink); text-decoration: underline; cursor: pointer; }

/* ---------- Panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.panel-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.panel-body { padding: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.stack > * + * { margin-top: 20px; }

/* Stats: one strip, not cards */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 20px; }
.stat { padding: 16px 20px; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat b { display: block; font-size: 30px; font-weight: 700; color: var(--ink); font-stretch: 85%; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.warn b { color: var(--fail); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
.data th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #f8fafa; }
.data td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data tr:last-child td { border-bottom: 0; }
.data tbody tr:hover td { background: #fafcfc; }
.data .actions { text-align: right; white-space: nowrap; }
.data td.num { text-align: right; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty h3 { margin-bottom: 6px; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef2f4; color: var(--muted); white-space: nowrap; }
.tag-pass { background: var(--pass-soft); color: var(--pass); }
.tag-fail { background: var(--fail-soft); color: var(--fail); }
.tag-buoy { background: var(--buoy-soft); color: #8a5b12; }
.tag-ink { background: var(--ink); color: #fff; }
.v-fail { color: var(--fail); font-weight: 600; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field .label { font-size: 13.5px; font-weight: 600; color: var(--text); }
.field .req { color: var(--fail); }
.field .hint { font-size: 12.5px; color: var(--muted); }
.field .err { font-size: 12.5px; color: var(--fail); font-weight: 600; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=email], input[type=password], input[type=tel], input[type=search], select, textarea {
  font: inherit; font-size: 15px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: #fff; color: var(--text); width: 100%; min-height: 44px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(43,127,209,.18); }
.field.has-err input, .field.has-err select { border-color: var(--fail); }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px 20px; }
.form-grid .span-all { grid-column: 1 / -1; }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; }
.form-section-title { font-size: 14px; color: var(--muted); font-weight: 600; margin: 4px 0 -4px; grid-column: 1 / -1; padding-top: 6px; border-top: 1px solid var(--line); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 20px; border-top: 1px solid var(--line); background: #fafcfc; border-radius: 0 0 var(--r) var(--r); flex-wrap: wrap; }

/* The pass / fail toggle: the one bold control */
.passfail { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; min-height: 48px; }
.passfail input { position: absolute; opacity: 0; pointer-events: none; }
.passfail label { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 650; font-size: 14px; cursor: pointer; color: var(--muted); padding: 8px; user-select: none; }
.passfail label + input + label { border-left: 1px solid var(--line-strong); }
.passfail label::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; flex: none; }
.passfail input:checked + label.ok { background: var(--pass); color: #fff; }
.passfail input:checked + label.no { background: var(--fail); color: #fff; }
.passfail input:checked + label::before { background: #fff; border-color: #fff; box-shadow: inset 0 0 0 3px currentColor; }
.passfail input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: -3px; }

.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 4px 16px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--ink); flex: none; }
.check-group { margin-bottom: 14px; }
.check-group h4 { margin: 0 0 4px; font-size: 13px; color: var(--muted); font-weight: 600; display: flex; gap: 10px; align-items: center; }

.filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.filters .field { min-width: 150px; }
.filters .field input { min-height: 40px; padding: 8px 10px; }

/* ---------- Alerts ---------- */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; border: 1px solid; }
.flash-success { background: var(--pass-soft); border-color: #b9dcc8; color: #1f5a41; }
.flash-error { background: var(--fail-soft); border-color: #ebc1b8; color: #8a2f1f; }
.flash-info { background: var(--buoy-soft); border-color: #efd5a8; color: #6c470d; }

/* ---------- Dashboard ---------- */
.bars { display: grid; grid-template-columns: repeat(14, 1fr); gap: 6px; align-items: end; height: 120px; padding-top: 8px; }
.bars .bar { background: var(--ink); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars .bar.today { background: var(--buoy); }
.bar-labels { display: grid; grid-template-columns: repeat(14, 1fr); gap: 6px; font-size: 11px; color: var(--muted); text-align: center; margin-top: 6px; }
.quick-list { list-style: none; margin: 0; padding: 0; }
.quick-list li + li { border-top: 1px solid var(--line); }
.quick-list a { display: flex; justify-content: space-between; gap: 10px; padding: 11px 20px; text-decoration: none; color: var(--text); font-size: 14px; }
.quick-list a:hover { background: #fafcfc; }
.quick-list .plus { color: var(--buoy); font-weight: 700; }

/* Forms index */
.section-block { margin-bottom: 28px; }
.section-block h2 { margin-bottom: 10px; }
.form-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.form-item { background: var(--surface); padding: 14px 16px; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.form-item a.title { font-weight: 600; text-decoration: none; color: var(--ink); }
.form-item a.title:hover { text-decoration: underline; }
.form-item .meta { font-size: 12.5px; color: var(--muted); }

/* Trace */
.trace-search { display: flex; gap: 10px; max-width: 560px; }
.trace-search input { font-size: 18px; min-height: 52px; }
.timeline { position: relative; margin-left: 10px; padding-left: 26px; border-left: 2px solid var(--line-strong); }
.timeline-step { position: relative; margin-bottom: 22px; }
.timeline-step::before { content: ""; position: absolute; left: -34px; top: 18px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 3px solid var(--ink); }
.timeline-step.has-issue::before { border-color: var(--fail); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); text-decoration: none; font-size: 13px; color: var(--ink); }
.chip:hover { border-color: var(--ink); }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0; }
.kv div { padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; font-weight: 500; }

/* Logo editor */
.logo-box { width: 140px; height: 140px; border: 1px dashed var(--line-strong); border-radius: var(--r); display: grid; place-items: center; background: #fafcfc; overflow: hidden; }
.logo-box img { max-width: 120px; max-height: 120px; object-fit: contain; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art {
  background: var(--ink); color: #d6e1e8; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
  background-image: repeating-linear-gradient(165deg, transparent 0 22px, rgba(255,255,255,.035) 22px 23px);
}
.login-art h1 { margin-bottom: 16px; color: #fff; font-size: 44px; font-stretch: 78%; max-width: 12ch; line-height: 1.05; }
.login-art p { max-width: 44ch; color: #b5c6d1; font-size: 16px; }
.login-art .flow { display: flex; gap: 0; margin-top: 28px; flex-wrap: wrap; }
.login-art .flow span { font-size: 13px; padding: 6px 12px; border: 1px solid rgba(255,255,255,.18); color: #e6eef3; }
.login-art .flow span + span { border-left: 0; }
.login-art .flow span:first-child { border-radius: 999px 0 0 999px; }
.login-art .flow span:last-child { border-radius: 0 999px 999px 0; background: var(--buoy); color: var(--ink-deep); border-color: var(--buoy); font-weight: 600; }
.login-form { display: grid; place-items: center; padding: 40px 24px; background: var(--surface); }
.login-form form { width: 100%; max-width: 360px; }
.login-form h2 { font-size: 24px; margin-bottom: 6px; }
.login-form .field { margin-bottom: 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 280px; z-index: 50; transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(12,36,53,.45); }
  .menu-btn { display: inline-flex; }
  .topbar, .acting-bar { padding-left: 16px; padding-right: 16px; }
  .content { padding: 20px 16px 40px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
  .form-grid, .form-grid-2, .grid-2 { grid-template-columns: 1fr; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-art { padding: 32px 24px; }
  .login-art h1 { font-size: 32px; }
  .user-chip .who { display: none; }
  h1 { font-size: 22px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print {
  .sidebar, .topbar, .acting-bar, .btn, .filters { display: none !important; }
  .shell { display: block; }
}

/* ---------- v2 additions ---------- */
.nav-count { margin-left: auto; background: var(--buoy); color: var(--ink-deep); font-size: 11.5px; font-weight: 700; border-radius: 999px; padding: 1px 8px; }
.plant-switch select { min-height: 38px; padding: 6px 34px 6px 12px; font-weight: 600; color: var(--ink); border-color: var(--line-strong); background-color: #f8fafa; }
.tag-wait { background: #eef2f4; color: var(--muted); }
.tag-ok { background: #e6eef5; color: var(--ink); }
.status-banner { display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 14px 20px; border-radius: var(--r); margin-bottom: 18px; border: 1px solid var(--line); background: var(--surface); }
.status-banner.locked { border-color: #b9cbdb; background: #eef4f9; }
.status-banner .lock { font-weight: 650; color: var(--ink); }
.history { list-style: none; margin: 0; padding: 0; }
.history li { padding: 12px 20px; border-top: 1px solid var(--line); font-size: 14px; }
.history li:first-child { border-top: 0; }
.history .when { color: var(--muted); font-size: 12.5px; }
.diff { margin: 6px 0 0; padding: 0; list-style: none; font-size: 13px; }
.diff li { padding: 2px 0; border: 0; }
.diff del { color: var(--fail); text-decoration: line-through; }
.diff ins { color: var(--pass); text-decoration: none; font-weight: 600; }
.field.is-issue input, .field.is-issue select { border-color: var(--fail); background: var(--fail-soft); }
.limit { font-size: 12px; color: var(--muted); }
/* builder */
.b-rows { display: grid; gap: 10px; }
.b-row { display: grid; grid-template-columns: 34px minmax(0, 2fr) minmax(0, 1.3fr) minmax(0, 2fr) auto; gap: 10px; align-items: start; padding: 12px; border: 1px solid var(--line); border-radius: var(--r); background: #fff; }
.b-row.is-hidden { opacity: .55; background: #f8fafa; }
.b-row .handle { display: flex; flex-direction: column; gap: 4px; }
.b-row .handle button { border: 1px solid var(--line); background: #fff; border-radius: 6px; width: 30px; height: 26px; cursor: pointer; color: var(--muted); font: inherit; line-height: 1; }
.b-row .handle button:hover { border-color: var(--ink); color: var(--ink); }
.b-row input[type=text], .b-row select, .b-row textarea { min-height: 38px; padding: 7px 10px; font-size: 14px; }
.b-row textarea { min-height: 62px; }
.b-row .opts { display: grid; gap: 6px; }
.b-row .flags { display: grid; gap: 2px; font-size: 13px; min-width: 150px; }
.b-row .flags .check { padding: 2px 0; font-size: 13px; }
.b-row .lim { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.b-row .locked-note { font-size: 12.5px; color: var(--muted); padding-top: 8px; }
.b-preview { font-size: 12px; color: var(--muted); }
@media (max-width: 1100px) { .b-row { grid-template-columns: 34px 1fr; } .b-row > :nth-child(n+3) { grid-column: 2; } }

[hidden] { display: none !important; }
