:root {
  --bg: #f4f1ec;
  --card: #ffffff;
  --ink: #1d1b19;
  --muted: #74706a;
  --line: #e4ded5;
  --soft: #ece7df;
  --accent: #1d1b19;
  --green: #3d6b4c;
  --wa: #1e9e55;
  --wa-dark: #17824a;
  --amber: #a86400;
  --amber-bg: #fff4e0;
  --red: #b3261e;
  --red-bg: #fdecea;
  --green-bg: #e8f3ec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(29, 27, 25, .06), 0 4px 14px rgba(29, 27, 25, .05);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: inherit; }
h1 { font-size: 1.45rem; margin: 0; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; font-weight: 600; }
h3 { font-size: 1rem; margin: .2rem 0; }
small, .small { font-size: .85rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.right { text-align: right; }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.text-green { color: var(--green); }

/* ---------- top bar & nav ---------- */
.topbar {
  background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; position: sticky; top: 0; z-index: 20;
}
.brand { color: #fff; text-decoration: none; font-weight: 600; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-cta { background: #fff !important; color: var(--ink) !important; }
.nav {
  display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px; background: #fff;
  border-bottom: 1px solid var(--line); scrollbar-width: none; position: sticky; top: 50px; z-index: 19;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  white-space: nowrap; text-decoration: none; padding: 7px 12px; border-radius: 999px; color: var(--muted); font-size: .92rem;
}
.nav a.on { background: var(--ink); color: #fff; }
.badge-red { background: var(--red); color: #fff; border-radius: 999px; padding: 0 6px; font-size: .75rem; }

.wrap { max-width: 1150px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 14px; }

/* ---------- cards & layout ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.card-head h2 { margin: 0; }
.card-head a { font-size: .9rem; color: var(--muted); }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "▸ "; color: var(--muted); }
details.card[open] > summary::before { content: "▾ "; }
details.card[open] > summary { margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 820px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.row-between.gap { align-items: flex-end; }
.grow { flex: 1; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-col { display: flex; flex-direction: column; gap: 6px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 820px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stats.compact { margin: 8px 0 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; text-decoration: none; box-shadow: var(--shadow); }
.stat span { color: var(--muted); font-size: .82rem; }
.stat strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stat strong.smaller { font-size: 1.05rem; }
.stat small { color: var(--muted); }
.stat-due { border-color: #f0d9b0; background: var(--amber-bg); }
.compact .stat { box-shadow: none; padding: 8px 10px; }
.compact .stat strong { font-size: 1.1rem; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { border-top: 1px solid var(--line); padding: 10px 0; }
.list li:first-child { border-top: 0; }
.list li > a { text-decoration: none; display: flex; }
.scroll-list { max-height: 70vh; overflow-y: auto; }
.pill { display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 999px; text-transform: capitalize; }
.pill-paid { background: var(--green-bg); color: var(--green); }
.pill-partial { background: var(--amber-bg); color: var(--amber); }
.pill-unpaid { background: var(--red-bg); color: var(--red); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 10px 0; }

/* ---------- forms ---------- */
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid #d6cfc4; border-radius: 9px;
  padding: 9px 11px; width: 100%; min-height: 42px;
}
input[type=checkbox] { width: 18px; min-height: 18px; }
input:focus, select:focus { outline: 2px solid var(--ink); outline-offset: 1px; border-color: var(--ink); }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 560px) { .form-grid { grid-template-columns: 1fr 1fr; } .span-2 { grid-column: span 2; } }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 140px; }
.search { max-width: 280px; }
.qty-input { width: 64px !important; flex: 0 0 64px !important; text-align: center; }
.qty-input.wide { width: 96px !important; flex: 0 0 96px !important; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px;
  padding: 8px 14px; border-radius: 9px; border: 1px solid #cfc7bb; background: #fff; color: var(--ink);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--soft); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #3a3632; }
.btn-wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn-wa:hover { background: var(--wa-dark); }
.btn-danger { color: var(--red); border-color: #e7b9b5; }
.btn-danger:hover { background: var(--red-bg); }
.btn-sm { min-height: 34px; padding: 5px 10px; font-size: .88rem; }
.btn-lg { min-height: 50px; font-size: 1.05rem; padding: 10px 20px; }
.btn-block { width: 100%; }
.btn-x { border: 0; background: none; font-size: 1.4rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }

/* ---------- flash ---------- */
.flash { padding: 11px 14px; border-radius: 10px; margin-bottom: 12px; border: 1px solid; }
.flash-success { background: var(--green-bg); border-color: #bcd9c5; color: #24452f; }
.flash-error { background: var(--red-bg); border-color: #efc1bd; color: #7d1a14; }
.flash-warning { background: var(--amber-bg); border-color: #f0d9b0; color: #6d4100; }
.alert-line { font-size: .9rem; margin: 6px 0; font-weight: 500; }

/* ---------- mini details ---------- */
details.mini { margin-top: 6px; }
details.mini > summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.mini-body { margin: 10px 0; }
.mini-body form { margin-bottom: 8px; }

/* ---------- services ---------- */
.svc-list { list-style: none; margin: 0; padding: 0; }
.svc-row { border-top: 1px solid var(--line); padding: 10px 0; }
.svc-row:first-child { border-top: 0; }
.svc-row.inactive { opacity: .55; }
.price { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- inventory ---------- */
.product-grid { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 700px) { .product-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1050px) { .product-grid { grid-template-columns: 1fr 1fr 1fr; } }
.product.is-low { border-color: #f0c98a; background: #fffaf0; }
.product.is-out { border-color: #efb3ae; background: #fff7f6; }
.qty-box { text-align: center; min-width: 64px; }
.qty-box strong { display: block; font-size: 1.8rem; line-height: 1; font-variant-numeric: tabular-nums; }
.qty-box small { color: var(--muted); }
.product-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.product-actions .inline-form { flex-wrap: nowrap; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: .82rem; }
th.right, td.right { text-align: right; }

/* ---------- new bill ---------- */
.bill-layout { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 900px) { .bill-layout { grid-template-columns: 1.25fr 1fr; } .sticky { position: sticky; top: 110px; } }
.search-wrap { position: relative; }
.suggest { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 10; max-height: 260px; overflow-y: auto; }
.suggest-item { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); background: #fff; font: inherit; color: var(--ink); cursor: pointer; }
.suggest-item:hover { background: var(--soft); }
.suggest-empty { padding: 10px 12px; color: var(--muted); }
.cat-group { border-top: 1px solid var(--line); padding: 8px 0; }
.cat-group > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; padding: 8px 0 4px; }
.chip {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 9px 11px;
  border: 1px solid #d6cfc4; border-radius: 10px; background: #fff; font: inherit; color: var(--ink); cursor: pointer; min-height: 54px;
}
.chip:hover { border-color: var(--ink); }
.chip.added { background: var(--green-bg); border-color: var(--green); }
.chip-name { font-weight: 500; font-size: .92rem; }
.chip-price { color: var(--muted); font-size: .8rem; }
.cart { list-style: none; margin: 0 0 10px; padding: 0; }
.cart-item { border-bottom: 1px solid var(--line); padding: 8px 0; }
.cart-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.mini-label { flex-direction: row; align-items: center; gap: 4px; }
.qty-ctrl { display: inline-flex; align-items: center; gap: 6px; }
.qty-show { min-width: 22px; text-align: center; font-weight: 600; }
.line-total { min-width: 80px; text-align: right; font-variant-numeric: tabular-nums; }
.totals { display: flex; flex-direction: column; gap: 10px; border-top: 2px solid var(--ink); padding-top: 10px; margin-bottom: 12px; }
.total-line { font-size: 1.25rem; }
.remaining-line { font-size: 1.05rem; }

/* ---------- bill view ---------- */
.send-card { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.send-card.highlight { border: 2px solid var(--wa); background: #f2fbf5; }
.receipt-head { text-align: center; border-bottom: 1px dashed var(--line); padding-bottom: 10px; margin-bottom: 10px; }
.receipt-head h2 { margin: 0; font-size: 1.2rem; }
.receipt-table { margin-top: 10px; }
.receipt-table td.right, .line-total, .totals strong { white-space: nowrap; }
.mobile-total {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; align-items: center;
  justify-content: space-between; gap: 10px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--ink); color: #fff; border: 0; font: inherit; width: 100%; cursor: pointer;
}
.mobile-total strong { font-size: 1.1rem; }
.has-mobile-total { padding-bottom: 70px; }
@media (min-width: 900px) { .mobile-total { display: none; } .has-mobile-total { padding-bottom: 0; } }
.receipt-table tfoot td { border-bottom: 0; padding: 4px 6px; }
.receipt-table tr.grand td { font-weight: 700; font-size: 1.1rem; border-top: 2px solid var(--ink); padding-top: 8px; }
.wa-preview { white-space: pre-wrap; font: .88rem/1.4 ui-monospace, Menlo, Consolas, monospace; background: var(--soft); padding: 10px; border-radius: 8px; margin: 10px 0 0; }

/* ---------- analytics ---------- */
.day-chart { display: flex; align-items: flex-end; gap: 2px; height: 170px; padding-top: 6px; }
.day-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; min-width: 0; }
.day-bar { width: 100%; background: var(--green); border-radius: 3px 3px 0 0; min-height: 0; }
.day-col small { font-size: .65rem; color: var(--muted); height: 14px; }
.rank { margin: 0; padding-left: 1.3rem; }
.rank li { padding: 6px 0; }
.rank .row-between > span:last-child, .list .row-between > strong { white-space: nowrap; }
.bar { height: 6px; background: var(--soft); border-radius: 99px; margin-top: 5px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--green); border-radius: 99px; }

/* ---------- login ---------- */
.login-box { max-width: 380px; margin: 10vh auto; display: flex; flex-direction: column; gap: 10px; }
.login-box form { display: flex; flex-direction: column; gap: 12px; }
.login-brand { text-align: center; font-weight: 300; font-size: 1.6rem; }

/* ---------- print ---------- */
@media print {
  .topbar, .nav, .no-print, .flash { display: none !important; }
  body { background: #fff; }
  .wrap { padding: 0; }
  .grid-2 { display: block; }
  .card { box-shadow: none; border: 0; }
}
