/* ============================================================
   Amardeep Emporiuma — Shop Billing
   Matches the public website: cream background, shop red, white header
   ============================================================ */

/* ─── DESIGN TOKENS ──────────────────────────────────────────── */
:root {
  --red:        #c8102e;
  --red-dark:   #9c0c23;
  --red-light:  #fdf0f2;
  --red-border: #ecc7cd;
  --bg:         #f6efe6;
  --surface:    #ffffff;
  --ink:        #2a1d16;
  --text:       #2a1d16;
  --text-2:     #5a4a40;
  --muted:      #8a7a6f;
  --border:     #e8dccb;
  --field:      #fbf8f4;
  --success:    #0f9d63;
  --shadow-sm:  0 1px 4px rgba(60, 30, 10, 0.06);
  --shadow-md:  0 4px 18px rgba(60, 30, 10, 0.08);
  --shadow-lg:  0 10px 34px rgba(60, 30, 10, 0.14);
  --radius:     12px;
  --radius-sm:  8px;
  --radius-xs:  6px;
  --ease:       0.18s ease;
}

/* ─── RESET ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button, a, input, select { touch-action: manipulation; }

body {
  background: var(--bg);
  font-family: 'Inter', Arial, 'Noto Sans Gujarati', sans-serif;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.gu { font-family: 'Noto Sans Gujarati', sans-serif; }

/* ─── NAV ──────────────────────────────────────────────────────── */
.top-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 28px;
  height: 64px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  min-width: 0;
}

.nav-brand-gu {
  font-family: 'Noto Sans Gujarati', sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--red);
  line-height: 1;
}

.nav-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.nav-links {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 4px;
  border-radius: 999px;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-2);
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: all var(--ease);
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.nav-btn svg { flex-shrink: 0; }
.nav-btn:hover { color: var(--ink); }
.nav-btn.active { color: #fff; background: var(--red); box-shadow: 0 2px 8px rgba(200, 16, 46, 0.3); }

/* ─── VIEWS ──────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

/* ─── BILL WRAPPER ──────────────────────────────────────────── */
.bill-wrapper {
  padding: 28px 16px 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ─── BILL PAPER ──────────────────────────────────────────────── */
.bill-paper {
  background: var(--surface);
  width: 100%;
  max-width: 820px;
  border: 2px solid var(--red);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.bill-inner { margin: 0; }

/* ─── BILL HEADER ──────────────────────────────────────────────── */
.bill-header {
  border-bottom: 2px solid var(--red);
  padding: 14px 20px 14px;
  text-align: center;
}

.header-top {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--red);
  font-family: 'Noto Sans Gujarati', 'Inter', sans-serif;
}

.shop-name-gu {
  font-family: 'Noto Sans Gujarati', sans-serif;
  font-size: 40px;
  font-weight: 700;
  color: var(--red);
  line-height: 1.15;
  margin-top: 2px;
}

.shop-name-en {
  font-size: 13px;
  font-weight: 700;
  color: var(--red);
  letter-spacing: 3px;
  margin-top: 2px;
}

.shop-tagline {
  display: inline-block;
  margin-top: 8px;
  background: var(--red);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 12px;
  border-radius: 999px;
}

.shop-address { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ─── CUSTOMER ROW ─────────────────────────────────────────────── */
.customer-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 2px solid var(--red);
  padding: 16px 20px 10px;
  gap: 16px 28px;
  flex-wrap: wrap;
}

.customer-left { flex: 1; min-width: 260px; }
.customer-right { min-width: 230px; }

.cust-field-row {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  gap: 10px;
}

.cust-label {
  font-family: 'Noto Sans Gujarati', 'Inter', sans-serif;
  font-size: 13px;
  color: var(--red);
  font-weight: 700;
  white-space: nowrap;
  min-width: 86px;
}

.customer-right .cust-label { min-width: 60px; }

.cust-input {
  flex: 1;
  min-width: 0;
  border: 1.5px solid var(--border);
  background: var(--field);
  border-radius: var(--radius-xs);
  outline: none;
  font-size: 14px;
  padding: 8px 10px;
  color: var(--text);
  font-family: inherit;
  transition: border-color var(--ease), background var(--ease), box-shadow var(--ease);
}

.cust-input:focus { border-color: var(--red); background: #fff; box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.08); }
.cust-input::placeholder { color: #b3a69c; }

.name-input { font-size: 15px; font-weight: 600; }

.bill-no-input {
  flex: 0 0 auto;
  width: 110px;
  color: var(--red);
  font-family: 'Courier New', monospace;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 1px;
  text-align: center;
  background: var(--red-light);
  border-color: var(--red-border);
  cursor: default;
}

.bill-no-input:focus { box-shadow: none; border-color: var(--red-border); background: var(--red-light); }

/* ─── ITEMS TABLE ─────────────────────────────────────────────── */
.table-section { border-bottom: 2px solid var(--red); padding-bottom: 4px; }

.items-table { width: 100%; border-collapse: collapse; }

.items-table th {
  background: var(--red);
  color: white;
  padding: 9px 6px;
  font-size: 13px;
  font-family: 'Noto Sans Gujarati', sans-serif;
  text-align: center;
  line-height: 1.3;
  font-weight: 600;
}

.items-table th small {
  font-size: 10px;
  font-weight: 500;
  opacity: 0.85;
  font-family: 'Inter', Arial, sans-serif;
}

.th-no    { width: 42px; }
.th-desc  { text-align: left !important; padding-left: 12px !important; }
.th-qty   { width: 78px; }
.th-meter { width: 78px; }
.th-rate  { width: 96px; }
.th-amt   { width: 124px; }
.th-del   { width: 40px; }

.items-table td {
  border-bottom: 1px solid var(--red-border);
  border-right: 1px solid #f5e1e4;
  padding: 0;
  vertical-align: middle;
}

.items-table td:last-child { border-right: 0; }

.td-no {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding: 4px 2px;
}

.td-input {
  width: 100%;
  border: none;
  outline: none;
  padding: 11px 8px;
  font-size: 14px;
  font-family: inherit;
  background: transparent;
  color: var(--text);
  transition: background var(--ease);
}

.td-input:focus, .td-select:focus { background: #fff8e8; }
.td-input::placeholder { color: #c4b8ae; }
.td-qty .td-input, .td-meter .td-input { text-align: center; }
.td-rate .td-input { text-align: right; }

.td-select {
  width: 100%;
  border: none;
  outline: none;
  padding: 11px 10px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background var(--ease);
}

.td-amt-cell {
  background: #fffafa;
  font-weight: 700;
  color: var(--red);
  text-align: right;
  padding: 11px 12px;
  font-size: 14px;
  white-space: nowrap;
}

.td-del { text-align: center; }

.del-row-btn {
  background: none;
  border: none;
  color: #cdb4b9;
  cursor: pointer;
  font-size: 15px;
  width: 30px;
  height: 30px;
  margin: 0 auto;
  border-radius: 50%;
  transition: all var(--ease);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.del-row-btn:hover { color: var(--red); background: var(--red-light); }

/* TOTAL ROW */
.total-row td { background: var(--red-light); border-bottom: 0; border-right: 0; }

.total-label {
  text-align: right;
  padding: 14px 14px;
  font-family: 'Noto Sans Gujarati', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--red);
}

.total-label span { font-family: 'Inter', sans-serif; font-size: 13px; font-weight: 600; }

.total-value {
  text-align: right;
  padding: 14px 12px;
  font-size: 19px;
  font-weight: 800;
  color: var(--red);
  white-space: nowrap;
}

.add-row-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 12px 14px 10px;
  padding: 8px 18px;
  background: transparent;
  border: 1.5px dashed var(--red-border);
  color: var(--red);
  border-radius: 999px;
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 600;
  transition: all var(--ease);
}

.add-row-btn:hover { background: var(--red-light); border-color: var(--red); }

/* ─── BILL FOOTER ──────────────────────────────────────────────── */
.bill-footer { padding: 12px 20px 16px; }

.footer-terms p {
  font-family: 'Noto Sans Gujarati', sans-serif;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 3px;
}

/* ─── ACTION BAR ──────────────────────────────────────────────── */
.action-bar {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  justify-content: center;
}

.btn {
  padding: 13px 30px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-print { background: var(--surface); color: var(--ink); border: 1.5px solid var(--border); }
.btn-print:hover { border-color: var(--ink); }

.btn-save {
  background: var(--red);
  color: white;
  box-shadow: 0 4px 14px rgba(200, 16, 46, 0.3);
}

.btn-save:hover { background: var(--red-dark); }
.btn-save:disabled { opacity: 0.65; cursor: not-allowed; box-shadow: none; }

/* ─── HISTORY ─────────────────────────────────────────────────── */
.history-wrapper {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 16px 60px;
}

/* Stats */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.stat-card.stat-highlight { background: var(--red); border-color: var(--red); }

.stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--ink);
  line-height: 1;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.stat-card.stat-highlight .stat-value { color: #fff; }

.stat-label {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.stat-card.stat-highlight .stat-label { color: rgba(255, 255, 255, 0.85); }

/* History header */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  gap: 14px;
  flex-wrap: wrap;
}

.history-title {
  font-family: 'Playfair Display', serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
}

.history-title .gu { font-size: 16px; font-weight: 400; color: var(--red); margin-left: 6px; }

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 340px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 11px 14px 11px 38px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.search-input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.08);
}

/* Bill cards */
.bills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}

.bill-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--red);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  transition: all var(--ease);
  box-shadow: var(--shadow-sm);
  animation: card-in 0.2s ease;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.bill-card:hover { box-shadow: var(--shadow-md); border-color: var(--red-border); border-left-color: var(--red); }

.card-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.card-bill-no {
  font-size: 12px;
  color: var(--red);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.btn-delete-bill {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: all var(--ease);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.btn-delete-bill:hover { background: var(--red-light); color: var(--red); }

.card-customer {
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-meta {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-dot { margin: 0 5px; opacity: 0.5; }

.card-total {
  font-size: 21px;
  font-weight: 800;
  color: var(--red);
  letter-spacing: -0.3px;
}

/* Loading & empty */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 70px 20px;
  color: var(--muted);
  font-size: 14px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.no-bills {
  text-align: center;
  padding: 70px 20px;
  color: var(--muted);
  font-size: 15px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ─── MODALS ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(42, 29, 22, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 16px;
  backdrop-filter: blur(3px);
}

.modal-overlay.hidden { display: none; }

.modal-box {
  background: white;
  border-radius: 16px;
  padding: 34px 28px 26px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.2s ease;
}

.modal-sm { max-width: 360px; }

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-icon {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: #e5f7ee;
  color: var(--success);
  font-size: 26px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
}

.modal-icon.error { background: var(--red-light); color: var(--red); }

.modal-icon-warn {
  background: #fff3e0;
  color: #d35400;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
}

.modal-box h3 {
  font-size: 21px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--ink);
}

#modal-msg, #delete-modal-msg {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.65;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

/* Button variants */
.btn-whatsapp {
  background: #25d366;
  color: white;
  padding: 12px 22px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background var(--ease);
}

.btn-whatsapp:hover { background: #1ebe5b; }

.btn-new-bill {
  background: var(--red);
  color: white;
  padding: 12px 22px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--ease);
}

.btn-new-bill:hover { background: var(--red-dark); }

.btn-secondary {
  background: var(--bg);
  color: var(--text-2);
  padding: 11px 26px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: background var(--ease);
}

.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: var(--red);
  color: white;
  padding: 12px 24px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--ease);
}

.btn-danger:hover { background: var(--red-dark); }

/* Preview modal */
.preview-box {
  max-width: 740px;
  width: 100%;
  padding: 0;
  text-align: left;
  max-height: 90vh;
  overflow-y: auto;
}

.preview-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 18px;
}

.preview-label {
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-close-btn {
  background: var(--bg);
  border: none;
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  transition: background var(--ease);
}

.preview-close-btn:hover { background: var(--border); }

#preview-content { padding: 16px 16px 20px; }

/* ─── TOAST ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--ink);
  color: white;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: all 0.24s ease;
  z-index: 9999;
  white-space: nowrap;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.toast-error { background: var(--red); }
.toast.toast-success { background: var(--success); }

/* ─── EMPTY ROWS (hidden during print/PDF) ─────────────────── */
.row-hidden,
.items-table tbody tr.row-hidden { display: none !important; }

/* ─── TABLE SCROLL WRAPPER ──────────────────────────────────── */
.table-scroll-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.items-table { min-width: 520px; }

/* ─── RESPONSIVE ────────────────────────────────────────────── */

/* Tablet (≤ 768px) */
@media (max-width: 768px) {
  .top-nav { padding: 0 16px; }
  .bill-wrapper { padding: 20px 10px 90px; }
  .history-wrapper { padding: 20px 12px 60px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

/* Mobile (≤ 600px) */
@media (max-width: 600px) {
  /* Nav */
  .top-nav { padding: 0 12px; height: 58px; }
  .nav-badge { display: none; }
  .nav-btn { padding: 8px 13px; font-size: 13px; gap: 5px; }

  /* Bill */
  .bill-wrapper { padding: 12px 8px 96px; }
  .bill-header { padding: 10px 12px 12px; }
  .header-top { font-size: 11px; }
  .shop-name-gu { font-size: 30px; }
  .shop-name-en { font-size: 11px; letter-spacing: 2px; }
  .shop-tagline { font-size: 10.5px; padding: 3px 10px; }
  .shop-address { font-size: 11px; }

  /* Customer */
  .customer-row { flex-direction: column; gap: 0; padding: 12px 12px 6px; }
  .customer-left, .customer-right { min-width: 0; width: 100%; }
  .cust-label, .customer-right .cust-label { min-width: 74px; font-size: 12px; }
  .cust-input { font-size: 15px; padding: 10px; }

  /* Table → item cards */
  .table-section { padding: 10px 8px 2px; }
  .table-scroll-wrap { overflow-x: visible; }
  .items-table { min-width: 0 !important; }
  .items-table, .items-table tbody, .items-table tfoot { display: block; }
  .items-table thead { display: none; }

  .items-table tbody tr {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    border: 1.5px solid var(--red-border);
    border-radius: 10px;
    margin-bottom: 10px;
    background: white;
    padding: 10px;
    box-shadow: var(--shadow-sm);
  }

  .items-table tbody tr td { border: none !important; padding: 0; }

  .td-no {
    grid-row: 1; grid-column: 1;
    background: var(--red); color: white;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700;
  }

  .td-desc { grid-row: 1; grid-column: 2 / 6; }
  .td-del  { grid-row: 1; grid-column: 6; display: flex; align-items: center; justify-content: center; }

  .td-qty   { grid-row: 2; grid-column: 1 / 3; }
  .td-meter { grid-row: 2; grid-column: 3 / 5; }
  .td-rate  { grid-row: 2; grid-column: 5 / 7; }

  .td-qty::before, .td-meter::before, .td-rate::before {
    display: block;
    font-size: 10.5px; color: var(--muted);
    font-weight: 700; margin-bottom: 4px;
    text-transform: uppercase; letter-spacing: 0.5px;
  }
  .td-qty::before   { content: "Qty"; }
  .td-meter::before { content: "Meter"; }
  .td-rate::before  { content: "Rate ₹"; }

  .td-select, .td-input {
    border: 1.5px solid var(--border) !important;
    background: var(--field);
    border-radius: 8px;
    font-size: 15px;
    padding: 10px;
  }

  .td-select:focus, .td-input:focus { border-color: var(--red) !important; background: #fff; }
  .td-qty .td-input, .td-meter .td-input, .td-rate .td-input { text-align: center; }

  .td-amt-cell {
    grid-row: 3; grid-column: 1 / -1;
    background: var(--red-light);
    border-radius: 8px;
    font-size: 16px; padding: 9px 12px;
    display: flex; align-items: center; justify-content: space-between;
  }

  .td-amt-cell::before {
    content: "Amount";
    font-size: 11px; color: var(--muted);
    font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  }

  /* Total row as card */
  .items-table tfoot .total-row {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    border-radius: 10px;
    background: var(--red-light);
    border: 1.5px solid var(--red-border);
    padding: 12px 14px;
  }

  .total-row td { padding: 0 !important; background: transparent !important; }
  .total-label  { text-align: left !important; flex: 1; }
  .total-value  { font-size: 22px !important; }
  .total-row td.no-print { display: none !important; }

  .add-row-btn { margin: 10px 0 8px; width: 100%; justify-content: center; padding: 11px; }

  .bill-footer { padding: 10px 12px 14px; }

  /* Action bar fixed to bottom */
  .action-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    margin: 0;
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    background: white;
    box-shadow: 0 -4px 18px rgba(60, 30, 10, 0.1);
    border-top: 1px solid var(--border);
    z-index: 200;
    gap: 10px;
  }

  .action-bar .btn { flex: 1; padding: 13px 10px; min-height: 50px; }
  .action-bar .btn-save { flex: 1.6; }

  /* History */
  .stats-row { gap: 10px; margin-bottom: 20px; }
  .stat-card { padding: 14px 16px; }
  .stat-value { font-size: 22px; }
  .history-wrapper { padding: 16px 12px 60px; }
  .history-header { flex-direction: column; align-items: stretch; gap: 12px; }
  .history-title { font-size: 24px; }
  .search-wrap { max-width: none; }
  .bills-grid { grid-template-columns: 1fr; gap: 10px; }
  .bill-card { padding: 14px 16px; }
  .card-customer { font-size: 16px; }
  .card-total { font-size: 19px; }
  .toast { bottom: 84px; }

  /* Modals */
  .modal-box { padding: 28px 20px 22px; }
  .modal-actions { flex-direction: column; }
  .btn-whatsapp, .btn-new-bill, .btn-danger { width: 100%; padding: 13px; }
  .preview-box { max-height: 95vh; }
  #preview-content { padding: 10px; }
}

/* Small phones (≤ 380px) */
@media (max-width: 380px) {
  .nav-brand-gu { font-size: 19px; }
  .nav-btn { padding: 7px 10px; font-size: 12.5px; }
  .nav-btn svg { display: none; }
  .shop-name-gu { font-size: 26px; }
  .stat-value { font-size: 19px; }
}

/* ─── PRINT STYLES ──────────────────────────────────────────── */
@media print {
  @page { margin: 8mm; }
  .no-print { display: none !important; }
  body { background: white; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .top-nav { display: none; }
  .bill-wrapper { padding: 0; }
  .bill-paper { box-shadow: none; max-width: 100%; width: 100%; border-radius: 0; }

  /* Fields print as plain text */
  .cust-input, .td-input, .td-select {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 4px 6px !important;
    -webkit-appearance: none;
    appearance: none;
  }
  .cust-input::placeholder, .td-input::placeholder { color: transparent; }
  .bill-no-input { background: var(--red-light) !important; }

  /* Mobile phones print the normal table, not item cards */
  .customer-row { flex-direction: row !important; }
  .customer-left { min-width: 0 !important; }
  .customer-right { min-width: 0 !important; width: auto !important; }
  .table-section { padding: 0 !important; }
  .table-scroll-wrap { overflow-x: visible; }
  .items-table        { display: table !important; min-width: 0 !important; }
  .items-table thead  { display: table-header-group !important; }
  .items-table tbody  { display: table-row-group !important; }
  .items-table tfoot  { display: table-footer-group !important; }
  .items-table tbody tr,
  .items-table tfoot tr { display: table-row !important; padding: 0 !important; border: 0 !important; box-shadow: none !important; border-radius: 0 !important; margin: 0 !important; }
  .items-table td,
  .items-table th { display: table-cell !important; border: 1px solid var(--red-border) !important; border-radius: 0 !important; }
  .td-no { background: transparent !important; color: var(--muted) !important; }
  .td-qty::before, .td-meter::before, .td-rate::before, .td-amt-cell::before { content: none !important; }
  .td-amt-cell { background: #fffafa !important; text-align: right !important; padding: 6px 10px !important; font-size: 13px !important; }
  .total-row td { background: var(--red-light) !important; padding: 10px !important; }
  .total-label  { text-align: right !important; font-size: 13px !important; }
  .total-value  { font-size: 17px !important; }
  .row-hidden, .items-table tbody tr.row-hidden { display: none !important; }
  .items-table .no-print { display: none !important; }
  .date-input::-webkit-calendar-picker-indicator { display: none; }
}
