/* Blackvine Business System — black & yellow theme */
:root {
  --black: #141414;
  --black-2: #262626;
  --yellow: #F5C400;
  --yellow-dark: #D9AC00;
  --yellow-soft: #FFF6CC;
  --ground: #F5F5F2;
  --surface: #FFFFFF;
  --line: #DEDED8;
  --line-soft: #ECECE7;
  --text: #141414;
  --muted: #5C5C57;
  --red: #B42318;
  --red-soft: #FDECEA;
  --green: #1F7A4D;
  --green-soft: #E9F6EE;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--text); background: var(--ground); }
a { color: var(--text); }
img { max-width: 100%; }
h1, h2 { line-height: 1.2; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
code { background: var(--line-soft); padding: 1px 6px; border-radius: 4px; word-break: break-all; }

/* ---------- Layout ---------- */
.shell { display: flex; flex-wrap: wrap; min-height: 100vh; }
.side { flex: 1 1 230px; max-width: 100%; background: var(--black); color: #fff; padding: 22px 14px; display: flex; flex-direction: column; gap: 6px; }
.main { flex: 999 1 560px; min-width: 0; padding: 28px clamp(16px, 3vw, 40px) 60px; display: flex; flex-direction: column; gap: 18px; }
@media (min-width: 900px) { .side { flex: 0 0 236px; } }

.brand { display: flex; flex-direction: column; gap: 4px; padding: 4px 10px 18px; text-decoration: none; color: #fff; border-bottom: 1px solid var(--black-2); margin-bottom: 8px; }
.brand img { max-height: 46px; width: auto; align-self: flex-start; background: #fff; padding: 4px 8px; border-radius: 6px; }
.brand-name { font-size: 20px; font-weight: 800; letter-spacing: .02em; }
.brand-sub { font-size: 12px; color: var(--yellow); }

.menu { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.menu a { display: flex; align-items: center; min-height: 40px; padding: 0 12px; border-radius: 8px; color: #D8D8D8; text-decoration: none; font-size: 14.5px; }
.menu a:hover { background: var(--black-2); color: #fff; }
.menu a.on { background: var(--yellow); color: var(--black); font-weight: 700; }
.side-foot { margin-top: auto; padding: 16px 10px 0; border-top: 1px solid var(--black-2); display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: #B5B5B5; }
.side-foot a { color: var(--yellow); }

@media (max-width: 899px) {
  .side { flex-basis: 100%; padding: 12px; }
  .brand { flex-direction: row; align-items: center; justify-content: space-between; padding-bottom: 10px; }
  .menu { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 4px; }
  .menu a { white-space: nowrap; }
  .side-foot { padding-top: 10px; }
}

.page-head h1 { margin: 0; font-size: 26px; font-weight: 750; }

/* ---------- Cards & text ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card h2 { margin: 0 0 12px; font-size: 17px; }
.card.empty { text-align: center; padding: 48px 20px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.card.empty p { margin: 0; color: var(--muted); }
.muted { color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 12px; font-weight: 400; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 18px; border-radius: 8px; border: 1px solid #C9C9C2; background: #fff; color: var(--text); font: inherit; font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { background: #F0F0EB; }
.btn-primary { background: var(--yellow); border-color: var(--yellow); color: var(--black); }
.btn-primary:hover { background: var(--yellow-dark); border-color: var(--yellow-dark); }
.btn-dark { background: var(--black); border-color: var(--black); color: var(--yellow); }
.btn-dark:hover { background: var(--black-2); }
.btn-block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Flash ---------- */
.flash { padding: 12px 16px; border-radius: 8px; font-size: 14px; border: 1px solid; }
.flash-success { background: var(--black); color: var(--yellow); border-color: var(--black); }
.flash-error { background: var(--red-soft); color: var(--red); border-color: #F3B8B2; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; font-weight: 600; }
.form input:not([type=checkbox]):not([type=file]), .form select, .form textarea {
  font: inherit; font-weight: 400; font-size: 15px; width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid #C9C9C2; border-radius: 8px; background: #fff; color: var(--text);
}
.form textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.form input:focus, .form select:focus, .form textarea:focus { border-color: var(--black); outline: 3px solid var(--yellow-soft); }
.form input[type=file] { font: inherit; font-size: 14px; }
.form fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.form legend { font-weight: 700; padding: 0 6px; }
.form .check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 18px; }
.grid2.tight { gap: 10px 14px; }
.span2 { grid-column: 1 / -1; }
.upload { display: flex; flex-direction: column; gap: 8px; }
.upload .label { font-size: 13.5px; font-weight: 600; }
.upload .preview { max-height: 80px; width: auto; align-self: flex-start; border: 1px solid var(--line); border-radius: 6px; padding: 6px; background: #fff; }
.sticky-save { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--ground) 30%); }

.numbering { display: flex; flex-direction: column; gap: 10px; }
.num-row { display: grid; grid-template-columns: 130px minmax(160px, 1fr) 140px minmax(160px, 1fr); gap: 10px 14px; align-items: end; padding-bottom: 10px; border-bottom: 1px solid var(--line-soft); }
.num-label { font-weight: 700; padding-bottom: 12px; }
.num-preview { padding-bottom: 12px; font-size: 14px; }
@media (max-width: 760px) { .num-row { grid-template-columns: 1fr 1fr; } .num-label, .num-preview { grid-column: 1 / -1; padding: 0; } }

/* ---------- Dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 4px; text-decoration: none; }
.stat:hover { border-color: var(--black); }
.stat-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-note { font-size: 13px; color: var(--muted); }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; }

/* ---------- Login / install ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--black); }
.auth-box { width: 100%; max-width: 400px; background: var(--surface); border-radius: 14px; padding: 32px 28px; border-top: 6px solid var(--yellow); display: flex; flex-direction: column; gap: 14px; }
.auth-box.wide { max-width: 620px; }
.auth-logo { max-height: 60px; width: auto; align-self: flex-start; }
.auth-title { margin: 0; font-size: 24px; font-weight: 800; }
.auth-h { margin: 0; font-size: 18px; }
.checks { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.checks li { padding: 3px 0; }
.checks .ok { color: var(--green); }
.checks .bad { color: var(--red); font-weight: 600; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
.table th { text-align: left; font-size: 12.5px; font-weight: 700; color: var(--muted); padding: 10px 12px; border-bottom: 2px solid var(--black); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tr:hover td { background: #FAFAF6; }
.table .btn { min-height: 36px; padding: 0 12px; }

/* ---------- Phase 2: lists, badges, details ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search], .toolbar select { font: inherit; font-size: 14.5px; min-height: 44px; padding: 0 12px; border: 1px solid #C9C9C2; border-radius: 8px; background: #fff; }
.toolbar input[type=search] { flex: 1 1 220px; min-width: 0; }
.toolbar .push { margin-left: auto; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table th.num { text-align: right; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--line-soft); white-space: nowrap; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-yellow { background: var(--yellow-soft); color: #6B5200; }
.badge-grey { background: var(--line-soft); color: var(--muted); }
.thumb-cell { width: 52px; }
.thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }
.thumb-empty { background: var(--line-soft); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.pager { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; margin-top: 14px; }
.empty-line { padding: 24px 0; text-align: center; margin: 0; }
.readonly { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; }
.readonly .label { font-weight: 600; }
.readonly strong { font-size: 20px; }
.btn-wa { background: var(--green); border-color: var(--green); color: #fff; }
.btn-wa:hover { background: #17603C; }
.grid-2col { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; font-size: 14.5px; }
.details dt { color: var(--muted); font-weight: 600; }
.details dd { margin: 0; overflow-wrap: anywhere; }
.pre { white-space: pre-line; }
.big { font-size: 22px; font-weight: 800; margin: 0; }

/* ---------- Phase 3: inventory ---------- */
.nowrap { white-space: nowrap; }
.toolbar .inline { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; }
.toolbar input[type=date] { font: inherit; font-size: 14.5px; min-height: 44px; padding: 0 10px; border: 1px solid #C9C9C2; border-radius: 8px; background: #fff; }

/* ---------- Phase 4: documents ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tab { padding: 10px 14px; text-decoration: none; font-size: 14px; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tab span { font-weight: 400; margin-left: 4px; }
.tab.on { color: var(--text); border-bottom-color: var(--yellow); }
.doc-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px 24px; align-items: flex-start; margin-bottom: 16px; }
.doc-head h2 { margin: 0; }
.doc-no { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; margin-top: 2px; }
.details.compact { font-size: 14px; gap: 4px 16px; }
.tax-field { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; }
.tax-field .check { min-height: 44px; }
.inline-rate { max-width: 140px; }
.items-edit { min-width: 860px; }
.items-edit td { padding: 6px; }
.items-edit input { font: inherit; font-size: 14px; width: 100%; min-height: 40px; padding: 6px 8px; border: 1px solid #C9C9C2; border-radius: 6px; background: #fff; }
.items-edit input.num { text-align: right; }
.items-edit .ln { color: var(--muted); text-align: center; }
.btn-icon { min-height: 40px; width: 40px; padding: 0; }
.totals-box { margin: 16px 0 0 auto; max-width: 340px; display: flex; flex-direction: column; gap: 6px; font-size: 14.5px; font-variant-numeric: tabular-nums; }
.totals-box div { display: flex; justify-content: space-between; gap: 16px; }
.totals-box span { color: var(--muted); }
.totals-box .grand { border-top: 2px solid var(--black); padding-top: 8px; font-size: 17px; }
.totals-box .grand span { color: var(--text); font-weight: 700; }
.doc-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.inline-form { display: contents; }
.wa-box { margin-top: 18px; padding: 14px 16px; border: 1px solid #9CC9B0; background: var(--green-soft); border-radius: 10px; font-size: 14px; }
.wa-box p { margin: 8px 0 0; }
.picker { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); border: 0; border-radius: 14px; padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.picker::backdrop { background: rgba(0,0,0,.55); }
.picker[open] { display: flex; flex-direction: column; gap: 12px; }
.picker-head { display: flex; justify-content: space-between; align-items: center; }
.picker-head h2 { margin: 0; font-size: 18px; }
#picker-search { font: inherit; font-size: 15px; min-height: 44px; padding: 0 12px; border: 1px solid #C9C9C2; border-radius: 8px; width: 100%; }
.picker-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; max-height: 55vh; border-top: 1px solid var(--line-soft); }
.picker-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line-soft); }
.picker-list li div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.picker-list li span { font-size: 13px; }
.picker-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* ---------- Phase 8: reports ---------- */
.quick-dates { display: flex; gap: 12px; font-size: 14px; }
.report-totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 16px; }
.report-totals .stat { padding: 12px 14px; }
.report-totals .stat-value { font-size: 20px; }