:root {
  --plum: #46334F; --accent: #9879AB; --lav: #E4D1EB; --lav-2: #F4ECF7; --ink: #2A1F30; --muted: #6B5A73;
  --bg: #FBF8FC; --card: #FFFFFF; --line: #E6DCEA;
  --green: #1E7B46; --green-bg: #DFF3E6; --yellow: #8A5A00; --yellow-bg: #FFF1C9;
  --red: #B42318; --red-bg: #FDE2E0; --gray: #4B4B4B; --gray-bg: #E3E3E3;
  --radius: 14px; --tap: 52px; --nav-h: 68px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 17px; line-height: 1.4; -webkit-text-size-adjust: 100%; }
a { color: var(--plum); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.topbar { position: sticky; top: 0; z-index: 10; background: var(--plum); color: #fff; display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; }
.flower { width: 24px; height: 24px; color: var(--lav); }
.wordmark { font-weight: 600; letter-spacing: .08em; font-size: 18px; }
.page-title { margin-left: auto; color: var(--lav); font-size: 15px; }

main { max-width: 760px; margin: 0 auto; padding: 14px 14px calc(var(--nav-h) + 90px + env(safe-area-inset-bottom)); outline: none; }

.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr);
  background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottomnav a { min-height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: 13px; font-weight: 500; }
.bottomnav svg { width: 26px; height: 26px; }
.bottomnav a.active { color: var(--plum); font-weight: 700; }
.bottomnav a.active svg { color: var(--accent); }

.notice { background: var(--lav-2); border: 1px solid var(--lav); border-left: 5px solid var(--accent); border-radius: var(--radius);
  padding: 12px 14px; margin: 0 0 14px; font-size: 15px; color: var(--ink); }
.notice strong { color: var(--plum); }

.searchbox { position: relative; margin-bottom: 10px; }
.searchbox svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 22px; height: 22px; color: var(--muted); }
.searchbox input { width: 100%; min-height: var(--tap); border: 2px solid var(--line); border-radius: 999px; padding: 10px 16px 10px 46px; background: #fff; font-size: 17px; }
.searchbox input:focus { border-color: var(--accent); outline: none; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chip { flex: 0 0 auto; min-height: 44px; padding: 8px 14px; border-radius: 999px; border: 2px solid var(--line); background: #fff; font-size: 15px; font-weight: 600; color: var(--plum); cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--plum); border-color: var(--plum); color: #fff; }
.chip .n { opacity: .75; font-weight: 500; margin-left: 4px; }

.row-links { display: flex; justify-content: space-between; align-items: center; margin: 0 2px 10px; font-size: 15px; color: var(--muted); }
.linkbtn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; color: var(--plum); font-weight: 600; text-decoration: none; background: none; border: 0; padding: 0 4px; cursor: pointer; }
.linkbtn svg { width: 20px; height: 20px; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.item > a, .item > button { display: flex; gap: 12px; align-items: center; width: 100%; min-height: 72px; padding: 12px 14px; text-decoration: none; color: inherit; background: none; border: 0; text-align: left; cursor: pointer; }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 650; font-size: 17px; color: var(--ink); overflow-wrap: anywhere; }
.item .sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.item .qty { font-size: 15px; margin-top: 4px; }
.tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--lav); color: var(--plum); vertical-align: middle; margin-left: 4px; }

.status { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.status::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.status.green { color: var(--green); background: var(--green-bg); }
.status.yellow { color: var(--yellow); background: var(--yellow-bg); }
.status.red { color: var(--red); background: var(--red-bg); }
.status.gray { color: var(--gray); background: var(--gray-bg); }
.status.unverified { color: var(--plum); background: #fff; border: 2px dashed var(--accent); }
.status.unverified::before { content: "?"; width: auto; height: auto; background: none; font-size: 13px; }

.fab { position: fixed; right: 18px; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); z-index: 9; width: 64px; height: 64px; border-radius: 50%;
  background: var(--plum); color: #fff; border: 0; box-shadow: 0 6px 18px rgba(70,51,79,.35); display: grid; place-items: center; cursor: pointer; }
.fab svg { width: 30px; height: 30px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.card h2, .card h3 { margin: 0 0 8px; color: var(--plum); }
h1.name { font-size: 24px; margin: 6px 0 6px; color: var(--plum); overflow-wrap: anywhere; }
.back { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; color: var(--plum); font-weight: 600; text-decoration: none; }
.back svg { width: 22px; height: 22px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 10px 0 0; }
.stat { background: var(--lav-2); border-radius: 12px; padding: 10px 12px; }
.stat .k { font-size: 13px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 700; color: var(--plum); }
.muted { color: var(--muted); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

.btn { min-height: var(--tap); padding: 12px 18px; border-radius: 12px; border: 2px solid var(--plum); background: var(--plum); color: #fff; font-weight: 700; font-size: 17px; cursor: pointer; }
.btn.secondary { background: #fff; color: var(--plum); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--plum); }
.btn.danger { background: #fff; color: var(--red); border-color: var(--red); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }

.bottle-meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 15px; margin: 6px 0 0; }
.bottle-meta dt { color: var(--muted); }
.bottle-meta dd { margin: 0; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(42,31,48,.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: #fff; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet h2 { margin: 0 0 4px; color: var(--plum); font-size: 21px; }
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: -6px auto 12px; }
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 20px; } }

.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.choice { min-height: 64px; padding: 10px; border-radius: 12px; border: 2px solid var(--lav); background: var(--lav-2); color: var(--plum); font-weight: 700; font-size: 16px; cursor: pointer; text-align: left; }
.choice small { display: block; font-weight: 500; color: var(--muted); font-size: 13px; }

label.field { display: block; margin: 14px 0 0; font-weight: 600; color: var(--plum); }
label.field .hint { display: block; font-weight: 400; font-size: 14px; color: var(--muted); }
.field input, .field select, .field textarea { display: block; width: 100%; margin-top: 6px; min-height: var(--tap); border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff; font-size: 17px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); outline: none; }
.seg { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.seg button { flex: 1 1 auto; min-height: 48px; border-radius: 12px; border: 2px solid var(--line); background: #fff; font-weight: 600; color: var(--plum); cursor: pointer; padding: 6px 10px; }
.seg button[aria-pressed="true"] { border-color: var(--plum); background: var(--plum); color: #fff; }
.preview { margin-top: 14px; padding: 12px; border-radius: 12px; background: var(--lav-2); font-size: 16px; }
.error { color: var(--red); font-weight: 600; margin-top: 10px; }
.sheet .actions { margin-top: 18px; }
.sheet .actions .btn { flex: 1; }

.event { padding: 12px 14px; }
.event .when { font-size: 13px; color: var(--muted); }
.event .what { font-weight: 650; }
.event .delta.neg { color: var(--red); } .event .delta.pos { color: var(--green); }
.event.reversed .what { text-decoration: line-through; color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 30; max-width: 90vw; }
#toast.show { opacity: 1; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.placeholder { text-align: center; padding: 30px 16px; }
.placeholder svg { width: 56px; height: 56px; color: var(--accent); }
.placeholder h2 { color: var(--plum); }
.legend { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

@media (min-width: 900px) {
  main { max-width: 980px; }
  .list.fragrances { grid-template-columns: 1fr 1fr; }
  .bottomnav { left: 50%; transform: translateX(-50%); max-width: 640px; border: 1px solid var(--line); border-radius: 18px 18px 0 0; }
}

/* ---------- Phase 3: capture & review ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
textarea { resize: vertical; }
.radio { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border: 2px solid var(--line); border-radius: 12px; margin-top: 8px; font-weight: 500; color: var(--ink); cursor: pointer; }
.radio input { width: 24px; height: 24px; margin: 2px 0 0; accent-color: var(--plum); flex: 0 0 auto; }
.radio small { display: block; color: var(--muted); font-size: 13px; }
.radio.disabled { opacity: .6; cursor: not-allowed; }
fieldset legend { font-weight: 600; color: var(--plum); }
.filepick { display: block; cursor: pointer; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.thumb { margin: 0; background: var(--lav-2); border-radius: 12px; overflow: hidden; border: 2px solid transparent; }
.thumb img, .thumb .nofile { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #ddd; }
.thumb .nofile { display: grid; place-items: center; color: var(--muted); }
.thumb figcaption { padding: 6px 8px; font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.thumb.failed { border-color: var(--red); } .thumb.duplicate { opacity: .7; }
.thumb .rm { min-height: 40px; padding: 0 8px; font-size: 14px; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 6px; border-radius: 6px; }
.badge.dup { background: var(--gray-bg); color: var(--gray); } .badge.near { background: var(--yellow-bg); color: var(--yellow); }
.badge.err { background: var(--red-bg); color: var(--red); } .badge.ok { background: var(--green-bg); color: var(--green); }
.fixture-banner { background: #FFF1C9; border-color: #E0B000; border-left-color: #B07F00; }
.tag.fixture, .fixture-text { background: #FFE08A; color: #6B4A00; }
.fixture-text { padding: 1px 6px; border-radius: 6px; }
.proposal.approved { border-color: var(--green); box-shadow: inset 4px 0 0 var(--green); }
.proposal.rejected { opacity: .65; } .proposal.committed { border-color: var(--accent); }
.proposal.is-fixture { background: #FFFBEA; }
.ptop { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.tag.kind { margin-left: 0; background: var(--plum); color: #fff; }
.conf { font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--lav-2); color: var(--plum); }
.conf.low { background: var(--yellow-bg); color: var(--yellow); } .conf.unreadable { background: var(--red-bg); color: var(--red); } .conf.high { background: var(--green-bg); color: var(--green); }
.src { color: var(--muted); margin-left: auto; }
.ba { margin-top: 6px; font-size: 16px; }
.evidence { margin-top: 6px; font-size: 14px; color: var(--muted); } .evidence summary { cursor: pointer; min-height: 32px; color: var(--plum); font-weight: 600; }
.pact { margin-top: 10px; } .pact .btn { flex: 1 1 auto; min-height: 48px; padding: 8px 12px; font-size: 16px; }
.commitbar { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding: 10px 14px; background: rgba(251,248,252,.96); border-top: 1px solid var(--line); z-index: 9; }
.commitbar .btn { max-width: 732px; margin: 0 auto; display: block; }

/* ---- Phase 3b: distinct badge families (quantity vs identity vs stock status) ---- */
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.qbadge, .idbadge { display: inline-flex; align-items: center; font-size: 12px; font-weight: 700; line-height: 1.2; padding: 3px 8px; white-space: nowrap; }
/* quantity: square-ish corners, outlined */
.qbadge { border-radius: 6px; border: 1.5px solid currentColor; background: #fff; }
.qbadge.unknown { color: #6b6670; border-style: dashed; }
.qbadge.est { color: #8a5a00; border-style: dotted; background: #FFF8E6; }
.qbadge.ok { color: #1f6b3a; }
.qbadge.zero { color: #fff; background: #4a4550; border-color: #4a4550; }
/* identity: pill with an "ID" lead, lavender */
.idbadge { border-radius: 999px; background: #F1ECF7; color: var(--plum); border: 1px solid #D9CCE8; }
.idbadge.ok { background: #E7F4EC; color: #1f6b3a; border-color: #BFE0CB; }
.idbadge.low { background: #FDECEC; color: #8a1f1f; border-color: #F3C4C4; }
.k-inline { font-size: 12px; color: var(--muted, #6b6670); margin: 0 2px 0 6px; }
.k-inline:first-child { margin-left: 0; }
.src-row { display: block; padding: 10px 14px; }
.src-row .src { font-weight: 700; margin-bottom: 2px; }

/* ---- Phase 4: activity tabs, variance badges, reconcile ---- */
.seg.tabs { display: flex; margin: 0 0 12px; }
.seg.tabs a { flex: 1; text-align: center; padding: 10px 6px; border-radius: 10px; font-weight: 700; color: var(--plum); text-decoration: none; }
.seg.tabs a.on { background: var(--plum); color: #fff; }
.daterow { display: flex; gap: 10px; } .daterow .field { flex: 1; margin-top: 8px; }
.vbadge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: #EEE9F3; color: var(--plum); margin-left: 4px; }
.vbadge.ok { background: #E7F4EC; color: #1f6b3a; } .vbadge.open { background: #FFF1D6; color: #7a4d00; border: 1px dashed #d9a640; }
.chip.warn { border-color: #d9a640; }
.choice-list { display: grid; gap: 6px; margin: 8px 0; }
.radio { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid #E4D1EB; border-radius: 10px; min-height: 44px; }
.radio input { width: 22px; height: 22px; margin: 0; }
.k-q { font-weight: 700; margin-top: 10px; }
.rec-sum { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 10px 0; }
@media (min-width: 900px) { .rec-sum { grid-template-columns: repeat(3, 1fr); } }
.item.rec { display: block; padding: 0; } .item.rec summary { padding: 12px 14px; cursor: pointer; list-style: none; }
.item.rec summary::-webkit-details-marker { display: none; }
.recbox { padding: 0 14px 14px; } .recl { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dotted #E4D1EB; }
.recl.total { font-weight: 800; border-bottom: none; border-top: 2px solid var(--plum); margin-top: 4px; padding-top: 6px; }
/* forecast */
.fc-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 8px; }
@media (min-width: 900px) { .fc-grid { grid-template-columns: repeat(3, 1fr); } }
.fc-none { margin-top: 6px; padding: 10px 12px; border: 1.5px dashed #c9bcd6; border-radius: 10px; background: #FBF9FD; }
.fc-card { margin-top: 12px; padding-top: 10px; border-top: 1px solid #E4D1EB; } .fc-card h3 { margin: 0 0 4px; font-size: 16px; }
.fc-notes { margin: 6px 0 0 18px; padding: 0; color: var(--muted, #6b6670); font-size: 14px; }
.item.fc .main { width: 100%; }
.daterow .field input { width: 100%; min-width: 0; box-sizing: border-box; } .daterow .field { min-width: 0; }

/* ---------- Phase 5: purchasing ---------- */
.notice.nosend { display: flex; gap: 10px; align-items: flex-start; }
.notice.nosend svg { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--plum); stroke-width: 2; margin-top: 2px; }
.warn { color: var(--yellow); background: var(--yellow-bg); border-radius: 10px; padding: 6px 10px; margin: 6px 0; font-size: 15px; }
.okline { color: var(--green); background: var(--green-bg); border-radius: 10px; padding: 8px 10px; font-size: 15px; }
.po-totals { display: grid; gap: 4px; margin: 10px 0 4px; font-size: 15px; }
.po-totals > div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed var(--line); padding: 3px 0; }
.po-totals .grand { font-size: 17px; border-bottom: 0; }
.po-totals small { color: var(--muted); }
.po-line { display: flex; align-items: flex-start; gap: 6px; padding: 10px 12px; }
.po-line .chk { padding-top: 2px; }
.po-line .chk input, .chkline input { width: 24px; height: 24px; min-height: 24px; margin: 0; accent-color: var(--plum); }
.chkline { display: flex !important; gap: 10px; align-items: center; }
.po-line details, .item details { margin-top: 6px; font-size: 15px; }
.po-line summary, .item summary, .card details > summary { cursor: pointer; color: var(--plum); font-weight: 600; min-height: 32px; }
.po-edit { display: grid; grid-template-columns: 1fr; gap: 6px; border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.po-recv { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin: 0 0 10px; }
.po-recv legend { font-weight: 650; padding: 0 4px; }
.actions.wrap { flex-wrap: wrap; }
.submit-off { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.submit-off .btn[disabled] { opacity: .45; cursor: not-allowed; }
.kv { display: grid; gap: 4px; margin: 8px 0; font-size: 15px; }
.item > button.linkish { font: inherit; }
textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 10px; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
@media (min-width: 760px) { .po-edit { grid-template-columns: 2fr 1fr 1fr auto; align-items: end; } }
