@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root,
html[data-theme="dark"] {
  --bg: #0a0e17;
  --bg-2: #0f1524;
  --sidebar: rgba(15, 21, 36, 0.85);
  --card: rgba(22, 30, 48, 0.75);
  --card-solid: #161e30;
  --border: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.12);
  --text: #f0f4fc;
  --muted: #8b9dc3;
  --primary: #f5a623;
  /* The primary and accent as bare RGB triples, so any rule needing a
     translucent tint can write rgba(var(--primary-rgb), .15) and still follow
     the shop's chosen brand colour. */
  --primary-rgb: 245, 166, 35;
  --accent-rgb: 99, 102, 241;
  --primary-glow: rgba(var(--primary-rgb), 0.35);
  --primary-dark: #e09010;
  --primary-text: #1a1200;
  --accent: #6366f1;
  --success: #22c55e;
  --success-glow: rgba(34, 197, 94, 0.2);
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.2);
  --warning: #f59e0b;
  --warning-glow: rgba(245, 158, 11, 0.2);
  --input-bg: rgba(0, 0, 0, 0.3);
  --table-head: rgba(0, 0, 0, 0.25);
  --row-hover: rgba(255, 255, 255, 0.04);
  --nav-hover: rgba(255, 255, 255, 0.06);
  --btn-bg: rgba(255, 255, 255, 0.06);
  --btn-hover: rgba(255, 255, 255, 0.1);
  --surface-muted: rgba(0, 0, 0, 0.25);
  --brand-text-1: #ffffff;
  --brand-text-2: #f5a623;
  --mesh-1: rgba(var(--accent-rgb), 0.12);
  --mesh-2: rgba(var(--primary-rgb), 0.1);
  --mesh-3: rgba(34, 197, 94, 0.05);
  --grid-line: rgba(255, 255, 255, 0.02);
  --backdrop: rgba(0, 0, 0, 0.7);
  --sidebar-shadow: 4px 0 32px rgba(0, 0, 0, 0.3);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.5);
  --glass: blur(20px) saturate(180%);
}

html[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-2: #eef1f8;
  --sidebar: rgba(255, 255, 255, 0.92);
  --card: rgba(255, 255, 255, 0.95);
  --card-solid: #ffffff;
  --border: rgba(15, 23, 42, 0.1);
  --border-light: rgba(15, 23, 42, 0.15);
  --text: #0f172a;
  --muted: #64748b;
  --primary: #e09010;
  --primary-rgb: 224, 144, 16;
  --accent-rgb: 79, 70, 229;
  --primary-glow: rgba(var(--primary-rgb), 0.25);
  --primary-dark: #c77d08;
  --primary-text: #ffffff;
  --accent: #4f46e5;
  --success: #16a34a;
  --success-glow: rgba(22, 163, 74, 0.12);
  --danger: #dc2626;
  --danger-glow: rgba(220, 38, 38, 0.1);
  --warning: #d97706;
  --warning-glow: rgba(217, 119, 6, 0.12);
  --input-bg: #f8fafc;
  --table-head: rgba(15, 23, 42, 0.04);
  --row-hover: rgba(15, 23, 42, 0.03);
  --nav-hover: rgba(15, 23, 42, 0.05);
  --btn-bg: #ffffff;
  --btn-hover: #f1f5f9;
  --surface-muted: #f1f5f9;
  --brand-text-1: #0f172a;
  --brand-text-2: #e09010;
  --mesh-1: rgba(79, 70, 229, 0.08);
  --mesh-2: rgba(var(--primary-rgb), 0.1);
  --mesh-3: rgba(22, 163, 74, 0.06);
  --grid-line: rgba(15, 23, 42, 0.04);
  --backdrop: rgba(15, 23, 42, 0.45);
  --sidebar-shadow: 4px 0 24px rgba(15, 23, 42, 0.08);
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
  --glass: blur(20px) saturate(160%);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Plus Jakarta Sans', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
}

/* Background mesh */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 10% 20%, var(--mesh-1) 0%, transparent 50%),
    radial-gradient(ellipse 60% 50% at 90% 80%, var(--mesh-2) 0%, transparent 50%),
    radial-gradient(ellipse 50% 40% at 50% 50%, var(--mesh-3) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
  transition: background 0.3s ease;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  /* background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px); */
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
  transition: background-image 0.3s ease;
}

.app {
  flex: 1;
  min-width: 0;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* ── Sidebar ── */
.sidebar {
  width: 268px;
  background: var(--sidebar);
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
  border-right: 1px solid var(--border);
  padding: 1.75rem 1.25rem;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  box-shadow: var(--sidebar-shadow);
  /* Pinned to the viewport. Only the nav LIST scrolls (see nav below): the
     shop's name and logo stay put at the top instead of sliding out of view.
     The mobile drawer overrides position further down. */
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

nav::-webkit-scrollbar { width: 6px; }
nav::-webkit-scrollbar-track { background: transparent; }
nav::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

.brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2.25rem;
  padding: 1rem 1.1rem;
  background: linear-gradient(135deg, rgba(var(--primary-rgb),0.15) 0%, rgba(var(--accent-rgb),0.1) 100%);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
}

.brand > div {
  flex: 1;
  min-width: 0;
}

.sidebar-close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  position: relative;
  z-index: 1;
}

.brand::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -30%;
  width: 100px;
  height: 100px;
  background: radial-gradient(circle, var(--primary-glow) 0%, transparent 70%);
  pointer-events: none;
}

/* The receipt control rides in the description cell beside the delete ✕, so it
   stays reachable on a phone where the ledger table already scrolls sideways. */
/* ── Audit log ─────────────────────────────────────────── */

.audit-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.audit-filters label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
  min-width: 0;
}

.audit-filters input,
.audit-filters select {
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-family: inherit;
  min-width: 0;
}

.audit-search { grid-column: span 2; }

.audit-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.audit-toolbar .hint { margin-inline-start: auto; }

/* A short, colour-coded word for the kind of change, so a page of entries can
   be skimmed for deletions without reading every line. */
.audit-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-inline-end: 0.4rem;
  background: var(--surface-muted);
  color: var(--muted);
}

.audit-badge.create { background: var(--success-glow); color: var(--success); }
.audit-badge.update { background: var(--warning-glow); color: var(--warning); }
.audit-badge.delete { background: var(--danger-glow); color: var(--danger); }

/* The shared table style centres its cells, which reads badly for a log of
   sentences and JSON. Everything here is left-aligned and top-aligned so rows
   of differing height stay scannable. */
.audit-table-wrap th,
.audit-table-wrap td {
  text-align: start;
  vertical-align: top;
}

.audit-who { font-weight: 700; }

/* The one-line answer to "kya hua": client, amount, products. */
.audit-summary {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}

.audit-role {
  display: inline-block;
  margin-inline-start: 0.35rem;
  font-size: 0.7rem;
  color: var(--muted);
}

.audit-detail summary {
  cursor: pointer;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
}

.audit-detail pre {
  margin: 0.4rem 0 0;
  padding: 0.5rem 0.6rem;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow: auto;
  color: var(--muted);
}

/* The table is dense; on a phone the card list replaces it entirely. */
.audit-list { display: none; }

@media (max-width: 768px) {
  .audit-table-wrap { display: none; }
  .audit-list { display: flex; flex-direction: column; gap: 0.6rem; }
  .audit-search { grid-column: span 2; }
  .audit-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 380px) {
  .audit-filters { grid-template-columns: 1fr; }
  .audit-search { grid-column: span 1; }
}

/* The shareable link to a shop's customer-facing rate page. */
.public-link-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.public-link-row input {
  flex: 1 1 220px;
  min-width: 0;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: inherit;
}

.public-rates-toggle { margin-top: 0.25rem; }

/* "Phone contacts se lein" inside the client/supplier/labour modals. The form
   is a stretched flex column, so without this the button spans the full row. */
.contact-pick {
  align-self: flex-start;
  margin-bottom: -0.35rem;
}

/* The flat whole-bill discount, sitting beside the total it reduces. */
.sell-bill-discount-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-inline-end: 0.9rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.sell-bill-discount-wrap input {
  width: 90px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
}

/* The eye on a password field: see what you typed before you submit it. */
.password-wrap {
  position: relative;
  display: block;
}

.password-wrap input {
  width: 100%;
  padding-right: 2.6rem;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 0.3rem;
  transform: translateY(-50%);
  width: 2.1rem;
  height: 2.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--muted);
}

.password-toggle:hover { color: var(--text); }
.password-toggle svg { width: 19px; height: 19px; }

/* An All-Transactions row opens its record on tap. */
.report-row-open { cursor: pointer; }
.report-row-open:hover td { background: var(--nav-hover); }

/* Image / PDF / Dono — the bill share chooser. */
.bill-share-options {
  display: flex;
  gap: 0.5rem;
}

.bill-share-options .btn {
  flex: 1 1 0;
  min-height: 52px;
}

/* Fix control on a wastage movement row — sits with the product name, like
   the ledger's own inline controls. */
.wastage-edit-btn {
  padding: 0.1rem 0.45rem;
  margin-inline-start: 0.4rem;
  line-height: 1.2;
  vertical-align: middle;
  white-space: nowrap;
}

.movement-card-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.45rem;
}

.ledger-row-receipt {
  padding: 0.15rem 0.5rem;
  line-height: 1.2;
  vertical-align: middle;
  white-space: nowrap;
}

.brand-icon {
  font-size: 2.25rem;
  filter: drop-shadow(0 2px 8px rgba(var(--primary-rgb),0.4));
  position: relative;
  z-index: 1;
  /* Fixed footprint whether the mark is the stock emoji or an uploaded logo,
     so swapping one for the other never shifts the name beside it. */
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* An uploaded shop logo, cropped to a circle inside that same box. */
.brand-icon.has-logo {
  border-radius: 50%;
  overflow: hidden;
  background: var(--card-solid);
  box-shadow: 0 0 0 1px var(--border-light), 0 2px 10px rgba(var(--primary-rgb), 0.35);
  /* The emoji's drop-shadow would trace the square image, not the circle. */
  filter: none;
}

.brand-icon .brand-logo {
  width: 100%;
  height: 100%;
  /* contain, not cover: a wide (text-banner) logo shows whole and small
     rather than being cropped to an unrecognisable centre slice. */
  object-fit: contain;
  display: block;
  border-radius: 50%;
  padding: 2px;
}

.brand h1 {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--brand-text-1) 0%, var(--brand-text-2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  position: relative;
  z-index: 1;
}

.brand p {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  position: relative;
  z-index: 1;
}

nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
  /* The scrolling part of the sidebar: brand above and footer below stay put. */
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;   /* breathing room so the thumb doesn't kiss the buttons */
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  text-align: left;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.nav-btn .nav-icon {
  font-size: 1.15rem;
  width: 1.5rem;
  text-align: center;
  opacity: 0.85;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* The stroke icons take the button's own colour, so the active page's icon
   lights up in the brand colour along with its label. */
.nav-icon svg {
  width: 19px;
  height: 19px;
  display: block;
}

.nav-btn:hover {
  background: var(--nav-hover);
  color: var(--text);
  border-color: var(--border);
  transform: translateX(3px);
}

.nav-btn.active {
  background: linear-gradient(135deg, rgba(var(--primary-rgb),0.25) 0%, rgba(var(--primary-rgb),0.08) 100%);
  color: var(--primary);
  font-weight: 700;
  border-color: rgba(var(--primary-rgb), 0.35);
  box-shadow: 0 4px 20px var(--primary-glow);
}

.nav-btn.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

/* ── Main Content ── */
.content {
  min-height: 100vh;
  padding: 1.75rem 2.25rem 2.5rem;
  overflow-y: auto;
  max-height: 100vh;
}

.content::-webkit-scrollbar { width: 6px; }
.content::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.topbar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex: 1;
  min-width: 0;
}

.topbar-foot {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.topbar-foot-row {
  display: contents;
}

.topbar-foot-details {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar-more-btn {
  display: none;
}

.topbar-dropdown-backdrop {
  display: none;
}

.topbar-logout-label {
  display: none;
}

.topbar-quick {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.topbar-logout-mobile.btn { display: none; }

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}

.topbar-left > div,
.topbar-title-block {
  min-width: 0;
}

.topbar-title-block {
  flex: 1;
}

.topbar-left > .topbar-more-btn {
  margin-left: auto;
  flex-shrink: 0;
}

.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
}

.menu-toggle span {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.25s, opacity 0.25s;
}

body.sidebar-open .menu-toggle span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

body.sidebar-open .menu-toggle span:nth-child(2) {
  opacity: 0;
}

body.sidebar-open .menu-toggle span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  z-index: 999;
  backdrop-filter: blur(4px);
}

.topbar-left h2 {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 0.2rem;
}

.topbar-sub {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
}

.topbar-date {
  font-size: 0.82rem;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-weight: 500;
  white-space: nowrap;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.25s ease;
  box-shadow: var(--shadow);
}

.theme-toggle:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  transform: translateY(-1px);
}

.theme-toggle .theme-icon { font-size: 1rem; line-height: 1; }

.page {
  display: none;
  animation: fadeUp 0.35s ease;
}

.page.active { display: block; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Stats Grid ── */
#dashboard-filter {
  margin-bottom: 1.15rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.15rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.4rem;
  position: relative;
  overflow: hidden;
  transition: transform 0.25s, box-shadow 0.25s, border-color 0.25s;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), transparent);
  opacity: 0.6;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--border-light);
}

.stat-card[data-page] {
  cursor: pointer;
}

.stat-card[data-page]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.stat-card.success::before { background: linear-gradient(90deg, var(--success), transparent); }
.stat-card.danger::before { background: linear-gradient(90deg, var(--danger), transparent); }
.stat-card.warning::before { background: linear-gradient(90deg, var(--warning), transparent); }

.stat-card .stat-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.stat-card .stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  background: rgba(var(--accent-rgb), 0.15);
  border: 1px solid rgba(var(--accent-rgb), 0.25);
}

.stat-card.success .stat-icon { background: var(--success-glow); border-color: rgba(34,197,94,0.3); }
.stat-card.danger .stat-icon { background: var(--danger-glow); border-color: rgba(239,68,68,0.3); }
.stat-card.warning .stat-icon { background: var(--warning-glow); border-color: rgba(245,158,11,0.3); }

.stat-card .label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-card .value {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.stat-card .sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.4rem;
  font-weight: 500;
}

.stat-card.success .value { color: var(--success); }
.stat-card.danger .value { color: var(--danger); }
.stat-card.warning .value { color: var(--warning); }

/* ── Cards ── */
.card {
  background: var(--card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  transition: border-color 0.25s;
}

.card:hover { border-color: var(--border-light); }

.card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.card-header .card-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  background: linear-gradient(135deg, rgba(var(--primary-rgb),0.2), rgba(var(--primary-rgb),0.05));
  border: 1px solid rgba(var(--primary-rgb),0.2);
}

.card h3 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.card-header h3 { margin: 0; }

.dashboard-mobile-fold .dashboard-fold-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  margin: 0 0 1.25rem;
  padding: 0 0 1rem;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: default;
}

.dashboard-mobile-fold .dashboard-fold-toggle h3 {
  flex: 1;
  min-width: 0;
}

.dashboard-fold-chevron {
  display: none;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text);
}

.dashboard-fold-chevron svg {
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
}

.dashboard-mobile-fold.dashboard-fold-open .dashboard-fold-chevron svg {
  transform: rotate(180deg);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead {
  background: var(--table-head);
}

th {
  padding: 0.85rem 1rem;
  text-align: left;
  color: var(--muted);
  font-weight: 900;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

td {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}

tbody tr {
  transition: background 0.15s;
  text-align: center;
}

tbody tr:hover td {
  background: var(--row-hover);
}

tbody tr:last-child td { border-bottom: none; }

.product-name {
  font-weight: 700;
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge.ok { background: var(--success-glow); color: var(--success); border: 1px solid rgba(34,197,94,0.3); }
.badge.low { background: var(--warning-glow); color: var(--warning); border: 1px solid rgba(245,158,11,0.3); }
.badge.credit { background: var(--danger-glow); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
.badge.cash { background: var(--success-glow); color: var(--success); border: 1px solid rgba(34,197,94,0.3); }
.badge.online { background: var(--success-glow); color: var(--success); border: 1px solid rgba(34,197,94,0.3); }
.badge.split { background: var(--warning-glow); color: var(--warning); border: 1px solid rgba(245,158,11,0.3); }

/* ── Buttons ── */
.btn {
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.6rem 1.15rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn:hover {
  background: var(--btn-hover);
  border-color: var(--border-light);
  transform: translateY(-1px);
}

.btn.primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: var(--primary-text);
  border: none;
  box-shadow: 0 4px 20px var(--primary-glow);
}

html[data-theme="light"] .btn.primary {
  /* Not a fixed white: --primary-text is chosen for contrast against whatever
     brand colour the shop picked. */
  color: var(--primary-text);
}

.btn.primary:hover {
  box-shadow: 0 6px 28px var(--primary-glow);
  transform: translateY(-2px); 
}

.btn.sm { padding: 0.38rem 0.75rem; font-size: 0.78rem; border-radius: 8px; }
.btn.danger { background: var(--danger-glow); color: var(--danger); border-color: rgba(239,68,68,0.3); }
.btn.whatsapp { background: linear-gradient(135deg, #25d366, #1da851); color: #fff; border: none; box-shadow: 0 4px 16px rgba(37,211,102,0.35); }
.btn.whatsapp:hover { box-shadow: 0 6px 24px rgba(37,211,102,0.45); }

.page-actions { margin-bottom: 1.25rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.page-actions label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; }

/* ── Date filter bar ── */
.filter-bar {
  margin-bottom: 0.85rem;
  padding: 0.65rem 0.75rem;
  background: var(--card-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.filter-bar-row {
  display: flex;
  align-items: stretch;
  gap: 0.55rem;
  min-width: 0;
}

.filter-date-input {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  width: 9.5rem;
  cursor: pointer;
}

.filter-date-input input[type="date"] {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.65rem 0.75rem 0.65rem 2.35rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-family: inherit;
  font-weight: 500;
  min-height: 44px;
  color-scheme: dark;
  transition: border-color 0.2s, box-shadow 0.2s;
  cursor: pointer;
  position: relative;
}

html[data-theme="light"] .filter-date-input input[type="date"] {
  color-scheme: light;
}

.filter-date-input input[type="date"]:focus {
  outline: none;
  border-color: rgba(var(--primary-rgb), 0.5);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.filter-date-input .filter-date-icon {
  position: absolute;
  left: 0.8rem;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  color: var(--muted);
  pointer-events: none;
}

.filter-date-input .filter-date-icon svg {
  width: 100%;
  height: 100%;
}

.filter-date-input input[type="date"]::-webkit-calendar-picker-indicator {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.filter-actions {
  display: flex;
  gap: 0.45rem;
  flex-shrink: 0;
  margin-left: auto;
}

.filter-btn {
  min-height: 44px;
  min-width: 5.25rem;
  padding: 0.55rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ── Forms ── */
.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.form label.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.form label.checkbox-label input[type="checkbox"] {
  width: auto;
  min-width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  padding: 0;
  flex-shrink: 0;
  accent-color: var(--primary);
}

.form input, .form select, .form textarea {
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 500;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form input:focus, .form select:focus {
  outline: none;
  border-color: rgba(var(--primary-rgb), 0.5);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.form input[readonly] {
  opacity: 0.85;
  cursor: default;
  color: var(--primary);
  font-weight: 600;
}

.form select { cursor: pointer; }

/* ── Searchable select (sell client) ── */
.sell-client-field {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.ss-native-hidden { display: none !important; }

.searchable-select { position: relative; }

.ss-control {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}
.ss-control[aria-expanded="true"],
.ss-control:focus {
  outline: none;
  border-color: rgba(var(--primary-rgb), 0.5);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.ss-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss-value.placeholder { color: var(--muted); font-weight: 500; }
.ss-caret { color: var(--muted); font-size: 0.8rem; flex-shrink: 0; }

.ss-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--card, var(--input-bg));
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ss-search-wrap { padding: 0.5rem; border-bottom: 1px solid var(--border); }
.ss-search {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
}
.ss-search:focus { outline: none; border-color: rgba(var(--primary-rgb), 0.5); }

/* ~10 rows tall, then scroll. */
.ss-options {
  list-style: none;
  margin: 0;
  padding: 0.25rem;
  max-height: 360px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.ss-option {
  display: block;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: transparent;
  text-align: left;
}
.ss-option:hover { background: var(--row-hover); }
.ss-option.selected { background: var(--primary-glow); color: var(--primary); font-weight: 700; }
.ss-empty { padding: 0.75rem; color: var(--muted); font-size: 0.85rem; text-align: center; }

/* "Other" pinned at the bottom, always visible below the scroll area. */
.ss-pinned {
  border-top: 1px solid var(--border);
  padding: 0.25rem;
  background: var(--table-head);
}
.ss-pinned.hidden { display: none; }
.ss-pinned-option { width: 100%; }

.form-inline {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.form-inline input {
  flex: 1;
  min-width: 0;
}

.form-inline select {
  flex: 0 0 auto;
  min-width: 5.5rem;
}

.form-inline .btn.sm {
  flex-shrink: 0;
  min-width: 3.5rem;
  padding: 0.45rem 0.65rem;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

input[type="number"].has-spinners::-webkit-outer-spin-button,
input[type="number"].has-spinners::-webkit-inner-spin-button {
  -webkit-appearance: inner-spin-button;
  opacity: 1;
  margin: 0;
}

input[type="number"].has-spinners {
  -moz-appearance: number-input;
  appearance: auto;
}

.discount-inline {
  align-items: center;
}

.discount-dir-btns {
  display: flex;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--card);
}

.discount-dir-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0 0.65rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s, color 0.2s;
}

.discount-dir-btn + .discount-dir-btn {
  border-left: 1px solid var(--border);
}

.discount-dir-btn.active {
  background: linear-gradient(135deg, rgba(var(--primary-rgb),0.25) 0%, rgba(var(--primary-rgb),0.08) 100%);
  color: var(--primary);
}

.discount-dir-btn[data-dir="down"].active {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.2) 0%, rgba(34, 197, 94, 0.06) 100%);
  color: var(--success);
}

.discount-dir-btn[data-dir="up"].active {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.18) 0%, rgba(239, 68, 68, 0.06) 100%);
  color: var(--danger);
}

.daybook-disc-down { color: var(--success); font-weight: 600; }
.daybook-disc-up { color: var(--danger); font-weight: 600; }

.rate-input {
  width: 100%;
  min-width: 7rem;
  max-width: 10rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 600;
}

.rate-input:focus {
  outline: none;
  border-color: rgba(var(--primary-rgb), 0.5);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.rate-tray, .rate-dozen {
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.form input[readonly] {
  background: var(--surface-2, #f5f5f5);
  color: var(--muted);
  cursor: default;
}

.total-preview {
  font-size: 1rem;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, rgba(var(--primary-rgb),0.1), rgba(var(--primary-rgb),0.03));
  border-radius: var(--radius-sm);
  border: 1px solid rgba(var(--primary-rgb), 0.25);
  font-weight: 600;
}

.total-preview strong {
  color: var(--primary);
  font-size: 1.4rem;
  font-weight: 800;
}

.hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 1rem;
  font-weight: 500;
}

.hidden { display: none !important; }

/* "Bol kar entry" on the dashboard: the launcher card and the popup with
   the big microphone, the examples and what was understood. */
.voice-launcher {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(var(--accent-rgb), 0.22), rgba(var(--primary-rgb), 0.12)), var(--card-solid);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow);
}
.voice-launcher-icon {
  width: 56px; height: 56px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 1.6rem;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  box-shadow: 0 0 0 6px rgba(var(--accent-rgb), 0.15);
}
.voice-launcher-text { display: grid; gap: 0.15rem; flex: 1 1 220px; min-width: 0; }
.voice-launcher-text strong { font-size: 1.1rem; }
.voice-launcher-text span { color: var(--muted); font-size: 0.9rem; }
.voice-launcher-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.voice-launcher-size {
  flex: none; margin-left: auto; width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border-light); background: var(--btn-bg); color: var(--muted);
  cursor: pointer; font-size: 0.95rem; line-height: 1;
}
.voice-launcher-size:hover { background: var(--btn-hover); color: var(--text); }
.voice-launcher--min { padding: 0.5rem 0.85rem; gap: 0.6rem; margin-bottom: 1rem; box-shadow: none; }
.voice-launcher--min .voice-launcher-icon { width: 34px; height: 34px; font-size: 1rem; box-shadow: none; }
.voice-launcher--min .voice-launcher-text { flex: 0 1 auto; }
.voice-launcher--min .voice-launcher-text strong { font-size: 0.95rem; }
/* Phones: title row with the size button, then the two buttons side by side
   on one line, splitting the width. */
@media (max-width: 640px) {
  .voice-launcher, .voice-launcher--min {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "icon text size" "actions actions actions";
    align-items: center;
    column-gap: 0.75rem;
    row-gap: 0.6rem;
  }
  .voice-launcher--min { row-gap: 0.5rem; }
  .voice-launcher-icon { grid-area: icon; }
  .voice-launcher-text { grid-area: text; }
  .voice-launcher-size { grid-area: size; margin-left: 0; }
  .voice-launcher-actions {
    grid-area: actions;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0.5rem;
  }
  .voice-launcher-actions .btn {
    width: 100%;
    justify-content: center;
    white-space: nowrap;
    padding-inline: 0.5rem;
    font-size: 0.9rem;
  }
}

dialog.voice-modal {
  width: min(560px, 94vw);
  border: 0; padding: 0;
  border-radius: var(--radius);
  background: var(--card-solid);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog.voice-modal::backdrop { background: var(--backdrop); backdrop-filter: blur(4px); }
.voice-modal-inner { padding: 1.1rem 1.25rem 1.25rem; display: grid; gap: 0.9rem; max-height: 92vh; overflow-y: auto; }
.voice-modal-head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; }
.voice-modal-head h3 { margin: 0; font-size: 1.15rem; }
.voice-seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  background: var(--surface-muted); border-radius: 999px;
}
.voice-seg button {
  border: 0; background: transparent; color: var(--muted); padding: 0.5rem;
  border-radius: 999px; font-weight: 700; cursor: pointer; font-size: 0.95rem;
}
.voice-seg button.active { background: var(--card-solid); color: var(--text); box-shadow: var(--shadow); }
.voice-stage { display: grid; justify-items: center; gap: 0.6rem; padding: 0.4rem 0 0; }
.voice-mic {
  position: relative; width: 92px; height: 92px; border-radius: 50%; border: 0; cursor: pointer;
  font-size: 2.2rem; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--primary));
  box-shadow: 0 10px 30px rgba(var(--accent-rgb), 0.35);
  transition: transform 0.15s ease;
}
.voice-mic:active { transform: scale(0.96); }
.voice-mic:disabled { opacity: 0.5; cursor: not-allowed; }
.voice-mic.live { background: linear-gradient(135deg, var(--danger), #f97316); }
.voice-mic.live::after {
  content: ''; position: absolute; inset: -8px; border-radius: 50%;
  border: 3px solid rgba(239, 68, 68, 0.6);
  animation: voice-ring 1.2s ease-out infinite;
}
@keyframes voice-ring { 0% { transform: scale(0.9); opacity: 1; } 100% { transform: scale(1.35); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .voice-mic.live::after { animation: none; } }
.voice-stage-status { font-weight: 600; color: var(--muted); text-align: center; min-height: 1.4em; }
.voice-stage-status.live { color: var(--danger); }
.voice-stage-status.ok { color: var(--success); }
.voice-stage-status.warn { color: var(--warning); }
.voice-examples { display: grid; gap: 0.4rem; }
.voice-examples-title { font-size: 0.76rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.voice-example {
  text-align: left; border: 1px solid var(--border); background: var(--btn-bg); color: var(--text);
  padding: 0.55rem 0.75rem; border-radius: var(--radius-sm); cursor: pointer; font-size: 0.92rem;
}
.voice-example:hover { background: var(--btn-hover); }
.voice-modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; }

/* "Bol kar entry": the microphone strip at the top of the Sale and Adaigi
   forms — button, language switch, what was heard, what was understood. */
.voice-panel {
  grid-column: 1 / -1;
  display: grid;
  gap: 0.4rem;
  padding: 0.6rem 0.75rem;
  border-radius: 12px;
  border: 1px dashed rgba(127, 127, 127, 0.35);
  background: rgba(99, 102, 241, 0.06);
  margin-bottom: 0.25rem;
}
.voice-row { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.voice-btn { font-weight: 700; }
.voice-btn.live {
  background: var(--danger);
  color: #fff;
  animation: voice-pulse 1.2s ease-in-out infinite;
}
@keyframes voice-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.45); } 50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); } }
@media (prefers-reduced-motion: reduce) { .voice-btn.live { animation: none; } }
.voice-lang { display: inline-flex; border: 1px solid rgba(127,127,127,0.35); border-radius: 999px; overflow: hidden; }
.voice-lang button {
  border: 0; background: transparent; color: inherit; padding: 0.25rem 0.7rem; font-size: 0.82rem; cursor: pointer;
}
.voice-lang button.active { background: var(--primary, #6366f1); color: #fff; }
.voice-status { font-size: 0.82rem; color: var(--muted); }
.voice-status.live { color: var(--danger); font-weight: 600; }
.voice-status.ok { color: var(--success); font-weight: 600; }
.voice-status.warn { color: var(--warning); font-weight: 600; }
.voice-hint { font-size: 0.78rem; color: var(--muted); }
.voice-transcript { font-size: 0.95rem; padding: 0.35rem 0.5rem; border-radius: 8px; background: rgba(127,127,127,0.12); direction: auto; }
.voice-transcript.interim { opacity: 0.6; font-style: italic; }
.voice-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.voice-chip {
  font-size: 0.82rem; padding: 0.2rem 0.55rem; border-radius: 999px;
  background: var(--success-glow); color: var(--success); border: 1px solid rgba(34,197,94,0.3);
}
.voice-chip-warn { color: var(--warning); }

/* Offline: the strip in the topbar that says the data is stale and how many
   entries wait in the outbox, and the draft rows woven into the lists. */
.offline-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem 0.75rem;
  flex-wrap: wrap;
  margin: 0 0 1rem;
  padding: 0.5rem 0.85rem;
  border-radius: 12px;
  background: var(--warning-glow);
  color: var(--warning);
  border: 1px solid rgba(245,158,11,0.35);
  font-size: 0.85rem;
  font-weight: 600;
}
.offline-bar-text { flex: 1 1 200px; min-width: 0; }
.offline-bar .btn { flex: none; }
.offline-bar.is-offline { background: var(--danger-glow); color: var(--danger); border-color: rgba(239,68,68,0.35); }
.offline-bar.has-failed { background: var(--danger-glow); color: var(--danger); border-color: rgba(239,68,68,0.35); }
.offline-bar-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.offline-bar .btn { padding: 0.15rem 0.55rem; }
.draft-row td { background: var(--warning-glow); }
.draft-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.6rem;
  font-size: 0.88rem;
}
.draft-kind { font-weight: 700; }
.draft-time, .draft-error { color: var(--muted); font-size: 0.8rem; }
.draft-error { color: var(--danger); flex-basis: 100%; }
.draft-actions { margin-left: auto; display: inline-flex; gap: 0.3rem; }
.draft-card { border-left: 3px solid var(--warning); }
.drafts-list { display: grid; gap: 0.5rem; max-height: 60vh; overflow-y: auto; }
.draft-item {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border, rgba(127,127,127,0.25));
  border-radius: 10px;
}
.draft-item.failed { border-color: rgba(239,68,68,0.5); }

/* Under the sale / purchase report: how many peti of each egg. */
.report-breakdown { margin-top: 1rem; }
.report-breakdown h4 { margin: 0 0 0.5rem; font-size: 0.95rem; }
.report-breakdown table { width: 100%; max-width: 560px; }
.report-breakdown td.num, .report-breakdown th.num { text-align: right; font-variant-numeric: tabular-nums; }
.report-breakdown tfoot td { font-weight: 800; border-top: 2px solid var(--border-light); }

/* Product form: the egg fields and the aam-item fields swap in and out but
   keep the form's own grid. */
.product-fields { display: contents; }
.product-fields.hidden { display: none !important; }
.badge.general { background: rgba(var(--accent-rgb), 0.18); color: var(--accent); border: 1px solid rgba(var(--accent-rgb), 0.35); }

/* Several udhar / deni lines at once: date, amount, note, remove. */
.manual-lines-head, .manual-line {
  display: grid;
  grid-template-columns: minmax(0, 9rem) minmax(0, 8rem) minmax(0, 1fr) 2.2rem;
  gap: 0.5rem;
  align-items: center;
}
.manual-lines-head { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.manual-lines { display: grid; gap: 0.5rem; }
.manual-line input { width: 100%; min-width: 0; }
.manual-total { text-align: right; font-size: 1rem; }
@media (max-width: 640px) {
  .manual-lines-head { display: none; }
  .manual-line { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 2.2rem; }
  .manual-line .manual-notes { grid-column: 1 / 3; }
}

/* Client khata on a phone: a big balance, action chips, search, three-column
   entries (details · udhar diya · adaigi mili) and two big buttons at the foot.
   On a desktop the table and the old footer stay as they were. */
.ledger-hero, .ledger-search, .ledger-cols-head, .ledger-btn-short { display: none; }
.ledger-call { display: none; }
.ledger-row { display: grid; grid-template-columns: minmax(0, 1fr) 5.9rem 5.9rem; border-bottom: 1px solid var(--border); }
.ledger-row-main { padding: 0.6rem 0.5rem 0.6rem 0.75rem; display: grid; gap: 0.2rem; min-width: 0; }
.ledger-row-date { font-size: 0.72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ledger-row-desc { font-size: 0.86rem; font-weight: 600; overflow-wrap: anywhere; }
.ledger-row-bal { justify-self: start; font-size: 0.72rem; font-weight: 700; padding: 0.12rem 0.45rem; border-radius: 6px; }
.ledger-row-bal.due { background: var(--danger-glow); color: var(--danger); }
.ledger-row-bal.advance { background: var(--success-glow); color: var(--success); }
.ledger-row-bal.clear { background: var(--btn-bg); color: var(--muted); }
.ledger-row-actions { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.ledger-row-actions .btn { padding: 0.15rem 0.5rem; font-size: 0.74rem; min-height: 0; }
.ledger-row-gave, .ledger-row-got { display: flex; align-items: center; justify-content: flex-end; padding: 0.6rem 0.65rem; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 0.92rem; }
.ledger-row-gave { background: rgba(239, 68, 68, 0.07); color: var(--danger); }
.ledger-row-got { color: var(--success); }

@media (max-width: 768px) {
  #client-ledger-view .ledger-call:not(.hidden) {
    display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
    border: 1px solid var(--border); background: var(--btn-bg); text-decoration: none; font-size: 1.1rem; flex: none;
  }
  #client-ledger-view .ledger-hero {
    display: grid; gap: 0.75rem; margin: 0.75rem 0 0; padding: 0.9rem; border-radius: 14px;
    background: var(--card-solid); border: 1px solid var(--border);
  }
  .ledger-hero-balance { display: grid; gap: 0.1rem; padding-bottom: 0.7rem; border-bottom: 1px solid var(--border); }
  .ledger-hero-balance strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
  .ledger-hero-balance span { font-size: 0.85rem; color: var(--muted); }
  #client-ledger-hero.due .ledger-hero-balance strong { color: var(--danger); }
  #client-ledger-hero.advance .ledger-hero-balance strong { color: var(--success); }
  .ledger-hero-chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.45rem; }
  .ledger-chip {
    display: grid; justify-items: center; gap: 0.2rem; padding: 0.55rem 0.2rem; border-radius: 12px;
    border: 1px solid var(--border); background: var(--btn-bg); color: var(--text); font-size: 0.74rem; font-weight: 600; cursor: pointer;
  }
  .ledger-chip span:first-child { font-size: 1.15rem; }
  .ledger-chip.active { border-color: var(--primary); }
  #client-ledger-view .ledger-search {
    display: flex; align-items: center; gap: 0.5rem; margin-top: 0.75rem; padding: 0 0.75rem;
    border: 1px solid var(--border); border-radius: 12px; background: var(--input-bg);
  }
  #client-ledger-view .ledger-search input { flex: 1; border: 0; background: transparent; padding: 0.7rem 0; color: var(--text); min-width: 0; }
  #client-ledger-view .ledger-search input:focus { outline: none; }
  /* The date filter and the summary box fold away behind the Tareekh chip. */
  #client-ledger-view:not(.ledger-filters-open) .ledger-filters { display: none; }
  #client-ledger-view .client-ledger-fp-body > .ledger-summary { display: none; }
  #client-ledger-view .ledger-cols-head {
    display: grid; grid-template-columns: minmax(0, 1fr) 5.9rem 5.9rem; margin-top: 0.75rem;
    font-size: 0.74rem; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border);
  }
  #client-ledger-view .ledger-cols-head span { padding: 0.45rem 0.65rem; text-align: right; }
  #client-ledger-view .ledger-cols-head span:first-child { text-align: left; padding-left: 0.75rem; }
  #client-ledger-view #client-ledger-list { padding-top: 0; gap: 0; background: var(--card-solid); border-radius: 0 0 12px 12px; }
  #client-ledger-view #client-ledger-list .draft-card { border-radius: 0; }
  /* Foot: share buttons move up into the chips; two big coloured buttons remain. */
  #client-ledger-view .client-ledger-fp-foot { flex-direction: row; gap: 0.6rem; }
  #client-ledger-view .client-ledger-fp-foot .ledger-share-actions { display: none; }
  #client-ledger-view .client-ledger-fp-foot > .btn { flex: 1; min-height: 50px; font-weight: 800; letter-spacing: 0.02em; border: 0; color: #fff; }
  #client-ledger-view .ledger-gave-btn { background: #b91c1c; }
  #client-ledger-view .ledger-got-btn { background: #15803d; }
  #client-ledger-view .ledger-btn-long { display: none; }
  #client-ledger-view .ledger-btn-short { display: inline; }
}

/* Stock page: hand correction of a product's count. */
.stock-adjust-set-btn { justify-self: start; }
.stock-adjust-set-btn.active { border-color: var(--primary); color: var(--primary); }
.stock-adjust-preview-line strong.up { color: var(--success); }
.stock-adjust-preview-line strong.down { color: var(--danger); }
.inventory-card .stock-adjust-btn { margin-top: 0.5rem; }

.reminder-card-preview img {
  display: block;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  border-radius: 12px;
  box-shadow: var(--shadow);
  background: #fff;
}
dialog.reminder-card-modal { max-width: 520px; }

/* Platform admin: how far into its subscription each shop is. Green while
   there is time, amber in the last days, red once the days are used up. */
.sub-badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.sub-badge.ok { background: var(--success-glow); color: var(--success); border: 1px solid rgba(34,197,94,0.3); }
.sub-badge.warn { background: var(--warning-glow); color: var(--warning); border: 1px solid rgba(245,158,11,0.35); }
.sub-badge.over { background: var(--danger); color: #fff; border: 1px solid var(--danger); }
.sub-meta { font-size: 0.78rem; color: var(--muted); margin-top: 0.25rem; white-space: nowrap; }
tr.sub-over td { background: var(--danger-glow); }
tr.sub-over td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
@media (max-width: 640px) { .form-row-2 { grid-template-columns: 1fr; } }

/* Under Baqi on a credit sale: the bank accounts the invoice will print. */
.sell-bank-note {
  margin: -0.35rem 0 0.75rem;
  line-height: 1.45;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  background: var(--panel-soft, rgba(99, 102, 241, 0.08));
}

.mobile-only { display: none; }
.desktop-only { display: block; }

/* ── Sell page ── */
.sell-layout {
  display: block;
}

.sell-actions-bar {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.sell-actions-bar .btn {
  min-height: 46px;
  font-size: 1rem;
}

.sell-actions-bar .date-range-picker {
  align-self: stretch;
  width: 100%;
}

/* Daily Product page filter bar. */
.daily-toolbar {
  margin-bottom: 1rem;
}

.daily-period-badge {
  margin-left: 0.5rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--surface-muted, rgba(255, 165, 0, 0.12));
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 600;
  vertical-align: middle;
  white-space: nowrap;
}

.daily-period-badge:empty {
  display: none;
}

/* Expense summary shows a single total card — keep it compact instead of
   stretching across the full row. */
#expense-summary-bar {
  grid-template-columns: minmax(0, 280px);
  margin-bottom: 1rem;
}

/* Purchase page toolbar: New Purchase button on the first line, the date +
   product filters on a second line below it. */
.purchase-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.purchase-new-btn {
  align-self: flex-start;
  min-height: 46px;
  font-size: 1rem;
}

.purchase-filter-row {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
}

.purchase-filter-row .date-range-picker {
  width: 100%;
}

.purchase-product-filter {
  width: 100%;
  margin: 0;
}

.purchase-product-filter select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.9rem;
  min-height: 44px;
  cursor: pointer;
}

@media (min-width: 900px) {
  .purchase-filter-row {
    flex-direction: row;
    align-items: center;
  }

  .purchase-filter-row .date-range-picker {
    flex: 1 1 auto;
    width: auto;
  }

  .purchase-product-filter {
    width: auto;
    min-width: 200px;
    flex: 0 0 auto;
  }
}

.purchase-history-mobile {
  margin-top: 0.75rem;
}

.purchase-history-mobile .btn,
.expenses-history-mobile .btn {
  width: 100%;
  min-height: 46px;
  justify-content: center;
}

.expenses-history-mobile {
  margin-top: 0.75rem;
}

.inventory-list,
.movements-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

#page-inventory .inventory-list.mobile-only {
  display: none;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 0.85rem;
}

.pagination-left,
.pagination-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pagination-left label {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.pagination-select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.pagination-info {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
  min-width: 5.5rem;
  text-align: right;
}

.pagination .btn.sm:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.inventory-card,
.movement-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.85rem;
  background: var(--bg);
}

.inventory-card-top,
.movement-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.inventory-card-name,
.movement-card-product {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.3;
}

.movement-card-qty {
  font-weight: 800;
  white-space: nowrap;
}

.inventory-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.inventory-card-meta strong,
.inventory-card-value strong {
  color: var(--text);
}

.inventory-card-value {
  font-size: 0.82rem;
  color: var(--muted);
}

.movement-card-date {
  font-size: 0.75rem;
  color: var(--muted);
}

.inventory-changes-mobile {
  margin-top: 0.75rem;
}

.inventory-changes-mobile .btn {
  width: 100%;
  min-height: 46px;
  justify-content: center;
}

#sell-modal:not([open]) {
  display: none !important;
}

#sell-modal.sell-modal:not([open]),
#purchase-modal.sell-modal:not([open]),
#expense-modal.sell-modal:not([open]) {
  display: none !important;
}

/* Sale-form full-screen page header bar. */
.sell-modal-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(255, 165, 0, 0.12), transparent 60%), var(--card-solid);
}

.sell-modal-header h3 {
  margin: 0;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}

.sell-modal-header .btn {
  flex-shrink: 0;
}

/* Split payment: cash + online amount fields with a stuck-on suffix tag. */
.sell-pay-block {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.sell-other-client {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.6rem;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.sell-other-client > label {
  min-width: 0;
  max-width: 100%;
}

.sell-other-client input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.sell-other-client.hidden {
  display: none;
}

@media (max-width: 760px) {
  .sell-other-client {
    grid-template-columns: 1fr;
  }
}

.sell-pay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.sell-pay-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.input-suffix {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  overflow: hidden;
}

.input-suffix:focus-within {
  border-color: var(--primary);
}

.input-suffix input {
  border: none;
  background: transparent;
  flex: 1;
  min-width: 0;
  border-radius: 0;
}

.input-suffix input:focus {
  outline: none;
  box-shadow: none;
}

.input-suffix-tag {
  display: flex;
  align-items: center;
  padding: 0 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-muted);
  border-left: 1px solid var(--border);
  white-space: nowrap;
}

/* Sale form as a centered popup dialog. Native dialog centering (inset:0 +
   margin:auto) is used instead of a top:50% transform — the transform trick
   caps the auto height at half the viewport and clips the form. */
#sell-modal.sell-modal,
#purchase-modal.sell-modal,
#expense-modal.sell-modal {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(960px, 92vw);
  max-width: min(960px, 92vw) !important;
  height: fit-content;
  max-height: 92vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card-solid);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 2000;
  box-shadow: var(--shadow-lg);
  animation: sellModalIn 0.25s ease;
}

@keyframes sellModalIn {
  from { opacity: 0; transform: scale(0.97) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Two-column layout: products on the left, payment on the right —
   the whole form fits on screen without scrolling. */
.sell-form-cols {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

.sell-col {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
}

.sell-col-payment {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
}

#sell-modal.sell-modal::backdrop,
#purchase-modal.sell-modal::backdrop,
#expense-modal.sell-modal::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1999;
}

/* Stack the two columns when the popup gets narrow. */
@media (max-width: 760px) {
  .sell-form-cols {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* On small screens the popup becomes full-screen for easier form entry. */
@media (max-width: 640px) {
  #sell-modal.sell-modal,
  #purchase-modal.sell-modal,
  #expense-modal.sell-modal {
    width: 100%;
    max-width: none !important;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: none;
  }
}

.sell-modal-form {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  width: 100%;
  padding: 1.25rem 1.5rem 0;
  align-content: start;
}

.sell-modal-form::-webkit-scrollbar {
  display: none;
}

.sell-lines {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sell-line {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.sell-line > label {
  gap: 0.3rem;
}

.sell-line-product-field {
  gap: 0.2rem;
}

.sell-line-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  line-height: 1.2;
}

.sell-line .sell-line-product {
  padding: 0.55rem 0.75rem;
}

.sell-line-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.sell-line-num {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.sell-line-remove {
  padding: 0.2rem 0.45rem;
  min-width: auto;
  line-height: 1;
}

.sell-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.sell-modal-footer {
  position: sticky;
  bottom: 0;
  margin: 0.75rem -1.5rem 0;
  padding: 0.85rem 1.5rem calc(0.85rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--card-solid);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.sell-modal-footer .total-preview {
  margin: 0;
  flex: 1;
}

.sell-modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0;
}

.sell-modal-actions .btn.primary {
  flex: 1;
  min-width: 220px;
  min-height: 48px;
  font-size: 1rem;
}


.sales-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

#page-sell .sales-list.mobile-only {
  display: none;
}

#page-dashboard .sales-list.mobile-only {
  display: none;
}

.sale-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
  background: var(--bg);
}

.sale-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.sale-card-product {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.3;
}

.sale-card-total {
  font-weight: 800;
  color: var(--primary);
  font-size: 1rem;
  white-space: nowrap;
}

.sale-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
}

.sale-card-meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.sale-card-actions {
  display: flex;
  gap: 0.4rem;
}

.sale-card-actions .btn {
  flex: 1;
  min-height: 38px;
  padding: 0.35rem 0.5rem;
}

.sales-empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
  font-size: 0.9rem;
}

/* ── Clients page ── */
.clients-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  align-items: start;
}

.client-page-actions {
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.client-search-input {
  min-width: 220px;
  padding: 0.55rem 0.85rem;
  font-size: 0.88rem;
  font-family: inherit;
  font-weight: 500;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.client-search-input:focus {
  outline: none;
  border-color: rgba(var(--primary-rgb), 0.5);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.client-filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.88rem;
  font-weight: 600;
  margin: 0;
  cursor: pointer;
}

.clients-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

#page-clients .clients-list.mobile-only {
  display: none;
}

.products-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

#page-products .products-list.mobile-only {
  display: none;
}

.product-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.85rem;
  background: var(--bg);
}

.product-card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.35rem;
}

.product-card-name {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.3;
}

.product-card-rate {
  font-weight: 800;
  color: var(--primary);
  font-size: 0.95rem;
  white-space: nowrap;
}

.product-card-stock {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
}

.product-card-stock strong {
  color: var(--text);
}

.product-card-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.product-card-actions .btn.icons {
  flex: 0 0 42px;
  width: 42px;
  min-width: 42px;
  min-height: 38px;
  padding: 0;
}

.product-card-actions .btn:not(.icons) {
  flex: 1 1 calc(50% - 0.25rem);
  min-height: 38px;
  min-width: 0;
}

.users-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

#page-users .users-list.mobile-only {
  display: none;
}

.suppliers-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

#page-suppliers .suppliers-list.mobile-only {
  display: none;
}

.supplier-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.85rem;
  background: var(--bg);
}

.supplier-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.supplier-card-name {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.supplier-card-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  flex-shrink: 0;
  gap: 0.4rem;
  align-items: center;
}

.supplier-card-actions .btn.icons {
  flex: 0 0 42px;
  width: 42px;
  min-width: 42px;
  min-height: 38px;
  padding: 0;
}

.supplier-detail-body {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin: 1rem 0;
}

.supplier-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.supplier-detail-row span {
  color: var(--muted);
  flex-shrink: 0;
}

.supplier-detail-row strong {
  text-align: right;
  font-weight: 600;
  word-break: break-word;
}

.labour-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

#page-labour .labour-list.mobile-only {
  display: none;
}

.labour-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.85rem;
  background: var(--bg);
}

.labour-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.labour-card-name {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.labour-card-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  flex-shrink: 0;
  gap: 0.4rem;
  align-items: center;
}

.labour-card-actions .btn.icons {
  flex: 0 0 42px;
  width: 42px;
  min-width: 42px;
  min-height: 38px;
  padding: 0;
}

.labour-detail-body {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin: 1rem 0;
}

.labour-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.labour-detail-row span {
  color: var(--muted);
  flex-shrink: 0;
}

.labour-detail-row strong {
  text-align: right;
  font-weight: 600;
  word-break: break-word;
}

.user-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.85rem;
  background: var(--bg);
}

.user-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.user-card-name {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.3;
}

.user-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
}

.user-card-username {
  font-weight: 600;
  color: var(--text);
}

.user-card-status.active {
  color: var(--success);
  font-weight: 700;
}

.user-card-status.inactive {
  color: var(--danger);
  font-weight: 700;
}

.user-card-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.user-card-actions .btn {
  flex: 1 1 calc(50% - 0.25rem);
  min-height: 38px;
  min-width: 0;
}

.client-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.85rem;
  background: var(--bg);
  cursor: pointer;
}

.client-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.client-card-top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.25rem;
}

.client-card-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.client-card-balance {
  font-weight: 800;
  white-space: nowrap;
}

.client-card-balance.due {
  color: var(--danger);
}

.client-card-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
}

.client-card-actions {
  display: flex;
  gap: 0.4rem;
}

.client-card-actions .btn {
  flex: 1;
  min-height: 38px;
}

.ledger-share-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.ledger-share-actions .btn {
  min-height: 36px;
  white-space: nowrap;
}

.ledger-table-scroll {
  position: relative;
}

.ledger-table-scroll table {
  table-layout: fixed;
  width: 100%;
  border-collapse: collapse;
}

.ledger-table-scroll thead th {
  background: var(--card-solid);
  box-shadow: 0 1px 0 var(--border);
  padding: 0.7rem 0.55rem;
  font-size: 0.72rem;
  vertical-align: middle;
}

.ledger-table-scroll tbody td {
  padding: 0.65rem 0.55rem;
  vertical-align: top;
  line-height: 1.35;
  background: var(--card-solid);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.ledger-table-scroll tbody tr:hover td {
  background: var(--surface-muted);
}

.ledger-table-scroll th:nth-child(1),
.ledger-table-scroll td:nth-child(1) {
  width: 17%;
  font-size: 0.78rem;
  white-space: nowrap;
}

.ledger-table-scroll th:nth-child(2),
.ledger-table-scroll td:nth-child(2) {
  width: 38%;
  text-align: left;
  font-size: 0.8rem;
}

.ledger-table-scroll th:nth-child(3),
.ledger-table-scroll td:nth-child(3),
.ledger-table-scroll th:nth-child(4),
.ledger-table-scroll td:nth-child(4) {
  width: 16%;
  white-space: nowrap;
}

.ledger-table-scroll th:nth-child(5),
.ledger-table-scroll td:nth-child(5) {
  width: 13%;
  font-size: 0.78rem;
  line-height: 1.3;
}

.ledger-table-scroll tbody tr:last-child td {
  border-bottom: 1px solid var(--border);
}

.ledger-filters {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.ledger-filters label {
  margin: 0;
  font-size: 0.78rem;
}

/* ── Date range picker ── */
.date-range-picker {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: 100%;
}

.date-range-presets {
  display: flex;
  gap: 0.3rem;
  padding: 0.28rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.date-range-preset {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  padding: 0.4rem 0.35rem;
  border: none;
  border-radius: calc(var(--radius-sm) - 4px);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.date-range-preset:hover {
  color: var(--text);
  background: var(--btn-hover);
}

.date-range-preset.active {
  background: var(--card-solid);
  color: var(--text);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.12);
}

html[data-theme="dark"] .date-range-preset.active {
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
}

.date-range-custom-row {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
}

.date-range-field {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}

.date-range-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.date-range-sep {
  flex-shrink: 0;
  color: var(--muted);
  padding-bottom: 0.55rem;
  font-weight: 600;
  opacity: 0.7;
}

.filter-date-input-sm {
  width: 100%;
}

.filter-date-input-sm input[type="date"] {
  min-height: 40px;
  padding: 0.5rem 0.6rem 0.5rem 2.1rem;
  font-size: 0.84rem;
}

.ledger-check {
  display: inline-flex !important;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  min-height: 48px;
}

.ledger-entry-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.ledger-entry {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  background: var(--bg);
}

.ledger-entry-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}

.ledger-entry-type {
  font-weight: 700;
  font-size: 0.85rem;
}

.ledger-entry-desc {
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  line-height: 1.35;
}

.ledger-entry-amounts {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.ledger-amt {
  font-weight: 800;
  font-size: 0.92rem;
}

.ledger-amt.due { color: var(--danger); }
.ledger-amt.paid { color: var(--success); }

.ledger-summary {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.ledger-summary-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.6rem;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.ledger-summary-box.highlight {
  border-color: var(--primary);
  background: rgba(245, 158, 11, 0.08);
}

.ledger-summary-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
}

.ledger-summary-value {
  font-size: 0.88rem;
  font-weight: 800;
}

.ledger-summary-value.due { color: var(--danger); }
.ledger-summary-value.paid { color: var(--success); }

.balance-due { color: var(--danger); font-weight: 700; }
.balance-paid { color: var(--success); font-weight: 700; }

/* ── CSV import (clients) ── */

.import-pick-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.import-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  background: var(--input-bg);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.import-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.import-count {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.import-count.new { background: var(--success-glow); color: var(--success); }
.import-count.dup { background: var(--warning-glow); color: var(--warning); }
.import-count.bad { background: var(--danger-glow); color: var(--danger); }

.import-sample {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
}

.import-sample-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 0.8fr);
  gap: 0.4rem;
  align-items: center;
}

.import-sample-row span:last-child { text-align: right; }

/* ── Settings page ── */

/* The shop letterhead and colour pickers moved out of the profile modal; they
   keep the modal's form styling, just capped so the fields stay readable. */
.settings-form {
  max-width: 640px;
}

.settings-save-row {
  justify-content: flex-end;
}

/* ── Egg broker (Broker Mode) ── */

/* Like Farm Mode, the trip page is the broker's home — right under Dashboard. */
body.broker-mode .nav-btn[data-page="dashboard"] { order: -2; }
body.broker-mode .nav-btn[data-page="broker"] { order: -1; }

/* The trip sheet has a lot of columns; give it room on a desk. */
dialog.wide-dialog { max-width: min(960px, 96vw); }

.farm-row-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}
.farm-row-3 > * { min-width: 0; }
.farm-row-3 input, .farm-row-3 select { width: 100%; min-width: 0; }
@media (max-width: 600px) {
  .farm-row-3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

.trip-lines {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* One farm on the sheet: party across the top, its figures in a grid below. */
.trip-line {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem;
  background: var(--input-bg);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
}
.trip-line > * { min-width: 0; }
.trip-line .tl-party-wrap { grid-column: span 3; }
.trip-line label span { font-size: 0.72rem; }
.trip-line input, .trip-line select { width: 100%; min-width: 0; padding: 0.55rem 0.65rem; font-size: 0.9rem; }
.trip-line .tl-amount {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}
.trip-line .tl-amount strong { font-size: 1rem; color: var(--text); padding-top: 0.2rem; }
.trip-line .tl-remove {
  align-self: end;
  justify-self: end;
  min-height: 40px;
}
@media (max-width: 600px) {
  .trip-line { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .trip-line .tl-party-wrap { grid-column: span 2; }
}

.trip-expense-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
}
.trip-expense-grid > * { min-width: 0; }
.trip-expense-grid input { width: 100%; min-width: 0; }
@media (max-width: 600px) {
  .trip-expense-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.trip-view-actions { flex-wrap: wrap; }

/* A farm's grade-by-grade figures. */
.farm-stock-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.35rem; }
.farm-stock-chips span {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
}
.farm-stock-chips span strong { color: var(--text); }
.farm-stock-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  align-items: center;
  gap: 0.4rem;
}
.farm-stock-row input { width: 100%; min-width: 0; }
.tl-farm-hint { grid-column: 1 / -1; font-size: 0.75rem; color: var(--muted); }

/* The read-back of a trip inside its modal. */
.trip-sheet { display: flex; flex-direction: column; gap: 0.75rem; }
.trip-sheet-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
}
.trip-sheet-meta div { background: var(--input-bg); border-radius: var(--radius-sm); padding: 0.5rem 0.65rem; }
.trip-sheet-meta span { display: block; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.trip-sheet-meta strong { font-size: 0.95rem; }
.trip-sheet .table-wrap { overflow-x: auto; }
.trip-sheet table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.trip-sheet th, .trip-sheet td { padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.trip-sheet th:first-child, .trip-sheet td:first-child,
.trip-sheet th:nth-child(2), .trip-sheet td:nth-child(2) { text-align: left; }
.trip-sheet th { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; }
.trip-sheet tfoot td { font-weight: 700; }
.trip-sheet-expenses { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.trip-sheet-expenses span { background: var(--input-bg); border-radius: 999px; padding: 0.25rem 0.65rem; font-size: 0.8rem; }

/* ── Poultry farm (Farm Mode) ── */

/* In Farm Mode the daily register is the page a farmer lives on, so it sits
   directly under Dashboard instead of down among the trader's pages. */
body.farm-mode .nav-btn[data-page="dashboard"] { order: -2; }
body.farm-mode .nav-btn[data-page="farm"] { order: -1; }

/* Filter chips over the farm purchase list. */
.farm-kind-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.farm-chip {
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
}

.farm-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text, #fff);
}

/* Hides the Farm menu entry while the shop is not in Farm Mode. Beats the
   super-admin rule that force-shows admin-only nav buttons. */
.farm-off { display: none !important; }

.farm-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
  overflow-x: auto;
}

.farm-tab {
  flex: 1 1 0;
  min-width: max-content;
  min-height: 44px;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.farm-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text, #fff);
}

.farm-date-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.farm-date-row input[type="date"] {
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
}

.farm-alert {
  font-size: 0.85rem;
  padding: 0.45rem 0.6rem;
  margin-bottom: 0.4rem;
  border-radius: var(--radius-sm);
  background: var(--warning-glow);
  color: var(--warning);
}

.farm-row-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.6rem;
}

/* Grid cells would otherwise keep the inputs' intrinsic width and push the
   modal sideways. */
.farm-row-2 > *,
.farm-egg-row > * { min-width: 0; }

.farm-row-2 input,
.farm-row-2 select,
.farm-egg-row input {
  width: 100%;
  min-width: 0;
}

.farm-eggs-block {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.farm-egg-rows {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.farm-egg-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 0.4rem;
}

.farm-egg-name {
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 0;
}

@media (max-width: 480px) {
  .farm-egg-row { grid-template-columns: 1fr 1fr; }
  .farm-egg-name { grid-column: 1 / -1; }
}

/* The per-bill expense block in the Sale form. */
.sell-expense-block {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.sell-expense-fields {
  display: grid;
  grid-template-columns: 1fr 1.25fr 1fr;
  gap: 0.4rem;
}

.sell-expense-fields input,
.sell-expense-fields select { min-width: 0; }

.user-perms { margin-top: 0.25rem; }

/* Profile → Custom Dashboard: the card checklist. */
.dash-prefs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.35rem 0.75rem;
  margin: 0.5rem 0 0.25rem;
}

.dash-pref-item {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}

.dash-pref-item input { accent-color: var(--primary); }

/* Each row: the checkbox + name on the left, the up/down movers on the right. */
.dash-pref-item {
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
  background: var(--input-bg);
}
.dash-pref-item > label {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  cursor: pointer;
}
.dash-pref-move { display: flex; gap: 0.25rem; flex-shrink: 0; }
.dash-pref-move button {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-size: 0.7rem;
}
.dash-pref-move button:disabled { opacity: 0.35; cursor: default; }
.dash-pref-reset { grid-column: 1 / -1; margin-top: 0.25rem; }

/* The template picker above the list. */
.dash-template-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.6rem;
  margin-top: 0.5rem;
}
.dash-template-pick { flex: 1 1 200px; }
.dash-template-btns { display: flex; flex-wrap: wrap; gap: 0.35rem; }

/* ── Banks page ── */

/* The money-position boxes flow into as many columns as fit, so a phone gets
   a tidy 2-up grid instead of one long stack. */
.cashflow-grid {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.cashflow-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.cashflow-actions .btn {
  flex: 1 1 140px;
  min-height: 44px;
}

/* One bank as a card on a phone. */
.banks-cards {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.bank-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  padding: 0.7rem 0.8rem;
}

.bank-card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.bank-card-name { font-weight: 700; min-width: 0; }
.bank-card-balance { font-size: 1.1rem; color: var(--primary); white-space: nowrap; }

.bank-card-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.bank-card-actions {
  margin-top: 0.6rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.balance-advance { color: var(--success); font-weight: 700; }
.balance-clear { color: var(--muted); }

td.due { color: var(--danger); font-weight: 700; }
td.paid { color: var(--success); font-weight: 700; }

.ledger-entry-meta {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
}

#client-ledger-view.client-ledger-fullpage:not(.hidden) {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* The card list is the mobile rendering of the same ledger the table shows. */
#client-ledger-list.mobile-only { display: none; }

#client-ledger-view .date-range-picker {
  max-width: 34rem;
}

#purchase-history-mobile-view,
#expenses-history-mobile-view,
#inventory-changes-mobile-view {
  display: none;
}

.client-ledger-fp-head {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--card-solid);
  flex-shrink: 0;
}

.client-ledger-back {
  flex-shrink: 0;
  min-height: 40px;
}

.client-ledger-fp-title {
  flex: 1;
  min-width: 0;
}

.client-ledger-fp-title h3 {
  margin: 0;
  font-size: 1.05rem;
}

.client-ledger-fp-title .hint {
  margin: 0.15rem 0 0;
}

.client-ledger-fp-title .hint.balance-due { color: var(--danger); }
.client-ledger-fp-title .hint.balance-advance { color: var(--success); }

.client-ledger-fp-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 1rem 1rem;
}

.client-ledger-fp-body .ledger-summary {
  margin-top: 0.75rem;
}

.client-ledger-fp-body .ledger-filters {
  padding-top: 0.75rem;
  margin: 0;
  border: none;
}

.client-ledger-fp-foot {
  flex-shrink: 0;
  padding: 0.75rem 1rem calc(0.85rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--card-solid);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
}

.client-ledger-fp-foot .ledger-share-actions {
  display: flex;
  gap: 0.45rem;
}

.client-ledger-fp-foot .ledger-share-actions .btn {
  min-height: 40px;
}

.client-ledger-fp-foot > .btn.primary {
  min-height: 42px;
}

body.client-ledger-open .mobile-bottom-nav,
body.purchase-history-open .mobile-bottom-nav,
body.expenses-history-open .mobile-bottom-nav,
body.inventory-changes-open .mobile-bottom-nav {
  display: none;
}

body.sidebar-open .mobile-bottom-nav {
  display: none;
}

body.sidebar-open .content {
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

body.client-ledger-open .content,
body.purchase-history-open .content,
body.expenses-history-open .content,
body.inventory-changes-open .content {
  padding-bottom: 0;
}

.balance-positive { color: var(--danger); font-weight: 700; }
.balance-zero { color: var(--muted); }

/* ── Modals ── */
dialog {
  background: var(--card-solid);
  border: 1px solid var(--border-light);
  border-radius: calc(var(--radius) + 4px);
  color: var(--text);
  padding: 0;
  max-width: 440px;
  width: 92%;
  margin: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s ease;
}

dialog[open] {
  display: block;
  position: fixed;
  inset: 0;
  margin: auto;
  height: fit-content;
  max-height: calc(100vh - 2rem);
  overflow: auto;
}

dialog::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(6px);
}

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

.client-opening-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.25rem 0 0;
  font-weight: 600;
  cursor: pointer;
}

.client-opening-fields {
  margin-top: 0.5rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  display: grid;
  gap: 0.65rem;
}

.modal-form { padding: 1.75rem; }
.modal-form h3 {
  margin-bottom: 1.25rem;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.tenant-detail-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
  font-size: 0.9rem;
}

.tenant-detail-meta .muted {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.form-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

.form-hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin: -0.25rem 0 0.75rem;
}

.password-field {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.password-field input {
  flex: 1;
}

.tenant-detail-users {
  margin-top: 1rem;
}

.tenant-detail-users h4 {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
}

#tenant-detail-modal {
  max-width: 560px;
  width: min(560px, 96vw);
}

.transfer-hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin: -0.25rem 0 0.5rem;
}

.daybook-toolbar {
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.daybook-toolbar .date-range-picker {
  flex: 1;
  min-width: 0;
}

.daybook-filters {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.daybook-filter-select {
  padding: 0.55rem 0.85rem;
  font-size: 0.88rem;
  font-family: inherit;
  font-weight: 600;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  /* min-width does the widening; a select otherwise shrinks to its content */
  min-width: 13rem;
  max-width: 18rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input.daybook-filter-select {
  cursor: text;
  font-weight: 500;
  width: 100%;
  padding-right: 2rem;
}

.daybook-combo {
  position: relative;
  display: flex;
  min-width: 13rem;
  max-width: 18rem;
  flex: 1;
}

.daybook-combo-arrow {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  opacity: 0.55;
  cursor: pointer;
}

.daybook-combo-arrow::after {
  content: '';
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
}

.daybook-combo-arrow:hover {
  opacity: 0.9;
}

.daybook-combo-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 0.3rem);
  left: 0;
  right: 0;
  max-height: 15rem;
  overflow-y: auto;
  padding: 0.3rem;
  background: var(--card-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.daybook-combo-option {
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.daybook-combo-option.is-all {
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  border-radius: 6px 6px 0 0;
  margin-bottom: 0.15rem;
}

.daybook-combo-option:hover,
.daybook-combo-option.active {
  background: var(--primary-glow);
}

.daybook-filter-select:focus {
  outline: none;
  border-color: rgba(var(--primary-rgb), 0.5);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ── Khata book layout ── */
.daybook-khata {
  background: var(--card);
  border: 2px solid var(--border-light);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
}

.daybook-summary-scroll,
.daybook-ledger-scroll {
  position: relative;
  min-width: 0;
  max-width: 100%;
}

.daybook-summary-scroll {
  margin-bottom: 0.75rem;
}

.daybook-rate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.daybook-rate-box {
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.65rem;
  text-align: center;
}

.daybook-rate-name {
  font-weight: 700;
  font-size: 0.88rem;
  margin-bottom: 0.25rem;
}

.daybook-rate-value {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.daybook-rate-qty {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
}

.daybook-rate-qty strong {
  color: var(--text);
}

.daybook-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.daybook-summary-box {
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.65rem;
  text-align: center;
}

.daybook-summary-box.success {
  border-color: rgba(34, 197, 94, 0.35);
  background: var(--success-glow);
}

.daybook-summary-box.warning {
  border-color: rgba(245, 158, 11, 0.4);
  background: var(--warning-glow);
}

.daybook-summary-box.danger {
  border-color: rgba(239, 68, 68, 0.4);
  background: var(--danger-glow);
}

.daybook-summary-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.daybook-summary-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
}

.daybook-ledger {
  overflow: auto;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-solid);
  isolation: isolate;
}

.daybook-grid {
  display: grid;
  gap: 0;
  min-width: max-content;
}

.daybook-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: 2.75rem;
  padding: 0.55rem 0.45rem;
  border: 1px solid var(--border);
  margin: -0.5px;
  background: var(--card-solid);
  font-size: 0.85rem;
  font-weight: 500;
  text-align: center;
  line-height: 1.25;
}

.daybook-cell-head {
  background: var(--table-head);
  font-weight: 700;
  min-height: 3.25rem;
}

.daybook-cell-name,
.daybook-cell-head.daybook-cell-name {
  align-items: flex-start;
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 4;
  background: var(--card-solid);
  border-right: 2px solid var(--border-light);
  box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
}

.daybook-cell-head.daybook-cell-name {
  z-index: 5;
  background: var(--card-solid);
}

.daybook-cell-total.daybook-cell-name {
  position: sticky;
  left: 0;
  z-index: 4;
  background: var(--card-solid);
  border-right: 2px solid var(--border-light);
  box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
}

.daybook-cell:not(.daybook-cell-name) {
  z-index: 0;
}

.daybook-cell-title {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text);
}

.daybook-cell-rate {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--primary);
}

.daybook-cell-total {
  background: linear-gradient(135deg, rgba(var(--primary-rgb), 0.14), rgba(var(--primary-rgb), 0.05));
  font-weight: 700;
  min-height: 2.85rem;
}

.daybook-cell-total.daybook-cell-name {
  background: var(--card-solid);
}

.daybook-cell-empty {
  grid-column: 1 / -1;
  padding: 2rem;
  color: var(--muted);
  font-weight: 600;
  background: var(--input-bg);
}

.daybook-cell-balance-positive {
  color: var(--danger);
  font-weight: 700;
}

.daybook-cell-balance-zero {
  color: var(--muted);
  font-weight: 600;
}

.daybook-cell-balance-negative {
  color: var(--success);
  font-weight: 700;
}

.transfer-preview {
  font-size: 0.85rem;
  color: var(--primary);
  font-weight: 600;
  margin: 0 0 0.75rem;
  min-height: 1.2rem;
}

dialog.modal-wide {
  max-width: 720px;
}

/* ── Transfer requests ── */
.req-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  margin-left: 0.4rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--danger, #dc2626);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}

.status-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: capitalize;
}
.status-badge.pending { background: #fef3c7; color: #92400e; }
.status-badge.approved { background: #dcfce7; color: #166534; }
.status-badge.rejected { background: #fee2e2; color: #991b1b; }

/* Requests review table: keep rows even so borders stay clean. */
#transfer-requests-modal .modal-form { gap: 0.85rem; }

#transfer-requests-modal .table-wrap {
  max-height: 62vh;
  overflow-y: auto;
}

#transfer-requests-modal thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--table-head);
}

#transfer-requests-modal th,
#transfer-requests-modal td {
  padding: 0.7rem 0.85rem;
  vertical-align: middle;
  white-space: nowrap;
}

#transfer-requests-modal td.action-btns {
  gap: 0.35rem;
  flex-wrap: nowrap;
  align-items: center;
}

#transfer-requests-modal td.action-btns .btn.sm {
  padding: 0.32rem 0.7rem;
  font-size: 0.78rem;
}

#transfer-requests-modal tbody tr:nth-child(even) td {
  background: var(--row-hover);
}
#transfer-requests-modal tbody tr:hover td {
  background: var(--row-hover);
}

/* ── Toast ── */
.toast {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  padding: 0.9rem 1.4rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 10000;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid rgba(255,255,255,0.1);
}

.toast.success { background: linear-gradient(135deg, #22c55e, #16a34a); color: #fff; }
.toast.error { background: linear-gradient(135deg, #ef4444, #dc2626); color: #fff; }
.toast.hidden { display: none; }

dialog > .toast.toast-in-dialog {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  border-radius: 0;
  z-index: 20;
  text-align: center;
  border-left: none;
  border-right: none;
  border-top: none;
}

.form-error {
  padding: 0.75rem 0.85rem;
  margin-bottom: 0.75rem;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.35;
}

@keyframes slideIn {
  from { transform: translateX(120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.action-btns { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: center; }

.summary-table { width: 100%; font-size: 0.92rem; }
.summary-table td { padding: 0.65rem 0; border-bottom: 1px solid var(--border); font-weight: 500; }
.summary-table td:last-child { text-align: right; font-weight: 700; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }

.bill-summary {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.15rem;
  margin: 1rem 0;
  font-size: 0.92rem;
  line-height: 1.9;
  font-weight: 500;
}

.bill-actions { flex-wrap: wrap; }

.bill-phone-label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
  margin: 0.75rem 0 0.25rem;
}

.bill-phone-label input {
  background: var(--input-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
}

/* ── Login ── */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 20%, var(--mesh-1) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, var(--mesh-2) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, var(--mesh-3) 0%, transparent 60%);
}

.login-page {
  width: 100%;
  max-width: 420px;
  padding: 1.5rem;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  backdrop-filter: var(--glass);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.login-brand .brand-icon {
  width: 3rem;
  height: 3rem;
  font-size: 2.75rem;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--brand-text-1);
}

.login-brand p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-form {
  gap: 1rem;
}

.login-btn {
  width: 100%;
  justify-content: center;
  margin-top: 0.5rem;
}

.login-error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0;
  padding: 0.6rem 0.8rem;
  background: var(--danger-glow);
  border-radius: var(--radius-sm);
}

.login-hint {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--muted);
}

.login-hint p { margin: 0.3rem 0; }
.login-hint code {
  background: var(--surface-muted);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

/* ── User bar ── */
.user-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0.85rem;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.user-bar-info {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.user-bar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.profile-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
  font-size: 0.9rem;
}

.profile-meta .muted {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

#profile-modal {
  max-width: 480px;
  width: min(480px, 96vw);
}

.topbar-profile-mobile { display: none; }

.user-bar-name { font-weight: 600; color: var(--text); }
.user-bar-role {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: capitalize;
}

.role-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.role-badge.super_admin {
  background: rgba(var(--accent-rgb), 0.2);
  color: var(--accent);
}

.role-badge.user {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.nav-btn.admin-only { display: none; }
body.is-super-admin .nav-btn.admin-only { display: flex; }

.mobile-bottom-nav {
  display: none;
  flex: none;
  flex-direction: row;
  flex-wrap: nowrap;
}

.mobile-bottom-nav .mobile-nav-btn.admin-only { display: none; }
body.is-super-admin .mobile-bottom-nav .mobile-nav-btn.admin-only { display: flex; }

/* Whole cards and forms can be admin-only too — the Settings page hides its
   shop-wide sections from staff this way. */
.card.admin-only,
form.admin-only { display: none; }
body.is-super-admin .card.admin-only,
body.is-super-admin form.admin-only { display: block; }

.btn.admin-only { display: none; }
body.is-super-admin .btn.admin-only { display: inline-flex; }

th.admin-only, td.admin-only { display: none; }
body.is-super-admin th.admin-only,
body.is-super-admin td.admin-only { display: table-cell; }

.pl-profit { color: var(--success); font-weight: 600; }
.pl-loss { color: var(--danger); font-weight: 600; }
.pl-even { color: var(--muted); font-weight: 600; }
.sale-card-pl { font-size: 0.8rem; font-weight: 600; }

.stats-grid.admin-only,
.grid-2.admin-only { display: none; }
body.is-super-admin .stats-grid.admin-only { display: grid; }
body.is-super-admin .grid-2.admin-only { display: grid; }

.nav-btn.platform-only { display: none; }
body.is-platform-admin .nav-btn.platform-only { display: flex; }
body.is-platform-admin .nav-btn:not(.platform-only),
body.is-platform-admin .mobile-nav-btn:not(.platform-only) { display: none !important; }
body.is-platform-admin .mobile-bottom-nav { display: none; }

.user-bar-shop {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.1rem;
}
body.is-platform-admin .user-bar-shop { display: none; }

#page-tenants.platform-only { display: none !important; }
body.is-platform-admin #page-tenants.platform-only.active { display: block !important; }

.role-badge.platform_admin {
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
}

.btn.sm svg { width: 19px; }
.icons { border: none !important; }
.btn.sm.icons:not(.danger) { color: var(--text); }
html[data-theme="light"] .btn.sm.icons:not(.danger) { color: #000000; }
.btn.sm.icons.danger { color: var(--danger); }
.table-head { font-weight: bold; text-align: center; }

/* ── Responsive ── */

/* Tablet */
@media (max-width: 1024px) {
  .content { padding: 1.5rem 1.25rem 2rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

  #page-products td.action-btns {
    justify-content: flex-end;
  }

  #page-products .table-head th:last-child {
    text-align: right;
  }
}

/* Mobile */
@media (max-width: 768px) {
  html,
  body {
    overflow-x: hidden;
    max-width: 100%;
  }

  body {
    display: block;
  }

  .sidebar-overlay {
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1050;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  body.sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  body.sidebar-open { overflow: hidden; }

  .app {
    width: 100%;
    max-width: 100vw;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(100%, 320px);
    max-width: 100%;
    z-index: 1100;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 1.25rem 1rem;
    padding-top: max(1.25rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    /* Same as desktop: the nav list scrolls, the shop name stays in view. */
    overflow: hidden;
    background: var(--card-solid);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  nav {
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 0.25rem;
  }

  .nav-btn {
    flex: none;
    min-width: 0;
    justify-content: flex-start;
    padding: 0.9rem 1rem;
    min-height: 48px;
  }

  .nav-btn:hover { transform: none; }

  .brand {
    margin-bottom: 0.5rem;
    padding: 1.5rem;
  }

  /* The drawer is narrower here; keep the mark from crowding the shop name. */
  .brand-icon {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 2rem;
  }

  .login-brand .brand-icon {
    width: 2.75rem;
    height: 2.75rem;
    font-size: 2.5rem;
  }

  .sidebar-footer { display: none; }

  .menu-toggle { display: flex; }

  .content {
    flex: 1;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    max-height: none;
    min-height: 100vh;
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom));
    overflow-x: hidden;
  }

  .page {
    min-width: 0;
    max-width: 100%;
  }

  #page-daybook .daybook-toolbar {
    margin-bottom: 0.65rem;
    flex-wrap: wrap;
  }

  #page-daybook .daybook-filters {
    width: 100%;
  }

  #page-daybook .daybook-combo,
  #page-daybook .daybook-filter-select {
    flex: 1;
    min-width: 0;
    max-width: none;
    font-size: 16px;
    min-height: 44px;
  }

  .daybook-khata {
    padding: 0.75rem 0 0;
    overflow: hidden;
    border-radius: var(--radius-sm);
  }

  .daybook-summary-scroll {
    margin-bottom: 0.65rem;
    padding: 0 0.75rem;
  }

  .daybook-summary-scroll::after {
    content: '';
    position: absolute;
    right: 0.75rem;
    top: 0;
    bottom: 0.35rem;
    width: 1.75rem;
    background: linear-gradient(to right, transparent, var(--card-solid));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
  }

  .daybook-summary-scroll.is-scrollable::after {
    opacity: 1;
  }

  .daybook-summary-grid {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 0.45rem;
    margin-bottom: 0;
    padding-bottom: 0.2rem;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .daybook-summary-grid::-webkit-scrollbar {
    display: none;
  }

  .daybook-summary-box {
    flex: 0 0 auto;
    min-width: 6.5rem;
    padding: 0.5rem 0.6rem;
    scroll-snap-align: start;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  }

  .daybook-summary-label {
    font-size: 0.6rem;
    margin-bottom: 0.15rem;
    letter-spacing: 0.04em;
    white-space: nowrap;
  }

  .daybook-summary-value {
    font-size: 0.88rem;
    white-space: nowrap;
    letter-spacing: -0.02em;
  }

  .daybook-ledger-scroll::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 1.25rem;
    background: linear-gradient(to right, transparent, var(--card-solid));
    pointer-events: none;
    z-index: 4;
  }

  .daybook-ledger {
    max-height: calc(100dvh - 20rem);
    overflow-x: auto;
    overflow-y: auto;
    border-left: none;
    border-right: none;
    border-radius: 0;
    width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  .daybook-cell {
    font-size: 0.75rem;
    min-height: 2.35rem;
    padding: 0.4rem 0.3rem;
  }

  .daybook-cell-head {
    min-height: 2.85rem;
  }

  .daybook-cell-title {
    font-size: 0.68rem;
    line-height: 1.2;
  }

  .daybook-cell-rate {
    font-size: 0.72rem;
  }

  .daybook-cell-name,
  .daybook-cell-head.daybook-cell-name,
  .daybook-cell-total.daybook-cell-name {
    min-width: 5rem;
    max-width: 5rem;
    box-shadow: 4px 0 12px rgba(0, 0, 0, 0.12);
  }

  .mobile-bottom-nav {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    flex: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 900;
    background: var(--card-solid);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom);
    align-items: stretch;
    gap: 0;
    min-height: calc(3.75rem + env(safe-area-inset-bottom));
  }

  .mobile-nav-btn {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    min-height: 3.75rem;
    padding: 0.4rem 0.15rem;
    background: transparent;
    border: none;
    border-radius: 0;
    color: var(--muted);
    cursor: pointer;
    font-family: inherit;
    transition: color 0.2s, background 0.2s;
    position: relative;
    white-space: nowrap;
  }

  .mobile-nav-btn .mobile-nav-icon {
    font-size: 1.25rem;
    line-height: 1;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-nav-btn .mobile-nav-icon svg {
    width: 21px;
    height: 21px;
    display: block;
  }

  .mobile-nav-btn .mobile-nav-label {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    line-height: 1.1;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .mobile-nav-btn.active {
    color: var(--primary);
    background: linear-gradient(180deg, rgba(var(--primary-rgb), 0.18) 0%, transparent 100%);
  }

  .mobile-nav-btn.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--primary);
    box-shadow: 0 0 12px var(--primary-glow);
  }

  .mobile-nav-btn:active {
    transform: scale(0.97);
  }

  .toast {
    left: 1rem;
    right: 1rem;
    top: auto;
    bottom: calc(5.5rem + env(safe-area-inset-bottom));
    text-align: center;
  }

  dialog > .toast.toast-in-dialog {
    top: 0;
    bottom: auto;
    left: 0;
    right: 0;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    margin-bottom: 0.85rem;
    padding-bottom: 0.75rem;
    position: relative;
    z-index: 1100;
    overflow: visible;
  }

  .topbar-head {
    gap: 0.65rem;
    flex: 1;
    min-width: 0;
    width: 100%;
  }

  .topbar-foot {
    position: relative;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.65rem;
    background: var(--card-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    width: 100%;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .topbar-foot-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
  }

  .topbar-more-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0;
    flex-shrink: 0;
    background: var(--card-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    cursor: pointer;
  }

  .topbar-more-btn[aria-expanded="true"] {
    background: var(--surface-muted);
    border-color: var(--primary);
    color: var(--primary);
  }

  .topbar-more-btn svg {
    width: 20px;
    height: 20px;
  }

  .topbar-dropdown-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1190;
    background: transparent;
  }

  .topbar-dropdown-backdrop.open {
    display: block;
  }

  .topbar-foot-details {
    position: fixed;
    top: 0;
    right: 0;
    left: auto;
    z-index: 1200;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: min(18rem, calc(100vw - 1.5rem));
    margin: 0;
    padding: 0.35rem 0;
    background: var(--card-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.12);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .topbar-foot-details.open {
    display: flex;
  }

  .topbar-foot .topbar-quick {
    flex-shrink: 0;
    margin-left: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0.25rem 0;
    border-top: 1px solid var(--border);
  }

  .topbar-left {
    flex: 1;
    min-width: 0;
    width: 100%;
  }

  .topbar-left > .topbar-more-btn:not([hidden]) {
    display: inline-flex;
  }

  .topbar-left h2 {
    font-size: 1.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.1rem;
  }

  .topbar-sub {
    font-size: 0.72rem;
    white-space: normal;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .topbar-quick {
    gap: 0;
  }

  .topbar-date {
    flex: 1;
    min-width: 0;
    font-size: 0.75rem;
    padding: 0;
    border: none;
    background: transparent;
    border-radius: 0;
  }

  .user-bar {
    justify-content: flex-start;
    gap: 0.35rem;
    padding: 0.75rem 0.85rem;
    border: none;
    background: transparent;
    border-radius: 0;
    width: 100%;
    min-width: 0;
    flex: none;
  }

  .user-bar-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
    min-width: 0;
    width: 100%;
  }

  .user-bar-name {
    display: block;
    font-size: 0.9rem;
    font-weight: 700;
  }

  .user-bar-shop {
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 0;
  }

  .user-bar-role {
    font-size: 0.72rem;
    flex-shrink: 0;
    padding: 0.15rem 0.5rem;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    white-space: nowrap;
  }

  .topbar-logout-desktop { display: none; }

  .topbar-foot-details .theme-toggle {
    width: 100%;
    height: auto;
    min-height: 44px;
    padding: 0.65rem 0.85rem;
    justify-content: flex-start;
    gap: 0.65rem;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .topbar-foot-details .theme-toggle .theme-label {
    display: inline;
    font-size: 0.88rem;
    font-weight: 500;
  }

  .topbar-foot-details .theme-toggle .theme-icon {
    font-size: 1.05rem;
  }

  .topbar-foot-details .topbar-profile-mobile {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    height: auto;
    min-height: 44px;
    padding: 0.65rem 0.85rem;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    font-size: 0.88rem;
    font-weight: 600;
  }

  .topbar-foot-details .topbar-logout-mobile {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.65rem;
    width: 100%;
    height: auto;
    min-height: 44px;
    padding: 0.65rem 0.85rem;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--danger);
    box-shadow: none;
  }

  .topbar-foot-details .topbar-logout-label {
    display: inline;
    font-size: 0.88rem;
    font-weight: 600;
  }

  .topbar-foot-details .topbar-logout-mobile svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
    margin-bottom: 1rem;
  }

  #page-dashboard .stats-grid {
    gap: 0.55rem;
    margin-bottom: 0.85rem;
  }

  #page-dashboard .stat-card:first-child {
    grid-column: 1 / -1;
    padding: 0.85rem 1rem;
  }

  #page-dashboard .stat-card:first-child .value {
    font-size: 1.65rem;
  }

  #page-dashboard .stat-card:first-child .sub {
    font-size: 0.75rem;
  }

  .stat-card {
    padding: 0.75rem 0.8rem;
  }

  .stat-card .stat-top {
    margin-bottom: 0.35rem;
  }

  .stat-card .value {
    font-size: 1.25rem;
    word-break: break-word;
  }

  .stat-card .label {
    font-size: 0.65rem;
    letter-spacing: 0.04em;
    line-height: 1.25;
  }

  .stat-card .sub {
    font-size: 0.68rem;
    margin-top: 0.2rem;
    line-height: 1.3;
  }

  .stat-card {
    background: var(--card-solid);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .stat-card .stat-icon {
    width: 30px;
    height: 30px;
    font-size: 0.9rem;
    border-radius: 8px;
  }

  #page-dashboard .grid-2 {
    gap: 0.85rem;
  }

  #page-dashboard .card {
    margin-bottom: 0.85rem;
  }

  #page-dashboard .card-header {
    margin-bottom: 0.65rem;
    padding-bottom: 0.55rem;
  }

  #page-dashboard .card-header h3 {
    font-size: 0.95rem;
  }

  #page-dashboard .hint {
    font-size: 0.78rem;
    margin-bottom: 0.5rem;
  }

  #page-dashboard .dashboard-mobile-fold .dashboard-fold-toggle {
    cursor: pointer;
    margin-bottom: 0;
    padding-bottom: 0.55rem;
    -webkit-tap-highlight-color: transparent;
  }

  #page-dashboard .dashboard-mobile-fold.dashboard-fold-open .dashboard-fold-toggle {
    margin-bottom: 0.65rem;
  }

  #page-dashboard .dashboard-mobile-fold:not(.dashboard-fold-open) .dashboard-fold-toggle {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
  }

  #page-dashboard .dashboard-fold-chevron {
    display: inline-flex;
  }

  #page-dashboard .dashboard-mobile-fold:not(.dashboard-fold-open) .dashboard-fold-body {
    display: none;
  }

  .card {
    padding: 1rem;
    margin-bottom: 1rem;
    background: var(--card-solid);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  dialog::backdrop {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .card-header {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
  }

  #page-expenses .filter-bar {
    margin-bottom: 0.75rem;
    padding: 0.55rem 0.65rem;
  }

  #page-expenses .filter-bar-row {
    gap: 0.5rem;
    align-items: center;
  }

  #page-expenses .filter-date-input {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
  }

  #page-expenses .filter-date-input .filter-date-icon {
    left: 0.75rem;
    width: 1.15rem;
    height: 1.15rem;
  }

  #page-expenses .filter-date-input input[type="date"] {
    font-size: 16px;
    min-height: 48px;
    padding: 0.65rem 0.75rem 0.65rem 2.25rem;
  }

  #page-expenses .filter-actions {
    flex-shrink: 0;
    margin-left: 0;
  }

  #page-expenses .filter-btn {
    min-height: 48px;
    min-width: 4.75rem;
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
  }

  .page-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .page-actions .btn,
  .page-actions label {
    width: 100%;
  }

  .form input,
  .form select,
  .form textarea {
    font-size: 16px;
    min-height: 48px;
  }

  .btn {
    min-height: 44px;
    justify-content: center;
  }

  .btn.primary {
    width: 100%;
  }

  .form .btn.primary {
    width: 100%;
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions .btn {
    width: 100%;
  }

  dialog {
    width: calc(100% - 1.5rem);
    max-width: none;
    max-height: calc(100vh - 1.5rem);
    margin: 0.75rem;
  }

  dialog.modal-wide {
    max-width: none;
  }

  .modal-form {
    padding: 1.25rem;
  }

  th, td {
    padding: 0.65rem 0.5rem;
    font-size: 0.8rem;
  }

  .action-btns {
    flex-direction: column;
    align-items: stretch;
  }

  .action-btns .btn {
    width: 100%;
  }

  .rate-input {
    max-width: none;
    min-width: 0;
  }

  #page-rates .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #page-rates .table-wrap table {
    width: max-content;
    min-width: 100%;
  }

  #page-rates th,
  #page-rates td {
    white-space: nowrap;
  }

  #page-rates .rate-input {
    width: 7rem;
    min-width: 7rem;
    max-width: 10rem;
  }

  #page-rates .rate-dozen {
    min-width: 4.5rem;
  }

  .form-inline {
    flex-direction: column;
  }

  .form-inline select {
    width: 100%;
    min-width: 0;
  }

  .bill-actions {
    flex-direction: column;
  }

  .bill-actions .btn {
    width: 100%;
  }

  .summary-table tr {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border);
  }

  .summary-table td {
    display: block;
    width: auto;
    padding: 0.55rem 0;
    border-bottom: none;
    text-align: left !important;
  }

  .summary-table td:first-child {
    flex: 1;
    min-width: 0;
  }

  .summary-table td:last-child {
    flex-shrink: 0;
    text-align: right !important;
    font-weight: 700;
  }

  .mobile-only { display: block; }
  .desktop-only { display: none !important; }

  .topbar-dropdown-backdrop.mobile-only {
    display: none;
  }

  .topbar-dropdown-backdrop.mobile-only.open {
    display: block;
  }

  .topbar-more-btn.mobile-only {
    display: inline-flex;
  }

  #sell-modal.sell-modal[open] {
    display: flex;
  }

  #page-sell .sell-history-card {
    padding: 0.85rem;
    margin-bottom: 0;
  }

  #page-sell .sales-list.mobile-only {
    display: flex;
  }

  #page-dashboard .sales-list.mobile-only {
    display: flex;
    gap: 0.5rem;
  }

  #page-dashboard .sale-card {
    padding: 0.7rem 0.75rem;
    background: var(--surface-muted);
  }

  #page-dashboard .sale-card-top {
    margin-bottom: 0.45rem;
  }

  #page-dashboard .sale-card-meta {
    margin-bottom: 0.5rem;
    line-height: 1.35;
  }

  #page-dashboard .sale-card-actions .btn {
    min-height: 36px;
    font-size: 0.82rem;
  }

  #page-sell .sell-history-card .card-header {
    margin-bottom: 0.65rem;
    padding-bottom: 0.55rem;
  }

  #page-purchase .purchase-layout {
    gap: 0;
  }

  #page-purchase .purchase-history-mobile {
    margin-top: 0.65rem;
  }

  #purchases-list-modal .modal-form {
    max-height: calc(100dvh - 2rem);
    overflow: auto;
  }

  #page-expenses .expenses-layout {
    gap: 0;
  }

  #page-expenses .expenses-history-mobile {
    margin-top: 0.65rem;
  }

  #expenses-list-modal .modal-form {
    max-height: calc(100dvh - 2rem);
    overflow: auto;
  }

  #page-inventory #inventory-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
    margin-bottom: 0.85rem;
  }

  #page-inventory #inventory-summary .stat-card {
    padding: 0.75rem 0.5rem 0.85rem;
    min-width: 0;
    background: var(--card-solid);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: var(--shadow);
  }

  #page-inventory #inventory-summary .stat-card .stat-top {
    margin-bottom: 0.45rem;
  }

  #page-inventory #inventory-summary .stat-card .stat-icon {
    display: none;
  }

  #page-inventory #inventory-summary .stat-card .label {
    font-size: 0.68rem;
    letter-spacing: 0.03em;
    line-height: 1.25;
  }

  #page-inventory #inventory-summary .stat-card .value {
    font-size: 1.5rem;
    line-height: 1.15;
    word-break: break-word;
    letter-spacing: -0.02em;
  }

  #page-inventory #inventory-summary .stat-card.success .value {
    font-size: 1rem;
    letter-spacing: -0.03em;
  }

  #page-inventory .inventory-stock-card {
    padding: 0.85rem;
    margin-bottom: 0;
  }

  #page-inventory .inventory-list.mobile-only {
    display: flex;
  }

  #page-inventory .inventory-card,
  #page-inventory .movement-card {
    background: var(--card-solid);
  }

  #page-inventory .inventory-changes-mobile {
    margin-top: 0.65rem;
  }

  #page-daily #daily-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
    margin-bottom: 0.85rem;
  }

  #page-daily #daily-summary .stat-card {
    padding: 0.75rem 0.55rem 0.85rem;
    min-width: 0;
    background: var(--card-solid);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: var(--shadow);
  }

  #page-daily #daily-summary .stat-card .stat-top {
    margin-bottom: 0.45rem;
  }

  #page-daily #daily-summary .stat-card .stat-icon {
    display: none;
  }

  #page-daily #daily-summary .stat-card .label {
    font-size: 0.68rem;
    letter-spacing: 0.03em;
    line-height: 1.25;
  }

  #page-daily #daily-summary .stat-card .value {
    font-size: 1.4rem;
    line-height: 1.15;
    word-break: break-word;
    letter-spacing: -0.02em;
  }

  #page-daily #daily-summary .stat-card.success .value,
  #page-daily #daily-summary .stat-card.warning .value {
    font-size: 1.05rem;
    letter-spacing: -0.03em;
  }

  #movements-list-modal .modal-form {
    max-height: calc(100dvh - 2rem);
    overflow: auto;
  }

  #movements-list-modal-body {
    max-height: calc(100dvh - 11rem);
    overflow-y: auto;
  }

  .sell-modal-header {
    padding: 0.85rem 1rem;
  }

  .sell-modal-header h3 {
    font-size: 1rem;
  }

  .sell-modal-form {
    padding: 0.85rem 1rem 0;
    -webkit-overflow-scrolling: touch;
  }

  .sell-modal-footer {
    margin: 0.5rem -1rem 0;
    padding: 0.75rem 1rem calc(0.85rem + env(safe-area-inset-bottom));
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08);
  }

  .sell-modal-actions .btn {
    min-height: 46px;
  }

  #page-sell .topbar-sub {
    display: none;
  }

  .clients-layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  #page-clients .clients-list-card {
    padding: 0.85rem;
    margin-bottom: 0;
  }

  #page-clients .clients-list.mobile-only {
    display: flex;
  }

  #page-suppliers .suppliers-list-card {
    padding: 0.85rem;
    margin-bottom: 0;
  }

  #page-suppliers .suppliers-list.mobile-only {
    display: flex;
  }

  #page-suppliers .supplier-card {
    background: var(--card-solid);
  }

  #page-suppliers .supplier-card-actions.action-btns {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
  }

  #page-suppliers .supplier-card-actions .btn {
    flex: 0 0 42px;
    width: 42px;
    min-width: 42px;
    min-height: 38px;
    padding: 0;
  }

  #page-labour .labour-list-card {
    padding: 0.85rem;
    margin-bottom: 0;
  }

  #page-labour .labour-list.mobile-only {
    display: flex;
  }

  #page-labour .labour-card {
    background: var(--card-solid);
  }

  #page-labour .labour-card-actions.action-btns {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
  }

  #page-labour .labour-card-actions .btn {
    flex: 0 0 42px;
    width: 42px;
    min-width: 42px;
    min-height: 38px;
    padding: 0;
  }

  #page-products .products-list-card {
    padding: 0.85rem;
    margin-bottom: 0;
  }

  #page-products .products-list.mobile-only {
    display: flex;
  }

  #page-products .page-actions {
    margin-bottom: 0.65rem;
  }

  #page-products .product-card {
    background: var(--card-solid);
  }

  #page-products .product-card-actions.action-btns {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-end;
  }

  #page-products .product-card-actions .btn {
    flex: 0 0 42px;
    width: 42px;
    min-width: 42px;
    min-height: 38px;
    padding: 0;
  }

  #page-users .users-list-card {
    padding: 0.85rem;
    margin-bottom: 0;
  }

  #page-users .users-list.mobile-only {
    display: flex;
  }

  #page-users .page-actions {
    margin-bottom: 0.65rem;
  }

  #page-users .user-card {
    background: var(--card-solid);
  }

  #page-users .user-card-actions.action-btns {
    flex-direction: row;
    align-items: stretch;
  }

  #page-users .user-card-actions .btn {
    width: auto;
  }

  #page-clients .client-page-actions {
    margin-bottom: 0.65rem;
  }

  #page-clients .client-search-input {
    width: 100%;
    min-width: 0;
    font-size: 16px;
    min-height: 44px;
  }

  #page-clients .client-filter-toggle {
    width: 100%;
    justify-content: flex-start;
  }

  #client-ledger-view.client-ledger-fullpage:not(.hidden),
  #purchase-history-mobile-view.purchase-history-fullpage:not(.hidden),
  #expenses-history-mobile-view.expenses-history-fullpage:not(.hidden),
  #inventory-changes-mobile-view.inventory-changes-fullpage:not(.hidden) {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0;
    z-index: 500;
    background: var(--bg);
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding-top: env(safe-area-inset-top);
  }

  .client-ledger-fp-foot {
    flex-direction: column;
    align-items: stretch;
  }

  .client-ledger-fp-foot .ledger-share-actions .btn {
    flex: 1;
    min-height: 42px;
  }

  .client-ledger-fp-foot > .btn.primary {
    width: 100%;
    min-height: 46px;
  }

  body.client-ledger-open .topbar,
  body.purchase-history-open .topbar,
  body.expenses-history-open .topbar,
  body.inventory-changes-open .topbar {
    display: none;
  }

  #client-ledger-list.mobile-only { display: flex; }

  #client-ledger-view .date-range-picker {
    max-width: none;
  }

  #client-ledger-view .ledger-filters {
    gap: 0.55rem;
  }

  #client-ledger-view .date-range-presets {
    flex-wrap: wrap;
  }

  #client-ledger-view .date-range-preset {
    flex: 1 1 calc(50% - 0.2rem);
    min-height: 40px;
    font-size: 0.8rem;
  }

  #client-ledger-view .ledger-check {
    grid-column: 1 / -1;
    min-height: auto;
  }

  #client-ledger-list {
    padding-top: 0.75rem;
  }
}

/* Small phones */
@media (max-width: 480px) {
  #page-dashboard .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }

  #page-dashboard .stat-card:first-child .value {
    font-size: 1.45rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar-left h2 {
    font-size: 1.2rem;
  }

  .brand h1 {
    font-size: 1.05rem;
  }

  .brand-icon {
    width: 2rem;
    height: 2rem;
    font-size: 1.75rem;
  }

  .login-brand .brand-icon {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 2.25rem;
  }

  .stat-card .value {
    font-size: 1.15rem;
  }

  #page-inventory #inventory-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.4rem;
  }

  #page-inventory #inventory-summary .stat-card {
    padding: 0.65rem 0.4rem 0.75rem;
  }

  #page-inventory #inventory-summary .stat-card .label {
    font-size: 0.6rem;
  }

  #page-inventory #inventory-summary .stat-card .value {
    font-size: 1.3rem;
  }

  #page-inventory #inventory-summary .stat-card.success .value {
    font-size: 0.88rem;
  }

  #page-daily #daily-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem;
  }

  #page-daily #daily-summary .stat-card {
    padding: 0.65rem 0.45rem 0.75rem;
  }

  #page-daily #daily-summary .stat-card .label {
    font-size: 0.6rem;
  }

  #page-daily #daily-summary .stat-card .value {
    font-size: 1.25rem;
  }

  #page-daily #daily-summary .stat-card.success .value,
  #page-daily #daily-summary .stat-card.warning .value {
    font-size: 0.92rem;
  }

  .total-preview strong {
    font-size: 1.2rem;
  }

  .login-page {
    padding: 1rem;
  }

  .login-card {
    padding: 1.5rem;
  }
}

/* Prevent hover lift on touch devices */
@media (hover: none) {
  .stat-card:hover,
  .btn:hover,
  .nav-btn:hover,
  .card:hover,
  .theme-toggle:hover {
    transform: none;
  }
}

/* PWA update banner */
.pwa-update-banner {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: calc(100vw - 2rem);
  padding: 0.6rem 0.75rem 0.6rem 1rem;
  background: var(--card-solid);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  color: var(--text, inherit);
  font-size: 0.9rem;
  animation: pwa-banner-in 0.25s ease-out;
}

.pwa-update-banner span {
  white-space: nowrap;
}

@keyframes pwa-banner-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

@media (max-width: 768px) {
  .pwa-update-banner {
    bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
  }
}

/* ── Supplier hisab ─────────────────────────────────────── */
.balance-pill {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  background: var(--surface-2, rgba(127, 127, 127, 0.12));
}
.balance-pill.big { font-size: 0.95rem; padding: 0.3rem 0.9rem; }
.balance-pill.due { color: var(--danger); background: var(--danger-glow); }
.balance-pill.advance { color: var(--success); background: var(--success-glow); }
.balance-pill.clear { color: var(--muted, #888); }
.balance-cell.due strong { color: var(--danger); }
.balance-cell.advance strong { color: var(--success); }

.supplier-card-actions { margin-top: 0.6rem; display: flex; gap: 0.4rem; flex-wrap: wrap; }

.supplier-hisab-modal { max-width: 640px; width: 100%; }
.supplier-hisab-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 0.8rem; flex-wrap: wrap;
}
.supplier-hisab-table { width: 100%; font-size: 0.88rem; }
.supplier-hisab-table td.advance { color: var(--success); font-weight: 700; }

/* A field that appears mid-form (the bank picker) briefly highlights itself so
   it is not mistaken for something that was always there — or never appeared. */
@keyframes field-flash {
  from { box-shadow: 0 0 0 3px var(--warning-glow, rgba(245,158,11,0.35)); }
  to   { box-shadow: 0 0 0 3px transparent; }
}

.field-flash {
  animation: field-flash 1.4s ease-out 1;
  border-radius: 10px;
}

.purchase-pay-row { display: flex; gap: 0.6rem; align-items: flex-end; }
.purchase-pay-row label { flex: 1; }
.purchase-pay-row .btn { flex: 0 0 auto; }
.purchase-baqi-preview { font-size: 0.9rem; color: var(--muted, #888); margin: 0.2rem 0; }
.purchase-baqi-preview strong { color: var(--danger); }

/* Purchase branch split */
.purchase-branch-split { border: 1px solid var(--line, #e5e7eb); border-radius: 10px; padding: 10px; margin: 4px 0; }
.purchase-branch-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; }
.purchase-branch-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.purchase-branch-row .pbs-branch { flex: 1 1 auto; }
.purchase-branch-row .pbs-qty { width: 90px; }

/* Branch-wise stock (Stock page) */
.branch-stock-group { margin-bottom: 14px; }
.branch-stock-name { font-weight: 700; margin-bottom: 6px; }
.branch-stock-table { width: 100%; border-collapse: collapse; }
.branch-stock-table td { padding: 6px 8px; border-bottom: 1px solid var(--line, #e5e7eb); }
.branch-stock-table td.right { text-align: right; }

/* Stock page branch filter */
.card-header-action { margin-left: auto; flex-shrink: 0; }
/* The ledger table already fills its card, so the edit action rides inside the
   details cell instead of claiming a sixth column that would overflow. */
.ledger-edit-btn { margin-left: 0.5rem; white-space: nowrap; vertical-align: middle; }
.inventory-branch-filter { display: inline-flex; align-items: center; gap: 8px; margin-bottom: 12px; font-weight: 600; }
.inventory-branch-filter select { padding: 6px 10px; border-radius: 8px; }

/* ── Supplier hisab fullpage ──────────────────────────────
   Mirrors the #client-ledger-view rules: those are ID-scoped, so the supplier
   view (same classes, different id) rendered unstyled — cards missing their
   container, the mobile list duplicating under the desktop table, and the
   bare date filters stretching full width. */
#supplier-ledger-view.client-ledger-fullpage:not(.hidden) {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Card list is the mobile rendering of the same ledger the table shows. */
#supplier-ledger-list.mobile-only { display: none; }

/* Compact From / To on one line instead of stacked full-width inputs. */
#supplier-ledger-view .ledger-filters {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
}
#supplier-ledger-view .date-range-field { width: auto; flex: 0 0 auto; }
#supplier-ledger-view .filter-date-input-sm { width: 11rem; }

/* Three summary boxes in a row (client view only has one, so its 1fr grid
   was fine); auto-fit lets them wrap on narrow screens. */
#supplier-ledger-view .ledger-summary {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

@media (max-width: 768px) {
  /* Full-screen takeover, same as the client hisab. */
  #supplier-ledger-view.client-ledger-fullpage:not(.hidden) {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0;
    z-index: 500;
    background: var(--bg);
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding-top: env(safe-area-inset-top);
  }

  /* Table is hidden by the generic .desktop-only rule; show the cards. */
  #supplier-ledger-list.mobile-only { display: flex; }

  /* From / To side by side, sharing the row. */
  #supplier-ledger-view .date-range-field { flex: 1 1 0; min-width: 0; }
  #supplier-ledger-view .filter-date-input-sm { width: 100%; }
}

/* Supplier hisab date presets (same picker as the client hisab). */
#supplier-ledger-view .date-range-picker { max-width: 34rem; }

/* ── Labour hisab fullpage (mirrors the supplier hisab rules) ── */
#labour-ledger-view.client-ledger-fullpage:not(.hidden) {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
#labour-ledger-list.mobile-only { display: none; }
#labour-ledger-view .ledger-filters {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
}
#labour-ledger-view .date-range-picker { max-width: 34rem; }
#labour-ledger-view .date-range-field { width: auto; flex: 0 0 auto; }
#labour-ledger-view .filter-date-input-sm { width: 11rem; }
#labour-ledger-view .ledger-summary {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

@media (max-width: 768px) {
  #labour-ledger-view.client-ledger-fullpage:not(.hidden) {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0;
    z-index: 500;
    background: var(--bg);
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding-top: env(safe-area-inset-top);
  }
  #labour-ledger-list.mobile-only { display: flex; }
  #labour-ledger-view .date-range-field { flex: 1 1 0; min-width: 0; }
  #labour-ledger-view .filter-date-input-sm { width: 100%; }
}

/* Daybook quantity display: peti/tray/darjan compact format. */
.daybook-qty-mixed { font-variant-numeric: tabular-nums; font-weight: 600; }
.daybook-qty-badge { position: relative; font-weight: 600; padding-right: 0.55em; }
.daybook-qty-unit {
  position: absolute;
  right: -0.15em;
  bottom: -0.35em;
  font-size: 0.6em;
  line-height: 1;
  font-weight: 700;
  color: var(--accent, #f5a623);
  padding: 0.05em 0.2em;
}
/* Darjan badge gets a rounded outline to set it apart from the tray badge. */
.daybook-qty-badge.daybook-qty-darjan .daybook-qty-unit {
  border: 1px solid currentColor;
  border-radius: 4px;
  bottom: -0.4em;
}

/* Action row inside a ledger card (mobile) — e.g. deleting a supplier payment. */
.ledger-entry-actions {
  display: flex;
  justify-content: flex-end;
  /* Receipt sits beside Delete here, so these need spacing and room to wrap. */
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

/* Inline remove control on a ledger row (supplier payment). Sits with the
   description so it stays on screen in the sideways-scrolling ledger table. */
.ledger-row-remove {
  padding: 0.1rem 0.4rem;
  margin-inline-start: 0.4rem;
  vertical-align: middle;
  line-height: 1.2;
}

/* Shop letterhead editor inside the profile modal. */
.shop-logo-row {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  margin-bottom: 0.9rem;
}

.shop-logo-preview {
  width: 76px;
  height: 76px;
  flex: 0 0 auto;
  border: 1px dashed var(--line, #e5e7eb);
  border-radius: 10px;
  display: grid;
  place-items: center;
  overflow: hidden;
  font-size: 0.7rem;
  color: var(--muted, #6b7280);
  text-align: center;
  padding: 0.25rem;
}

.shop-logo-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.shop-logo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.shop-logo-actions .hint { flex-basis: 100%; }

/* Repeatable shop phone numbers in the profile modal. */
.shop-phones { display: flex; flex-direction: column; gap: 0.4rem; }

.shop-phones-label {
  font-size: 0.82rem;
  color: var(--muted, #6b7280);
}

.shop-phone-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.shop-phone-row input { flex: 1; }

.shop-phones > .btn { align-self: flex-start; }

/* ── Reports ─────────────────────────────────────────────── */
.reports-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 0.85rem;
  margin-top: 0.4rem;
}

.report-card {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  text-align: start;
  padding: 0.9rem;
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 12px;
  background: var(--card, #fff);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.report-card:hover {
  border-color: var(--accent, #f5a623);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

.report-card-icon {
  font-size: 1.4rem;
  line-height: 1;
  flex: 0 0 auto;
}

.report-card-title {
  display: block;
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.report-card-sub {
  display: block;
  font-size: 0.76rem;
  color: var(--muted, #6b7280);
  line-height: 1.35;
}

.reports-detail-head {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.reports-detail-title { flex: 1; min-width: 0; }
.reports-detail-title h3 { margin: 0; }
.reports-detail-title .hint { margin: 0.1rem 0 0; }

.report-table-scroll { max-height: 62vh; overflow: auto; }
.report-table-scroll thead th { position: sticky; top: 0; z-index: 1; }

#report-foot td {
  font-weight: 700;
  border-top: 2px solid var(--line, #e5e7eb);
}

td.num, th.num { text-align: end; white-space: nowrap; }

/* The base .ledger-summary is one column; each view sets its own track count. */
#report-summary {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

/* The "delete these sales first" dialog carries a table, so it needs more room
   than the 440px a plain form modal gets. */
#purchase-blocked-modal { max-width: 560px; }
#purchase-blocked-modal td { vertical-align: middle; }
.blocked-sales-wrap { max-height: 44vh; overflow: auto; }

/* ── Purchase modal on a phone ───────────────────────────
   The pay row (two amounts + Full) and the sticky footer were laid out for a
   desktop width and pushed the form sideways on a 390px screen — the Online
   box and the Full button ended up past the right edge. Inputs also refuse to
   shrink below their intrinsic size without min-width: 0. */
@media (max-width: 768px) {
  .purchase-pay-row {
    flex-wrap: wrap;
  }

  /* Cash and Online share a line; Full drops beneath them full width. */
  .purchase-pay-row label {
    flex: 1 1 calc(50% - 0.3rem);
    min-width: 0;
  }

  .purchase-pay-row .btn {
    flex: 1 1 100%;
    min-height: 42px;
  }

  .purchase-pay-row input {
    width: 100%;
    min-width: 0;
  }

  /* Branch split: the branch picker keeps the line, qty and remove follow. */
  .purchase-branch-row {
    flex-wrap: wrap;
  }

  .purchase-branch-row .pbs-branch {
    flex: 1 1 100%;
    min-width: 0;
  }

  .purchase-branch-row .pbs-qty {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
  }

  /* Total on its own line, then Cancel + Record share the next one. */
  .sell-modal-footer {
    flex-wrap: wrap;
    gap: 0.55rem;
  }

  .sell-modal-footer .total-preview {
    flex: 1 1 100%;
  }

  .sell-modal-actions {
    flex: 1 1 100%;
  }

  .sell-modal-actions .btn.primary {
    min-width: 0;
    flex: 1 1 auto;
  }

  /* Nothing in this form should ever scroll sideways. */
  #purchase-form,
  #purchase-form .sell-form-row,
  #purchase-form label {
    min-width: 0;
  }

  #purchase-form input,
  #purchase-form select {
    max-width: 100%;
    min-width: 0;
  }
}

/* ── Daily reminders ─────────────────────────────────────── */
.reminder-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin: 0.5rem 0 0.9rem;
}

.reminder-filters label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.78rem;
  color: var(--muted, #6b7280);
  flex: 1 1 150px;
  min-width: 0;
}

.reminder-filters input { min-width: 0; }

#reminders-summary { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.reminder-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.reminder-card {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-inline-start: 4px solid var(--warning, #f5a623);
  border-radius: var(--radius-sm, 10px);
  background: var(--bg);
}

.reminder-card.urgent { border-inline-start-color: var(--danger, #e2574c); }

.reminder-main { flex: 1 1 200px; min-width: 0; }

.reminder-name { font-weight: 700; }

.reminder-meta {
  font-size: 0.76rem;
  color: var(--muted, #6b7280);
  margin-top: 0.15rem;
}

.reminder-amount {
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--danger, #e2574c);
  white-space: nowrap;
}

.reminder-tags { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-top: 0.3rem; }

.reminder-tag {
  font-size: 0.68rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--warning-glow, rgba(245,158,11,0.16));
  color: var(--warning, #f5a623);
}

.reminder-tag.due {
  background: rgba(226, 87, 76, 0.14);
  color: var(--danger, #e2574c);
}

.reminder-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

@media (max-width: 768px) {
  .reminder-card { align-items: flex-start; }
  .reminder-actions { flex: 1 1 100%; }
  .reminder-actions .btn { flex: 1; }
}

/* ── PDF preview ─────────────────────────────────────────
   Shown before any document is downloaded, so a bill or statement can be
   checked without leaving the app. */
dialog.pdf-preview {
  max-width: min(880px, 96vw);
  width: 96%;
  height: min(92vh, 1000px);
}

dialog.pdf-preview[open] {
  display: flex;
  flex-direction: column;
  max-height: 92vh;
}

.pdf-preview-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
}

.pdf-preview-title h3 { margin: 0; }
.pdf-preview-title .hint { margin: 0.15rem 0 0; word-break: break-all; }

.pdf-preview-body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--bg);
}

.pdf-preview-body iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #525659;   /* the grey a PDF viewer paints behind the page */
}

.pdf-preview-loading,
.pdf-preview-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1.5rem;
  color: var(--muted, #6b7280);
  font-size: 0.85rem;
  background: var(--bg);
}

.pdf-preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
  padding: 0.8rem 1rem calc(0.8rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
  dialog.pdf-preview { height: 94vh; max-height: 94vh; }
  .pdf-preview-actions .btn { flex: 1 1 auto; min-height: 44px; }
  .pdf-preview-actions .btn.primary { flex: 1 1 100%; order: -1; }
}

/* ── Sale modal on a phone ───────────────────────────────
   Same cause as the purchase modal: grid children and form controls will not
   shrink past their intrinsic width without min-width: 0, so the qty/unit row
   pushed the form sideways. */
@media (max-width: 768px) {
  #sell-form,
  #sell-form .sell-form-row,
  #sell-form .sell-form-cols,
  #sell-form .sell-col,
  #sell-form .sell-line,
  #sell-form label {
    min-width: 0;
  }

  #sell-form input,
  #sell-form select {
    max-width: 100%;
    min-width: 0;
  }

  .sell-pay-fields,
  .sell-pay-fields .input-suffix {
    min-width: 0;
  }

  .sell-pay-fields input { width: 100%; min-width: 0; }
}

/* Banks page card lists: hidden on desktop, flex columns on a phone — the
   generic .mobile-only flip sets display:block, which would eat the gap. */
#banks-cards.mobile-only,
#bank-ledger-cards.mobile-only { display: none; }

@media (max-width: 768px) {
  #banks-cards.mobile-only,
  #bank-ledger-cards.mobile-only {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
  }
}
