/* NutriCalc UK — interface styles */
:root {
  --ink: #18242c;
  --ink-2: #4a5961;
  --muted: #7b878d;
  --line: #dfe4e2;
  --bg: #f4f5f2;
  --card: #ffffff;
  --accent: #0e5c52;
  --accent-2: #12796b;
  --accent-soft: #e3efec;
  --warn: #9a6200;
  --warn-soft: #fff4dc;
  --err: #a3271f;
  --err-soft: #fbe7e5;
  --ok: #1f6b3a;
  --ok-soft: #e4f3e8;
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; font-weight: 650; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; font-weight: 650; margin: 0 0 .75rem; }
h3 { font-size: 1rem; font-weight: 650; margin: 1rem 0 .5rem; }
p { margin: .4rem 0; }
small, .small { font-size: .85rem; color: var(--muted); }
code { font-family: var(--mono); font-size: .88em; background: #eef1ef; padding: 1px 5px; border-radius: 4px; }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.5rem;
  background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .6rem; min-width: 200px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 7px; background: var(--accent-2);
  display: grid; place-items: center; font-weight: 800; font-size: 1.05rem;
}
.brand strong { display: block; font-size: .95rem; line-height: 1.1; }
.brand small { color: #aab7bd; font-size: .75rem; }
.topbar nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.topbar nav a { color: #cdd6da; padding: .45rem .75rem; border-radius: 6px; font-size: .92rem; }
.topbar nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.topbar nav a.active { background: rgba(255,255,255,.14); color: #fff; }
.userbox { display: flex; align-items: center; gap: .75rem; font-size: .88rem; }
.userbox a { color: #fff; }
.role { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; background: rgba(255,255,255,.15); padding: 1px 6px; border-radius: 4px; margin-left: 3px; }
.linkbtn { background: none; border: 0; color: #cdd6da; cursor: pointer; font: inherit; padding: 0; }
.linkbtn:hover { color: #fff; text-decoration: underline; }
form.inline { display: inline; margin: 0; }

/* ---- Layout ---- */
.container { max-width: 1240px; margin: 0 auto; padding: 1.5rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head .sub { color: var(--ink-2); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.card > h2:first-child { margin-top: 0; }
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } .topbar { flex-wrap: wrap; } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; }
.stat .n { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .85rem; }
.stat.warn .n { color: var(--warn); }
.stat.err .n { color: var(--err); }
.footer { text-align: center; color: var(--muted); font-size: .78rem; padding: 1.5rem; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .95rem; border-radius: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-size: .92rem;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f0f2f1; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-danger { color: var(--err); border-color: #e9c2bf; }
.btn-danger:hover { background: var(--err-soft); }
.btn-sm { padding: .25rem .6rem; font-size: .83rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---- Tables ---- */
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.data th { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfa; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:hover td { background: #fbfcfb; }
table.data tfoot td { font-weight: 650; border-top: 2px solid var(--ink); }
.table-wrap { overflow-x: auto; }

/* ---- Forms ---- */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--ink-2); margin-bottom: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], input[type=file], select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid #cdd4d1; border-radius: 6px; font: inherit; font-size: .93rem; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 80px; }
.field { margin-bottom: .9rem; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: .2rem; font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 1rem; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-4 { grid-column: 1 / -1; }
@media (max-width: 900px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.checks { display: flex; flex-wrap: wrap; gap: .35rem 1.1rem; }
.checks label { font-weight: 400; display: flex; gap: .35rem; align-items: center; color: var(--ink); margin: 0; }
.nutr-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .5rem 1rem; }
@media (max-width: 900px) { .nutr-grid { grid-template-columns: repeat(3, 1fr); } }
.nutr-grid input { text-align: right; font-variant-numeric: tabular-nums; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 650; padding: 0 .4rem; font-size: .95rem; }
input[type=text].qty-input { width: 110px; text-align: right; }
.unit-select { width: 80px; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters input[type=search] { max-width: 320px; }
.filters select { width: auto; }

/* ---- Alerts & badges ---- */
.alert { padding: .7rem 1rem; border-radius: 6px; margin-bottom: 1rem; border: 1px solid transparent; font-size: .93rem; }
.alert ul { margin: .3rem 0 0 1.1rem; padding: 0; }
.alert-success { background: var(--ok-soft); border-color: #bfe0c8; color: var(--ok); }
.alert-error { background: var(--err-soft); border-color: #f0c4bf; color: var(--err); }
.alert-warn { background: var(--warn-soft); border-color: #f1dcab; color: #6f4700; }
.alert-info { background: var(--accent-soft); border-color: #c4ddd7; color: var(--accent); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .74rem; font-weight: 650; letter-spacing: .02em; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-muted { background: #eceeed; color: var(--ink-2); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-err { background: var(--err-soft); color: var(--err); }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: .75rem; background: #eef1ef; color: var(--ink-2); margin: 1px 2px 1px 0; }
.tag-allergen { background: #fde9d4; color: #8a4300; font-weight: 600; }

/* ---- Nutrition declaration (back of pack) ---- */
.nutri-table { border-collapse: collapse; width: 100%; max-width: 560px; font-size: .95rem; border: 2px solid #000; color: #000; background: #fff; }
.nutri-table th, .nutri-table td { border: 1px solid #000; padding: .3rem .55rem; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nutri-table th:first-child, .nutri-table td:first-child { text-align: left; }
.nutri-table thead th { white-space: normal; }
.nutri-table .nt-title { text-align: left; font-size: 1.15rem; font-weight: 800; border-bottom: 2px solid #000; }
.nutri-table thead tr:nth-child(2) th { font-weight: 700; font-size: .85rem; }
.nutri-table tr.sub td:first-child { padding-left: 1.4rem; }
.nutri-table.compact { font-size: .85rem; }
.nt-notes { max-width: 560px; font-size: .8rem; color: #222; margin-top: .35rem; }
.nt-notes p { margin: .15rem 0; }

/* ---- Front of pack ---- */
.fop { display: inline-block; border: 1px solid #222; border-radius: 10px; padding: .6rem; background: #fff; color: #000; max-width: 640px; }
.fop-head { font-weight: 700; font-size: .9rem; margin-bottom: .4rem; }
.fop-boxes { display: flex; gap: .4rem; }
.fop-box { flex: 1; min-width: 92px; border: 1px solid #222; border-radius: 40px 40px 12px 12px; padding: .5rem .3rem .45rem; text-align: center; }
.fop-label { font-size: .8rem; font-weight: 700; }
.fop-value { font-size: 1.05rem; font-weight: 800; line-height: 1.2; }
.fop-value2 { font-size: .9rem; font-weight: 700; }
.fop-level { font-size: .72rem; font-weight: 800; letter-spacing: .06em; margin-top: .1rem; }
.fop-ri { margin-top: .3rem; background: #fff; border-radius: 99px; font-weight: 800; font-size: .92rem; padding: .1rem 0; }
.fop-energy { background: #fff; }
.fop-low { background: #8fce6b; }
.fop-medium { background: #ffbf3c; }
.fop-high { background: #ec4c3c; color: #fff; }
.fop-high .fop-ri { color: #000; }
.fop-foot { font-size: .78rem; margin-top: .45rem; }

/* ---- Ingredient list ---- */
.ing-list { font-size: .95rem; line-height: 1.55; max-width: 640px; }
.ing-list strong { font-weight: 800; }

/* ---- Workings ---- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.issues li { margin-bottom: .2rem; }
.row-filter { margin-bottom: .5rem; }

/* ---- Login ---- */
body.login { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 2rem; }
.login-card .brand { color: var(--ink); margin-bottom: 1.25rem; }
.login-card .brand small { color: var(--muted); }

/* ---- Label sheet ---- */
.label-sheet { background: #fff; border: 1px solid var(--line); padding: 1.5rem; border-radius: var(--radius); position: relative; overflow: hidden; }
.label-sheet h1 { font-size: 1.3rem; }
.label-sheet section { margin-bottom: 1.4rem; break-inside: avoid; }
.label-sheet h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 .4rem; }
.watermark {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-size: 6rem; font-weight: 900; color: rgba(163, 39, 31, .16); transform: rotate(-24deg); letter-spacing: .1em; z-index: 5;
}
.label-meta { font-size: .8rem; color: var(--ink-2); border-top: 1px solid var(--line); padding-top: .6rem; }

@media print {
  .no-print, .topbar, .footer { display: none !important; }
  body { background: #fff; }
  .container { max-width: none; padding: 0; }
  .label-sheet { border: 0; padding: 0; }
  .card { border: 0; padding: 0; }
  .fop-low, .fop-medium, .fop-high { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
