:root {
  --paper: #fbfaf6;
  --surface: #ffffff;
  --ink: #1c2620;
  --muted: #6d786f;
  --line: #e7e4da;
  --green: #2f7d4f;
  --green-dark: #24623d;
  --green-soft: #eaf3ec;
  --fresh: #2f7d4f;
  --fresh-bg: #e8f2ea;
  --risk: #a9791b;
  --risk-bg: #f7efd8;
  --expired: #b23b2e;
  --expired-bg: #f6e4e1;
  --blue: #3a5a8c;
  --blue-bg: #e6ecf5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28,38,32,.04), 0 4px 16px rgba(28,38,32,.05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
}
a { color: var(--green-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 2rem;
  padding: 0 clamp(1rem, 4vw, 2.5rem);
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600; font-size: 1.3rem; letter-spacing: -.01em;
  color: var(--ink); display: flex; align-items: center; gap: .5rem;
}
.brand:hover { text-decoration: none; }
.brand-flow { color: var(--green); }
.leaf {
  width: 14px; height: 14px; border-radius: 0 12px 0 12px;
  background: var(--green); display: inline-block; transform: rotate(-8deg);
}
.topbar nav { display: flex; gap: .35rem; flex-wrap: wrap; }
.topbar nav a {
  color: var(--muted); font-size: .92rem; font-weight: 500;
  padding: .4rem .7rem; border-radius: 7px;
}
.topbar nav a:hover { color: var(--ink); background: var(--paper); text-decoration: none; }
.topbar nav a.on { color: var(--green-dark); background: var(--fresh-bg); }

/* ---- layout ---- */
main { max-width: 1080px; margin: 0 auto; padding: clamp(1.2rem, 4vw, 2.2rem); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.4rem; }
h1 { font-family: "Fraunces", Georgia, serif; font-weight: 600; font-size: 1.7rem; margin: .1rem 0; letter-spacing: -.01em; }
h2 { font-size: 1rem; font-weight: 600; margin: 0 0 .9rem; }
.sub { color: var(--muted); margin: .1rem 0 0; }
.back { font-size: .85rem; color: var(--muted); }
.head-actions { display: flex; gap: .5rem; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; margin-bottom: 1.1rem; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } .topbar { flex-wrap: wrap; height: auto; padding-block: .6rem; } }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.2rem 1.3rem; margin-bottom: 1.1rem;
}
.card.narrow { max-width: 460px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .3rem; }

/* ---- stats ---- */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.1rem; margin-bottom: 1.1rem; }
@media (max-width: 760px) { .stat-row { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.2rem; box-shadow: var(--shadow);
}
.stat.alert { border-color: #e7c9c3; background: var(--expired-bg); }
.stat-num { font-family: "Fraunces", serif; font-size: 2rem; font-weight: 600; display: block; line-height: 1; }
.stat-label { color: var(--muted); font-size: .82rem; }

/* ---- tables ---- */
.grid { width: 100%; border-collapse: collapse; font-size: .92rem; }
.grid th { text-align: left; font-weight: 500; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; padding: 0 .6rem .5rem; border-bottom: 1px solid var(--line); }
.grid td { padding: .7rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: none; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid.compact td { padding: .4rem .6rem; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--fresh-bg); }
.prod { font-weight: 500; }
.fam { color: var(--muted); font-size: .8rem; display: inline-block; margin-left: .35rem; }
.ref { font-weight: 600; color: var(--green-dark); }
.num.low { color: var(--expired); font-weight: 600; }

/* ---- pills ---- */
.pill { display: inline-block; font-size: .75rem; font-weight: 600; padding: .18rem .55rem; border-radius: 999px; white-space: nowrap; }
.pill.fresh { color: var(--fresh); background: var(--fresh-bg); }
.pill.at_risk { color: var(--risk); background: var(--risk-bg); }
.pill.expired { color: var(--expired); background: var(--expired-bg); }
.pill.status-new { color: var(--blue); background: var(--blue-bg); }
.pill.status-packed { color: var(--risk); background: var(--risk-bg); }
.pill.status-shipped { color: var(--fresh); background: var(--fresh-bg); }
.pill.status-delivered { color: var(--muted); background: var(--paper); border: 1px solid var(--line); }
.pill.status-cancelled { color: var(--expired); background: var(--expired-bg); }

/* ---- attention lists ---- */
.attn { list-style: none; margin: 0; padding: 0; }
.attn li { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.attn li:last-child { border-bottom: none; }
.attn-name { font-weight: 500; }
.attn-meta { color: var(--muted); font-size: .85rem; }
.empty { color: var(--muted); }

/* ---- filters ---- */
.filters { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters a { font-size: .85rem; color: var(--muted); padding: .3rem .7rem; border-radius: 7px; border: 1px solid transparent; }
.filters a:hover { background: var(--surface); text-decoration: none; }
.filters a.on { color: var(--green-dark); background: var(--fresh-bg); border-color: #cfe4d6; }

/* ---- buttons ---- */
.btn {
  display: inline-block; font: inherit; font-weight: 500; font-size: .9rem;
  padding: .5rem .95rem; border-radius: 8px; border: 1px solid var(--green);
  background: var(--green); color: #fff; cursor: pointer;
}
.btn:hover { background: var(--green-dark); border-color: var(--green-dark); text-decoration: none; }
.btn.ghost { background: transparent; color: var(--green-dark); }
.btn.ghost:hover { background: var(--fresh-bg); }
.btn.danger { background: var(--expired); border-color: var(--expired); }
.btn.danger:hover { background: #922f24; border-color: #922f24; }
.btn.danger-ghost { background: transparent; color: var(--expired); border-color: #e0c0bb; }
.btn.danger-ghost:hover { background: var(--expired-bg); }
.head-actions form { display: inline; margin: 0; }

/* ---- forms ---- */
.form label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: .85rem; }
.form input, .form select, .form textarea {
  display: block; width: 100%; margin-top: .3rem; font: inherit;
  padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper); color: var(--ink);
}
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--green); outline-offset: 0; border-color: var(--green); }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.form .qty { max-width: 90px; margin: 0 0 0 auto; text-align: right; }
.hint { color: var(--muted); font-size: .88rem; margin: 0 0 1rem; }
.form-actions { margin-top: .4rem; }

/* ---- detail list ---- */
.detail { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; margin: 0; font-size: .92rem; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.detail .addr { white-space: pre-line; }

/* ---- flash ---- */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1.2rem; font-size: .9rem; }
.flash.ok { background: var(--fresh-bg); color: var(--green-dark); border: 1px solid #cfe4d6; }
.flash.bad { background: var(--expired-bg); color: var(--expired); border: 1px solid #e7c9c3; }

/* ============================================================
   Freshness lifecycle — life bars, ribbon, stages
   ============================================================ */
:root {
  --stage-fresh: #2f7d4f;
  --stage-soon: #b98a1f;
  --stage-discount: #cf6a2c;
  --stage-expired: #b23b2e;
  --stage-fresh-bg: #e8f2ea;
  --stage-soon-bg: #f7efd8;
  --stage-discount-bg: #f9e8db;
  --stage-expired-bg: #f6e4e1;
}

/* stage pills reuse + new stages */
.pill.sell_soon { color: var(--stage-soon); background: var(--stage-soon-bg); }
.pill.discount { color: var(--stage-discount); background: var(--stage-discount-bg); }

/* life bar */
.lifecol { width: 130px; }
.lifebar {
  height: 7px; border-radius: 99px; background: #ecebe3;
  overflow: hidden; min-width: 90px;
}
.lifebar i { display: block; height: 100%; border-radius: 99px; transition: width .3s ease; }
.lifebar i.fresh { background: linear-gradient(90deg, #3d9663, var(--stage-fresh)); }
.lifebar i.sell_soon { background: linear-gradient(90deg, #d3a63b, var(--stage-soon)); }
.lifebar i.discount { background: linear-gradient(90deg, #e08a4d, var(--stage-discount)); }
.lifebar i.expired { background: repeating-linear-gradient(45deg, #d9a49d, #d9a49d 5px, var(--stage-expired-bg) 5px, var(--stage-expired-bg) 10px); }

/* days-left chip */
.days { font-size: .75rem; font-weight: 600; margin-left: .4rem; }
.days.fresh { color: var(--stage-fresh); }
.days.sell_soon { color: var(--stage-soon); }
.days.discount { color: var(--stage-discount); }
.days.expired { color: var(--stage-expired); }

/* the ribbon */
.hero { padding-bottom: 1rem; }
.ribbon {
  display: flex; height: 38px; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line); margin: .4rem 0 .8rem;
}
.ribbon .seg { min-width: 4px; }
.ribbon .seg.fresh { background: var(--stage-fresh); }
.ribbon .seg.sell_soon { background: var(--stage-soon); }
.ribbon .seg.discount { background: var(--stage-discount); }
.ribbon .seg.expired { background: repeating-linear-gradient(45deg, var(--stage-expired), var(--stage-expired) 6px, #8f2f24 6px, #8f2f24 12px); }
.legend { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .84rem; color: var(--muted); }
.legend b { color: var(--ink); font-weight: 600; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: .35rem; }
.legend .dot.fresh { background: var(--stage-fresh); }
.legend .dot.sell_soon { background: var(--stage-soon); }
.legend .dot.discount { background: var(--stage-discount); }
.legend .dot.expired { background: var(--stage-expired); }
.legend .total { margin-left: auto; }

/* stat variants */
.stat.warn { border-color: #ead9b5; background: var(--stage-soon-bg); }

/* freshness filter links */
.filters .count { opacity: .65; font-weight: 600; margin-left: .15rem; }
.filters a.stagelink.on.fresh { color: var(--stage-fresh); background: var(--stage-fresh-bg); border-color: #cfe4d6; }
.filters a.stagelink.on.sell_soon { color: var(--stage-soon); background: var(--stage-soon-bg); border-color: #ead9b5; }
.filters a.stagelink.on.discount { color: var(--stage-discount); background: var(--stage-discount-bg); border-color: #ecd0ba; }
.filters a.stagelink.on.expired { color: var(--stage-expired); background: var(--stage-expired-bg); border-color: #e7c9c3; }

/* action labels on the board */
.act { font-size: .8rem; font-weight: 600; white-space: nowrap; }
.act.danger { color: var(--stage-expired); }
.act.discount { color: var(--stage-discount); }
.act.soon { color: var(--stage-soon); }

/* ships-first badge */
.badge-ships {
  display: inline-block; font-size: .68rem; font-weight: 700;
  letter-spacing: .03em; text-transform: uppercase;
  color: var(--green-dark); background: var(--fresh-bg);
  border: 1px solid #cfe4d6; border-radius: 5px;
  padding: .1rem .4rem; margin-left: .45rem; vertical-align: middle;
}
