:root {
  color-scheme: light;
  --ink: #17211f;
  --home-ink: #eef2f1;
  --home-bg: #252b29;
  --muted: #687572;
  --line: #d9e1df;
  --soft: #f4f7f6;
  --paper: #ffffff;
  --brand: #0f766e;
  --brand-dark: #0b5f59;
  --accent: #e0a82e;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(24, 36, 33, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #eef3f1;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.home-mode {
  background: var(--home-bg);
}

body.locked {
  overflow: hidden;
}

body.locked .topbar,
body.locked .module-tabs,
body.locked .home-panel,
body.locked .app-shell,
body.locked .reports-panel,
body.locked .work-panel {
  filter: blur(5px);
  pointer-events: none;
  user-select: none;
}

body.customer-display-mode {
  background: #0f1816;
  color: white;
}

body.customer-display-mode > :not(.customer-display-screen) {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar,
.module-tabs,
.home-panel,
.app-shell,
.reports-panel,
.work-panel {
  width: min(1180px, calc(100% - 28px));
  margin-inline: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 0 14px;
}

.topbar h1 span {
  color: var(--brand);
}

body.home-mode .topbar {
  width: 100%;
  padding: 14px 24px;
  color: white;
  background: #1d2220;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

body.home-mode .topbar .eyebrow {
  color: rgba(255, 255, 255, 0.74);
}

body.home-mode .topbar h1 {
  font-size: 2rem;
}

body.home-mode .module-tabs {
  display: none;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(238, 243, 241, 0.88);
  backdrop-filter: blur(8px);
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 2rem;
}

.login-card p {
  margin: 6px 0 0;
  color: var(--muted);
}

.login-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.eyebrow,
.panel-header p,
.summary-card span {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 3.2rem);
}

h2 {
  font-size: 1.15rem;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 16px;
  align-items: start;
}

.home-panel {
  width: 100%;
  min-height: calc(100vh - 83px);
  gap: 0;
  padding: clamp(18px, 3vw, 44px) clamp(18px, 3vw, 42px) 24px;
  color: var(--home-ink);
  background: var(--home-bg);
}

.home-hero {
  min-height: min(680px, calc(100vh - 230px));
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(460px, 730px);
  gap: clamp(24px, 7vw, 110px);
  align-items: center;
}

.home-business {
  display: grid;
  align-content: center;
  gap: 8px;
}

.home-business strong {
  font-size: clamp(1.1rem, 2vw, 1.55rem);
}

.home-business span {
  color: rgba(255, 255, 255, 0.86);
  font-size: clamp(1.35rem, 2.8vw, 2.2rem);
}

.home-business time {
  font-size: clamp(2.6rem, 6vw, 5rem);
  line-height: 1;
}

.dashboard-grid {
  display: grid;
  gap: 10px;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.module-grid button {
  min-height: 88px;
  padding: 14px 16px;
  border: 1px solid #cfd4da;
  border-radius: 8px;
  background: linear-gradient(135deg, #f7f8fb, #e4e8ee);
  color: var(--ink);
  display: flex;
  align-items: center;
  align-content: center;
  gap: 12px;
  text-align: left;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
  touch-action: manipulation;
}

.module-grid strong {
  font-size: clamp(1rem, 1.6vw, 1.25rem);
}

.module-icon {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--brand);
  border-radius: 8px;
  font-weight: 900;
}

.module-grid span,
.summary-card small {
  color: var(--muted);
}

.home-bottom-bar {
  display: block;
  align-items: end;
}

.home-bottom-bar .dashboard-grid {
  grid-template-columns: repeat(7, minmax(120px, 1fr));
}

.home-bottom-bar .summary-card {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.14);
  color: white;
  box-shadow: none;
}

.home-bottom-bar .summary-card span,
.home-bottom-bar .summary-card small {
  color: rgba(255, 255, 255, 0.68);
}

.module-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 12px;
}

.module-tabs button {
  flex: 0 0 auto;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--paper);
  color: var(--muted);
  font-weight: 800;
}

.module-tabs button.active {
  color: white;
  background: var(--brand);
  border-color: var(--brand);
}

.app-view {
  display: none;
}

.app-view.active {
  display: grid;
}

.products-panel,
.cart-panel,
.reports-panel,
.work-panel,
dialog {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.products-panel,
.cart-panel {
  padding: 18px;
}

.cart-panel {
  position: sticky;
  top: 14px;
}

.sale-toolbar,
.sale-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.sale-toolbar button {
  min-height: 40px;
  border: 1px solid #33438e;
  border-radius: 8px;
  background: #4052a4;
  color: white;
  font-weight: 800;
}

.sale-toolbar button.active {
  background: #fff5da;
  color: var(--ink);
  border-color: var(--accent);
}

.sale-actions {
  grid-template-columns: repeat(3, 1fr);
  margin: 10px 0 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button,
.ghost-button,
.checkout-button,
.payment-buttons button,
.icon-button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 750;
}

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

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

.ghost-button,
.payment-buttons button {
  background: var(--soft);
  color: var(--ink);
  border-color: var(--line);
}

.icon-button {
  width: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--soft);
  border-color: var(--line);
  font-size: 1.35rem;
}

.search-box,
.product-form label,
.calculator label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.search-box {
  margin: 18px 0 12px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: white;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: 2px;
}

.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
}

.category-tabs button {
  flex: 0 0 auto;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 13px;
  background: white;
  color: var(--muted);
  font-weight: 750;
}

.category-tabs button.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
}

.product-card {
  min-height: 156px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 14px;
  text-align: left;
  display: grid;
  align-content: space-between;
  gap: 10px;
  touch-action: manipulation;
}

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

.product-card strong {
  display: block;
  overflow-wrap: anywhere;
}

.product-card.low-stock {
  border-color: #f0b429;
  background: #fffaf0;
}

.product-thumb {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--soft);
}

.product-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.product-price {
  font-size: 1.25rem;
  font-weight: 850;
  color: var(--brand-dark);
}

.cart-items {
  display: grid;
  gap: 8px;
  margin: 16px 0;
  min-height: 160px;
  max-height: 35vh;
  overflow: auto;
}

.empty-state {
  min-height: 150px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
}

.cart-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.cart-row strong {
  display: block;
  overflow-wrap: anywhere;
}

.qty-controls {
  display: grid;
  grid-template-columns: 52px 42px 52px;
  align-items: center;
  text-align: center;
}

.qty-controls button {
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: 8px;
  font-weight: 850;
  font-size: 1.35rem;
  touch-action: manipulation;
}

.calculator {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.totals {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}

.totals div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.totals dt {
  color: var(--muted);
}

.totals dd {
  margin: 0;
  font-weight: 800;
}

.grand-total {
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 1.35rem;
}

.payment-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.payment-buttons button,
.sale-actions button,
.sale-toolbar button,
.checkout-button {
  min-height: 54px;
  touch-action: manipulation;
}

.payment-buttons button.active {
  background: #fff5da;
  border-color: var(--accent);
}

.customer-box {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.customer-box[hidden] {
  display: none;
}

.customer-display-screen {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 24px;
  padding: clamp(22px, 4vw, 52px);
}

.customer-display-screen[hidden] {
  display: none;
}

.customer-display-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  padding-bottom: 20px;
}

.customer-display-header h1 {
  font-size: clamp(2rem, 5vw, 4.8rem);
}

.customer-display-header strong {
  color: #f7d77d;
  font-size: clamp(1.1rem, 2.5vw, 2rem);
}

.customer-display-items {
  display: grid;
  align-content: start;
  gap: 14px;
  overflow: auto;
}

.customer-display-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  padding: 18px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
  font-size: clamp(1.15rem, 2.8vw, 2.2rem);
}

.customer-display-row span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.78em;
}

.customer-display-total {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: baseline;
  padding-top: 18px;
  border-top: 2px solid rgba(255, 255, 255, 0.34);
}

.customer-display-total span {
  color: rgba(255, 255, 255, 0.72);
  font-size: clamp(1.4rem, 3vw, 2.5rem);
}

.customer-display-total strong {
  color: #f7d77d;
  font-size: clamp(3.2rem, 9vw, 8rem);
}

.customer-display-note {
  margin: 0;
  color: rgba(255, 255, 255, 0.66);
  text-align: center;
  font-size: clamp(1rem, 2vw, 1.6rem);
}

.customer-box label,
.scanner label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.customer-box p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.checkout-button {
  width: 100%;
  margin-top: 10px;
  min-height: 52px;
  font-size: 1rem;
}

.reports-panel {
  grid-template-columns: repeat(5, 1fr) auto;
  gap: 10px;
  align-items: stretch;
  margin-top: 16px;
  padding: 12px;
}

.work-panel {
  gap: 16px;
  margin-top: 0;
  padding: 18px;
}

.compact-search {
  margin: 0;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

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

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

.sort-button {
  min-height: 30px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 850;
  text-align: left;
  text-transform: inherit;
}

.sort-button::after {
  content: " ↕";
  color: #9aa5a2;
}

.sort-button.active[data-direction="asc"]::after {
  content: " ↑";
  color: var(--brand);
}

.sort-button.active[data-direction="desc"]::after {
  content: " ↓";
  color: var(--brand);
}

td {
  font-weight: 650;
}

.stock-product-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stock-product-cell span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
}

.status-pill {
  display: inline-grid;
  min-height: 28px;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 0.78rem;
}

.status-pill.warn {
  background: #fff5da;
  color: #8a5a00;
}

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

.row-actions button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  font-weight: 800;
}

.row-actions .danger-button {
  color: var(--danger);
}

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

.finance-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.accounting-layout {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 14px;
  align-items: start;
}

.accounting-form {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.accounting-form h3 {
  margin: 0;
}

.accounting-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.compact-panel-header {
  margin-top: 10px;
}

.summary-card {
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  align-content: center;
  gap: 5px;
}

.summary-card strong {
  font-size: 1.2rem;
  overflow-wrap: anywhere;
}

.sync-card strong {
  color: var(--brand-dark);
}

.check-row {
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
  color: var(--ink);
}

.check-row input {
  min-height: auto;
}

dialog {
  width: min(560px, calc(100% - 24px));
  padding: 0;
  border: 1px solid var(--line);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.36);
}

.product-form,
.receipt,
.scanner {
  padding: 18px;
}

.product-form {
  display: grid;
  gap: 12px;
}

.form-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.form-tabs button,
.quick-tax button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  font-weight: 800;
}

.form-tabs button.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

.form-section {
  display: none;
  gap: 12px;
}

.form-section.active {
  display: grid;
}

.inline-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.quick-tax {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.profit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.profit-box {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.profit-box span,
.profit-box small {
  color: var(--muted);
}

.profit-box strong {
  font-size: 1.35rem;
  color: var(--brand-dark);
}

.scanner {
  display: grid;
  gap: 12px;
  position: relative;
}

.scanner video {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  background: var(--ink);
}

.scanner-line {
  position: absolute;
  left: 34px;
  right: 34px;
  top: 180px;
  height: 2px;
  background: var(--accent);
  box-shadow: 0 0 18px rgba(224, 168, 46, 0.8);
  pointer-events: none;
}

.receipt {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.55;
  white-space: pre-wrap;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px 18px;
}

.compact-actions {
  padding: 0;
  flex-wrap: wrap;
}

.settings-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(18px);
  opacity: 0;
  pointer-events: none;
  background: var(--ink);
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  transition: 180ms ease;
  max-width: min(420px, calc(100% - 24px));
}

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

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

  .home-hero,
  .home-bottom-bar {
    grid-template-columns: 1fr;
  }

  .home-hero {
    min-height: auto;
  }

  .home-bottom-bar .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid,
  .module-grid {
    grid-template-columns: 1fr 1fr;
  }

  .cart-panel {
    position: static;
  }

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

  .finance-grid {
    grid-template-columns: 1fr 1fr;
  }

  .accounting-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar,
  .module-tabs,
  .home-panel,
  .app-shell,
  .reports-panel,
  .work-panel {
    width: min(100% - 18px, 1180px);
  }

  .topbar {
    padding-top: 14px;
  }

  body.home-mode .topbar,
  body.home-mode .home-panel {
    width: 100%;
  }

  .products-panel,
  .cart-panel {
    padding: 12px;
  }

  .panel-header {
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions button {
    flex: 1 1 128px;
  }

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

  .product-card {
    min-height: 124px;
  }

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

  .finance-grid {
    grid-template-columns: 1fr;
  }

  .accounting-summary {
    grid-template-columns: 1fr;
  }

  .profit-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-grid,
  .module-grid {
    grid-template-columns: 1fr 1fr;
  }

  .home-bottom-bar .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .sale-toolbar {
    grid-template-columns: repeat(2, 1fr);
  }

  .reports-panel .ghost-button {
    width: 100%;
  }
}

@media print {
  body > *:not(#receiptDialog) {
    display: none;
  }

  #receiptDialog {
    display: block;
    position: static;
    box-shadow: none;
    border: 0;
  }

  .dialog-actions {
    display: none;
  }
}
