/* Atkinson Hyperlegible for dyslexia-friendly reading of all data & controls;
   Playfair Display for an elegant Italian editorial title. */
@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible:ital,wght@0,400;0,700;1,400&family=Playfair+Display:wght@600;700;800&display=swap');

:root {
  --bg:        #f7f2e8;  /* warm ivory / travertine  */
  --bg-2:      #f1ead9;  /* deeper cream for accents */
  --surface:   #fffdf8;  /* warm white               */
  --border:    #e4dccc;  /* warm taupe               */
  --accent:    #16724a;  /* cypress / basil green     */
  --accent-h:  #0f5a39;
  --accent-soft:#e7f0ea;
  --terra:     #b5432b;  /* Pompeian terracotta      */
  --terra-h:   #97331f;
  --gold:      #bf9440;  /* Tuscan ochre             */
  --success:   #2e7d4f;
  --error:     #b5432b;
  --text:      #2a2018;  /* espresso                 */
  --muted:     #6f6455;  /* warm brown-grey          */
  --radius:    12px;
  --shadow:    0 2px 10px rgba(60, 45, 25, .06);
  --tricolore: linear-gradient(to right,
                 #16724a 0 33.33%, #fbf8f1 33.33% 66.66%, #b5432b 66.66% 100%);
  font-size: 19px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Atkinson Hyperlegible', Arial, sans-serif;
  background:
    radial-gradient(1200px 500px at 100% -10%, rgba(191,148,64,.07), transparent 60%),
    radial-gradient(900px 500px at -10% 0%, rgba(22,114,74,.06), transparent 55%),
    var(--bg);
  color: var(--text);
  line-height: 1.6;
  padding: 1.75rem 1.5rem 3rem;
  max-width: 980px;
  margin: 0 auto;
  min-height: 100vh;
}

/* Tricolore ribbon across the very top of the page */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 5px;
  background: var(--tricolore);
  z-index: 200;
}

/* ---- Header ---- */
.app-header { margin-bottom: 1.5rem; }
h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 800;
  font-size: 2.35rem;
  line-height: 1.05;
  letter-spacing: -.01em;
  color: var(--text);
}
h1 .accent { color: var(--accent); font-style: italic; }
.tagline {
  margin-top: .35rem;
  color: var(--muted);
  font-size: .98rem;
}
.tagline::before {
  content: '';
  display: inline-block;
  width: 2.2rem; height: 3px;
  margin-right: .6rem;
  vertical-align: middle;
  border-radius: 2px;
  background: var(--tricolore);
}

h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.9rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .06em;
  display: flex;
  align-items: center;
  gap: .5rem;
}
h2::before {
  content: '';
  width: .55rem; height: .55rem;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 3px var(--accent-soft);
  flex: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  margin-bottom: 1.35rem;
  box-shadow: var(--shadow);
  overflow-x: auto;
}
/* Break the map out of the centered 980px column to span the whole window */
.card-wide {
  width: 100vw;
  margin-left: calc(50% - 50vw);
  border-radius: 0;
}

/* ---- Scan input ---- */
#scan-wrap { position: relative; }

#scan-input {
  width: 100%;
  font-size: 1.3rem;
  font-family: inherit;
  padding: 0.8rem 1rem;
  border: 2.5px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--text);
  outline: none;
  transition: box-shadow .15s;
}
#scan-input:focus { box-shadow: 0 0 0 4px rgba(22,114,74,.22); }
#scan-input::placeholder { color: #8a9b8f; }

/* ---- Raw scan debug box ---- */
#raw-box {
  font-size: .82rem;
  color: var(--muted);
  margin-top: .5rem;
  padding: .45rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-2);
  font-family: 'SF Mono', ui-monospace, monospace;
  word-break: break-all;
  min-height: 2rem;
}
#raw-box .tag {
  display: inline-block;
  margin-left: .5rem;
  padding: .1em .45em;
  border-radius: 4px;
  font-size: .78rem;
  font-weight: 700;
}
.tag-gs { background: var(--accent-soft); color: var(--accent); }
.tag-info { background: var(--bg-2); color: var(--muted); }
.tag-nogs { background: #f7e3dc; color: var(--terra); }

/* ---- Delivery table ---- */
#delivery-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
#delivery-table th {
  text-align: left;
  padding: .55rem .6rem;
  border-bottom: 2px solid var(--accent);
  color: var(--accent);
  font-weight: 700;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}
#delivery-table td {
  padding: .6rem .6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
#delivery-table tbody tr:nth-child(even) { background: rgba(241,234,217,.45); }
#delivery-table tr:last-child td { border-bottom: none; }

.product-name { font-weight: 700; }
.product-code { font-size: .8rem; color: var(--muted); }

/* ---- Quantity controls ---- */
.qty-wrap { display: flex; align-items: center; gap: .35rem; }
.qty-btn {
  width: 2rem; height: 2rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, border-color .12s;
  color: var(--text);
}
.qty-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.qty-btn:focus-visible { outline: 3px solid var(--accent); }

.qty-input {
  width: 4.25rem;
  text-align: center;
  font-family: inherit;
  font-size: 1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: .2rem;
  background: var(--surface);
}
.qty-unit { font-size: .8rem; font-weight: 700; color: var(--muted); min-width: 1.7rem; }
.qty-weigh {
  border: 1.5px solid var(--gold);
  background: var(--surface);
  color: #8a6a1f;
  border-radius: 8px;
  height: 2rem;
  padding: 0 .5rem;
  font-size: .85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s;
}
.qty-weigh:hover { background: #f6efdd; }
.qty-weigh:focus-visible { outline: 3px solid var(--gold); }

/* ---- Row actions (＋ lot / Remove) ---- */
.row-actions { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.btn-addlot {
  background: none;
  border: 1.5px solid var(--accent);
  color: var(--accent);
  border-radius: 8px;
  padding: .25rem .6rem;
  cursor: pointer;
  font-size: .85rem;
  font-family: inherit;
  white-space: nowrap;
  transition: background .12s;
}
.btn-addlot:hover { background: var(--accent-soft); }
.btn-addlot:focus-visible { outline: 3px solid var(--accent); }

.btn-remove {
  background: none;
  border: 1.5px solid var(--terra);
  color: var(--terra);
  border-radius: 8px;
  padding: .25rem .6rem;
  cursor: pointer;
  font-size: .85rem;
  font-family: inherit;
  transition: background .12s;
}
.btn-remove:hover { background: #f7e3dc; }
.btn-remove:focus-visible { outline: 3px solid var(--terra); }

/* ---- Row status badge ---- */
.row-status {
  font-size: .78rem;
  font-weight: 700;
  padding: .18em .55em;
  border-radius: 999px;
  white-space: nowrap;
}
.status-ok      { background: var(--accent-soft); color: var(--accent); }
.status-err     { background: #f7e3dc; color: var(--terra); }
.status-pending { background: var(--bg-2); color: var(--muted); }
.status-warn    { background: #f8edcf; color: #8a6a1f; }

.qty-expected { font-size: .9rem; color: var(--muted); white-space: nowrap; }

/* ---- Buttons ---- */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: .75rem 1.6rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(22,114,74,.22);
  transition: background .15s, transform .05s;
}
.btn-primary:hover { background: var(--accent-h); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

/* ---- Demo / preview mode banner ---- */
#demo-banner {
  background: #f8edcf;
  border: 1px solid var(--gold);
  border-left: 5px solid var(--gold);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  margin-bottom: 1.35rem;
  font-size: .9rem;
  color: #7a5c00;
}

/* ---- Toast notifications ---- */
#toast-area { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; }
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent);
  border-radius: 10px;
  padding: .7rem 1rem;
  font-size: .88rem;
  box-shadow: 0 6px 20px rgba(60,45,25,.14);
  max-width: 340px;
  animation: slidein .2s ease;
}
.toast.ok  { border-left-color: var(--success); }
.toast.err { border-left-color: var(--terra); }
@keyframes slidein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- Editable lot / date cells ---- */
.cell-input {
  font-family: inherit;
  font-size: .9rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: .3rem .5rem;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  min-width: 0;
}
.lot-input  { width: 9rem; }
.date-input { width: 9.5rem; }
.cell-input:focus { outline: 3px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

/* ---- Empty state ---- */
.empty-state { text-align: center; color: var(--muted); padding: 2rem 1.5rem; font-size: .95rem; }

/* ---- Camera / vision button ---- */
.btn-camera {
  background: var(--surface);
  color: var(--terra);
  border: 2px solid var(--terra);
  border-radius: 0,5rem;
  padding: .6rem 1.25rem;
  font-family: inherit;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-camera:hover   { background: var(--terra); color: #fff; }
.btn-camera:focus-visible { outline: 3px solid var(--terra); outline-offset: 3px; }
.btn-camera:disabled { opacity: .55; cursor: not-allowed; }

.camera-status {
  margin-left: .75rem;
  font-size: .88rem;
  color: var(--muted);
  font-style: italic;
  vertical-align: middle;
}

/* Select controls inherit the warm theme */
select {
  color: var(--text);
  background: var(--surface);
}

/* ---- Top navigation (Delivery / Storage) ---- */
.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: 1rem;
}
.app-nav a {
  text-decoration: none;
  font-weight: 700;
  font-size: .9rem;
  color: var(--muted);
  padding: .4rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: 0;
  background: var(--surface);
  transition: background .12s, color .12s, border-color .12s;
}
.app-nav a:hover { background: var(--accent-soft); color: var(--accent); }
.app-nav a.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---- Storage page: scan input mirrors the delivery scan box ---- */
#bin-scan-input {
  width: 100%;
  font-size: 1.3rem;
  font-family: inherit;
  padding: 0.8rem 1rem;
  border: 2.5px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--text);
  outline: none;
  transition: box-shadow .15s;
}
#bin-scan-input:focus { box-shadow: 0 0 0 4px rgba(22,114,74,.22); }
#bin-scan-input::placeholder { color: #8a9b8f; }

.raw-box {
  font-size: .82rem;
  color: var(--muted);
  margin-top: .5rem;
  padding: .45rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-2);
  font-family: 'SF Mono', ui-monospace, monospace;
  word-break: break-all;
  min-height: 2rem;
}

/* Form inputs/selects on the storage page (delivery page uses id/inline styles,
   which win over this by specificity). */
.card input[type="text"],
.card input[type="number"],
.card input[type="date"],
.card input[type="search"],
.card select:not(#supplier-select) {
  font-family: inherit;
  font-size: 1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: .5rem .6rem;
  background: var(--surface);
  color: var(--text);
}
.card input:focus, .card select:focus { outline: 3px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

/* Labelled field grid used by the place / new-bin forms */
.place-grid {
  display: flex;
  gap: .8rem;
  flex-wrap: wrap;
}
.place-grid label {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  font-weight: 700;
  font-size: .85rem;
  color: var(--muted);
  flex: 1;
  min-width: 8rem;
}

/* Bin chips list */
.bin-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .55rem .8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-2);
  margin-bottom: .5rem;
  font-size: .92rem;
}
.bin-count {
  font-size: .78rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: .1em .55em;
  border-radius: 999px;
  margin-left: .4rem;
  white-space: nowrap;
}
.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  font-family: inherit;
  padding: .2rem .4rem;
  border-radius: 6px;
  transition: background .12s, color .12s;
}
.link-btn:hover { background: var(--accent-soft); color: var(--accent); }
.link-btn:disabled { opacity: .35; cursor: not-allowed; }

/* View toggle (By bin / By product) */
.view-toggle { display: inline-flex; border: 1.5px solid var(--border); border-radius: 999px; overflow: hidden; }
.view-toggle button {
  border: none;
  background: var(--surface);
  color: var(--muted);
  font-family: inherit;
  font-weight: 700;
  font-size: .85rem;
  padding: .45rem .95rem;
  cursor: pointer;
}
.view-toggle button.active { background: var(--accent); color: #fff; }

/* Storage map groups + tables */
.map-group { margin-bottom: 1.25rem; }
.map-group-head {
  font-weight: 700;
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  padding-bottom: .35rem;
  margin-bottom: .25rem;
}
.map-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.map-table td { padding: .5rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.map-table tr:last-child td { border-bottom: none; }
.map-name { font-weight: 700; }
.map-sub { display: block; font-weight: 400; font-size: .78rem; color: var(--muted); }
.map-qty { font-weight: 700; white-space: nowrap; }

/* Row actions: green move arrow, then edit, then remove — well separated */
.map-actions { white-space: nowrap; }
.map-actions .act-btn {
  width: 2.3rem;
  height: 2.3rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 1.35rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  transition: background .12s, color .12s, transform .05s;
}
.map-actions .act-btn + .act-btn { margin-left: 1rem; }   /* generous gap */
.map-actions .act-btn:active { transform: translateY(1px); }
.map-actions .act-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.act-move {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 6px rgba(22,114,74,.25);
}
.act-move:hover { background: var(--accent-h); }

.act-edit { background: var(--bg-2); color: var(--muted); }
.act-edit:hover { background: var(--accent-soft); color: var(--accent); }

.act-remove { background: var(--bg-2); color: var(--muted); }
.act-remove:hover { background: #f7e3dc; color: var(--terra); }

.edit-row td { background: var(--accent-soft); }

.pill {
  display: inline-block;
  font-size: .78rem;
  font-weight: 700;
  padding: .12em .55em;
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--muted);
  white-space: nowrap;
}
.pill.exp-soon { background: #f8edcf; color: #8a6a1f; }
.pill.exp-past { background: #f7e3dc; color: var(--terra); }

.move-row td { background: var(--accent-soft); }
.move-form { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; font-size: .88rem; }
.move-form .btn-primary { padding: .4rem .9rem; font-size: .88rem; }

/* ---- Expiry advice banner ---- */
.advice-card { border-left: 5px solid var(--gold); }
.advice-card h2 { color: #8a6a1f; }
.advice-card h2::before { background: var(--terra); box-shadow: 0 0 0 3px #f7e3dc; }
.advice-row {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  flex-wrap: wrap;
  padding: .45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.advice-row:last-child { border-bottom: none; }
.advice-name { font-weight: 700; }
.advice-meta { color: var(--muted); font-size: .82rem; }

/* ---- Warehouse floor plan ---- */
.bin-map { overflow-x: auto; }
.floor { display: flex; gap: .8rem; align-items: stretch; min-width: 1320px; }
.floor-col { display: flex; flex-direction: column; gap: .7rem; }
.floor-left   { flex: 0 0 190px; }
.floor-center { flex: 1 1 auto; }
.floor-right  { flex: 0 0 240px; }

/* Coloured context boxes (labels only, not clickable) */
.zone {
  border: 3px solid var(--border);
  border-radius: 10px;
  padding: .55rem .7rem;
  background: var(--surface);
}
.zone-red    { border-color: #e8583f; }
.zone-yellow { border-color: #f0c04a; }
.zone-green  { border-color: #42b06e; }
.zone-black  { border-color: #1c1c1c; }

.mobili { text-align: center; font-weight: 700; font-size: 1.05rem; color: var(--muted); padding: .85rem; }
.cella .zone-title { text-align: center; font-weight: 700; margin-bottom: .25rem; }
.cella-list { list-style: disc; padding-left: 1.2rem; font-size: .85rem; }
.floor-right .zone { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; font-weight: 700; color: var(--muted); min-height: 120px; }
.floor-right .lab { min-height: 230px; }
.rooms-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; height: 100%; }
.rooms-grid .lab { grid-column: 1 / -1; }
.binbox { display: flex; flex-direction: column; gap: .4rem; }
.binbox .zone-title { text-align: center; font-weight: 700; }
.floor-right .binbox { align-items: stretch; justify-content: flex-start; }

/* Rack blocks: the lettered racks sitting side by side */
.rackblock { padding: .7rem; }
.racks { display: flex; gap: 4.2rem; align-items: flex-start; justify-content: center; flex-wrap: nowrap; }
.rack-grid { display: grid; gap: .3rem; }
.olio-rack { display: flex; align-items: center; }

/* A single storage position — a live, clickable bin tile */
.cell {
  min-width: 3.6rem;
  height: 3rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-family: inherit;
  font-size: .85rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  padding: 0 .35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, border-color .12s, transform .05s;
}
.cell:hover { border-color: var(--accent); }
.cell:active { transform: translateY(1px); }
.cell:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.cell.selected { outline: 3px solid var(--accent); outline-offset: 1px; }
.cell.tile-empty { background: var(--surface); color: var(--muted); }
.cell.tile-ok    { background: #e7f0ea; border-color: #9cc4ac; color: var(--accent); }
.cell.tile-soon  { background: #f8edcf; border-color: #e3c778; color: #8a6a1f; }
.cell.tile-past  { background: #f7e3dc; border-color: #dda28f; color: var(--terra); }
.cell.cell-missing { opacity: .4; border-style: dashed; cursor: not-allowed; }
.olio-rack .cell { height: 3.8rem; min-width: 4.2rem; }

/* Map legend */
.map-legend {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: .9rem;
  font-size: .8rem;
  color: var(--muted);
}
.map-legend .dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; margin-right: .3rem; vertical-align: middle; }
.dot-ok { background: var(--success); }
.dot-soon { background: var(--gold); }
.dot-past { background: var(--terra); }
.dot-empty { background: var(--border); }
.map-legend-hint { margin-left: auto; font-style: italic; }

/* ---- Small screens ---- */
@media (max-width: 560px) {
  :root { font-size: 17px; }
  body { padding: 1.25rem 1rem 2.5rem; }
  h1 { font-size: 2rem; }
  .card { padding: 1.1rem 1.15rem; }
  .place-grid label { min-width: 6.5rem; }
}
