:root {
  --ink: #172019;
  --muted: #5b665b;
  --line: #e2e6dc;
  --bg: #f3f5ef;
  --card: #ffffff;
  --dark: #182920;
  --green: #1f5135;
  --green-active: #163c27;
  --lime: #d9efb8;
  --amber-bg: #fff4df;
  --amber-ink: #925403;
  --red-bg: #fdeaea;
  --red-ink: #b12020;
  --blue-bg: #e9f2fc;
  --blue-ink: #1a4f8b;
  --wa: #128c7e;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  color: var(--ink);
  background: #e5e8df;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: 0.42; cursor: not-allowed; }
h1, h2, h3, p { margin: 0; }
small { display: block; }
svg { width: 20px; height: 20px; vertical-align: middle; flex-shrink: 0; }

/* Mobile-only centered phone viewport on larger screens, edge-to-edge on phones */
.app-frame {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--dark);
  color: #f3f8ef;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--lime);
  color: #173321;
  font-weight: 800;
  font-size: 14px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.app-title {
  font-size: 16px;
  font-weight: 750;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-sub {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: #b7cbb9;
  margin-top: 1px;
}
.app-sub .dot { width: 7px; height: 7px; border-radius: 50%; background: #6ee787; }
.app-sub.offline .dot { background: #f59e0b; }

.header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.hdr-btn {
  border: 1px solid #385041;
  background: #243b2e;
  color: #edf5e7;
  border-radius: 20px;
  padding: 6px 11px;
  font-size: 12.5px;
  font-weight: 650;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.hdr-btn svg { width: 15px; height: 15px; }

.app-body {
  flex: 1;
  padding: 14px 13px 150px;
}

.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.page-title h1 { font-size: 22px; letter-spacing: -0.4px; }
.page-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 15px;
  font-weight: 700;
  font-size: 14.5px;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-decoration: none;
}
.btn-primary { background: var(--green); color: white; }
.btn-primary:active:enabled { background: var(--green-active); }
.btn-wa { background: var(--wa); color: white; }
.btn-secondary { background: white; border-color: #d3dbd0; color: #243928; }
.btn-danger { background: #fff4f4; border-color: #f3c5c5; color: var(--red-ink); }
.btn-sm { min-height: 38px; padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; }

/* Search */
.search-box {
  display: flex;
  align-items: center;
  gap: 9px;
  background: white;
  border: 1.5px solid #d5ddd1;
  border-radius: 12px;
  padding: 0 13px;
  height: 48px;
}
.search-box:focus-within { border-color: var(--green); }
.search-box input {
  border: 0;
  outline: none;
  background: none;
  width: 100%;
  font-size: 16px;
  color: var(--ink);
}

/* Horizontal scrollable pills */
.pills-row {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 10px 0 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.pills-row::-webkit-scrollbar { display: none; }
.pill-chip {
  background: white;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 600;
  color: #425043;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 38px;
}
.pill-chip.active {
  background: var(--green);
  border-color: var(--green);
  color: white;
}
.pill-chip.add-cat {
  background: #eef6e5;
  border-color: #c2d9ae;
  color: var(--green);
}

/* Segment tabs */
.seg-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  background: #e7ebe1;
  padding: 4px;
  border-radius: 12px;
  margin-bottom: 12px;
}
.seg-tab {
  border: 0;
  background: transparent;
  border-radius: 9px;
  padding: 9px 4px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}
.seg-tab.active {
  background: white;
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* Summary Strip & Clean Home Dashboard */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.dash-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 15px 14px;
  display: grid;
  gap: 4px;
}
.dash-card small {
  font-size: 12px;
  color: var(--muted);
  font-weight: 650;
}
.dash-card strong {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--ink);
}
.dash-card .dash-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.dash-section {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 15px 14px;
  margin-bottom: 12px;
}
.dash-section-title {
  font-size: 14.5px;
  font-weight: 750;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.inv-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  text-align: center;
}
.inv-stat {
  background: #f6f8f2;
  border-radius: 12px;
  padding: 10px 6px;
}
.inv-stat strong { display: block; font-size: 19px; font-weight: 800; }
.inv-stat small { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.status-banner {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 650;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 0;
  width: 100%;
  text-align: left;
}
.status-banner.ok { background: #e8f5e4; color: #1d5726; }
.status-banner.warn { background: var(--amber-bg); color: var(--amber-ink); }

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.kpi-box {
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 11px;
}
.kpi-box small { font-size: 11px; color: var(--muted); font-weight: 600; }
.kpi-box strong { display: block; font-size: 17px; margin-top: 2px; }

/* Mobile Cards */
.card-list { display: grid; gap: 10px; margin-top: 10px; }
.item-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px;
  display: grid;
  gap: 9px;
}
.item-card.out-card { opacity: 0.65; }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card-title { font-size: 16px; font-weight: 750; line-height: 1.25; }
.card-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.card-price { font-size: 17px; font-weight: 800; color: var(--ink); white-space: nowrap; }

.size-row { display: flex; flex-wrap: wrap; gap: 5px; }
.size-pill {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 7px;
  background: #f2f5ed;
  border: 1px solid #dfe5d7;
  color: #29412d;
  font-weight: 600;
}
.size-pill.out { opacity: 0.45; text-decoration: line-through; }

.card-actions {
  display: flex;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid #eff2ea;
}
.card-actions > * { flex: 1; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 11.5px;
  font-weight: 750;
  white-space: nowrap;
}
.badge.ok { background: #e5f4e1; color: #1d5726; }
.badge.low { background: var(--amber-bg); color: var(--amber-ink); }
.badge.out { background: var(--red-bg); color: var(--red-ink); }
.badge.info { background: var(--blue-bg); color: var(--blue-ink); }

/* Floating Bill Bar above Bottom Nav */
.cart-dock {
  position: fixed;
  bottom: calc(68px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(460px, calc(100vw - 20px));
  background: var(--dark);
  color: white;
  border-radius: 15px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: 0 10px 26px rgba(15, 36, 22, 0.35);
  z-index: 35;
}
.cart-dock .btn {
  background: var(--lime);
  color: #16301f;
  min-height: 40px;
  padding: 8px 14px;
  font-size: 14px;
}

/* Fixed Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, 100vw);
  background: white;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(7px + env(safe-area-inset-bottom));
  z-index: 40;
}
.bottom-nav button {
  background: none;
  border: 0;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 2px;
  font-size: 11.5px;
  font-weight: 650;
  border-radius: 10px;
}
.bottom-nav button.selected {
  color: var(--green);
  background: #ebf4e4;
}
.bottom-nav svg { width: 21px; height: 21px; }

/* Bottom Sheet / Full-width Mobile Dialogs */
dialog {
  border: 0;
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(22px + env(safe-area-inset-bottom));
  width: min(480px, 100vw);
  max-width: 100vw;
  max-height: 92dvh;
  margin: auto auto 0;
  color: var(--ink);
  overflow-y: auto;
  box-shadow: 0 -10px 35px rgba(0,0,0,0.25);
}
dialog::backdrop { background: rgba(14, 24, 18, 0.65); }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: -16px;
  background: white;
  z-index: 5;
  padding-top: 4px;
}
.sheet-head h2 { font-size: 18px; }
.icon-close {
  border: 0;
  background: #eff3ea;
  color: var(--ink);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

/* Forms */
.field { display: grid; gap: 5px; font-size: 13px; font-weight: 650; margin: 10px 0; }
.field input, .field select, .field textarea, .num-input {
  width: 100%;
  min-width: 0;
  padding: 11px 12px;
  border: 1.5px solid #d4dcd0;
  border-radius: 10px;
  background: white;
  color: var(--ink);
  font-size: 16px;
  font-weight: 450;
  min-height: 46px;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); outline: none; }
.field small { font-size: 12px; font-weight: 400; color: var(--muted); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Tap option chips (e.g. Cash / UPI / Card) */
.tap-chips { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 4px; }
.tap-chip {
  flex: 1;
  min-width: 70px;
  padding: 10px 8px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: white;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}
.tap-chip.active {
  background: #e5f2db;
  border-color: var(--green);
  color: var(--green);
}

/* Stepper inside Cart / Stock */
.stepper { display: flex; align-items: center; gap: 6px; }
.step-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid #d4dcd0;
  background: #f4f7ef;
  color: var(--ink);
  font-weight: 800;
  font-size: 18px;
  display: grid;
  place-items: center;
}
.stepper input {
  width: 58px;
  text-align: center;
  padding: 6px;
  border: 1px solid #d4dcd0;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 700;
  min-height: 38px;
}

.cart-row {
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 8px;
}
.cart-row:last-child { border-bottom: 0; }
.cart-row-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.cart-row-bot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.variant-card {
  background: #f7f9f4;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
  display: grid;
  gap: 8px;
}

.size-picker-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 10px 0; }
.size-pick-btn {
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: white;
  padding: 12px;
  text-align: left;
  display: grid;
  gap: 4px;
}
.size-pick-btn:active:enabled { background: #eaf4e2; border-color: var(--green); }

.summary-box {
  background: #f4f7ef;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 6px;
  margin: 12px 0;
}
.summary-row { display: flex; justify-content: space-between; font-size: 14px; }
.summary-row.total { font-size: 18px; font-weight: 800; border-top: 1px dashed #c8d1c2; padding-top: 8px; margin-top: 2px; }

.sheet-actions { display: grid; gap: 8px; margin-top: 14px; }
.sheet-actions-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.help-step { background: #f6f8f3; border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 9px; }
.help-step strong { display: block; font-size: 14.5px; color: var(--green); margin-bottom: 4px; }
.help-step p { font-size: 13.5px; color: var(--muted); line-height: 1.45; }

.receipt { font-size: 13.5px; }
.receipt-header { text-align: center; border-bottom: 1px dashed #ccc; padding-bottom: 10px; margin-bottom: 10px; }
.receipt-header h2 { font-size: 20px; }
.receipt-header p { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.receipt table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.receipt th, .receipt td { padding: 7px 4px; border-bottom: 1px solid #eee; font-size: 13px; text-align: left; }
.receipt-totals { border-top: 1px dashed #ccc; padding-top: 8px; display: grid; gap: 4px; }
.receipt-totals .grand { font-size: 18px; font-weight: 800; display: flex; justify-content: space-between; }

.hidden { display: none !important; }
.empty-msg { text-align: center; padding: 30px 16px; color: var(--muted); font-size: 14px; }

#print-area { display: none; }
#toast {
  position: fixed;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, calc(100vw - 24px));
  background: #1b3826;
  color: white;
  border-radius: 12px;
  padding: 11px 15px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  z-index: 70;
  box-shadow: 0 8px 24px rgba(0,0,0,0.22);
}
#toast:empty { display: none; }

.barcode-sheet { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.barcode-tag { border: 1px dashed #888; padding: 8px 10px; border-radius: 4px; font-size: 11px; break-inside: avoid; }
.barcode-tag strong { font-size: 12px; display: block; }
.barcode-bars { font-family: "Courier New", monospace; font-weight: 700; letter-spacing: 1px; margin: 4px 0; font-size: 13px; }

@media print {
  body { background: white; color: black; }
  .app-frame, dialog, #toast { display: none !important; }
  #print-area { display: block !important; margin: auto; }
  #print-area.thermal { max-width: 78mm; font-size: 11px; }
  #print-area.a4 { max-width: 700px; font-size: 13px; }
  #print-area.labels { max-width: 100%; }
}
