@font-face {
  font-family: 'BalooMP';
  src: url('../Baloo-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f6f7f9;
  color: #172033;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --brand: #c4141c;
  --brand-dark: #991b1f;
  --line: #d8dde6;
  --muted: #647086;
  --panel: #ffffff;
  --panel-alt: #f1f4f8;
  --blue: #2563eb;
  --green: #15803d;
  --orange: #c2410c;
  --red: #b91c1c;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
}

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

button {
  cursor: pointer;
  touch-action: manipulation;
}

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

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  background: #f6f7f9;
}

.topbar {
  min-height: 70px;
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 18px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(18px);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 210px;
}

.brand-word {
  font-family: 'BalooMP', Inter, sans-serif;
  color: var(--brand);
  font-size: 32px;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand-subtitle {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: #233047;
}

.brand-subtitle b {
  font-size: 14px;
}

.brand-subtitle span {
  color: var(--muted);
  font-size: 12px;
}

.searchbar {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 0.7fr);
  gap: 10px;
}

.input-shell {
  height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-alt);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 12px;
}

.input-shell:focus-within {
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
  background: #fff;
}

.input-shell input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #172033;
}

.scan-input {
  border-color: rgba(196, 20, 28, 0.22);
  background: #fff7f7;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.shell {
  min-height: 0;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
}

.sidebar {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-right: 1px solid var(--line);
  background: #fbfcfe;
}

.sidebar-header,
.detail-toolbar,
.detail-summary,
.section-band,
.modal-header,
.modal-footer {
  border-bottom: 1px solid var(--line);
}

.sidebar-header {
  padding: 14px;
}

.side-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.order-list {
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.order-row {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
}

.order-row:hover,
.order-row.is-selected {
  background: #fff;
  border-color: var(--line);
}

.order-row.is-selected {
  box-shadow: inset 3px 0 0 var(--brand);
}

.order-title {
  font-weight: 750;
  font-size: 14px;
  line-height: 1.25;
}

.order-meta,
.tiny {
  color: var(--muted);
  font-size: 12px;
}

.order-amounts {
  text-align: right;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.detail {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
  background: #f6f7f9;
}

.detail-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px;
  background: #fff;
}

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

.detail-title h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.detail-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.detail-summary {
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) minmax(360px, 1.6fr) auto;
  gap: 14px;
  padding: 12px 16px;
  background: #fff;
}

.notes textarea {
  width: 100%;
  height: 90px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  outline: 0;
  background: #fff;
}

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

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.stat label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 4px;
}

.stat b {
  display: block;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.filter-stack {
  display: grid;
  gap: 8px;
  align-content: start;
}

.switch {
  min-width: 140px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
}

.switch input {
  inline-size: 18px;
  block-size: 18px;
  accent-color: var(--brand);
}

.items-pane {
  min-height: 0;
  overflow: auto;
  padding: 14px 16px 120px;
}

.items-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.items-head h2 {
  margin: 0;
  font-size: 16px;
}

.product-row {
  display: grid;
  grid-template-columns: 4px minmax(230px, 1.4fr) minmax(260px, 1fr) minmax(250px, 1.2fr) auto;
  gap: 10px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  margin-bottom: 10px;
  padding: 10px;
}

.status-strip {
  border-radius: 8px;
  background: var(--green);
}

.status-strip.danger {
  background: var(--red);
}

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

.barcode-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 5px;
}

.barcode {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--green);
  border: 0;
  background: transparent;
  padding: 0;
}

.barcode.invalid {
  color: var(--red);
}

.product-name {
  font-weight: 800;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.code-badge,
.pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}

.code-badge {
  background: #eef2f7;
  color: #455369;
}

.status-pill.ok {
  background: #dcfce7;
  color: #166534;
}

.status-pill.warn {
  background: #ffedd5;
  color: #9a3412;
}

.status-pill.danger {
  background: #fee2e2;
  color: #991b1b;
}

.ok {
  color: var(--green);
}

.warn {
  color: var(--orange);
}

.danger {
  color: var(--red);
}

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

.field-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fbfcfe;
}

.field-card label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 5px;
}

.field-card input {
  width: 100%;
  min-width: 0;
  height: 36px;
  border: 1px solid #cfd6e1;
  border-radius: 8px;
  background: #fff;
  outline: 0;
  padding: 0 8px;
  text-align: center;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.field-card strong {
  display: block;
  min-height: 36px;
  line-height: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.field-card.clickable {
  cursor: pointer;
}

.field-card.clickable:hover {
  border-color: rgba(37, 99, 235, 0.38);
  background: #eff6ff;
}

.info-scroller {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.mini-metric {
  min-width: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px;
  background: #fbfcfe;
  text-align: center;
  font-size: 11px;
}

.mini-metric span {
  display: block;
  color: var(--muted);
  margin-bottom: 2px;
}

.mini-metric b {
  display: block;
}

.row-actions,
.print-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.print-actions {
  max-width: 260px;
}

.btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #172033;
  padding: 0 12px;
  font-weight: 750;
  font-size: 13px;
  text-decoration: none;
}

.btn:hover {
  background: #f8fafc;
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn.blue {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.btn.green {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.btn.orange {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
}

.btn.danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.btn.ghost {
  background: transparent;
}

.btn.icon {
  inline-size: 38px;
  padding: 0;
}

.btn.small {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.btn.print {
  min-height: 30px;
  padding: 0 8px;
  font-size: 11px;
}

.empty {
  height: 100%;
  display: grid;
  place-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.empty b {
  color: #172033;
  font-size: 18px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 24, 39, 0.44);
  backdrop-filter: blur(10px);
}

.modal {
  width: min(980px, 100%);
  max-height: min(860px, calc(100dvh - 36px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 22px 80px rgba(15, 23, 42, 0.28);
}

.modal.wide {
  width: min(1220px, 100%);
}

.modal.narrow {
  width: min(620px, 100%);
}

.modal-header,
.modal-footer {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.modal-body {
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.modal-footer {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

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

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

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

.form-field {
  display: grid;
  gap: 6px;
}

.form-field label {
  color: #344055;
  font-size: 12px;
  font-weight: 800;
}

.form-field input,
.form-field textarea,
.form-field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  outline: 0;
  padding: 10px;
}

.form-field textarea {
  min-height: 120px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.result-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.result-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.result-row:hover {
  border-color: rgba(37, 99, 235, 0.4);
  background: #f8fbff;
}

.selection-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.stepper {
  display: inline-grid;
  grid-template-columns: 38px 58px 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.stepper button {
  border: 0;
  background: #fff;
  font-weight: 900;
}

.stepper input {
  width: 58px;
  border: 0;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  text-align: center;
  font-weight: 850;
}

.tabbar,
.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.tabbar button,
.segmented button {
  border: 0;
  background: transparent;
  min-height: 34px;
  padding: 0 12px;
  font-weight: 800;
}

.tabbar button.is-active,
.segmented button.is-active {
  background: #172033;
  color: #fff;
}

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

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th,
.table td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
}

.table th {
  color: var(--muted);
  font-size: 11px;
}

.table td.num,
.table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(520px, calc(100vw - 32px));
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 12px 16px;
  background: #172033;
  color: #fff;
  box-shadow: 0 12px 38px rgba(15, 23, 42, 0.28);
  font-weight: 750;
  font-size: 13px;
}

.toast.error {
  background: #991b1b;
}

.toast.info {
  background: #1d4ed8;
}

.skeleton {
  position: relative;
  overflow: hidden;
  background: #edf1f6;
  border-radius: 8px;
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.7), transparent);
  animation: shimmer 1.1s infinite;
}

@keyframes shimmer {
  100% {
    transform: translateX(100%);
  }
}

.hide-mobile {
  display: inline-flex;
}

.mobile-only {
  display: none;
}

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

  .brand {
    justify-content: space-between;
  }

  .top-actions {
    justify-content: flex-start;
  }

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

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

  .product-row {
    grid-template-columns: 4px 1fr;
  }

  .row-actions,
  .print-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100dvh;
  }

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

  .shell {
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    max-height: 42dvh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .detail {
    min-height: 58dvh;
  }

  .detail-toolbar,
  .detail-summary {
    padding: 12px;
  }

  .stats-grid,
  .qty-price-grid,
  .two-col,
  .three-col,
  .erp-grid {
    grid-template-columns: 1fr;
  }

  .items-pane {
    padding: 12px 12px 120px;
  }

  .items-head {
    grid-template-columns: 1fr;
  }

  .hide-mobile {
    display: none;
  }

  .mobile-only {
    display: inline-flex;
  }
}
