/* fooddb shared design system — one token set for the operator console and
   the user panel, speaking the same visual language as the landing page:
   soft drop shadows, 16px cards, hairline borders, gradient accents.

   NOTE: templates/landing.html is a standalone document with its OWN copy of
   these tokens (it never loads this file). --chip and --shadow below were
   synced to it; move both together or the two surfaces drift apart. */

:root {
  --bg: #f7f8fb; --card: #ffffff; --chip: #eef1f6;
  --ink: #101828; --mut: #5b6472; --line: #e6e8ef;
  --brand: #16a34a; --brand2: #0ea5e9; --brand3: #8b5cf6;
  --grad: linear-gradient(90deg, var(--brand), var(--brand2));
  --ok: #067647; --ok-soft: #e6f4ea; --bad: #b42318; --bad-soft: #fdecea;
  --warn-soft: #fef3e2; --warn-ink: #b25e09;
  --code-bg: #0f172a; --code-ink: #d7e3f4;
  --shadow: 0 10px 30px rgb(16 24 40 / .08);
  --radius: 14px; --radius-lg: 16px;
  /* legacy console aliases */
  --surface: var(--card); --surface2: var(--chip); --muted: var(--mut);
  --accent: var(--brand2); --accent-ink: #ffffff; --accent-soft: #e3f2fd;
}
[data-theme=dark] {
  --bg: #0b1020; --card: #121a2e; --chip: #1a2440;
  --ink: #e8edf6; --mut: #93a0b4; --line: #232d45;
  --ok: #3fbf7f; --ok-soft: #12291d; --bad: #f97066; --bad-soft: #331311;
  --warn-soft: #302410; --warn-ink: #e2a55e;
  --code-bg: #0a0f1d; --code-ink: #c9d7ec;
  --shadow: 0 10px 30px rgb(0 0 0 / .35);
  --accent-soft: #14304a;
}

* { box-sizing: border-box; }
html { color-scheme: light; } [data-theme=dark] { color-scheme: dark; }
body { margin: 0; background: var(--bg); color: var(--ink);
       font: 16px/1.6 -apple-system, "Segoe UI", Roboto, Inter, Arial, sans-serif;
       -webkit-font-smoothing: antialiased; }

/* Content links. Without this every table-cell link falls back to the UA's
   blue-and-underlined (and purple when visited). Header/pager/lang links set
   their own colour below and keep winning. */
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* header shell (console + panel) */
header { position: sticky; top: 0; z-index: 10; display: flex; gap: 4px;
         align-items: center; padding: 10px 20px;
         background: color-mix(in srgb, var(--bg) 82%, transparent);
         backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
header .brand { font-weight: 800; font-size: 17px; letter-spacing: -.02em;
                margin-right: 14px; }
header .brand em { font-style: normal; background: var(--grad);
                   -webkit-background-clip: text; background-clip: text; color: transparent; }
header a { color: var(--mut); text-decoration: none; font-weight: 550;
           padding: 6px 10px; border-radius: 9px; }
header a:hover { color: var(--ink); background: var(--chip); }
main { max-width: 1080px; margin: 26px auto; padding: 0 18px; }
main.wide { max-width: none; padding: 0 24px; }
h1 { font-size: clamp(24px, 3vw, 30px); letter-spacing: -.02em; margin: 10px 0 16px;
     font-weight: 800; }
h2 { font-size: 16px; font-weight: 700; letter-spacing: -.01em; margin: 28px 0 10px;
     padding-bottom: 8px; border-bottom: 1px solid var(--line); }
h2.plain { border: 0; padding: 0; }
.lead { color: var(--mut); margin: -6px 0 18px; }

/* tables */
table { width: 100%; border-collapse: collapse; background: var(--card);
        border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow); }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--mut); font-weight: 600; font-size: 12.5px;
     text-transform: uppercase; letter-spacing: .04em; background: var(--chip); }
tbody tr, table tr { transition: background .12s ease; }
tbody tr:hover, table tr:hover td { background: var(--chip); }
tr:last-child td { border-bottom: 0; }
td.thumb { width: 46px; padding: 5px 6px 5px 12px; }
td.thumb img { width: 36px; height: 36px; object-fit: cover; border-radius: 8px;
               display: block; cursor: zoom-in; background: var(--chip); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px;
         font-size: 11.5px; font-weight: 650; }
.badge.operator      { background: var(--accent-soft); color: var(--accent); }
.badge.openfoodfacts { background: var(--ok-soft); color: var(--ok); }
.badge.opennutrition { background: var(--warn-soft); color: var(--warn-ink); }
.badge.usda          { background: var(--chip); color: var(--mut); }
.badge.blocked       { background: var(--bad-soft); color: var(--bad); cursor: help; }
.badge.plan          { background: var(--ok-soft); color: var(--ok); font-size: 12.5px; }

/* cards + forms */
form.card, .card { background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 22px; box-shadow: var(--shadow);
  transition: transform .25s ease, box-shadow .25s ease; }
/* The lift is opt-in: a form card must not jump under the cursor mid-edit. */
.card.lift:hover { transform: translateY(-4px); }
label { display: block; margin: 12px 0 4px; font-weight: 600; font-size: 13px; }
input[type=text], input[type=password], input[type=email], input[type=search],
input[type=number], input[type=file], input:not([type]),
select, textarea { width: 100%;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; background: var(--card); color: var(--ink); }
input, select, textarea { transition: border-color .15s ease, box-shadow .15s ease; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 0; border-color: var(--brand2);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand2) 18%, transparent); }
td select { width: auto; min-width: 90px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0 14px; }
button { margin-top: 16px; background: var(--grad); color: #fff;
         border: 1px solid transparent; padding: 9px 18px; border-radius: 10px;
         font: inherit; font-weight: 650; cursor: pointer;
         transition: filter .15s ease, border-color .15s ease, background .15s ease; }
button:hover { filter: brightness(1.07); }
button.danger { background: var(--bad); }
/* Secondary: a solid hairline, not a dashed one — dashed reads as a
   drop-zone placeholder rather than a real action (landing's .tbtn). */
button.ghost { background: var(--card); color: var(--ink);
               border: 1px solid var(--line); font-weight: 600; }
button.ghost:hover { filter: none; border-color: var(--brand2); color: var(--brand2); }

/* utility */
.muted { color: var(--mut); font-size: 13px; }
.error { color: var(--bad); }
.field-error { color: var(--bad); font-size: 12px; }
code { background: var(--chip); padding: 1px 6px; border-radius: 6px;
       cursor: copy; font-size: 13px; }
.flash { background: var(--ok-soft); color: var(--ok); border: 1px solid transparent;
         padding: 9px 14px; border-radius: 10px; margin-bottom: 16px;
         animation: fadeout .4s ease 5s forwards; }
@keyframes fadeout { to { opacity: 0; visibility: hidden; margin: 0; padding: 0; height: 0; } }
/* A warning flash explains why THIS page was reached, so it must not fade away
   while the operator is still reading the form it applies to. */
.flash.warn { background: var(--warn-soft); color: var(--warn-ink); animation: none; }

.langs a { color: var(--mut); font-size: 12.5px; padding: 4px 5px; }
.langs a.on { color: var(--ink); font-weight: 750; }
#theme { margin: 0 2px; padding: 5px 9px; background: transparent;
         border: 1px solid var(--line); border-radius: 9px; color: var(--mut); }

/* pager */
.pager { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin: 16px 0; }
.pager a, .pager span.cell { min-width: 32px; text-align: center; padding: 6px 10px;
  border-radius: 9px; text-decoration: none; color: var(--mut); font-size: 13.5px;
  transition: background .15s ease, color .15s ease; }
.pager a:hover { background: var(--chip); color: var(--ink); text-decoration: none; }
/* Must out-specify `.pager span.cell` (0,2,1) or the white never lands and
   the active page renders muted grey on the brand gradient. */
.pager span.cell.current, .pager .cell.current {
  background: var(--grad); color: #fff; font-weight: 700; }
.pager span.cell:not(.current):not(:hover) { cursor: default; }
.pager .ends { margin-left: auto; display: flex; gap: 4px; }

/* console specifics */
.photo-card { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.photo-card img { max-width: 180px; max-height: 180px; border-radius: 10px; cursor: zoom-in; }
/* Photo editor under the preview: left-aligned inside a centered card, so the
   field reads as a form control rather than as a caption. */
.photo-edit { margin-top: 12px; text-align: left; }
.photo-edit label { display: block; }
.photo-edit .clear-photo { display: flex; gap: 7px; align-items: center; margin-top: 8px;
  font-size: 13px; font-weight: 500; color: var(--mut); cursor: pointer; }
.photo-edit .clear-photo input { margin: 0; cursor: pointer; }
.name-row { display: grid; grid-template-columns: 90px 1fr auto; gap: 10px; margin-bottom: 8px; }
/* Row remove: quiet until hovered, so a grid of them does not read as a row of
   warnings. Sized to the input height so the row stays visually aligned. */
.name-row .rmname { margin: 0; padding: 0; width: 34px; align-self: stretch;
  background: none; border: 1px solid var(--line); border-radius: 10px;
  color: var(--mut); font-size: 18px; line-height: 1; cursor: pointer;
  box-shadow: none; transition: color .15s, border-color .15s, background .15s; }
.name-row .rmname:hover { color: var(--bad); border-color: currentColor;
  background: color-mix(in srgb, currentColor 8%, transparent); }
.row-edit input[type=text] { padding: 5px 8px; font-size: 14px; }
.row-edit .mini { width: 74px; display: inline-block; }
.row-edit button { margin: 4px 4px 0 0; padding: 5px 12px; font-size: 13px; }

dialog#lightbox { border: 0; border-radius: 14px; padding: 6px; background: var(--card);
                  max-width: min(92vw, 720px); box-shadow: var(--shadow); }
dialog#lightbox::backdrop { background: rgb(0 0 0 / .55); }
dialog#lightbox img { max-width: 100%; max-height: 80vh; display: block; border-radius: 10px; }

#toasts { position: fixed; bottom: 20px; right: 20px; display: flex;
          flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--ink); color: var(--bg); padding: 9px 16px;
         border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow);
         animation: fadeout .3s ease 2.2s forwards; }
.htmx-request { opacity: .55; transition: opacity .15s; }

/* panel specifics */
.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
              gap: 16px; }
.keybox { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
          background: var(--code-bg); color: var(--code-ink); border-radius: 10px;
          padding: 12px 14px; font: 13.5px/1.5 ui-monospace, Consolas, Menlo, monospace;
          word-break: break-all; }
.keybox code { background: transparent; color: inherit; padding: 0; }
.usage-bar { height: 10px; border-radius: 999px; background: var(--chip);
             overflow: hidden; margin: 10px 0 4px; }
.usage-bar i { display: block; height: 100%; background: var(--grad); }
.usage-days { display: flex; gap: 4px; align-items: flex-end; height: 64px; margin-top: 14px; }
.usage-days i { flex: 1; min-height: 2px; border-radius: 3px 3px 0 0;
                background: var(--accent-soft); position: relative; }
.usage-days i b { position: absolute; inset: auto 0 0 0; border-radius: 3px 3px 0 0;
                  background: var(--grad); display: block; }
.stat-big { font-size: 34px; font-weight: 800; letter-spacing: -.02em;
            background: var(--grad); -webkit-background-clip: text;
            background-clip: text; color: transparent; }
pre.code { background: var(--code-bg); color: var(--code-ink); border-radius: var(--radius);
  padding: 18px 20px; overflow-x: auto; font: 13px/1.7 ui-monospace, Consolas, Menlo, monospace;
  box-shadow: var(--shadow); }

/* spreadsheet catalogue */
/* Scrolls in both axes so the header row and the pinned columns can freeze
   against it; the floor keeps it usable on short screens. */
/* `isolation: isolate` is load-bearing: overflow alone does NOT create a
   stacking context, so without it the pinned cells' z-index competes in the
   root context and paints over the sticky bulk bar below the table. */
.sheet-wrap { overflow: auto; max-height: max(420px, calc(100vh - 290px));
  isolation: isolate; border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); background: var(--card); }
/* `overflow: hidden` on the table itself (see the global rule) would make the
   table its own scroll container and silently kill every position:sticky in
   its cells — this override is what makes the frozen header and pinned
   columns work at all. */
.sheet { box-shadow: none; min-width: 100%; overflow: visible; border-radius: 0; }
.sheet th { white-space: nowrap; }
.sheet thead th { position: sticky; top: 0; z-index: 4; background: var(--chip); }
.sheet th a { color: inherit; text-decoration: none; display: inline-flex;
              align-items: center; gap: 4px; }
.sheet th a:hover { color: var(--ink); text-decoration: none; }
.sheet th .dir { color: var(--accent); }
.sheet td input { padding: 5px 8px; font-size: 14px; min-width: 64px; }
.sheet td.c-sel, .sheet th.c-sel { width: 34px; padding: 5px 4px 5px 12px; }
.sheet td.c-sel input, .sheet th.c-sel input { width: auto; }

/* Pinned columns. Sticky cells must paint their own background (transparent
   cells let scrolled content bleed through) and draw their edge with an
   inset shadow — border-collapse drops real borders on overlap. */
.sheet td.c-sel, .sheet th.c-sel,
.sheet td.thumb, .sheet th.thumb,
.sheet td.c-barcode, .sheet th.c-barcode,
.sheet td.c-name, .sheet th.c-name,
.sheet tr > :last-child { position: sticky; z-index: 2; background: var(--card); }
.sheet thead th.c-sel, .sheet thead th.thumb,
.sheet thead th.c-barcode, .sheet thead th.c-name,
.sheet thead tr > :last-child { z-index: 5; background: var(--chip); }
.sheet tr:hover > td.c-sel, .sheet tr:hover > td.thumb,
.sheet tr:hover > td.c-barcode, .sheet tr:hover > td.c-name,
.sheet tr:hover > td:last-child { background: var(--chip); }
.sheet .c-sel { left: 0; }
.sheet .thumb { left: 34px; }
.sheet .c-barcode { left: 80px; width: 140px; }
.sheet .c-name { left: 220px; box-shadow: inset -1px 0 var(--line); }
.sheet tr > :last-child { right: 0; min-width: 132px;
  box-shadow: inset 1px 0 var(--line); }

/* One line, ellipsised: the max-width has to sit on the inner element —
   on a td alone it is only a hint under auto table layout. */
.sheet .c-name a, .sheet .c-brand span { display: block; max-width: 280px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.sheet .c-name a:hover { color: var(--brand2); text-decoration: none; }
.sheet .c-brand span { max-width: 150px; color: var(--mut); }
.sheet .c-name input { min-width: 240px; }
.sheet .rowact { display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px; color: var(--mut);
  background: var(--chip); text-decoration: none; }
.sheet .rowact:hover { color: var(--brand2); text-decoration: none; }
.sheet tr.row-edit > td { background: color-mix(in srgb, var(--brand2) 7%, var(--card)); }

@media (max-width: 1000px) {
  /* Below this the pinned columns would eat the viewport; let it scroll flat. */
  .sheet td, .sheet th { position: static !important; }
}
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.filters > div { margin: 0; min-width: 150px; }
.filters button { margin-top: 0; }
/* A field's label row, carrying an inline modifier control on the right. The
   toggle MUST live here rather than under the input: .filters aligns its
   columns on `align-items: end`, so an extra row below the control makes that
   column taller and lifts its input above every other filter. Reproducing the
   base label margin (12px 0 4px) keeps this column exactly as tall as the
   plain-label ones. */
.field-head { display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; margin: 12px 0 4px; }
.field-head > label { margin: 0; }
.smart-toggle { display: inline-flex; align-items: center; gap: 6px; margin: 0;
  font-size: 13px; font-weight: 500; color: var(--mut); cursor: pointer;
  white-space: nowrap; }
.smart-toggle input { margin: 0; cursor: pointer; }
.colpicker { position: relative; }
.colpicker > summary { cursor: pointer; list-style: none; font-weight: 600;
  font-size: 13px; color: var(--mut); padding: 9px 11px; border: 1px dashed var(--line);
  border-radius: 10px; }
.colpicker[open] > summary { color: var(--ink); }
.colpicker .menu { position: absolute; z-index: 20; top: calc(100% + 6px); left: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 12px 14px; min-width: 260px;
  max-height: 320px; overflow-y: auto; columns: 2; column-gap: 14px; }
.colpicker .menu label { display: flex; gap: 7px; align-items: center; margin: 0 0 6px;
  font-weight: 500; font-size: 13px; break-inside: avoid; }
.colpicker .menu input[type=checkbox] { width: auto; }
/* z-index 6: above the sheet's pinned cells (max 5), below header (10),
   the column-picker menu (20) and toasts (50). */
.bulkbar { position: sticky; bottom: 12px; z-index: 6; margin-top: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; box-shadow: var(--shadow); display: flex; gap: 10px;
  align-items: center; flex-wrap: wrap; }
.bulkbar button { margin-top: 0; padding: 7px 14px; font-size: 13.5px; }
.bulkbar select, .bulkbar input { width: auto; }
.food-head { display: grid; grid-template-columns: 220px 1fr; gap: 18px;
  align-items: start; margin-bottom: 16px; }
@media (max-width: 700px) { .food-head { grid-template-columns: 1fr; } }
.photo-empty { display: flex; align-items: center; justify-content: center;
  min-height: 150px; border: 1px dashed var(--line); border-radius: 12px;
  color: var(--mut); font-size: 13px; background: var(--chip); }

/* Disclosure panels (food form's extended nutrition, the column picker) */
details.panel > summary { cursor: pointer; list-style: none; font-weight: 700;
  font-size: 15px; padding: 10px 14px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--chip); }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::after { content: " ▾"; color: var(--mut); }
details.panel[open] > summary::after { content: " ▴"; }
details.panel[open] > summary { border-color: var(--brand2); }

/* Danger zone: a footnote, not a peer of the editing card. */
.danger-zone { background: var(--bad-soft); border: 1px solid
  color-mix(in srgb, var(--bad) 35%, var(--line)); box-shadow: none; }
.danger-zone h2 { color: var(--bad); border-bottom-color:
  color-mix(in srgb, var(--bad) 25%, var(--line)); margin-top: 0; }
.crumb { color: var(--mut); font-size: 13px; margin: 0 0 4px; }

/* Entrance animation (landing's .up/.d1-.d3) */
.up { opacity: 0; transform: translateY(14px); animation: fadeUp .5s ease forwards; }
.d1 { animation-delay: .06s; } .d2 { animation-delay: .12s; } .d3 { animation-delay: .18s; }
@keyframes fadeUp { to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .up { opacity: 1; transform: none; animation: none; }
  .card, tbody tr, table tr, button, input, select, textarea, .pager a { transition: none; }
  .card.lift:hover { transform: none; }
  .flash, .toast { animation: none; }
}

@media (max-width: 700px) {
  td.thumb, th.thumb { display: none; }
  header { flex-wrap: wrap; }
  main { margin-top: 16px; }
}
