/* VIB Stock: white, restrained pastel pink, dark readable text, subtle gold. Readability first. */
:root {
  --bg: #ffffff; --ink: #2a2326; --muted: #655a5f; --line: #e9e1e3; --soft: #fbf6f7;
  --pink: #f8dfe5; --pink-2: #f1c7d1; --rose: #8f3350; --rose-dark: #742841;
  --gold: #b8943f; --gold-ink: #7a5f1d;
  --ok: #24613f; --ok-bg: #e6f3ec; --warn: #7a4f00; --warn-bg: #fff3d6; --err: #a3231c; --err-bg: #fdeae8;
  --radius: 10px; --touch: 44px;
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; line-height: 1.45; -webkit-text-size-adjust: 100%; }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.02rem; }
p { margin: 0.4rem 0; }
a { color: var(--rose); text-underline-offset: 2px; }
a:hover { color: var(--rose-dark); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: #fff; padding: 0.6rem 1rem; z-index: 100; }
.skip:focus { left: 0; }
.muted { color: var(--muted); } .pad { padding: 0.75rem 0; } .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; } .nowrap { white-space: nowrap; } .small { font-size: 0.875rem; }
.neg { color: var(--err); font-weight: 600; } .pos { color: var(--ok); }

/* Shell */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.shell > div { min-width: 0; }
.side { border-right: 1px solid var(--line); background: var(--soft); padding: 1rem 0.75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 0.25rem; }
.brand { display: flex; align-items: baseline; gap: 0.5rem; padding: 0.25rem 0.5rem 0.9rem; border-bottom: 1px solid var(--gold); margin-bottom: 0.6rem; }
.brand b { font-family: Georgia, serif; font-size: 1.45rem; letter-spacing: 0.02em; }
.brand span { font-size: 0.72rem; letter-spacing: 0.22em; color: var(--rose); font-weight: 600; }
.side a.nav { display: flex; align-items: center; justify-content: space-between; min-height: var(--touch); padding: 0 0.75rem; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; }
.side a.nav:hover { background: var(--pink); }
.side a.nav.active { background: var(--pink); box-shadow: inset 3px 0 0 var(--gold); font-weight: 650; }
.side .who { margin-top: auto; padding: 0.75rem 0.5rem 0; border-top: 1px solid var(--line); font-size: 0.875rem; }
.side .who .btn { margin-top: 0.4rem; }
.topbar { display: none; }
main { padding: 1.5rem clamp(1rem, 3vw, 2.25rem) 4rem; min-width: 0; max-width: 1280px; }
.demo-banner { background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid #ecd9a5; padding: 0.5rem 1rem; font-weight: 600; text-align: center; grid-column: 1 / -1; }
.offline-banner { background: var(--err-bg); color: var(--err); padding: 0.5rem 1rem; text-align: center; font-weight: 600; position: sticky; top: 0; z-index: 30; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); margin: 0 0 1rem; overflow-x: auto; }
.tabs a { padding: 0.65rem 0.9rem; min-height: var(--touch); display: inline-flex; align-items: center; gap: 0.4rem; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--gold); font-weight: 650; }
.count { background: var(--rose); color: #fff; border-radius: 99px; font-size: 0.72rem; padding: 0.05rem 0.45rem; font-weight: 700; }

/* Buttons */
.btn { min-height: var(--touch); padding: 0 1rem; border-radius: 8px; border: 1px solid #cfc3c7; background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; text-decoration: none; }
.btn:hover { border-color: var(--rose); color: var(--rose-dark); }
.btn.primary { background: var(--rose); border-color: var(--rose); color: #fff; }
.btn.primary:hover { background: var(--rose-dark); color: #fff; }
.btn.danger { color: var(--err); border-color: #e0b4b0; }
.btn.small { min-height: 36px; padding: 0 0.7rem; font-size: 0.875rem; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--rose); }
.btn.icon { min-width: var(--touch); padding: 0; font-size: 1.3rem; line-height: 1; border-color: transparent; background: transparent; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn, .tabs a, a.nav { transition: background-color .12s ease, border-color .12s ease, color .12s ease, transform .08s ease, box-shadow .12s ease; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.btn:active:not(:disabled) { transform: scale(0.97); box-shadow: inset 0 2px 4px rgba(0,0,0,.08); }
.btn.ghost:hover { background: var(--pink); }
/* Page loading: keep the current page visible, dim it a little and show a thin bar until the new one is ready. */
#main { position: relative; }
#main.busy > * { opacity: .6; transition: opacity .15s ease .12s; pointer-events: none; }
#main.busy::before { content: ''; position: fixed; top: 0; left: 0; height: 3px; width: 40%; background: var(--rose); z-index: 60; animation: busybar 0.9s ease-in-out infinite; }
@keyframes busybar { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 0.9rem; margin-bottom: 1.25rem; }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; background: #fff; display: flex; flex-direction: column; gap: 0.3rem; position: relative; }
.card.link { text-decoration: none; color: inherit; }
.card.link:hover { border-color: var(--gold); }
.card .k { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 650; }
.card .v { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; font-family: Georgia, serif; }
.card .sub { font-size: 0.85rem; color: var(--muted); }
.card .fresh { font-size: 0.75rem; color: var(--muted); margin-top: auto; padding-top: 0.4rem; border-top: 1px dashed var(--line); }
.card.alert { border-left: 4px solid var(--rose); } .card.good { border-left: 4px solid #9cc4ac; } .card.setup { background: var(--soft); border-style: dashed; }
.card ul { margin: 0.25rem 0 0; padding-left: 1.1rem; font-size: 0.875rem; }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.6rem; margin-bottom: 1.25rem; }
.quick .btn { min-height: 56px; background: var(--pink); border-color: var(--pink-2); }
.quick .btn:hover { border-color: var(--gold); color: var(--ink); }
.panel { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; background: #fff; }
.panel > h2, .panel > h3 { margin-bottom: 0.6rem; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 1rem; font-size: 0.95rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 550; }

/* Notes & badges */
.note { border-radius: 8px; padding: 0.7rem 0.9rem; margin: 0 0 1rem; border: 1px solid var(--line); background: var(--soft); font-size: 0.93rem; }
.note.warn { background: var(--warn-bg); border-color: #ecd9a5; color: #4d3300; }
.note.err { background: var(--err-bg); border-color: #efc2be; color: #6e1711; }
.note.ok { background: var(--ok-bg); border-color: #bcdccb; color: #17432b; }
.note.info { background: #fbf6f7; border-left: 4px solid var(--gold); }
.badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 99px; font-size: 0.76rem; font-weight: 650; background: #efe9eb; color: var(--ink); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); } .badge.muted { color: var(--muted); } .badge.gold { background: #f6edd6; color: var(--gold-ink); }
details.term { display: inline-block; font-size: 0.85rem; vertical-align: top; max-width: 46rem; }
details.term summary { cursor: pointer; color: var(--rose); list-style: none; display: inline-flex; align-items: center; gap: 0.3rem; min-height: 32px; }
details.term summary::before { content: "?"; display: inline-grid; place-items: center; width: 1.15rem; height: 1.15rem; border-radius: 50%; border: 1.5px solid var(--gold); color: var(--gold-ink); font-size: 0.72rem; font-weight: 700; }
details.term p { background: var(--soft); border-left: 3px solid var(--gold); padding: 0.5rem 0.75rem; margin: 0.2rem 0 0.6rem; color: var(--ink); }
.empty { text-align: center; padding: 2.2rem 1rem; border: 1px dashed #d9cdd1; border-radius: var(--radius); background: var(--soft); margin-bottom: 1rem; }
.empty p { color: var(--muted); max-width: 34rem; margin: 0.5rem auto 1rem; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; }
table { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
th, td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--soft); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 650; white-space: nowrap; position: sticky; top: 0; }
th.num, td.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
td:first-child { min-width: 9.5rem; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: #fdf3f5; }
tfoot td { font-weight: 700; background: var(--soft); border-top: 2px solid var(--gold); }

/* Forms */
.toolbar { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.toolbar .field { margin: 0; min-width: 150px; } .toolbar .grow { flex: 1 1 220px; }
.range { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.form .grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem 1rem; }
.form .span2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.field label { font-size: 0.85rem; font-weight: 600; }
.field.check { flex-direction: row; align-items: center; gap: 0.6rem; min-height: var(--touch); font-weight: 600; font-size: 0.93rem; cursor: pointer; }
.field.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--rose); }
input, select, textarea { font: inherit; color: var(--ink); min-height: var(--touch); padding: 0.45rem 0.65rem; border: 1px solid #b9adb1; border-radius: 8px; background: #fff; width: 100%; }
textarea { min-height: 5rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--pink-2); border-color: var(--rose); }
input[type=date], input[type=datetime-local] { width: auto; }
.hint { color: var(--muted); font-size: 0.8rem; } .req { color: var(--err); }
.form-error { color: var(--err); font-weight: 600; margin: 0.6rem 0 0; min-height: 1.2rem; }
.actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1rem; flex-wrap: wrap; }
.lines { border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem; margin: 0.6rem 0; background: var(--soft); }
.lines > h3 { margin-bottom: 0.4rem; }
.line-row { display: flex; gap: 0.5rem; align-items: flex-end; flex-wrap: wrap; padding: 0.4rem 0; border-bottom: 1px dashed var(--line); }
.line-row .field { flex: 1 1 110px; }
.field[hidden] { display: none; }
.line-row:not(:first-child) .field label { position: absolute; left: -9999px; }

/* Modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(42, 35, 38, 0.45); display: grid; place-items: start center; padding: 4vh 0.75rem; overflow-y: auto; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: min(640px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); border-top: 4px solid var(--gold); }
.modal.wide { width: min(1040px, 100%); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 0.9rem 1.1rem 0.4rem; }
.modal-body { padding: 0.4rem 1.1rem 1.1rem; }
#toasts { position: fixed; bottom: 1rem; right: 1rem; left: 1rem; display: flex; flex-direction: column; align-items: flex-end; gap: 0.5rem; z-index: 80; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 0.7rem 1rem; border-radius: 8px; max-width: 30rem; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.err { background: var(--err); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(180deg, #fff 0%, var(--pink) 100%); }
.login .box { width: min(400px, 100%); background: #fff; border-radius: 14px; padding: 1.75rem; border: 1px solid var(--line); border-top: 4px solid var(--gold); }
.login h1 { margin-bottom: 0.2rem; } .login .field { margin-top: 0.9rem; } .login .btn { width: 100%; margin-top: 1.1rem; }

.count-item { border: 1px solid var(--line); border-radius: var(--radius); padding: 0.8rem; margin-bottom: 0.6rem; }
.count-item.done { border-left: 4px solid #9cc4ac; } .count-item.recount { border-left: 4px solid var(--rose); background: #fff8f9; }
.count-item .entries { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; margin-top: 0.5rem; }
.count-item .entries .field { flex: 1 1 110px; max-width: 170px; }
.bar { height: 8px; border-radius: 99px; background: #efe9eb; overflow: hidden; } .bar > i { display: block; height: 100%; background: var(--gold); }
.preview-doc { width: 100%; height: 60vh; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); object-fit: contain; }
.print-only { display: none; }

/* Mobile */
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 0.4rem 0.75rem; border-bottom: 1px solid var(--gold); position: sticky; top: 0; background: #fff; z-index: 20; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(290px, 85vw); z-index: 40; transform: translateX(-105%); transition: transform .18s ease; box-shadow: 4px 0 30px rgba(0,0,0,.15); }
  .side.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(42,35,38,.4); z-index: 39; }
  main { padding: 1rem 0.75rem 5rem; }
  .form .grid { grid-template-columns: 1fr; }
  h1 { font-size: 1.35rem; }
  .table-wrap.stack table, .table-wrap.stack thead, .table-wrap.stack tbody, .table-wrap.stack tr, .table-wrap.stack td { display: block; }
  input[type=date], input[type=datetime-local] { width: 100%; }
  .range input { flex: 1 1 130px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Print-friendly reports and purchase orders */
@media print {
  .side, .topbar, .no-print, #toasts, .demo-banner, .tabs, .btn { display: none !important; }
  .shell { display: block; } main { padding: 0; max-width: none; }
  .print-only { display: block; }
  .table-wrap { border: 0; overflow: visible; } th { position: static; }
  .card, .panel { break-inside: avoid; }
  body { font-size: 11pt; }
  .modal-back { position: static; background: none; padding: 0; } .modal { box-shadow: none; border: 0; width: 100%; } .modal header .btn { display: none; }
  body.modal-print .shell { display: none; }
}

details.history > summary { cursor: pointer; font-weight: 600; color: var(--rose); }
details.history[open] > summary { margin-bottom: 0.6rem; }
