/* YATI Gold Shop - Responsive UI */
:root {
  --bg: #f6f1e6;
  --bg-soft: #fbf7ef;
  --surface: #fffcf7;
  --text: #2a2218;
  --text-muted: #7a6a52;
  --border: #e6d9c4;
  --primary: #b8860b;
  --primary-dark: #8a6508;
  --primary-soft: #fff3d4;
  --accent: #c9a227;
  --gold: #d4af37;
  --gold-soft: #fff8e7;
  --danger: #b42318;
  --warning: #b54708;
  --ok: #027a48;
  --waiting: #b54708;
  --service: #175cd3;
  --completed: #027a48;
  --cancelled: #667085;
  --shadow: 0 10px 28px rgba(42, 34, 24, 0.1);
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-w: 240px;
  --header-h: 64px;
  --bottom-nav-h: 68px;
  --touch: 48px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(160deg, #f3e9d4 0%, #f6f1e6 45%, #faf6ee 100%);
  min-height: 100%;
}

body {
  min-height: 100vh;
  font-size: 1rem;
}

a {
  color: inherit;
  text-decoration: none;
}

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

/* Layout */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #3a2c14 0%, #2a2010 100%);
  color: #f7efd9;
  padding: 24px 16px;
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 40;
  transition: width 0.2s ease, transform 0.2s ease, padding 0.2s ease, opacity 0.2s ease;
  overflow: hidden;
  border-right: 1px solid rgba(212, 175, 55, 0.28);
}

.sidebar-toggle {
  position: absolute;
  top: 16px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #f7efd9;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  z-index: 2;
}

.sidebar-toggle:hover {
  background: rgba(212, 175, 55, 0.22);
}

.sidebar-expand-fab {
  display: none;
  position: fixed;
  top: 20px;
  left: 0;
  z-index: 45;
  width: 28px;
  height: 48px;
  padding: 0;
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-left: none;
  border-radius: 0 10px 10px 0;
  background: linear-gradient(180deg, #3a2c14 0%, #2a2010 100%);
  color: #f7efd9;
  cursor: pointer;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.12);
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.sidebar-expand-fab:hover {
  width: 34px;
}

body.sidebar-collapsed {
  --sidebar-w: 0px;
}

body.sidebar-collapsed .sidebar {
  width: 0;
  padding: 0;
  border: none;
  pointer-events: none;
  transform: translateX(-8px);
  opacity: 0;
}

body.sidebar-collapsed .sidebar-expand-fab {
  display: inline-flex;
}

body.sidebar-collapsed .main {
  margin-left: 0;
  padding-left: 36px;
}

.brand {
  padding: 8px 40px 16px 12px;
  display: flex;
  justify-content: center;
}

.sidebar-logo {
  width: min(168px, 100%);
  height: auto;
  display: block;
  border-radius: 12px;
  background: #fff;
  object-fit: contain;
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-sub {
  margin-top: 4px;
  font-size: 0.85rem;
  opacity: 0.7;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--touch);
  padding: 0 14px;
  border-radius: 12px;
  color: #e8d9b0;
  font-weight: 600;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(212, 175, 55, 0.18);
  color: #fff8e7;
}

.nav-link.active {
  background: linear-gradient(135deg, #d4af37 0%, #b8860b 100%);
  color: #2a2010;
}

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  padding: 24px;
  padding-bottom: 40px;
  transition: margin-left 0.2s ease, padding-left 0.2s ease;
}

.top-header,
.bottom-nav {
  display: none;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
}

.page-sub {
  margin: 4px 0 0;
  color: var(--text-muted);
}

/* Cards / Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-pad {
  padding: 18px;
}

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

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

.stat-label {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.stat-value {
  margin-top: 8px;
  font-size: 1.7rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

/* Forms & controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch);
  padding: 0 18px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #d4af37 0%, #b8860b 100%);
  color: #2a2010;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, filter 0.15s ease;
}

.btn:hover {
  background: linear-gradient(135deg, #e0c04a 0%, #c9a227 100%);
  filter: brightness(1.02);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--primary-soft);
  color: var(--text);
  filter: none;
}

.btn-secondary:hover {
  background: #f0e4c0;
  filter: none;
}

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

.btn-accent {
  background: var(--accent);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: 40px;
  padding: 0 12px;
  font-size: 0.92rem;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: var(--touch);
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
}

.textarea {
  min-height: 96px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}

.label {
  display: block;
  margin-bottom: 6px;
  font-weight: 650;
  font-size: 0.92rem;
}

.form-row {
  margin-bottom: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.settings-header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.settings-pass-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.settings-pass-span {
  grid-column: 1 / -1;
}

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

.settings-actions-grid .btn {
  min-width: 0;
  width: 100%;
}

.settings-span-2 {
  grid-column: 1 / -1;
}

.printer-scan-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.search-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.search-bar .input {
  flex: 1;
  min-width: 180px;
}

.gold-pe-panel {
  flex: 1 1 100%;
  min-width: 0;
}

.gold-pe-toggle {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}

.gold-pe-toggle-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.gold-pe-toggle-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 650;
}

.gold-pe-toggle-summary {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--accent);
  word-break: break-word;
}

.gold-pe-toggle-chevron {
  flex-shrink: 0;
  font-size: 1rem;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}

.gold-pe-panel.open .gold-pe-toggle-chevron {
  transform: rotate(180deg);
}

.gold-pe-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex: 1 1 100%;
}

.gold-pe-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 650;
  font-size: 0.9rem;
  user-select: none;
}

.gold-pe-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.gold-pe-item:has(.gold-pe-check:checked),
.gold-pe-item:has(#pctMarkupCheck:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

.gold-pe-item .gold-pe-price {
  width: 110px;
  min-width: 90px;
  flex: 0 0 auto;
  font-weight: 700;
  color: var(--accent);
  padding: 6px 8px;
  min-height: 36px;
}

.gold-pe-item #pctMarkupInput {
  width: 72px;
  min-width: 64px;
}

@media (max-width: 640px) {
  .gold-pe-toggle {
    display: flex;
  }

  .gold-pe-row {
    display: none;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: stretch;
    margin-top: 8px;
  }

  .gold-pe-panel.open .gold-pe-row {
    display: grid;
  }

  .gold-pe-item {
    width: 100%;
    min-width: 0;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .gold-pe-item .gold-pe-price {
    width: 100%;
    min-width: 0;
    flex: 1 1 100%;
  }

  .gold-pe-item #pctMarkupInput {
    width: 100%;
    min-width: 0;
  }
}

.date-range {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-range span {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.date-range .input {
  flex: 0 0 auto;
  min-width: 150px;
  width: 160px;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

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

table.data-table th,
table.data-table td {
  padding: 14px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.data-table th {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 700;
  background: var(--bg-soft);
}

table.data-table tr:hover td {
  background: #f8fbf9;
}

table.data-table-compact th,
table.data-table-compact td {
  padding: 7px 10px;
  font-size: 0.92rem;
}

table.data-table-compact th {
  font-size: 0.78rem;
}

table.data-table-compact .badge {
  min-height: 22px;
  padding: 0 8px;
  font-size: 0.72rem;
}

.session-cards-compact {
  gap: 8px;
}

.session-card-compact {
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: none;
}

.session-card-compact .title {
  font-size: 0.98rem;
}

.session-card-compact .muted {
  margin-top: 4px;
  font-size: 0.82rem;
}

.session-card-compact .badge {
  min-height: 22px;
  padding: 0 8px;
  font-size: 0.72rem;
}

.session-card-compact .actions {
  margin-top: 8px;
  gap: 6px;
}

.session-card-compact .timer {
  font-size: 1.35rem;
  margin-top: 4px;
}

.session-card-compact .timer-remain {
  font-size: 0.75rem;
  margin-top: 2px;
}

.data-table-compact .timer-sm {
  font-size: 0.95rem;
}

.data-table-compact .timer-remain {
  font-size: 0.72rem;
  margin-top: 2px;
}

.data-table-compact .btn-sm {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.78rem;
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

.badge-waiting { background: #ffefd6; color: var(--waiting); }
.badge-service { background: #dcebff; color: var(--service); }
.badge-completed { background: #d9f5e7; color: var(--completed); }
.badge-cancelled { background: #eaecf0; color: var(--cancelled); }
.badge-vip { background: #fff1d6; color: #9a6700; }
.badge-friend { background: #e8f4fd; color: #1565a8; }

/* Customers split layout */
.split {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 16px;
  min-height: calc(100vh - 140px);
}

.list-panel,
.detail-panel {
  min-height: 480px;
}

.customer-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  cursor: pointer;
  min-height: 48px;
}

.customer-item:hover,
.customer-item.active {
  background: var(--primary-soft);
}

.customer-item .name {
  font-weight: 700;
  font-size: 0.95rem;
}

.customer-item .meta {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.customer-item .badge {
  min-height: 20px;
  padding: 0 7px;
  font-size: 0.7rem;
}

.detail-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  color: var(--text-muted);
  padding: 24px;
  text-align: center;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

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

.kv {
  background: var(--bg-soft);
  border-radius: 12px;
  padding: 12px 14px;
}

.kv .k {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.kv .v {
  margin-top: 4px;
  font-size: 1.05rem;
  font-weight: 700;
}

.section-title {
  margin: 22px 0 10px;
  font-size: 1.05rem;
  font-weight: 750;
}

/* Session cards (mobile) */
.session-cards {
  display: none;
  gap: 12px;
}

.session-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.session-card .row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.session-card .title {
  font-size: 1.15rem;
  font-weight: 750;
}

.session-card .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-size: 2rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  color: var(--primary);
}

.timer-box {
  line-height: 1.2;
}

.timer-sm {
  font-size: 1.05rem;
}

.timer-remain {
  margin-top: 4px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
}

.timer-remain.timer-over {
  color: var(--danger);
}

/* Duration chips */
.chip-group {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.chip {
  min-height: var(--touch);
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #fff;
  font-weight: 700;
  cursor: pointer;
}

.chip.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

/* Modal / drawer sheet */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 28, 22, 0.45);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 80;
  padding: 16px;
}

.overlay.open {
  display: flex;
}

.sheet {
  width: min(560px, 100%);
  max-height: min(90vh, 820px);
  overflow: auto;
  background: #fff;
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.sheet.product-form-sheet {
  width: min(780px, 100%);
  max-height: min(92vh, 900px);
  padding: 22px 24px 20px;
}

.sheet.sale-detail-sheet {
  width: min(1280px, 96vw);
  max-height: min(92vh, 900px);
  padding: 22px 24px 20px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sale-detail-meta {
  margin-bottom: 10px;
  word-break: break-word;
  line-height: 1.4;
}

.sale-detail-body-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.sale-detail-sheet .table-wrap {
  overflow-x: auto;
}

.sales-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.sales-pager .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.sale-detail-cards {
  display: none;
}

.sale-detail-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
  padding: 12px;
  margin-bottom: 10px;
}

.sale-detail-card:last-child {
  margin-bottom: 0;
}

.sale-detail-card-title {
  font-weight: 800;
  font-size: 1rem;
  margin-bottom: 8px;
  line-height: 1.3;
  word-break: break-word;
}

.sale-detail-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
}

.sale-detail-card-grid > div {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sale-detail-card-grid span {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 650;
}

.sale-detail-card-grid strong {
  font-size: 0.88rem;
  font-weight: 700;
  word-break: break-word;
}

.sheet h2 {
  margin: 0 0 14px;
  font-size: 1.3rem;
}

.product-form-sheet h2 {
  margin-bottom: 6px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.form-section {
  margin-top: 16px;
}

.form-section:first-of-type {
  margin-top: 12px;
}

.form-section-title {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.product-form-sheet .form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  align-items: start;
}

.product-form-sheet .form-row {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.product-form-sheet .form-row-span {
  grid-column: 1 / -1;
}

.product-form-sheet .label {
  margin-bottom: 6px;
  min-height: 1.2em;
  line-height: 1.2;
}

.product-form-sheet .input,
.product-form-sheet .select {
  min-height: 44px;
  box-sizing: border-box;
}

.product-form-sheet .waste-row {
  margin: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.product-form-sheet .weight-mode-checks {
  min-height: 44px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft, #f6f7f5);
}

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

.sheet-actions-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.sheet-actions-split .btn {
  width: 100%;
  min-height: 44px;
  justify-content: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #2a2010;
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  max-width: 90vw;
}

.toast.show {
  opacity: 1;
}

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

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
}

.payment-box .line {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
}

.payment-box .total {
  font-size: 1.35rem;
  font-weight: 800;
  margin-top: 8px;
}

.pay-methods {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 12px 0;
}

.pay-methods .chip {
  width: 100%;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-soft);
}

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

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

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

  .split {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .detail-panel.mobile-hidden {
    display: none;
  }

  .list-panel.mobile-hidden {
    display: none;
  }

  .date-range {
    flex: 1 1 140px;
  }

  .date-range .input {
    width: 100%;
    min-width: 0;
  }

  .sales-filter-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: end;
  }

  .sales-filter-bar .date-range {
    flex: none;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    min-width: 0;
    width: 100%;
  }

  .sales-filter-bar .date-range .input {
    width: 100%;
    min-width: 0;
  }

  .sales-filter-bar .btn {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 768px) {
  html {
    font-size: 12.5px; /* scale rem-based UI smaller on phones */
  }

  .sheet.product-form-sheet {
    width: 100%;
    max-width: 100%;
    padding: 14px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .product-form-sheet .form-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px 12px;
  }

  .sales-filter-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: end;
  }

  .sales-filter-bar .date-range {
    flex: none;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    min-width: 0;
    width: 100%;
  }

  .sales-filter-bar .date-range .input {
    width: 100%;
    min-width: 0;
  }

  .sales-filter-bar .btn {
    width: 100%;
    min-width: 0;
  }

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

  .settings-pass-grid,
  .settings-actions-grid {
    gap: 8px;
  }

  .settings-grid .panel-pad {
    padding: 12px;
  }

  .settings-grid .panel h2 {
    font-size: 0.95rem !important;
  }

  .settings-actions-grid .btn {
    min-height: 42px;
    padding: 8px 10px;
    font-size: 0.88rem;
  }

  .sidebar {
    display: none;
  }

  .sidebar-toggle,
  .sidebar-expand-fab,
  body.sidebar-collapsed .sidebar-expand-fab {
    display: none !important;
  }

  body.sidebar-collapsed .main {
    margin-left: 0;
    padding-left: 16px;
  }

  .top-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--header-h);
    padding: 0 16px;
    background: linear-gradient(90deg, #3a2c14 0%, #2a2010 100%);
    color: #fff;
  }

  .top-header .brand-name {
    font-size: 1.05rem;
  }

  .top-header-brand {
    display: flex;
    align-items: center;
    min-width: 0;
  }

  .top-header-logo {
    height: 40px;
    width: auto;
    max-width: 140px;
    object-fit: contain;
    border-radius: 8px;
    background: #fff;
  }

  .bottom-nav {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(72px, 1fr);
    overflow-x: auto;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--bottom-nav-h);
    background: #fff;
    border-top: 1px solid var(--border);
    z-index: 50;
  }

  .bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
  }

  .bottom-nav a.active {
    color: var(--primary);
  }

.lang-switch {
  display: inline-flex;
  gap: 6px;
  background: rgba(255, 255, 255, 0.1);
  padding: 4px;
  border-radius: 10px;
}

.lang-btn {
  min-height: 36px;
  min-width: 44px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #e8d9b0;
  font-weight: 700;
  cursor: pointer;
}

.lang-btn.active {
  background: linear-gradient(135deg, #d4af37 0%, #b8860b 100%);
  color: #2a2010;
}

.sidebar .lang-switch {
  width: 100%;
  justify-content: stretch;
}

.sidebar .lang-btn {
  flex: 1;
}

  .main {
    margin-left: 0;
    padding: 16px;
    padding-bottom: calc(var(--bottom-nav-h) + 24px);
  }

  .page-title {
    font-size: 1.4rem;
  }

  .printer-scan-grid {
    grid-template-columns: 1fr;
  }

  .desktop-only-table {
    display: none;
  }

  .session-cards {
    display: flex;
    flex-direction: column;
  }

  .form-grid,
  .kv-grid,
  .chip-group,
  .printer-scan-grid {
    grid-template-columns: 1fr 1fr;
  }

  .chip-group {
    grid-template-columns: 1fr 1fr;
  }

  .overlay {
    align-items: flex-end;
    padding: 0;
  }

  .sheet {
    width: 100%;
    border-radius: 18px 18px 0 0;
    max-height: 88vh;
  }

  .sheet.sale-detail-sheet {
    width: 100%;
    max-width: 100%;
    max-height: min(92vh, 100dvh);
    border-radius: 18px 18px 0 0;
    padding: 14px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .sale-detail-sheet .sale-detail-table-wrap {
    display: none;
  }

  .sale-detail-cards {
    display: block;
  }

  .sale-detail-sheet .sheet-actions {
    flex-shrink: 0;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    gap: 8px;
  }

  .sale-detail-sheet .sheet-actions .btn {
    flex: 1;
    min-width: 0;
  }

  .toast {
    bottom: calc(var(--bottom-nav-h) + 16px);
  }
}

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

  .pay-methods,
  .printer-scan-grid {
    grid-template-columns: 1fr;
  }

  /* Keep Add/Edit Product on 2 columns even on narrow phones */
  .product-form-sheet .form-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
  }

  .product-form-sheet .label {
    font-size: 0.78rem;
    margin-bottom: 4px;
  }

  .product-form-sheet .input,
  .product-form-sheet .select {
    min-height: 40px;
    padding: 8px 10px;
  }

  .product-form-sheet .waste-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }
}

.printer-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 3000;
}

.printer-modal-backdrop.show {
  display: flex;
}

.printer-modal {
  width: min(720px, 100%);
  background: var(--surface, #fff);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  border: 1px solid var(--border);
}

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

.printer-modal-title {
  font-weight: 650;
  font-size: 1.05rem;
}

.printer-modal-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.printer-modal-body {
  padding: 14px 16px;
  display: grid;
  gap: 14px;
  max-height: min(70vh, 560px);
  overflow-y: auto;
}

.printer-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

.printer-label {
  font-size: 0.85rem;
  font-weight: 650;
}

.printer-paper-width {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.printer-radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}

.printer-wifi-item {
  display: grid;
  gap: 4px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.printer-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--surface);
}

.printer-field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.printer-chip {
  display: block;
  padding: 10px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 650;
}

.printer-wifi-form {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(88px, 0.7fr) auto;
  gap: 8px;
  align-items: end;
}

.printer-listbox {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.printer-listbox .device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
}

.printer-listbox .device-meta {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.printer-listbox .mono {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.85rem;
}

@media (max-width: 640px) {
  .printer-wifi-form {
    grid-template-columns: minmax(0, 1.4fr) minmax(72px, 0.7fr);
  }

  .printer-wifi-form > .btn {
    grid-column: 1 / -1;
  }

  .printer-paper-width {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 8px;
    align-items: center;
  }
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 18% 12%, rgba(212, 175, 55, 0.45) 0%, transparent 48%),
    radial-gradient(ellipse at 85% 88%, rgba(184, 134, 11, 0.35) 0%, transparent 46%),
    linear-gradient(155deg, #2a2010 0%, #4a3818 42%, #3a2c14 100%);
}

.login-card {
  width: min(400px, 100%);
  background: linear-gradient(180deg, #fffcf7 0%, #faf3e4 100%);
  border: 1px solid rgba(212, 175, 55, 0.55);
  border-radius: var(--radius);
  box-shadow:
    0 0 0 1px rgba(255, 248, 231, 0.35) inset,
    0 18px 48px rgba(20, 14, 6, 0.35);
  padding: 28px 24px;
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #8a6508, #d4af37, #f0d78a, #d4af37, #8a6508);
}

.login-brand {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

.login-logo {
  width: min(220px, 72%);
  height: auto;
  display: block;
  border-radius: 14px;
  object-fit: contain;
  box-shadow: 0 6px 18px rgba(184, 134, 11, 0.22);
  border: 1px solid rgba(212, 175, 55, 0.35);
}

.login-card .brand-name {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--primary-dark);
}

.login-card .input {
  text-align: center;
  border-color: #e0d0a8;
  background: #fffdf8;
}

.login-card .input:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}

.login-card .btn {
  background: linear-gradient(135deg, #d4af37 0%, #b8860b 55%, #8a6508 100%);
  color: #2a2010;
  font-weight: 800;
  border: 1px solid rgba(255, 248, 231, 0.35);
  box-shadow: 0 8px 18px rgba(138, 101, 8, 0.28);
}

.login-card .btn:hover {
  background: linear-gradient(135deg, #e0c04a 0%, #c9a227 55%, #b8860b 100%);
  filter: none;
}

.login-card .muted {
  color: var(--text-muted);
}

.login-title {
  text-align: center;
  margin: 10px 0 4px;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.18em;
  color: var(--primary-dark) !important;
}

.login-copy {
  margin: 18px 0 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.login-access a {
  color: var(--primary-dark);
  font-weight: 700;
  word-break: break-all;
}

.select-sm {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 0.9rem;
}

.user-chip {
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border-radius: 999px;
  background: rgba(16, 28, 22, 0.08);
  border: 1px solid rgba(16, 28, 22, 0.12);
}

.sidebar .lang-switch {
  width: 100%;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(212, 175, 55, 0.28);
}

.lang-btn {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1.2;
  opacity: 0.72;
}

.sidebar .lang-btn {
  flex: 1;
  color: #f7efd9;
}

.lang-btn.active {
  opacity: 1;
  background: #fff;
  color: #1a1a2e;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.sidebar .lang-btn.active {
  background: #d4af37;
  color: #1a1a2e;
}

.login-card .lang-switch {
  display: flex;
  width: fit-content;
  margin: 0 auto 12px;
}

.user-chip-label {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.65);
  margin-bottom: 2px;
}

.user-chip-name {
  font-weight: 750;
  color: #fff;
  font-size: 0.95rem;
  word-break: break-word;
}

.user-chip-name-mobile {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary-dark);
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-detail {
  max-width: 420px;
  word-break: break-word;
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* ===== Easy Sales POS extensions ===== */
.pos-layout {
  display: grid;
  grid-template-columns: 1fr minmax(400px, 520px);
  gap: 16px;
  align-items: start;
  min-height: calc(100vh - 120px);
}

.pos-products,
.pos-cart {
  min-width: 0;
}

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

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  position: relative;
  transition: box-shadow 0.15s, transform 0.15s;
  min-height: var(--touch);
}

.product-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-1px);
  border-color: var(--primary);
}

.product-card.expired {
  opacity: 0.55;
  border-color: var(--danger);
}

.product-card.expiring {
  border-color: var(--warning);
}

.product-image {
  width: 100%;
  height: 110px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--bg-soft);
  margin-bottom: 8px;
}

.product-info h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.25;
}

.product-category,
.product-stock,
.product-unit,
.product-expiration {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.product-price {
  color: var(--accent);
  font-weight: 800;
  font-size: 0.95rem;
  margin: 4px 0;
}

.product-waste {
  font-size: 0.82rem;
  font-weight: 650;
  color: #b45309;
  margin-bottom: 2px;
}

.product-diamond {
  font-size: 0.82rem;
  font-weight: 650;
  color: #1d4ed8;
  margin-bottom: 2px;
}

.product-cost {
  font-size: 0.82rem;
  font-weight: 650;
  color: #0f766e;
  margin-bottom: 2px;
}

.product-purchase-date {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.product-stock.stock-low {
  color: var(--danger);
  font-weight: 700;
}

.product-expiration.expired {
  color: var(--danger);
  font-weight: 700;
}

.product-expiration.warning {
  color: var(--warning);
  font-weight: 700;
}

.product-delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(180, 35, 24, 0.9);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}

.product-edit-btn {
  position: absolute;
  top: 6px;
  right: 38px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(30, 90, 60, 0.92);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip,
.category-tab {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

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

.cart-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 36vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.cart-item {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
}

.cart-item-image {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
}

.cart-item-name {
  font-weight: 700;
  font-size: 0.92rem;
}

.cart-spec-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.cart-spec-label {
  margin: 0;
  white-space: nowrap;
  font-size: 12px;
  min-width: 3.5em;
}

.cart-spec-input {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  padding: 6px 10px;
  font-size: 13px;
}

.cart-item-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.cart-item-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.qty-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.qty-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}

.payment-box {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.weight-mode-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.weight-mode-checks .check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.weight-mode-checks input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.cart-summary-grid {
  margin-bottom: 8px;
  gap: 8px;
}

.cart-summary-grid .kv {
  margin-bottom: 0;
  background: var(--bg-soft);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.88rem;
}

.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.kv strong {
  color: var(--accent);
}

.waste-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 10px 0;
}

.waste-row:has(> :nth-child(2):last-child) {
  grid-template-columns: repeat(2, 1fr);
}

.waste-row .select {
  width: 100%;
  min-width: 0;
}

.cart-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  margin-left: 4px;
}

.mobile-pos-tabs {
  display: none;
  gap: 8px;
  margin-bottom: 12px;
}

.empty-state {
  text-align: center;
  padding: 28px 12px;
  color: var(--text-muted);
}

.price-highlight {
  color: var(--accent);
  font-weight: 800;
}

@media (max-width: 1024px) {
  .pos-layout {
    grid-template-columns: 1fr;
  }

  .mobile-pos-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .pos-products.mobile-hidden,
  .pos-cart.mobile-hidden {
    display: none;
  }

  .cart-list {
    max-height: none;
  }
}

@media (max-width: 768px) {
  .pos-layout {
    min-height: auto;
  }

  .waste-row {
    grid-template-columns: 1fr;
  }

  .product-form-sheet .waste-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .product-card {
    display: grid;
    grid-template-columns: 88px 1fr;
    gap: 10px 12px;
    align-items: start;
    padding: 10px 12px;
    padding-right: 72px; /* room for edit/delete */
  }

  .product-image {
    width: 88px;
    height: 88px;
    margin-bottom: 0;
    object-fit: cover;
  }

  .product-info {
    min-width: 0;
  }

  .product-info h3 {
    font-size: 1rem;
    margin-bottom: 2px;
  }

  .product-category,
  .product-stock,
  .product-purchase-date {
    font-size: 0.75rem;
  }

  .product-price {
    margin: 2px 0;
  }
}

body.keyboard-open .bottom-nav {
  display: none !important;
}

.main.pos-main {
  padding-bottom: calc(var(--bottom-nav-h) + 24px);
}

@media (min-width: 769px) {
  .main.pos-main {
    padding-bottom: 40px;
  }
}
