:root {
  --page-bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef2f7;
  --text: #111827;
  --muted: #64748b;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --danger: #dc2626;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  --shadow: 0 6px 20px rgba(15, 23, 42, 0.08);
  --radius: 14px;
  --touch: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Arial, sans-serif;
  background: var(--page-bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

body {
  position: fixed;
  inset: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: white;
  min-height: var(--touch);
  padding: 0 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.appShell {
  height: 100%;
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
  overflow: hidden;
}

.customerHeader {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  min-height: calc(68px + var(--safe-top));
  padding: calc(8px + var(--safe-top)) 12px 8px;
  background: rgba(17, 24, 39, 0.96);
  color: white;
}

.headerText {
  min-width: 0;
  flex: 1;
}

.customerHeader h1 {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

.customerHeader p {
  max-width: 100%;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #d1d5db;
  font-size: 13px;
  line-height: 1.25;
}

.menuWrap {
  position: relative;
  flex: 0 0 auto;
}

.menuButton {
  width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: white;
  font-size: 19px;
  line-height: 1;
}

.customerMenu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  display: none;
  min-width: 176px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.customerMenu.open {
  display: grid;
}

.customerMenu button {
  justify-content: flex-start;
  width: 100%;
  min-height: 44px;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 14px;
  font-weight: 600;
}

.customerMenu button + button {
  border-top: 1px solid var(--line);
}

.customerMenu .dangerMenuItem {
  color: var(--danger);
}

.tabBar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding: 7px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.tabBar button {
  min-width: 0;
  height: 36px;
  min-height: 36px;
  padding: 0 4px;
  overflow: hidden;
  border-radius: 10px;
  background: var(--surface-soft);
  color: #334155;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
}

.tabBar button.active {
  background: var(--primary);
  color: white;
}

main {
  min-height: 0;
  overflow: hidden;
}

.view {
  display: none;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 10px;
  padding-bottom: calc(86px + var(--safe-bottom));
}

.view.active {
  display: block;
}

.searchRow {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 25% minmax(0, 1fr) 15%;
  gap: 6px;
  align-items: center;
  margin: -2px -2px 8px;
  padding: 2px 2px 8px;
  background: var(--page-bg);
}

.sectionTools {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.statementFilters {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.statementFilters button {
  height: 40px;
  min-height: 40px;
}

input,
select {
  width: 100%;
  height: 40px;
  min-width: 0;
  border: 1px solid #d4dae5;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
  font-size: 15px;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 17px, calc(100% - 8px) 17px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 20px;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.refreshButton {
  min-width: 0;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 12px;
  font-size: 18px;
}

.productList,
.cartList,
.orderList {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.ipadProductsLayout {
  min-width: 0;
}

.ipadCartAside {
  display: none;
}

.mobileCartSummary {
  position: sticky;
  bottom: calc(8px + var(--safe-bottom));
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.96);
  padding: 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(14px);
}

.mobileCartSummary div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.mobileCartSummary span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.mobileCartSummary strong {
  color: var(--text);
  font-size: 15px;
}

.mobileCartSummary button {
  flex: 0 0 auto;
  min-height: 42px;
}

.productCard,
.cartItem,
.orderCard,
.statementBox {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}

.productCard {
  position: relative;
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  gap: 10px;
  min-height: 170px;
  padding: 12px;
  overflow: hidden;
}

.productImage {
  width: 80px;
  height: 80px;
  align-self: start;
  border-radius: 12px;
  object-fit: cover;
  background: #e5e7eb;
}

.productBody {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.productTitle {
  min-height: 22px;
  padding-right: 88px;
  overflow: hidden;
  color: var(--text);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
}

.productMeta,
.orderMeta,
.statementMeta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.38;
}

.statementCardLine {
  display: block;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface);
}

.statementCardLine summary {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
}

.priceRow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 15px;
  margin-bottom: 2px;
}

.stockBadge {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  max-width: 104px;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
}

.inStock {
  background: var(--success-bg);
  color: var(--success-text);
}

.lowStock {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.outStock {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.qtyRow {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.productQtyRow {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 6px;
  max-width: 154px;
}

.qtyRow input {
  height: 38px;
  width: 52px;
  flex: 0 0 52px;
  text-align: center;
}

.qtyStep {
  width: 34px;
  height: 34px;
  min-height: 34px;
  flex: 0 0 34px;
  padding: 0;
  border-radius: 50%;
  background: #e2e8f0;
  color: #0f172a;
  font-size: 18px;
}

.addStep {
  background: var(--primary);
  color: white;
}

.cartItem,
.orderCard,
.statementBox {
  padding: 12px;
}

.cartItemHeader,
.orderHeader {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.cartItemHeader > div,
.orderHeader > div {
  min-width: 0;
}

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

.cartFooter {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 18px rgba(15, 23, 42, 0.10);
}

.cartFooter button {
  min-width: 120px;
}

.emptyState {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  color: var(--muted);
}

.modalBackdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  align-items: end;
  padding: 12px;
  padding-top: calc(12px + var(--safe-top));
  padding-bottom: calc(12px + var(--safe-bottom));
  background: rgba(15, 23, 42, 0.42);
}

.modalBackdrop[hidden] {
  display: none;
}

.accountSheet {
  width: min(100%, 520px);
  max-height: min(82vh, 680px);
  margin: 0 auto;
  overflow: hidden;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.modalHeader h2 {
  font-size: 18px;
}

.closeButton {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.accountInfoContent {
  display: grid;
  gap: 0;
  max-height: calc(82vh - 66px);
  overflow-y: auto;
  padding: 0 16px 16px;
}

.accountInfoRow {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.accountInfoRow span {
  color: var(--muted);
  font-size: 14px;
}

.accountInfoRow strong {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-align: right;
}

.orderItems {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.orderLine {
  padding-top: 6px;
  border-top: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.statementTableWrap {
  width: 100%;
  overflow-x: auto;
}

.statementTable {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
}

.statementTable th,
.statementTable td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  font-size: 14px;
}

.statementTable th {
  background: var(--surface-soft);
  color: var(--text);
}

.statementTotals {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.paymentRecords {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.paymentRecords h3 {
  color: var(--text);
  font-size: 16px;
}

.paymentRecord {
  display: grid;
  gap: 5px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.paymentRecord div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
}

.paymentRecord strong {
  font-size: 16px;
}

.paymentRecord p {
  color: var(--text);
  line-height: 1.45;
}

.emptyPaymentRecords {
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 14px;
}

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

  .statementFilters button {
    grid-column: 1 / -1;
  }
}

@media (min-width: 768px) {
  .customerHeader {
    min-height: calc(78px + var(--safe-top));
    padding-inline: 18px;
  }

  .customerHeader h1 {
    font-size: 22px;
  }

  .tabBar {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 8px 14px;
  }

  .tabBar button {
    flex: 0 1 150px;
    max-width: 160px;
    padding: 0 14px;
  }

  .view {
    padding: 14px 18px;
    padding-bottom: calc(96px + var(--safe-bottom));
  }

  #productsView.view {
    padding-bottom: calc(86px + var(--safe-bottom));
  }

  .searchRow {
    max-width: 900px;
    margin: 0 auto 12px;
    padding-bottom: 10px;
  }

  .ipadProductsLayout {
    display: block;
    max-width: none;
    margin: 0;
  }

  .ipadCartAside {
    display: none;
  }

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

  .productCard {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    min-height: 0;
    padding: 14px;
  }

  .productImage {
    width: 100%;
    height: clamp(104px, 16vw, 132px);
  }

  .productTitle {
    min-height: 42px;
    padding-right: 0;
    -webkit-line-clamp: 2;
    font-size: 17px;
  }

  .productMeta {
    font-size: 13px;
    line-height: 1.42;
  }

  .productQtyRow {
    margin-top: auto;
    max-width: 154px;
  }
}

@media (min-width: 1024px) {
  .customerHeader {
    min-height: calc(72px + var(--safe-top));
    padding: calc(8px + var(--safe-top)) 22px 8px;
  }

  .view {
    padding: 14px 22px;
    padding-bottom: calc(22px + var(--safe-bottom));
  }

  #productsView.active {
    overflow: hidden;
  }

  #productsView.active .searchRow {
    position: sticky;
    top: 0;
  }

  .ipadProductsLayout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 14px;
    height: calc(100% - 54px);
    min-height: 0;
    max-width: 1280px;
    margin: 0 auto;
  }

  .ipadProductsLayout .productList {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-content: start;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .ipadCartAside {
    display: block;
    min-width: 0;
  }

  .ipadCartPanel {
    position: sticky;
    top: 0;
    display: grid;
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    padding: 16px;
    box-shadow: var(--shadow);
  }

  .ipadCartPanel h2 {
    font-size: 18px;
  }

  .ipadCartStat {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px;
    color: var(--muted);
    font-size: 14px;
  }

  .ipadCartStat strong {
    color: var(--text);
    font-size: 18px;
  }

  .ipadCartPanel button {
    width: 100%;
    min-height: 48px;
  }

  .productCard {
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
    padding: 15px;
  }

  .productImage {
    width: 100%;
    height: 126px;
  }

  .mobileCartSummary {
    display: none;
  }

  .cartFooter {
    display: none;
  }
}

@media (max-width: 390px) {
  .tabBar button {
    font-size: 12px;
  }

  .productCard {
    grid-template-columns: 74px minmax(0, 1fr);
    gap: 8px;
  }

  .productImage {
    width: 74px;
    height: 74px;
  }

  .productTitle {
    padding-right: 78px;
    font-size: 15px;
  }

  .productMeta {
    font-size: 12px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --page-bg: #0f172a;
    --surface: #182235;
    --surface-soft: #263247;
    --text: #f8fafc;
    --muted: #b6c2d1;
    --line: #334155;
    --shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
  }

  .customerHeader {
    background: rgba(2, 6, 23, 0.98);
  }

  .tabBar button {
    color: #dbeafe;
  }

  .qtyStep {
    background: #334155;
    color: #f8fafc;
  }

  .cartFooter {
    background: rgba(24, 34, 53, 0.96);
  }

  .mobileCartSummary {
    background: rgba(24, 34, 53, 0.96);
  }
}
