:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-strong: #f0efe8;
  --text: #1e2428;
  --muted: #69737b;
  --line: #dedbd2;
  --primary: #146c5c;
  --primary-dark: #0d4f43;
  --accent: #d88a26;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(38, 43, 46, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #13201d;
  color: white;
  display: flex;
  flex-direction: column;
  padding: 24px;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--accent);
  color: #1e1710;
  font-weight: 800;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}

.logo-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-mark.has-logo,
.business-logo-preview.has-logo,
.business-card-logo.has-logo,
.product-photo-preview.has-logo,
.supply-photo-preview.has-logo,
.product-thumb.has-logo {
  background: #ffffff;
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p {
  color: #bdd0c9;
  font-size: 14px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #d7e2dd;
  padding: 12px 14px;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

.side-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.mobile-menu-button,
.sidebar-close,
.mobile-menu-backdrop,
.mobile-bottom-nav {
  display: none;
}

.content {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.topbar h2 {
  margin: 0;
  font-size: 32px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 14px;
}

.search-wrap {
  width: min(420px, 100%);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 11px 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.view {
  display: none;
}

.active-view {
  display: grid;
  gap: 20px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
}

.stat-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 18px;
  display: grid;
  gap: 10px;
}

.stat-card span {
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}

.stat-card strong {
  font-size: 28px;
}

.two-column,
.three-column,
.sale-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 20px;
}

.three-column {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel {
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-heading h3,
.total-panel h3 {
  margin: 0;
  font-size: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 130px auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
}

.scan-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.form-grid.expanded {
  grid-template-columns: minmax(160px, 1.2fr) minmax(220px, 1.4fr) repeat(5, minmax(105px, 1fr)) auto;
}

.inline-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.form-grid.purchase-grid {
  grid-template-columns: minmax(160px, 1.2fr) 100px 140px 140px minmax(160px, 1fr) auto;
}

.form-grid.compact-grid {
  grid-template-columns: 180px minmax(220px, 1fr);
}

.supply-rows {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.legacy-purchase-panel {
  display: none;
}

.supply-row {
  display: grid;
  grid-template-columns: 54px 84px minmax(190px, 1.4fr) 80px 110px 110px 84px auto;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-warm);
  padding: 12px;
}

.supply-row input[type="hidden"] {
  display: none;
}

.primary-button,
.small-button,
.ghost-button,
.import-label {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 10px 14px;
  font-weight: 800;
}

.primary-button,
.small-button {
  background: var(--primary);
  color: white;
}

.primary-button:hover,
.small-button:hover {
  background: var(--primary-dark);
}

.secondary,
.ghost-button,
.import-label {
  background: var(--surface-strong);
  color: var(--text);
}

.danger {
  background: var(--danger);
}

.wide {
  width: 100%;
}

.import-label {
  display: grid;
  place-items: center;
  color: white;
  background: rgba(255, 255, 255, 0.12);
}

.import-label input {
  display: none;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.total-panel {
  display: grid;
  align-content: start;
  gap: 16px;
}

.summary-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.summary-line strong {
  font-size: 24px;
}

.list {
  display: grid;
  gap: 10px;
}

.list-item,
.customer-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffdfa;
}

.business-form {
  display: grid;
  grid-template-columns: minmax(220px, 0.55fr) minmax(260px, 1fr) auto;
  align-items: end;
  gap: 16px;
}

.sync-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) minmax(180px, 0.7fr) auto;
  align-items: end;
  gap: 12px;
}

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.business-logo-editor {
  display: grid;
  grid-template-columns: 82px 1fr 1fr;
  align-items: center;
  gap: 10px;
}

.product-photo-editor {
  display: grid;
  grid-template-columns: 82px 1fr 1fr;
  align-items: center;
  gap: 10px;
}

.business-logo-preview,
.business-card-logo,
.product-photo-preview,
.supply-photo-preview,
.product-thumb {
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #1e1710;
  font-weight: 900;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}

.business-logo-preview,
.product-photo-preview {
  width: 82px;
  height: 82px;
  font-size: 24px;
}

.product-thumb,
.supply-photo-preview {
  width: 54px;
  height: 54px;
  font-size: 13px;
  flex: 0 0 auto;
}

.business-card-logo {
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
}

.product-photo-upload input,
.supply-photo-upload input {
  display: none;
}

.business-card.active-business {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(20, 108, 92, 0.18);
}

.logo-upload {
  color: var(--text);
  display: grid;
  place-items: center;
  text-align: center;
}

.logo-upload input {
  display: none;
}

.item-main {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.item-main strong {
  display: block;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.icon-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  min-width: 38px;
  min-height: 36px;
  padding: 8px 10px;
}

.barcode-chip {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
  color: var(--text);
  padding: 8px 10px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  letter-spacing: 0;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.pill {
  border-radius: 999px;
  background: #e5f2ee;
  color: var(--primary-dark);
  padding: 8px 12px;
  font-weight: 800;
}

.analytics-heading {
  align-items: flex-start;
}

.analytics-heading p {
  margin: 6px 0 0;
}

.range-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.range-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--button-quiet);
  min-height: 38px;
  padding: 8px 12px;
  font-weight: 800;
  color: var(--text);
}

.range-button.active {
  background: var(--primary);
  color: var(--primary-contrast);
  border-color: var(--primary);
}

.analytics-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.mini-stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
  padding: 14px;
  display: grid;
  gap: 8px;
}

.mini-stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.mini-stat strong {
  font-size: 20px;
}

.chart-panel {
  min-width: 0;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-legend i {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
}

.legend-sales {
  background: #146c5c;
}

.legend-profit {
  background: #d88a26;
}

.legend-purchases {
  background: #8a3ffc;
}

.legend-balance {
  background: #1f76d2;
}

.chart-wrap {
  position: relative;
  width: 100%;
  min-height: 360px;
}

#businessChart {
  width: 100%;
  height: 360px;
  display: block;
}

.chart-tooltip {
  position: absolute;
  display: none;
  min-width: 180px;
  border-radius: 8px;
  background: #13201d;
  color: white;
  padding: 10px 12px;
  font-size: 13px;
  box-shadow: var(--shadow);
  pointer-events: none;
  z-index: 5;
}

.chart-tooltip strong {
  display: block;
  margin-bottom: 6px;
}

.insight-good {
  border-left: 4px solid var(--primary);
}

.insight-warn {
  border-left: 4px solid var(--accent);
}

.insight-bad {
  border-left: 4px solid var(--danger);
}

.empty {
  color: var(--muted);
  padding: 14px;
  background: var(--surface-strong);
  border-radius: 8px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  min-width: 220px;
  max-width: 360px;
  padding: 13px 16px;
  background: #13201d;
  color: white;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

dialog {
  border: 0;
  border-radius: 8px;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.wide-dialog {
  width: min(680px, calc(100vw - 28px));
  max-width: 680px;
}

dialog::backdrop {
  background: rgba(19, 32, 29, 0.42);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.barcode-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  display: grid;
  place-items: center;
  min-height: 190px;
  padding: 18px;
  overflow-x: auto;
}

.barcode-preview svg {
  max-width: 100%;
  height: auto;
}

.bulk-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.bulk-barcode-list {
  display: grid;
  gap: 8px;
  max-height: min(58vh, 520px);
  overflow: auto;
  padding-right: 4px;
}

.bulk-barcode-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-warm);
  padding: 12px;
}

.bulk-check {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.bulk-check input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.bulk-check span {
  min-width: 0;
}

.bulk-check strong,
.bulk-check small {
  display: block;
}

.bulk-check small {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.bulk-quantity {
  min-width: 0;
}

.bulk-quantity input {
  text-align: center;
}

.scanner-box {
  position: relative;
  background: #101816;
  border-radius: 8px;
  overflow: hidden;
  min-height: 320px;
}

.scanner-box video {
  width: 100%;
  min-height: 320px;
  object-fit: cover;
  display: block;
}

.scanner-line {
  position: absolute;
  left: 12%;
  right: 12%;
  top: 50%;
  height: 3px;
  background: var(--accent);
  box-shadow: 0 0 18px rgba(216, 138, 38, 0.8);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    padding: 16px;
  }

  .nav {
    grid-template-columns: repeat(3, 1fr);
  }

  .side-footer {
    grid-template-columns: 1fr 1fr;
  }

  .stats-grid,
  .analytics-stats,
  .two-column,
  .three-column,
  .sale-layout,
  .business-form,
  .sync-form,
  .form-grid.expanded,
  .form-grid.purchase-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 680px) {
  .content {
    padding: 18px;
  }

  .topbar,
  .item-main {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar h2 {
    font-size: 26px;
  }

  .nav,
  .stats-grid,
  .analytics-stats,
  .two-column,
  .three-column,
  .sale-layout,
  .business-form,
  .sync-form,
  .business-logo-editor,
  .form-grid,
  .scan-strip,
  .form-grid.expanded,
  .form-grid.purchase-grid,
  .form-grid.compact-grid,
  .product-photo-editor,
  .side-footer {
    grid-template-columns: 1fr;
  }
}

/* Professional polish layer */
:root {
  --bg: #f5f3ee;
  --bg-soft: #fbfaf7;
  --surface: #ffffff;
  --surface-warm: #fffdfa;
  --surface-strong: #ece8dd;
  --text: #1b2324;
  --heading: #101718;
  --muted: #6d777b;
  --line: #ded8cb;
  --line-strong: #cfc7b8;
  --primary: #0f7664;
  --primary-dark: #0b574a;
  --primary-soft: #e4f4ef;
  --accent: #df9229;
  --accent-soft: #fff0d8;
  --danger: #b42318;
  --purple: #7c3aed;
  --blue: #1f76d2;
  --shadow: 0 18px 45px rgba(32, 38, 37, 0.09);
  --shadow-soft: 0 8px 22px rgba(32, 38, 37, 0.06);
  --radius: 8px;
  --sidebar: #10201c;
  --primary-contrast: #ffffff;
  --button-quiet: var(--surface-strong);
  --button-quiet-hover: #e4dfd2;
}

html {
  scroll-behavior: smooth;
}

body {
  background:
    radial-gradient(circle at top right, rgba(223, 146, 41, 0.12), transparent 28rem),
    linear-gradient(180deg, var(--bg-soft), var(--bg));
  color: var(--text);
  line-height: 1.45;
}

button,
.import-label {
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

button:hover,
.import-label:hover {
  transform: translateY(-1px);
}

button:active,
.import-label:active {
  transform: translateY(0);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(15, 118, 100, 0.18);
  outline-offset: 2px;
  border-color: var(--primary);
}

.app-shell {
  grid-template-columns: 292px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 16rem),
    var(--sidebar);
  padding: 28px 24px;
  gap: 26px;
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.08);
}

.brand {
  min-width: 0;
}

.brand-mark {
  width: 52px;
  height: 52px;
  background: linear-gradient(145deg, #f0a23c, #c97916);
  font-weight: 900;
  box-shadow: 0 12px 26px rgba(223, 146, 41, 0.28);
  flex: 0 0 auto;
}

.brand h1 {
  color: #ffffff;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.brand p {
  color: #bdd2ca;
  font-size: 13px;
  margin-top: 4px;
}

.nav {
  gap: 6px;
}

.nav-item {
  border: 1px solid transparent;
  min-height: 44px;
  font-weight: 750;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.08);
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.15);
  box-shadow: inset 3px 0 0 var(--accent);
}

.content {
  padding: 34px;
}

.topbar {
  gap: 22px;
  margin-bottom: 26px;
}

.topbar h2 {
  color: var(--heading);
  font-size: clamp(28px, 3vw, 42px);
  letter-spacing: 0;
  line-height: 1;
}

.eyebrow {
  font-weight: 650;
}

.search-wrap {
  width: min(460px, 100%);
}

input,
select,
textarea {
  border-color: var(--line);
  border-radius: var(--radius);
  min-height: 44px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--line-strong);
}

input::placeholder,
textarea::placeholder {
  color: #9aa1a4;
}

label {
  font-size: 12px;
  font-weight: 800;
}

.active-view {
  animation: viewIn 0.22s ease both;
}

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

.stat-card,
.panel {
  background: rgba(255, 255, 255, 0.92);
  border-color: rgba(222, 216, 203, 0.9);
  box-shadow: var(--shadow-soft);
}

.stat-card {
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.stat-card span {
  font-size: 12px;
  font-weight: 800;
}

.stat-card strong {
  color: var(--heading);
  font-size: clamp(22px, 2.1vw, 30px);
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.panel {
  padding: 20px;
}

.panel-heading {
  align-items: flex-start;
  margin-bottom: 18px;
}

.panel-heading h3,
.total-panel h3 {
  color: var(--heading);
  line-height: 1.2;
}

.scan-strip {
  border-color: rgba(15, 118, 100, 0.18);
  background: linear-gradient(180deg, #ffffff, #f4fbf8);
}

.primary-button,
.small-button,
.ghost-button,
.import-label {
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 850;
  white-space: nowrap;
}

.primary-button,
.small-button {
  background: linear-gradient(180deg, #12806c, var(--primary));
  color: var(--primary-contrast);
  box-shadow: 0 10px 20px rgba(15, 118, 100, 0.18);
}

.primary-button:hover,
.small-button:hover {
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  box-shadow: 0 14px 26px rgba(15, 118, 100, 0.22);
}

.secondary,
.ghost-button {
  background: var(--button-quiet);
  color: var(--text);
  border-color: rgba(207, 199, 184, 0.65);
  box-shadow: none;
}

.ghost-button:hover,
.secondary:hover {
  background: var(--button-quiet-hover);
}

.danger {
  background: linear-gradient(180deg, #c3362a, var(--danger));
}

.import-label {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.12);
}

.import-label:hover {
  background: rgba(255, 255, 255, 0.18);
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
}

th,
td {
  padding: 13px 12px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7f4ed;
  font-size: 11px;
  letter-spacing: 0;
}

tbody tr {
  transition: background 0.14s ease;
}

tbody tr:hover {
  background: #fbf8f0;
}

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

.summary-line {
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-warm);
}

.summary-line span {
  color: var(--muted);
  font-weight: 750;
}

.summary-line strong {
  color: var(--heading);
  overflow-wrap: anywhere;
}

.list-item,
.customer-card {
  background: var(--surface-warm);
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.list-item:hover,
.customer-card:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  box-shadow: 0 10px 22px rgba(32, 38, 37, 0.06);
}

.business-logo-preview,
.business-card-logo {
  background: linear-gradient(145deg, #f0a23c, #c97916);
}

.business-logo-preview {
  box-shadow: 0 14px 28px rgba(223, 146, 41, 0.18);
}

.business-card.active-business {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 100, 0.13);
}

.item-main strong {
  color: var(--heading);
}

.icon-button {
  font-weight: 750;
}

.icon-button:hover,
.barcode-chip:hover,
.range-button:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.discount-input {
  max-width: 88px;
  min-height: 36px;
  padding: 7px 9px;
}

.discount-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #85510d;
  padding: 6px 9px;
  font-weight: 850;
  margin-right: 6px;
}

.discount-warning {
  display: none;
  border: 1px solid rgba(180, 35, 24, 0.26);
  border-radius: var(--radius);
  background: #fff1ef;
  color: var(--danger);
  padding: 12px 14px;
  gap: 4px;
}

.discount-warning.show {
  display: grid;
}

.discount-warning strong {
  color: var(--danger);
}

.cards-grid {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.pill {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 850;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.range-button.active {
  box-shadow: 0 10px 18px rgba(15, 118, 100, 0.16);
}

.mini-stat {
  background: var(--surface-warm);
}

.mini-stat strong {
  color: var(--heading);
  overflow-wrap: anywhere;
}

.legend-sales {
  background: var(--primary);
}

.legend-profit {
  background: var(--accent);
}

.legend-purchases {
  background: var(--purple);
}

.legend-balance {
  background: var(--blue);
}

.chart-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #ffffff, #fbf8f0);
  padding: 8px;
}

.chart-tooltip,
.toast {
  background: var(--sidebar);
}

.toast {
  z-index: 30;
}

dialog {
  border-radius: var(--radius);
}

dialog::backdrop {
  background: rgba(16, 32, 28, 0.48);
  backdrop-filter: blur(2px);
}

@media (max-width: 1180px) {
  .stats-grid,
  .analytics-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .three-column {
    grid-template-columns: 1fr;
  }

  .form-grid.expanded,
  .form-grid.purchase-grid,
  .sync-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }

  .two-column,
  .sale-layout,
  .business-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .content {
    padding: 18px;
  }

  .topbar,
  .panel-heading,
  .item-main {
    align-items: stretch;
    flex-direction: column;
  }

  .search-wrap {
    width: 100%;
  }

  .inline-field {
    grid-template-columns: 1fr;
  }

  .topbar h2 {
    font-size: 30px;
  }

  .panel,
  .stat-card {
    padding: 16px;
  }
}

.four-column {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
}

.legend-expenses {
  background: var(--danger);
}

.form-grid.expense-grid {
  grid-template-columns: minmax(190px, 1.2fr) 150px 130px 140px minmax(180px, 1fr) auto;
}

@media (max-width: 1180px) {
  .four-column {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid.expense-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .four-column,
  .form-grid.expense-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  html {
    width: 100%;
    overflow-x: hidden;
  }

  body {
    background: var(--bg-soft);
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
    width: 100%;
    overflow-x: hidden;
  }

  body.mobile-menu-open {
    overflow: hidden;
  }

  .app-shell {
    display: block;
    min-height: 100vh;
  }

  .mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(16, 32, 28, 0.42);
    backdrop-filter: blur(3px);
  }

  body.mobile-menu-open .mobile-menu-backdrop {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(86vw, 326px);
    height: 100dvh;
    padding: calc(16px + env(safe-area-inset-top)) 16px 18px;
    transform: translateX(-104%);
    transition: transform 0.22s ease;
    border-radius: 0 18px 18px 0;
    box-shadow: 18px 0 45px rgba(16, 32, 28, 0.28);
  }

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

  .sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: flex-end;
    min-height: 38px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    padding: 0 14px;
    font-weight: 800;
  }

  .brand {
    padding-right: 8px;
  }

  .nav {
    overflow-y: auto;
    padding-right: 2px;
  }

  .content {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    padding: calc(14px + env(safe-area-inset-top)) 12px 18px;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    margin: -14px -12px 14px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    background: rgba(251, 250, 247, 0.94);
    border-bottom: 1px solid rgba(222, 216, 203, 0.75);
    backdrop-filter: blur(12px);
  }

  .mobile-menu-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--heading);
    font-size: 0;
    box-shadow: var(--shadow-soft);
  }

  .mobile-menu-button::before {
    content: "";
    width: 20px;
    height: 14px;
    background:
      linear-gradient(var(--heading), var(--heading)) 0 0 / 100% 2px no-repeat,
      linear-gradient(var(--heading), var(--heading)) 0 50% / 100% 2px no-repeat,
      linear-gradient(var(--heading), var(--heading)) 0 100% / 100% 2px no-repeat;
  }

  .topbar-title {
    min-width: 0;
  }

  .eyebrow {
    margin-bottom: 2px;
    font-size: 12px;
  }

  .topbar h2 {
    font-size: 24px;
    line-height: 1.08;
  }

  .search-wrap {
    grid-column: 1 / -1;
    width: 100%;
  }

  .search-wrap input {
    min-height: 44px;
    border-radius: 12px;
    background: #ffffff;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  .active-view {
    gap: 14px;
  }

  .stats-grid,
  .analytics-stats,
  .four-column {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stat-card {
    min-height: 104px;
    padding: 14px;
  }

  .stat-card strong {
    font-size: 22px;
  }

  .panel {
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 10px 26px rgba(32, 38, 37, 0.07);
  }

  .panel-heading {
    align-items: start;
    gap: 12px;
  }

  .form-grid,
  .form-grid.expanded,
  .form-grid.purchase-grid,
  .form-grid.compact-grid,
  .form-grid.expense-grid,
  .sync-form,
  .business-form,
  .business-logo-editor,
  .product-photo-editor,
  .sale-layout,
  .two-column,
  .three-column,
  .scan-strip {
    grid-template-columns: 1fr;
  }

  .supply-row {
    grid-template-columns: 58px 1fr;
    align-items: stretch;
    gap: 9px;
    padding: 10px;
  }

  .supply-row label:nth-of-type(1) {
    grid-column: auto;
  }

  .supply-row label:nth-of-type(2) {
    grid-column: 2;
  }

  .supply-row label:nth-of-type(n + 3),
  .supply-row button {
    grid-column: 1 / -1;
  }

  .supply-photo-preview {
    width: 58px;
    height: 58px;
  }

  .row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .row-actions button,
  .small-button,
  .icon-button,
  .ghost-button,
  .import-label {
    min-height: 44px;
  }

  .business-card,
  .list-item,
  .customer-card {
    border-radius: 14px;
  }

  .bulk-toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .bulk-barcode-item {
    grid-template-columns: 1fr;
  }

  .mobile-bottom-nav {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    padding: 7px;
    border: 1px solid rgba(222, 216, 203, 0.86);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 18px 42px rgba(16, 32, 28, 0.18);
    backdrop-filter: blur(14px);
  }

  .mobile-bottom-nav .mobile-tab,
  .mobile-bottom-nav .nav-item {
    min-height: 46px;
    border: 0;
    border-radius: 13px;
    background: transparent;
    color: var(--muted);
    padding: 4px 2px;
    text-align: center;
    font-size: 11px;
    font-weight: 850;
    box-shadow: none;
  }

  .mobile-bottom-nav .nav-item.active {
    background: var(--primary-soft);
    color: var(--primary-dark);
    box-shadow: none;
  }

  .mobile-bottom-nav .mobile-tab::before {
    display: block;
    margin-bottom: 2px;
    color: currentColor;
    font-size: 16px;
    line-height: 1;
  }

  .mobile-bottom-nav [data-view="dashboard"]::before {
    content: "I";
  }

  .mobile-bottom-nav [data-view="sale"]::before {
    content: "+";
  }

  .mobile-bottom-nav [data-view="products"]::before {
    content: "P";
  }

  .mobile-bottom-nav [data-view="analytics"]::before {
    content: "^";
  }

  .mobile-bottom-nav #bottomMore::before {
    content: "=";
  }
}

@media (max-width: 430px) {
  .content {
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .mobile-menu-button {
    width: 42px;
    height: 42px;
  }

  .stats-grid,
  .analytics-stats,
  .four-column {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 12px;
  }

  .panel-heading {
    display: grid;
    grid-template-columns: 1fr;
  }

  .dialog-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .dialog-actions button {
    width: 100%;
  }

  .supply-row {
    grid-template-columns: 54px 1fr;
  }

  .supply-row label:nth-of-type(1),
  .supply-row label:nth-of-type(2),
  .supply-row label:nth-of-type(n + 3),
  .supply-row button {
    grid-column: 1 / -1;
  }

  .mobile-bottom-nav {
    left: 8px;
    right: 8px;
    border-radius: 16px;
  }
}

body[data-theme="dark"] {
  --bg: #101514;
  --bg-soft: #151b1a;
  --surface: #1d2423;
  --surface-warm: #202826;
  --surface-strong: #2b3432;
  --text: #edf3f0;
  --heading: #ffffff;
  --muted: #a6b2ad;
  --line: #34413d;
  --line-strong: #4a5a55;
  --primary: #34d399;
  --primary-dark: #7ddfbd;
  --primary-soft: #15372f;
  --accent: #f2a33a;
  --accent-soft: #3c2b14;
  --danger: #fb7185;
  --sidebar: #0a0f0e;
  --primary-contrast: #061310;
  --button-quiet: #26302e;
  --button-quiet-hover: #303c38;
}

body[data-theme="pink"] {
  --bg: #fff4f8;
  --bg-soft: #fffafd;
  --surface: #ffffff;
  --surface-warm: #fff7fb;
  --surface-strong: #f8dce8;
  --text: #392630;
  --heading: #23151c;
  --muted: #80616f;
  --line: #eed1dc;
  --line-strong: #dfaabd;
  --primary: #c02665;
  --primary-dark: #8f164b;
  --primary-soft: #fde7f0;
  --accent: #f59e0b;
  --accent-soft: #fff1d6;
  --danger: #b42318;
  --sidebar: #351827;
  --primary-contrast: #ffffff;
  --button-quiet: #f8dce8;
  --button-quiet-hover: #f2c7d8;
}

body[data-theme="luxury"] {
  --bg: #100f0c;
  --bg-soft: #171510;
  --surface: #211f18;
  --surface-warm: #262217;
  --surface-strong: #3a3322;
  --text: #f4ead0;
  --heading: #fff7df;
  --muted: #c7b78e;
  --line: #473f2c;
  --line-strong: #7b693a;
  --primary: #d4af37;
  --primary-dark: #f2d675;
  --primary-soft: #3a3018;
  --accent: #f0c95a;
  --accent-soft: #3b3015;
  --danger: #f87171;
  --sidebar: #050504;
  --primary-contrast: #17100a;
  --button-quiet: #302a1c;
  --button-quiet-hover: #3b321f;
}

body[data-theme="dark"],
body[data-theme="luxury"] {
  color-scheme: dark;
}

body[data-theme="dark"] input,
body[data-theme="dark"] select,
body[data-theme="dark"] textarea,
body[data-theme="dark"] .range-button,
body[data-theme="dark"] .ghost-button,
body[data-theme="dark"] .secondary,
body[data-theme="dark"] .icon-button,
body[data-theme="dark"] .barcode-chip,
body[data-theme="luxury"] input,
body[data-theme="luxury"] select,
body[data-theme="luxury"] textarea,
body[data-theme="luxury"] .range-button,
body[data-theme="luxury"] .ghost-button,
body[data-theme="luxury"] .secondary,
body[data-theme="luxury"] .icon-button,
body[data-theme="luxury"] .barcode-chip {
  background: var(--surface-strong);
  color: var(--text);
}

body[data-theme="dark"] .range-button:hover,
body[data-theme="dark"] .ghost-button:hover,
body[data-theme="dark"] .secondary:hover,
body[data-theme="dark"] .icon-button:hover,
body[data-theme="dark"] .barcode-chip:hover,
body[data-theme="luxury"] .range-button:hover,
body[data-theme="luxury"] .ghost-button:hover,
body[data-theme="luxury"] .secondary:hover,
body[data-theme="luxury"] .icon-button:hover,
body[data-theme="luxury"] .barcode-chip:hover {
  background: var(--button-quiet-hover);
  color: var(--heading);
}

body[data-theme="dark"] .range-button.active,
body[data-theme="luxury"] .range-button.active {
  background: var(--primary);
  color: var(--primary-contrast);
  border-color: var(--primary);
}

body[data-theme="dark"] .panel,
body[data-theme="dark"] .stat-card,
body[data-theme="dark"] .list-item,
body[data-theme="dark"] .customer-card,
body[data-theme="dark"] .business-card,
body[data-theme="luxury"] .panel,
body[data-theme="luxury"] .stat-card,
body[data-theme="luxury"] .list-item,
body[data-theme="luxury"] .customer-card,
body[data-theme="luxury"] .business-card {
  background: var(--surface);
}

body[data-theme="dark"] .mobile-bottom-nav,
body[data-theme="luxury"] .mobile-bottom-nav,
body[data-theme="dark"] .topbar,
body[data-theme="luxury"] .topbar {
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.theme-option {
  display: grid;
  gap: 10px;
  min-height: 178px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-warm);
  color: var(--text);
  padding: 14px;
  text-align: left;
}

.theme-option strong {
  color: var(--heading);
  font-size: 17px;
}

.theme-option small {
  color: var(--muted);
  line-height: 1.35;
}

.theme-option.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent), var(--shadow-soft);
}

.theme-preview {
  display: block;
  height: 74px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  overflow: hidden;
  position: relative;
}

.theme-preview::before,
.theme-preview::after {
  content: "";
  position: absolute;
  border-radius: 8px;
}

.theme-preview::before {
  left: 12px;
  top: 12px;
  width: 34px;
  height: 34px;
}

.theme-preview::after {
  right: 12px;
  top: 16px;
  width: 58px;
  height: 10px;
  box-shadow: 0 18px 0 currentColor;
}

.theme-preview-light {
  background: linear-gradient(90deg, #10201c 0 28%, #fbfaf7 28% 100%);
  color: #0f7664;
}

.theme-preview-light::before {
  background: #df9229;
}

.theme-preview-pink {
  background: linear-gradient(90deg, #351827 0 28%, #fff4f8 28% 100%);
  color: #c02665;
}

.theme-preview-pink::before {
  background: #f8b6cc;
}

.theme-preview-dark {
  background: linear-gradient(90deg, #0a0f0e 0 28%, #151b1a 28% 100%);
  color: #34d399;
}

.theme-preview-dark::before {
  background: #f2a33a;
}

.theme-preview-luxury {
  background: linear-gradient(90deg, #050504 0 28%, #171510 28% 100%);
  color: #d4af37;
}

.theme-preview-luxury::before {
  background: #d4af37;
}

@media (max-width: 980px) {
  .theme-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .theme-grid {
    grid-template-columns: 1fr;
  }

  .theme-option {
    min-height: auto;
  }
}

/* Mobile width guard: prevent panels from being clipped on narrow iPhone screens. */
@media (max-width: 860px) {
  html,
  body {
    min-width: 0;
    max-width: 100%;
  }

  html {
    overflow-x: auto;
  }

  body {
    overflow-x: clip;
  }

  .app-shell,
  .content,
  .content > *,
  .view,
  .active-view,
  .panel,
  .stat-card,
  .table-wrap,
  .chart-panel,
  .chart-wrap,
  .list,
  .cards-grid,
  .business-card,
  .list-item,
  .customer-card {
    min-width: 0;
    max-width: 100%;
  }

  .content {
    width: auto;
    max-width: none;
    overflow: visible;
  }

  .topbar {
    width: auto;
    max-width: none;
    margin: 0 0 14px;
    padding-left: 0;
    padding-right: 0;
  }

  .table-wrap,
  .barcode-output {
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }
}
