:root {
  --pico-font-size: 95%;
  --ok: #2e7d32;
  --danger: #c62828;
}

/* Fertistock colors: olive and harvest gold, shared with the owner's Cerealscope apps.
   Same selector as Pico's light theme, so these win. */
:root:not([data-theme=dark]), [data-theme=light] {
  --brand: #5a7328;
  --brand-strong: #34451a;
  --brand-soft: #edf3e3;
  --wheat: #c47c10;
  --wheat-soft: #f8eedb;
  --pico-text-selection-color: rgba(196, 124, 16, .25);
  --pico-primary: var(--brand);
  --pico-primary-background: var(--brand);
  --pico-primary-underline: rgba(90, 115, 40, .45);
  --pico-primary-hover: var(--brand-strong);
  --pico-primary-hover-background: var(--brand-strong);
  --pico-primary-focus: rgba(90, 115, 40, .35);
}

/* Header: olive bar with a gold line under it. */
.app-header { background: var(--brand-strong); border-bottom: 4px solid var(--wheat); margin-bottom: 1.75rem; }
.app-header nav { --pico-nav-element-spacing-vertical: .55rem; padding-block: .25rem; }
.app-header nav form { margin: 0; }
.app-header nav a:not([role=button]) { color: rgba(255, 255, 255, .82); text-decoration: none; border-radius: 0;
                                       box-shadow: inset 0 -2px 0 transparent; }
.app-header nav a:not([role=button]):hover { color: #fff; }
.app-header nav a[aria-current=page]:not([role=button]) { color: #fff; box-shadow: inset 0 -2px 0 var(--wheat); }
.app-header .new-bon { margin: 0; padding: .35rem .8rem; background: var(--wheat); border-color: var(--wheat);
                       color: #2b1e03; font-weight: 600; }  /* dark text: white on this gold is too faint */
.app-header .new-bon:hover, .app-header .new-bon[aria-current=page] { background: #d8902a; border-color: #d8902a; color: #2b1e03; }
.app-header .logout { margin: 0; padding: .35rem .8rem; background: transparent; border-color: rgba(255, 255, 255, .55);
                      color: #fff; }
.app-header .logout:hover { background: rgba(255, 255, 255, .12); border-color: #fff; }
.brand { display: flex; align-items: center; gap: .7rem; text-decoration: none; line-height: 1.15; }
.brand img { height: 54px; width: auto; padding: 2px; background: #fff; border-radius: 12px; }
.brand strong { color: #fff; font-size: 1.3rem; letter-spacing: .01em; }
.brand small { color: var(--wheat-soft); }

/* Footer: same olive as the header, kept at the bottom of short pages such as the login. */
body { display: flex; flex-direction: column; min-height: 100vh; }
body > main { flex: 1 0 auto; width: 100%; }
.app-footer { margin-top: 2.5rem; padding-block: .9rem; background: var(--brand-strong);
              border-top: 3px solid var(--wheat); color: rgba(255, 255, 255, .75); font-size: .85rem; }
.app-footer .container { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem 1.5rem; }
.app-footer strong { color: var(--wheat-soft); }

/* Phones: the menu goes on its own lines under the name instead of overflowing. */
@media (max-width: 860px) {
  .app-header nav { --pico-nav-element-spacing-vertical: .3rem; --pico-nav-element-spacing-horizontal: .35rem;
                    flex-wrap: wrap; }
  .app-header nav > ul { flex-wrap: wrap; width: 100%; }
  .app-header :is(.new-bon, .logout) { padding: .25rem .6rem; font-size: .9rem; }
  .app-header nav > ul + ul { border-top: 1px solid rgba(255, 255, 255, .15); }
  .brand img { height: 42px; }
  .app-footer .container { justify-content: center; text-align: center; }
}

.page-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .5rem 1rem; }
.page-head h1, .page-head h2 { margin-bottom: .5rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.actions > *, .actions button[type=submit] { margin: 0; width: auto; }  /* Pico makes submit buttons full width */

.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.required, .error, .negative { color: var(--danger); }
small.error { display: block; }
.ok { color: var(--ok); }
.muted { color: var(--pico-muted-color); }

.badge { display: inline-block; padding: .05rem .55rem; border-radius: 1rem; font-size: .8em; white-space: nowrap; }
.badge.RECEPTION { background: var(--brand-soft); color: var(--brand-strong); }
.badge.SORTIE { background: var(--wheat-soft); color: #7a4f00; }
.badge.CANCELLED { background: #fde2e1; color: #a1271f; }
tr.cancelled td { opacity: .55; }

.message.success { border-left: 4px solid var(--ok); }
.message.error { border-left: 4px solid var(--danger); }
.form-errors { border-left: 4px solid var(--danger); color: var(--danger); }

/* Bon form: numbered sections (CSS counter), the save button stays in view. */
.bon-form { counter-reset: step; }
.form-hint { font-size: .85em; color: var(--pico-muted-color); margin-bottom: .75rem; }
.form-card { margin-bottom: 1.25rem; padding: 1rem 1.25rem .35rem; background: #fff;
             border: 1px solid var(--pico-muted-border-color); border-left: 4px solid var(--brand);
             border-radius: var(--pico-border-radius); }
.form-card > h2 { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; font-size: 1.15rem;
                  color: var(--brand-strong); }
.form-card > h2::before { counter-increment: step; content: counter(step); display: inline-grid; place-items: center;
                          width: 1.75rem; height: 1.75rem; border-radius: 50%; background: var(--brand); color: #fff;
                          font-size: .9rem; }
.form-card > button { margin-bottom: 1rem; }
.form-actions { position: sticky; bottom: 0; z-index: 1; padding: .75rem 0; background: var(--pico-background-color);
                border-top: 1px solid var(--pico-muted-border-color); }

.lines td { vertical-align: top; }
.lines :is(input, select) { margin-bottom: 0; min-width: 7rem; }
.lines select[name$=bag_weight_kg] { min-width: 9.5rem; }
.lines td small { display: block; }

.overflow-auto { overflow-x: auto; }
.login { max-width: 26rem; margin: 2rem auto; }
dl.fields { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.25rem; }
dl.fields dt { color: var(--pico-muted-color); }
dl.fields dd { margin: 0; }

/* Stock page: one card per product, the stock left in large. */
.stock-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(13.5rem, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stock-card { display: flex; flex-direction: column; gap: .2rem; padding: .9rem 1.1rem 1rem; background: #fff;
              border: 1px solid var(--pico-muted-border-color); border-top: 4px solid var(--wheat);
              border-radius: var(--pico-border-radius); box-shadow: var(--pico-card-box-shadow);
              color: var(--pico-color); text-decoration: none; }
.stock-card:hover { border-color: var(--brand); border-top-color: var(--wheat); }
.stock-card-name { font-weight: 600; line-height: 1.25; }
.stock-card-name small { display: block; font-weight: normal; font-size: .8em; color: var(--pico-muted-color); }
.stock-card-qty { margin-top: .35rem; font-size: 2rem; font-weight: 700; line-height: 1.1; color: var(--brand-strong);
                  font-variant-numeric: tabular-nums; }
.stock-card-qty small { font-size: 1rem; font-weight: 600; color: var(--pico-muted-color); }
.stock-card-bags { font-size: .9em; color: var(--pico-muted-color); }
.stock-card.empty { border-top-color: var(--pico-muted-border-color); }
.stock-card.empty .stock-card-qty { color: var(--pico-muted-color); }
.stock-card.negative { border-top-color: var(--danger); }
.stock-card.negative .stock-card-qty { color: var(--danger); }

/* Reports: on paper, the menu and the filters disappear; the official header and the signatures appear. */
.report-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); gap: 0 1.5rem; }
.report-list article h3 { margin-bottom: .5rem; }
.report-list article p { margin: 0; }
.report-title { text-align: center; margin-bottom: .25rem; }
.report-subtitle { text-align: center; }
.report h3 { margin: 1.5rem 0 .5rem; }
.report-note { font-size: .85em; text-align: right; }
.print-only { display: none; }

@media print {
  @page { size: A4 portrait; margin: 12mm; }
  :root { --pico-font-size: 10pt; --pico-spacing: .5rem; --pico-typography-spacing-vertical: .5rem; }
  .app-header, .app-footer, .no-print, .message { display: none !important; }
  .print-only { display: block; }
  body { display: block; min-height: 0; }
  body, main.container { max-width: none; margin: 0; padding: 0; }
  .overflow-auto { overflow: visible; }
  .report-header { display: grid; grid-template-columns: 20mm 1fr 20mm; align-items: center; text-align: center;
                   border-bottom: 2px solid #000; padding-bottom: 2mm; margin-bottom: 3mm; }
  .report-header img { width: 18mm; }
  .report-header p { margin: 0; font-weight: bold; font-size: 9pt; }
  .report-header p.agrement { font-weight: normal; }
  .report-place { display: flex; justify-content: space-between; font-weight: bold; }
  .report h2 { font-size: 14pt; margin-top: 4mm; }
  .report h3 { font-size: 11pt; margin: 4mm 0 1.5mm; }
  .report table { border-collapse: collapse; margin-bottom: 2mm; }
  .report :is(th, td) { border: 1px solid #000; padding: 1mm 2mm; background: none !important; color: #000; }
  .report th { font-weight: bold; }
  .report tfoot { display: table-row-group; }  /* the total once, at the end, not at the foot of each page */
  .report td p { margin: 0 0 1mm; }
  .month-block, .report tr { break-inside: avoid; }
  .signatures { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6mm; margin-top: 8mm;
                text-align: center; font-weight: bold; break-inside: avoid; }
  .signatures div { height: 28mm; }
}
