/* Perfect Color CRM — Light theme + mobile-first */
.crm-body {
  --bg: #f3f0e8;
  --bg-soft: #ebe7dd;
  --surface: #ffffff;
  --text: #1c1b19;
  --muted: #6f6a62;
  --line: rgba(28, 27, 25, 0.1);
  --gold: #9a7b3c;
  --gold-soft: rgba(154, 123, 60, 0.14);
  --ok: #1f7a4d;
  --warn: #b36b00;
  --danger: #c0392b;
  --shadow: 0 8px 24px rgba(28, 27, 25, 0.08);
  --nav-h: 64px;

  min-height: 100vh;
  margin: 0;
  font-family: "Manrope", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(ellipse at 10% 0%, rgba(154, 123, 60, 0.1), transparent 42%),
    linear-gradient(180deg, #f7f5ef 0%, var(--bg) 45%, #efebe3 100%);
  -webkit-tap-highlight-color: transparent;
}

.crm-body .btn--primary {
  background: var(--gold);
  border: 1px solid var(--gold);
  color: #fff;
}
.crm-body .btn--secondary {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
}
.crm-body .btn--ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}

/* Login */
.crm-brand-logo {
  display: block;
  margin: 0 auto 16px;
  text-decoration: none;
  text-align: center;
  font-size: 1.35rem;
}
.crm-brand-logo--compact {
  margin: 0 0 4px;
  font-size: 1.0625rem;
  text-align: left;
}
.crm-brand-logo span {
  color: var(--gold);
}
.crm-header__left h1 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--muted);
  font-weight: 600;
}

.crm-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.crm-login[hidden] { display: none !important; }
.crm-login__card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
}
.crm-login__eyebrow,
.crm-header__eyebrow {
  margin: 0 0 6px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--gold);
  font-weight: 700;
}
.crm-login__card h1 { margin: 0 0 8px; font-size: 1.65rem; color: var(--text); }
.crm-login__hint { margin: 0 0 18px; color: var(--muted); font-size: 0.92rem; line-height: 1.45; }
.crm-login__btn { width: 100%; margin-top: 6px; min-height: 48px; }
.crm-login__error, .crm-lookup__error { color: var(--danger); font-size: 0.88rem; margin: 0 0 10px; }
.crm-login__back { display: inline-block; margin-top: 16px; color: var(--muted); text-decoration: none; font-size: 0.9rem; }
.crm-login__wait { text-align: center; margin-top: 8px; padding: 18px 8px 4px; }
.crm-login__pulse {
  width: 42px; height: 42px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid rgba(154,123,60,0.2); border-top-color: var(--gold);
  animation: crm-spin 0.9s linear infinite;
}
@keyframes crm-spin { to { transform: rotate(360deg); } }
.crm-login__wait-title { margin: 0 0 8px; font-weight: 700; font-size: 1.05rem; }
.crm-login__wait-hint { margin: 0 0 16px; color: var(--muted); font-size: 0.88rem; line-height: 1.45; }
.crm-login form[hidden],
.crm-login__wait[hidden] { display: none !important; }

/* Fields */
.crm-field { display: block; margin-bottom: 12px; }
.crm-field span { display: block; margin-bottom: 6px; font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.crm-field input,
.crm-field select,
.crm-lookup input,
.crm-row input,
.crm-cart-row input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  min-height: 46px;
}
.crm-field input::placeholder,
.crm-lookup input::placeholder,
.crm-row input::placeholder { color: #9c968c; }

/* App shell */
.crm-app { max-width: 1100px; margin: 0 auto; padding: 16px 14px 36px; }
.crm-app[hidden] { display: none !important; }
.crm-header {
  display: flex; flex-wrap: wrap; gap: 10px;
  justify-content: space-between; align-items: flex-end; margin-bottom: 12px;
}
.crm-header h1 { margin: 4px 0 0; font-size: 1.45rem; color: var(--text); }
.crm-header__actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.crm-icon-btn { min-width: 42px; min-height: 42px; font-size: 1.05rem; }

.crm-tabs {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 14px; padding: 6px 0 10px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, #f3f0e8 80%, transparent);
}
.crm-tab {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 650;
  cursor: pointer;
}
.crm-tab.is-active {
  background: var(--gold);
  border-color: var(--gold);
  color: #fff;
}

.crm-panel { display: none; }
.crm-panel.is-active { display: block; }
.crm-panel h2 { margin: 0 0 6px; font-size: 1.18rem; color: var(--text); }
.crm-panel__sub { margin: 0 0 14px; color: var(--muted); font-size: 0.9rem; }
.crm-subhead { margin: 18px 0 10px; font-size: 1rem; color: var(--text); }
.crm-empty { color: var(--muted); margin: 8px 0; }

/* Stats / cards */
.crm-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.crm-stat,
.crm-card,
.crm-qr-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.crm-stat__label {
  font-size: 0.75rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700;
}
.crm-stat__value { margin-top: 6px; font-size: 1.15rem; font-weight: 800; color: var(--text); }
.crm-stat.is-warn .crm-stat__value { color: var(--warn); }
.crm-card h3 { margin: 0 0 12px; font-size: 1rem; color: var(--text); }
.crm-quick { display: flex; flex-wrap: wrap; gap: 8px; }
.crm-dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}
.crm-dash-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.crm-dash-actions .btn {
  width: 100%;
  min-height: 48px;
  justify-content: center;
}

/* POS layout */
.crm-pos {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 14px;
  align-items: start;
}
.crm-row--scan { display: flex; gap: 8px; }
.crm-row--scan input { flex: 1; }
.crm-favs { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.crm-fav {
  border: 1px solid rgba(154,123,60,0.35);
  background: var(--gold-soft);
  color: #5c481f;
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
}

.crm-catalog {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  max-height: 62vh;
  overflow: auto;
  margin-top: 8px;
  padding-bottom: 4px;
}
.crm-cat-item {
  position: relative;
  display: flex;
  align-items: stretch;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 14px;
  box-shadow: 0 2px 10px rgba(28,27,25,0.04);
}
.crm-cat-item__img {
  width: 56px;
  min-width: 56px;
  height: 56px;
  object-fit: cover;
  align-self: center;
  margin-left: 8px;
  border-radius: 10px;
  background: #f3f0ea;
  flex-shrink: 0;
}
.crm-stock-name {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.crm-stock-img-cell {
  width: 60px;
  padding: 6px 4px !important;
}
.crm-stock-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 10px;
  background: #f3f0ea;
  display: block;
}
.crm-thumb {
  object-fit: cover;
  border-radius: 10px;
  background: #f3f0ea;
  flex-shrink: 0;
}
.crm-prod-media {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-top: 6px;
}
.crm-prod-media__img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #f3f0ea;
}
.crm-prod-media__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.crm-file-label { cursor: pointer; display: inline-flex; align-items: center; }
.crm-field--full { grid-column: 1 / -1; }
.crm-check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
}
.crm-qr-card__img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  border-radius: 10px;
  margin: 8px 0;
  background: #f3f0ea;
}
.crm-cat-item__main {
  flex: 1;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 12px;
  font: inherit;
  cursor: pointer;
}
.crm-cat-item strong { display: block; font-size: 0.92rem; color: var(--text); }
.crm-cat-item span { display: block; margin-top: 4px; color: var(--muted); font-size: 0.8rem; }
.crm-cat-item__star {
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--gold);
  width: 44px;
  font-size: 1.1rem;
  cursor: pointer;
}
.crm-cat-item.is-fav { border-color: rgba(154,123,60,0.5); background: #fffdf8; }
.crm-cat-item.is-low { border-color: rgba(179,107,0,0.45); }
.crm-cat-item.is-empty { opacity: 0.55; }

.crm-cart { margin-bottom: 12px; min-height: 48px; }
.crm-cart-row {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 0.9rem;
}
.crm-cart-row__img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 10px;
  background: #f3f0ea;
}
.crm-cart-row__main { min-width: 0; }
.crm-cart-row input { width: 68px; min-height: 40px; padding: 8px; }
.crm-pos__total {
  font-size: 1.3rem;
  font-weight: 800;
  margin: 10px 0;
  color: var(--gold);
}
.crm-pos__pay { width: 100%; margin-top: 10px; min-height: 50px; font-size: 1.05rem; }
.crm-pos__change { margin: 6px 0 0; font-weight: 700; color: var(--ok); }
.crm-pos__change.is-warn { color: var(--warn); }
.crm-customer-hint {
  margin: -4px 0 10px;
  font-size: 0.84rem;
  font-weight: 650;
}
.crm-customer-hint.is-ok { color: var(--ok); }
.crm-customer-hint.is-new { color: var(--gold); }

.crm-pos-dock,
.crm-pos-backdrop,
.crm-pos__sheet-head,
.crm-mobile-only { display: none !important; }

/* Tables / forms */
.crm-table-wrap {
  overflow: auto;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.crm-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.crm-table th, .crm-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  color: var(--text);
}
.crm-table th { background: var(--bg-soft); color: var(--muted); font-weight: 700; }
.crm-table tr.is-low td { color: var(--warn); }
.crm-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  align-items: end;
}
.crm-lines { margin: 12px 0; display: grid; gap: 12px; }
.crm-line {
  display: grid;
  grid-template-columns: 1.4fr 0.6fr 0.8fr auto;
  gap: 8px;
  align-items: center;
}
.crm-buy-row {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: grid;
  gap: 10px;
}
.crm-buy-row__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.crm-buy-row__foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}
.crm-buy-row__foot strong {
  font-size: 0.92rem;
  color: var(--text);
}
.crm-cart-qty {
  display: grid;
  gap: 4px;
  min-width: 88px;
}
.crm-cart-qty span {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: lowercase;
}
.crm-cart-qty input,
.invent-qty,
.crm-ret-qty {
  width: 100%;
  min-width: 72px;
  max-width: 120px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font: inherit;
}
.crm-cart-controls {
  display: grid;
  gap: 6px;
  min-width: 120px;
}
.crm-kg-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.crm-kg-chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  min-height: 32px;
  cursor: pointer;
}
.crm-kg-chip:active { transform: scale(0.96); }
.stock-unit-sel {
  min-width: 72px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 700;
}
.crm-moves { font-size: 0.88rem; color: var(--muted); }
.crm-move {
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
  color: var(--text);
}
.crm-lookup { display: flex; gap: 8px; flex-wrap: wrap; }
.crm-lookup input { flex: 1 1 220px; }

.crm-receipt,
.crm-order {
  margin-top: 14px;
  background: #fffcf4;
  color: #171717;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0;
  font-family: "IBM Plex Mono", Menlo, monospace;
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  overflow: hidden;
}
.crm-receipt__paper { padding: 16px 14px 8px; }
.crm-receipt__actions {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px dashed rgba(0,0,0,.12);
  font-family: "Manrope", system-ui, sans-serif;
  background: #fffaf0;
}
.fiscal-receipt { font-family: "IBM Plex Mono", "Courier New", monospace; font-size: 12px; line-height: 1.42; color: #111; }
.fiscal-receipt__head { text-align: center; margin-bottom: 6px; }
.fiscal-receipt__store { font-weight: 800; font-size: 14px; letter-spacing: .08em; }
.fiscal-receipt__type, .fiscal-receipt__kind { font-weight: 700; font-size: 12px; }
.fiscal-dash { color: #444; letter-spacing: -.04em; margin: 6px 0; text-align: center; }
.fiscal-dash--thin { opacity: .85; }
.fiscal-meta { text-align: center; font-size: 11px; }
.fiscal-item { margin: 8px 0 4px; }
.fiscal-item__name { font-weight: 700; }
.fiscal-item__calc { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; margin-top: 2px; }
.fiscal-row { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.fiscal-total { display: flex; justify-content: space-between; gap: 8px; font-weight: 800; font-size: 15px; margin: 8px 0; padding: 6px 0; border-top: 2px dashed #222; border-bottom: 2px dashed #222; }
.fiscal-payments { margin: 4px 0; }
.fiscal-footer { font-size: 11px; line-height: 1.45; margin-top: 6px; }
.fiscal-meta__ids { margin-top: 6px; text-align: center; font-size: 10px; color: #555; }
.fiscal-thanks { text-align: center; font-weight: 800; font-size: 13px; margin: 10px 0 4px; letter-spacing: .08em; }
.fiscal-muted { color: #555; font-size: 10px; text-align: center; }
.fiscal-receipt__site { margin-bottom: 4px; }
.fiscal-qr { display: flex; justify-content: center; margin: 10px 0; padding: 8px; background: #fff; border: 1px solid rgba(0,0,0,.08); }
.fiscal-row--warn { color: #8a4b00; }
@media print {
  body.crm-printing-receipt > *:not(#posReceipt) { display: none !important; }
  body.crm-printing-receipt #posReceipt {
    display: block !important;
    position: static !important;
    box-shadow: none !important;
    border: 0 !important;
    margin: 0 !important;
    background: #fff !important;
  }
  body.crm-printing-receipt .crm-receipt__actions,
  body.crm-printing-receipt #posReceiptConfirm { display: none !important; }
}
.crm-order__head {
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin-bottom: 10px; font-family: "Manrope", system-ui, sans-serif;
}
.crm-order__badge {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  background: var(--text); color: #fff; font-size: 11px; font-weight: 700;
}
.crm-order__row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 4px 0; border-bottom: 1px dashed rgba(0,0,0,0.08);
}
.crm-order__actions {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px;
  font-family: "Manrope", system-ui, sans-serif;
}
.crm-orders-list { display: grid; gap: 8px; }
.crm-order-card {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  width: 100%; text-align: left;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 14px;
  padding: 14px;
  cursor: pointer;
  font: inherit;
  box-shadow: 0 2px 10px rgba(28,27,25,0.04);
}
.crm-order-card__meta { color: var(--muted); font-size: 0.82rem; }

.crm-qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}
.crm-qr-card { text-align: center; }
.crm-qr-card__box {
  display: inline-flex; padding: 8px; background: #fff; border-radius: 8px; margin: 8px 0;
  border: 1px solid var(--line);
}
.crm-qr-card__check { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 6px; }
.crm-qr-card button { margin-top: 8px; }

.crm-msg, .crm-link__msg { margin: 10px 0 0; font-size: 0.9rem; font-weight: 650; }
.crm-msg.is-ok, .crm-link__msg.is-ok { color: var(--ok); }
.crm-msg.is-err, .crm-link__msg.is-err { color: var(--danger); }

/* Search */
.crm-search-bar {
  position: relative;
  margin-bottom: 10px;
  display: none;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.crm-search-bar:not([hidden]) { display: flex; }
.crm-search-bar input { flex: 1 1 200px; }
.crm-search-results { width: 100%; display: grid; gap: 6px; }
.crm-search-hit {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
}
.crm-search-hit__img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 10px;
  background: #f3f0ea;
  flex-shrink: 0;
}
.crm-search-hit__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.crm-search-hit__body strong {
  font-size: 0.92rem;
  line-height: 1.25;
}
.crm-search-hit__body span {
  color: var(--muted);
  font-size: 0.8rem;
}
.crm-pos-search-results {
  display: grid;
  gap: 6px;
  margin: -2px 0 10px;
  position: relative;
  z-index: 12;
}
.crm-pos-search-results[hidden] { display: none !important; }
.crm-pos-search-empty {
  margin: 0;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 0.88rem;
  background: var(--bg-soft);
  border-radius: 10px;
}
.crm-fav {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.crm-fav__img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 8px;
  background: #f3f0ea;
}
/* Toast / FAB / bottom / sheet */
.crm-toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 130000;
  background: #1d1d22;
  color: #fff;
  padding: 12px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 650;
  max-width: 90vw;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.crm-toast.is-ok { border: 1px solid rgba(109,222,160,0.45); }
.crm-toast.is-err { border: 1px solid rgba(255,123,123,0.5); color: #ffc9c9; }
.crm-toast[hidden] { display: none !important; }

.crm-fab {
  display: none;
  position: fixed;
  right: 16px;
  bottom: calc(84px + env(safe-area-inset-bottom));
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--gold);
  color: #fff;
  font-size: 1.3rem;
  box-shadow: 0 10px 24px rgba(0,0,0,0.2);
  z-index: 40;
}
.crm-fab[hidden] { display: none !important; }

.crm-bottom {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  justify-content: space-around;
}
.crm-bottom__btn {
  flex: 1;
  border: 0;
  background: transparent;
  color: #8c867c;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  font: inherit;
  min-height: 52px;
}
.crm-bottom__btn span { font-size: 1.15rem; line-height: 1; }
.crm-bottom__btn small { font-size: 0.68rem; font-weight: 700; }
.crm-bottom__btn.is-active { color: var(--gold); }

.crm-sheet { position: fixed; inset: 0; z-index: 60; display: none; }
.crm-sheet:not([hidden]) { display: block; }
.crm-sheet__backdrop { position: absolute; inset: 0; background: rgba(20,18,14,0.4); }
.crm-sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  max-height: 78vh;
  overflow: auto;
  color: var(--text);
}
.crm-sheet__handle {
  width: 42px; height: 4px; border-radius: 999px;
  background: rgba(0,0,0,0.18); margin: 4px auto 12px;
}
.crm-sheet__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.crm-sheet__item {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 14px;
  padding: 16px 12px;
  font: inherit;
  font-weight: 650;
  text-align: left;
  min-height: 56px;
}
.crm-sheet__links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.crm-sheet__links a,
.crm-sheet__links button {
  color: var(--gold);
  background: none; border: 0; font: inherit;
  text-decoration: none; padding: 8px 0;
}
body.crm-sheet-open,
body.crm-pos-cart-open { overflow: hidden; }

/* Scanner */
.crm-scan-modal {
  position: fixed; inset: 0; z-index: 120000;
  background: rgba(20,18,14,0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.crm-scan-modal[hidden] { display: none !important; }
.crm-scan-modal__card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  color: var(--text);
  box-shadow: var(--shadow);
}
.crm-scan-modal__head {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;
}
.crm-scan-modal__hint,
.crm-scan-modal__status { margin: 0 0 8px; color: var(--muted); font-size: 0.88rem; }
.crm-scan-reader {
  border-radius: 12px; overflow: hidden; background: #111; min-height: 240px;
}

/* Sennik print — A4, 40 ta / varaq (5×8), 40×20 mm (4×2 cm) */
.crm-sennik-sheet { display: none; }
body.crm-printing-sennik .crm-sennik-sheet {
  display: block !important;
  background: #fff;
  color: #111;
}
body.crm-printing-sennik > *:not(.crm-sennik-sheet) { display: none !important; }

.crm-sennik-page {
  width: 210mm;
  height: 297mm;
  box-sizing: border-box;
  padding: 8.5mm 5mm;
  display: grid;
  grid-template-columns: repeat(5, 40mm);
  grid-template-rows: repeat(8, 20mm);
  gap: 0 0;
  justify-content: space-between;
  align-content: start;
  background: #fff;
}
.crm-sennik-page--break {
  break-after: page;
  page-break-after: always;
}

.crm-sennik-tag {
  width: 40mm;
  height: 20mm;
  box-sizing: border-box;
  border: 0.3mm solid #222;
  border-radius: 0;
  padding: 1.2mm 1.6mm 1mm;
  text-align: left;
  overflow: hidden;
  page-break-inside: avoid;
  break-inside: avoid;
  font-family: "Manrope", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #fff;
  color: #111;
}
.crm-sennik-tag--empty {
  border-style: dashed;
  border-color: #ddd;
  background: transparent;
}
.crm-sennik-tag__top { min-height: 0; }
.crm-sennik-tag__brand {
  font-size: 4.5pt;
  letter-spacing: 0.14em;
  font-weight: 800;
  line-height: 1;
  color: #444;
}
.crm-sennik-tag__name {
  margin-top: 0.4mm;
  font-size: 6.5pt;
  font-weight: 700;
  line-height: 1.1;
  max-height: 7.2mm;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.crm-sennik-tag__bottom {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1mm;
  align-items: end;
}
.crm-sennik-tag__price {
  font-size: 8.5pt;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}
.crm-sennik-tag__right {
  text-align: right;
  max-width: 22mm;
}
.crm-sennik-tag__barcode {
  display: block;
  width: 22mm;
  height: 5.5mm;
  max-width: 22mm;
}
.crm-sennik-tag__code {
  font-size: 4pt;
  font-family: "IBM Plex Mono", Menlo, monospace;
  line-height: 1;
  margin-top: 0.2mm;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 22mm;
}
.crm-sennik-tag__meta {
  font-size: 4pt;
  color: #555;
  line-height: 1;
  margin-top: 0.2mm;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }
  body.crm-printing-sennik {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  body.crm-printing-sennik .crm-sennik-sheet {
    display: block !important;
  }
  .crm-sennik-page {
    margin: 0;
  }
  .crm-sennik-tag--empty {
    border-color: transparent;
  }
}

/* Sennik preview modal */
.crm-sennik-preview {
  position: fixed;
  inset: 0;
  z-index: 100010;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.crm-sennik-preview[hidden] { display: none !important; }
.crm-sennik-preview__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.55);
}
.crm-sennik-preview__panel {
  position: relative;
  z-index: 1;
  width: min(920px, 100%);
  max-height: 92vh;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.crm-sennik-preview__head,
.crm-sennik-preview__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #e8e4dc;
}
.crm-sennik-preview__foot { border-bottom: 0; border-top: 1px solid #e8e4dc; justify-content: flex-end; }
.crm-sennik-preview__count { font-size: .85rem; color: #666; font-weight: 600; }
.crm-sennik-preview__body {
  overflow: auto;
  padding: 12px;
  background: #f3f0ea;
}
body.crm-sennik-preview-open .crm-sennik-preview__body .crm-sennik-page {
  transform: scale(0.42);
  transform-origin: top left;
  margin-bottom: -170mm;
  box-shadow: 0 4px 24px rgba(0,0,0,.12);
}

/* ========== PHONE ========== */
@media (max-width: 860px) {
  .crm-body { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
  .crm-app {
    padding: 12px 12px calc(24px + 56px);
    max-width: 100%;
  }
  .crm-header h1 { font-size: 1.2rem; }
  .crm-desk-only { display: none !important; }
  .crm-tabs--desk { display: none !important; }
  .crm-panel__sub { display: none; }
  .crm-bottom { display: flex; }
  .crm-fab:not([hidden]) { display: grid; place-items: center; }
  .crm-mobile-only { display: block !important; }

  .crm-stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .crm-dash-grid,
  .crm-form-grid,
  .crm-line,
  .crm-buy-row__grid,
  .crm-sheet__grid { grid-template-columns: 1fr; }
  .crm-panel[data-panel="buy"] .crm-panel__sub,
  .crm-panel[data-panel="pos"] .crm-panel__sub,
  .crm-panel[data-panel="invent"] .crm-panel__sub,
  .crm-panel[data-panel="transfers"] .crm-panel__sub { display: block; }
  .crm-dash-actions { grid-template-columns: 1fr 1fr; }

  .crm-row--scan {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
  }
  .crm-row--scan .btn { min-height: 48px; white-space: nowrap; }

  .crm-field input,
  .crm-field select,
  .crm-lookup input,
  .crm-row input {
    min-height: 48px;
    font-size: 16px;
  }

  /* POS: products only; cart = bottom sheet */
  .crm-pos {
    display: block;
    padding-bottom: 8px;
  }
  .crm-catalog {
    max-height: none;
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .crm-cat-item { min-height: 64px; }

  .crm-pos-dock {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(var(--nav-h) + 8px + env(safe-area-inset-bottom));
    z-index: 35;
    display: none !important;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 54px;
    padding: 12px 16px;
    border: 0;
    border-radius: 16px;
    background: var(--gold);
    color: #fff;
    font: inherit;
    font-weight: 750;
    box-shadow: 0 10px 28px rgba(0,0,0,0.16);
  }
  .crm-pos-dock:not([hidden]) { display: flex !important; }
  .crm-pos-dock__go { opacity: 0.92; font-weight: 650; }

  .crm-pos-backdrop {
    position: fixed; inset: 0; z-index: 45;
    background: rgba(20,18,14,0.35);
    display: none !important;
  }
  .crm-pos-backdrop:not([hidden]) { display: block !important; }

  .crm-pos__right {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 55;
    max-height: min(90vh, 760px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateY(110%);
    transition: transform 0.28s ease;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    border: 1px solid var(--line);
    border-bottom: 0;
    padding: 8px 14px calc(16px + env(safe-area-inset-bottom));
    box-shadow: 0 -16px 40px rgba(0,0,0,0.14);
  }
  .crm-pos.is-cart-open .crm-pos__right { transform: translateY(0); }
  .crm-pos__sheet-head {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding: 8px 2px 12px;
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 2;
  }
  .crm-pos__right .crm-card {
    box-shadow: none;
    border: 0;
    padding: 0;
    background: transparent;
  }
  .crm-cart { max-height: 26vh; overflow: auto; }
  .crm-pos__pay { position: sticky; bottom: 0; }

  .crm-fab {
    bottom: calc(var(--nav-h) + 72px + env(safe-area-inset-bottom));
  }
  .crm-toast {
    bottom: calc(var(--nav-h) + 72px + env(safe-area-inset-bottom));
  }

  .crm-table th, .crm-table td { padding: 12px 10px; font-size: 0.84rem; }
  .crm-order-card { min-height: 64px; }
  .crm-qr-grid { grid-template-columns: 1fr 1fr; }
  .crm-card { margin-bottom: 12px; }
  .crm-login__card { padding: 22px 16px; }
}

@media (max-width: 420px) {
  .crm-qr-grid { grid-template-columns: 1fr; }
  .crm-dash-actions { grid-template-columns: 1fr; }
}

@supports (padding: max(0px)) {
  .crm-app {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
}

/* CRM UI modals */
.crm-ui-modal.pc-modal {
  z-index: 1100;
  padding: 12px;
  align-items: end;
}
@media (min-width: 720px) {
  .crm-ui-modal.pc-modal { place-items: center; align-items: center; }
}
.crm-ui-modal .pc-modal__dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(90vh, 860px);
  background: #fffaf3;
  border-color: var(--line);
  color: var(--text);
}
.crm-ui-modal .pc-modal__dialog--wide {
  width: min(740px, calc(100vw - 24px));
}
.crm-ui-modal .pc-modal__title {
  margin: 0 0 14px;
  padding-right: 44px;
  color: var(--text);
  font-size: 1.15rem;
}
.crm-form-grid--modal { grid-template-columns: 1fr; }
@media (min-width: 560px) {
  .crm-form-grid--modal { grid-template-columns: 1fr 1fr; }
}
.crm-modal__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 14px;
  grid-column: 1 / -1;
}
.crm-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.crm-card__head h3 { margin: 0; }
.crm-doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.crm-doc-frame {
  width: 100%;
  height: min(68vh, 640px);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #111;
}
body.pc-modal-open { overflow: hidden; }

/* To'lov tasdiq rasmi */
.crm-confirm-upload {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.crm-confirm-upload__img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.crm-confirm-preview img {
  max-width: 100%;
  max-height: 180px;
  border-radius: 12px;
  border: 1px solid var(--line);
  margin: 8px 0;
}

/* Mijoz timeline */
.crm-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 8px;
}
.crm-timeline__item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  position: relative;
}
.crm-timeline__item:last-child { border-bottom: none; }
.crm-timeline__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
  margin-top: 6px;
  flex-shrink: 0;
}
.crm-timeline__item--online_order .crm-timeline__dot { background: #2563eb; }
.crm-timeline__item--note .crm-timeline__dot { background: var(--muted); }
.crm-timeline__item--debt_payment .crm-timeline__dot { background: var(--ok); }
.crm-timeline__item--return .crm-timeline__dot { background: var(--danger); }
.crm-timeline__content { flex: 1; min-width: 0; }
.crm-timeline__head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}
.crm-timeline__amount {
  font-weight: 700;
  color: var(--gold);
  white-space: nowrap;
}
.crm-timeline__body {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--bg-soft);
  border-radius: 8px;
  font-size: 0.92rem;
  line-height: 1.45;
}
.crm-timeline__img {
  display: block;
  max-width: 160px;
  max-height: 120px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  margin-top: 8px;
}
.crm-timeline__items {
  margin: 6px 0 0;
  padding-left: 18px;
  font-size: 0.88rem;
  color: var(--muted);
}
.crm-timeline__actions { margin-top: 8px; }

/* Mijoz sahifasi */
.crm-customer-page { padding-bottom: 32px; }
.crm-customer-stats { margin-bottom: 14px; }
.crm-customer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 900px) {
  .crm-customer-grid { grid-template-columns: 1.2fr 0.8fr; }
}
.crm-stat.is-warn strong { color: var(--warn); }
.crm-stat.is-highlight .crm-stat__value { color: var(--gold); font-size: 1.15em; }

/* Smena */
.crm-shift-badge.is-open {
  background: rgba(31, 122, 77, 0.12);
  border-color: rgba(31, 122, 77, 0.35);
  color: var(--ok);
}
.crm-shift-live {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.crm-shift-close-summary { margin-bottom: 12px; }
.crm-stats--compact { margin-bottom: 0; }
.crm-tag.is-open {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(31, 122, 77, 0.12);
  color: var(--ok);
  font-size: 0.82rem;
  font-weight: 700;
}

/* Termal chek chop */
@media print {
  body.crm-body * { visibility: hidden !important; }
  body.crm-body .crm-receipt, body.crm-body .crm-receipt * { visibility: visible !important; }
  body.crm-body .crm-receipt {
    position: absolute;
    left: 0;
    top: 0;
    width: 58mm;
  }
}

/* POS qarz xulosasi */
.crm-pos-debt {
  margin: 10px 0 4px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(180, 120, 40, 0.08);
  border: 1px solid rgba(180, 120, 40, 0.22);
}
.crm-pos-debt__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
  font-size: 0.92rem;
}
.crm-pos-debt__row--warn strong { color: #b45309; }

/* Mijoz qarz / sotuvlar */
.crm-debt-list { display: flex; flex-direction: column; gap: 10px; }
.crm-debt-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.crm-debt-row__nums {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  text-align: right;
  font-size: 0.88rem;
}
.crm-debt-row__grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  margin-top: 8px;
}
.crm-debt-row__grid .crm-stat__label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}
.crm-sales-list { display: flex; flex-direction: column; gap: 8px; }
.crm-sale-row {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.crm-sale-row__head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.crm-customer-page .crm-customer-grid { margin-bottom: 0; }
.crm-customer-stats .crm-stat.is-warn strong { color: #b45309; }
.is-warn { color: #b45309; }

@media (max-width: 860px) {
  .crm-debt-row__grid { grid-template-columns: 1fr 1fr; }
  .crm-customer-page .crm-header__actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  .crm-customer-page .crm-header h1 { font-size: 1.15rem; word-break: break-word; }
  .crm-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .crm-pos-debt { font-size: 0.95rem; }
}
