:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e2e6ea;
  --brand: #7a4b2b;
  --brand-ink: #fff;
  --accent: #2563eb;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; gap: 1rem;
  background: var(--brand); color: var(--brand-ink);
  padding: 0 1.25rem; height: 52px;
  position: sticky; top: 0; z-index: 30;
}
.topbar a { color: var(--brand-ink); }
.brand a { font-weight: 700; font-size: 1.05rem; }
.brand-sub { font-weight: 400; opacity: .8; font-size: .8rem; }
.hamburger { display: none; background: none; border: 1px solid rgba(255,255,255,.5);
  color: #fff; border-radius: 6px; font-size: 1.1rem; line-height: 1; padding: .25rem .55rem; cursor: pointer; }
.topbar-right { display: flex; align-items: center; gap: .75rem; margin-left: auto; }

/* Layout: left sidebar + content */
.shell { display: flex; flex: 1; align-items: stretch; }
.sidebar { width: 230px; flex: 0 0 230px; background: var(--panel);
  border-right: 1px solid var(--line); padding: .75rem 0; }
.sidenav { display: flex; flex-direction: column; position: sticky; top: 64px; }
.navgroup { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: .8rem 1.1rem .25rem; }
.navitem { display: block; padding: .5rem 1.1rem; color: var(--ink); font-size: .92rem;
  border-left: 3px solid transparent; }
.navitem:hover { background: #f1f3f5; text-decoration: none; }
.navitem.active { background: #f3ede8; border-left-color: var(--brand); font-weight: 600; }
.nav-overlay { display: none; }
.who { font-size: .85rem; opacity: .85; }
.langform select { border-radius: 4px; border: none; padding: 2px 4px; }
.linkbtn { background: none; border: 1px solid rgba(255,255,255,.5); color: #fff;
  border-radius: 4px; padding: 3px 8px; cursor: pointer; font-size: .82rem; }
.linkbtn:hover { background: rgba(255,255,255,.12); }
.logoutform { margin: 0; }

/* Fill the full window width (minus the fixed sidebar); wide column sets must not be squeezed. */
.content { flex: 1 1 auto; min-width: 0; width: 100%; padding: 1.25rem 1.5rem; }
/* Keep text-heavy single-column screens (auth, help prose) readable rather than edge-to-edge. */
.content > .authbox, .content.narrow { max-width: 1180px; }

.messages { list-style: none; margin: 0 0 .75rem; padding: 0; }
.msg { padding: .6rem .9rem; border-radius: 6px; margin-bottom: .4rem; font-size: .9rem; }
.msg.success { background: #ecfdf5; color: var(--ok); border: 1px solid #bbf7d0; }
.msg.error, .msg.danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.msg.warning { background: #fffbeb; color: var(--warn); border: 1px solid #fde68a; }
.msg.info { background: #eff6ff; color: var(--accent); border: 1px solid #bfdbfe; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.field-group { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .9rem 0;
  margin: 0 0 1rem; }
.field-group > legend { font-size: .8rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; padding: 0 .4rem; }
.field-group small.muted { display: block; margin-top: .15rem; font-size: .8rem; }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }

table.grid { width: 100%; border-collapse: collapse; font-size: .88rem; background: var(--panel); }
table.grid th, table.grid td { border: 1px solid var(--line); padding: .45rem .6rem; text-align: left; vertical-align: top; }
table.grid th { background: #f1f3f5; font-weight: 600; }
table.grid tr:hover td { background: #fafbfc; }

.btn { display: inline-block; background: var(--accent); color: #fff; border: none;
  border-radius: 6px; padding: .5rem .9rem; cursor: pointer; font-size: .9rem; }
.btn:hover { filter: brightness(1.05); text-decoration: none; }
.btn.secondary { background: #e5e7eb; color: var(--ink); }
.btn.ok { background: var(--ok); }
.btn.danger { background: var(--danger); }

.badge { display: inline-block; padding: .15rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge.draft { background: #e5e7eb; color: #374151; }
.badge.completed { background: #dbeafe; color: #1e40af; }
.badge.authorised { background: #dcfce7; color: #166534; }
.badge.expired { background: #fee2e2; color: #991b1b; }
.badge.soon { background: #fef3c7; color: #92400e; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; margin-top: 1rem; }
.chartbox { min-width: 0; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 1rem 1.1rem; }
.tile .num { font-size: 2rem; font-weight: 700; }
.tile .lbl { color: var(--muted); font-size: .85rem; }

form .field { margin-bottom: .8rem; }
form label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25rem; }
form input, form select, form textarea { width: 100%; padding: .45rem .55rem; border: 1px solid var(--line);
  border-radius: 6px; font-size: .9rem; font-family: inherit; }
form .errorlist { color: var(--danger); font-size: .8rem; list-style: none; padding: 0; margin: .2rem 0; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; }
.filters .field { margin: 0; }

.appfooter {
  border-top: 1px solid var(--line);
  background: #fff;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 10px 16px;
}
.appfooter a { color: var(--muted); }
.appfooter a:hover { color: var(--ink); }
.appfooter .dot { margin: 0 8px; color: #cbd2d9; }

.pager { display: flex; align-items: center; gap: .5rem; margin: .6rem 0; }
.pager .btn { padding: .3rem .6rem; }
.pageinfo { color: var(--muted); font-size: .85rem; }
.filters .chk { font-weight: 400; display: flex; align-items: center; gap: .35rem; white-space: nowrap; }
.filters .chk input { width: auto; }
table.grid th a { color: inherit; }
table.grid th a:hover { text-decoration: underline; }
table.grid tr.dim td { opacity: .5; font-style: italic; }

.authbox { max-width: 360px; margin: 4rem auto; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* Responsive: collapse sidebar into an off-canvas drawer toggled by the hamburger */
@media (max-width: 820px) {
  .hamburger { display: inline-block; }
  .brand-sub { display: none; }
  .sidebar {
    position: fixed; top: 52px; bottom: 0; left: -260px; width: 240px; z-index: 40;
    transition: left .2s ease; overflow-y: auto; box-shadow: 2px 0 8px rgba(0,0,0,.15);
  }
  .sidenav { position: static; top: auto; }
  body.nav-open .sidebar { left: 0; }
  body.nav-open .nav-overlay {
    display: block; position: fixed; top: 52px; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.35); z-index: 35;
  }
  .content { padding: 1rem; }
}

/* Settings hub / link cards */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.linkcard { display: block; text-decoration: none; color: inherit; transition: border-color .15s, transform .05s; }
.linkcard:hover { border-color: #0d9488; }
.linkcard:active { transform: translateY(1px); }
.linkcard h2 { margin: 0 0 .35rem; font-size: 1.05rem; }

/* Role-aware dashboard quick actions */
.quickactions { margin-bottom: 1rem; }
.quickactions .qa-title { display: block; margin-bottom: .5rem; color: var(--brand, #7a4b2b); }
.quickactions .qa-links { display: flex; flex-wrap: wrap; gap: .5rem; }
.small { font-size: .85em; }

/* Status pills (trace-test result, etc.) */
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .8em; font-weight: 600; }
.pill.ok { background: #d6f3e2; color: #1f7a4d; }
.pill.bad { background: #f7d9d9; color: #b22; }

/* Grouped form sections (receipt wizard) */
.formsection { border: 1px solid var(--border, #d9d9e0); border-radius: 8px; padding: .6rem 1rem 1rem; margin: 0 0 1rem; }
.formsection > legend { font-weight: 600; color: var(--brand, #7a4b2b); padding: 0 .4rem; }

/* First-run onboarding hints */
.onboarding { border-left: 4px solid #e0a800; background: #fffbef; margin-bottom: 1rem; }
.onboarding ul { margin: .4rem 0 0; padding-left: 1.1rem; }

/* EAN-128 mismatch diagnostics */
.ean-bad { color: #b22; font-weight: 600; }
.ean-cell-bad { background: #fdecec; color: #b22; font-weight: 600; }
.ean-ok { color: #1f7a4d; }
.ean-row { white-space: nowrap; }
