:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Arial, "Noto Sans Arabic", sans-serif;
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-soft: #fbfaf7;
  --surface-strong: #eff8f5;
  --text: #202020;
  --muted: #6f6d69;
  --border: #e5e2dc;
  --border-strong: #dfdcd5;
  --primary: #202124;
  --primary-strong: #111111;
  --accent: #008c7a;
  --accent-pressed: #007869;
  --accent-soft: #e2f5f1;
  --secondary: #4d4d49;
  --button-dark: #008c7a;
  --button-dark-pressed: #007869;
  --button-light: #fffefd;
  --button-weak: #f0efeb;
  --button-weak-border: #e4e1dc;
  --success: #008c7a;
  --danger: #b42318;
  --warning-bg: #fff9ec;
  --button-shadow: 0 5px 10px rgba(0, 140, 122, 0.22), 0 2px 0 rgba(0, 0, 0, 0.07);
  --weak-button-shadow: 0 1px 0 rgba(255, 255, 255, 0.9) inset;
  --shadow: 0 8px 22px rgba(32, 28, 20, 0.045);
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 0, rgba(255, 255, 255, 0.85) 0, rgba(255, 255, 255, 0) 280px),
    linear-gradient(180deg, #fffefd 0, rgba(255, 254, 253, 0) 260px),
    var(--bg);
  touch-action: manipulation;
  color: var(--text);
  font-weight: 620;
}

.app-shell {
  width: min(100%, 1120px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(8px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) calc(94px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 10px;
  align-items: start;
}

.topbar,
.data-status,
.visit-status {
  grid-column: 1 / -1;
}

#salesperson-section,
#store-section,
#sku-section,
#collection-section,
#location-section,
#after-sales-section,
#photo-section,
#notes-section,
#pdf-bill-section {
  grid-column: 1;
}

#preview-section {
  grid-column: 2;
  grid-row: 4 / span 7;
  position: sticky;
  top: calc(12px + env(safe-area-inset-top));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 54px;
  margin: -8px -10px 10px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  background: rgba(247, 246, 242, 0.92);
  border-bottom: 1px solid rgba(228, 225, 220, 0.86);
  backdrop-filter: blur(18px);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(19px, 4vw, 25px);
  font-weight: 950;
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 19px;
  font-weight: 950;
  line-height: 1.18;
  letter-spacing: 0;
}

.panel,
.unlock-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 12px;
}

.unlock-panel {
  max-width: 440px;
  margin: 56px auto 0;
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}

.field {
  display: grid;
  gap: 4px;
  margin-bottom: 9px;
}

.field span,
.sku-field span {
  font-size: 13px;
  font-weight: 850;
  color: var(--secondary);
}

input,
select,
textarea,
button {
  min-height: 40px;
  font: inherit;
  font-size: 16px;
  border-radius: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  padding: 7px 10px;
  background: #fffefd;
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.75);
}

select {
  appearance: none;
  -webkit-appearance: none;
  min-height: 40px;
  padding: 7px 38px 7px 14px;
  border-color: var(--button-weak-border);
  border-radius: 999px;
  background-color: var(--button-light);
  background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M7 10l5 5 5-5' stroke='%236f6d69' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  background-size: 16px 16px;
  color: #202020;
  font-weight: 850;
  line-height: 1.2;
  box-shadow: var(--weak-button-shadow);
  cursor: pointer;
}

select:hover {
  border-color: var(--border-strong);
  background-color: #ffffff;
}

select:focus {
  background-color: #ffffff;
}

select option {
  background: #fffefd;
  color: #202020;
  font-weight: 700;
}

.topbar select {
  width: auto;
  min-width: 108px;
  padding-left: 14px;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(7, 139, 121, 0.18);
  outline-offset: 2px;
  border-color: var(--accent);
}

textarea {
  min-height: 168px;
  resize: vertical;
}

button {
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  padding: 7px 23px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: var(--button-shadow);
  -webkit-tap-highlight-color: transparent;
}

button:active {
  border-color: var(--accent-pressed);
  background: var(--accent-pressed);
  transform: translateY(1px);
}

button.secondary {
  border-color: var(--button-weak-border);
  background: var(--button-light);
  color: #6f6d69;
  box-shadow: var(--weak-button-shadow);
}

button.ghost {
  border: 1px solid var(--button-weak-border);
  background: var(--button-light);
  color: #6f6d69;
  box-shadow: var(--weak-button-shadow);
}

.store-lookup-row {
  display: grid;
  grid-template-columns: max-content 96px max-content;
  gap: 7px;
  align-items: center;
  justify-content: start;
  margin-bottom: 8px;
}

.store-ris-label {
  color: var(--secondary);
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.store-lookup-row input {
  min-width: 0;
  height: 40px;
}

.store-lookup-row button {
  min-width: 112px;
  padding-right: 18px;
  padding-left: 18px;
  white-space: nowrap;
}

.store-result {
  margin-top: 2px;
}

.new-store-grid {
  display: grid;
  gap: 8px;
}

.new-store-row {
  display: grid;
  gap: 7px;
  align-items: end;
}

.new-store-row-main {
  grid-template-columns: minmax(82px, 0.58fr) minmax(0, 1.42fr);
}

.new-store-row-optional {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.new-store-grid .field {
  min-width: 0;
  margin-bottom: 0;
}

.new-store-ris-field input,
.new-store-phone-field input {
  text-align: center;
}

.new-store-hint {
  margin-top: 7px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  padding: 0;
  margin-bottom: 9px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.segmented-control button {
  min-height: 40px;
  border-radius: 999px;
  border-color: transparent;
  background: transparent;
  color: var(--secondary);
  font-weight: 880;
  box-shadow: none;
}

.segmented-control button:not(.ghost) {
  border-color: var(--button-weak-border);
  background: var(--button-weak);
  color: #202020;
  box-shadow: var(--weak-button-shadow);
}

[hidden] {
  display: none !important;
}

.choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: flex-start;
  margin-bottom: 9px;
}

.choice-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 82px;
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid var(--button-weak-border);
  border-radius: 999px;
  background: transparent;
  color: var(--secondary);
  font-weight: 880;
  box-shadow: none;
}

.choice-option input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.choice-option.is-selected {
  border-color: var(--button-weak-border);
  background: var(--button-weak);
  color: #202020;
  box-shadow: var(--weak-button-shadow);
}

.choice-option.is-selected input {
  accent-color: var(--accent);
}

.number-input,
.formula,
.ltr {
  direction: ltr;
  text-align: left;
}

.number-input {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#visit-preview {
  direction: ltr;
  text-align: left;
  unicode-bidi: plaintext;
}

#note-text {
  direction: auto;
  text-align: start;
}

.error {
  color: var(--danger);
  font-weight: 800;
}

.success {
  color: var(--success);
  font-weight: 800;
}

.data-warning {
  color: #c2410c;
  font-weight: 850;
}

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

.data-status {
  display: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.data-status.success {
  color: var(--success);
}

.data-status.error {
  display: block;
  color: var(--danger);
}

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

.status-card,
.status-pill {
  border: 1px solid var(--button-weak-border);
  background: #fffefd;
  border-radius: 16px;
}

.status-card {
  display: grid;
  gap: 2px;
  min-height: 50px;
  padding: 7px 9px;
}

.status-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.status-card strong {
  font-size: 14px;
  font-weight: 950;
  line-height: 1.25;
}

.status-card.is-ready,
.status-pill.is-ready {
  border-color: rgba(0, 140, 122, 0.18);
  background: var(--accent-soft);
}

.status-pill {
  align-self: start;
  min-height: 30px;
  padding: 5px 12px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 950;
  white-space: nowrap;
  border-radius: 999px;
}

.product-line {
  border: 1px solid var(--button-weak-border);
  border-radius: 16px;
  margin-top: 8px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: none;
}

.product-line summary {
  display: grid;
  grid-template-columns: minmax(76px, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 11px;
  cursor: pointer;
  font-weight: 950;
  letter-spacing: 0;
  background: #fffefd;
}

.product-line-name {
  min-width: 0;
}

.product-line-count,
.product-line-missing {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  min-height: 24px;
  padding: 2px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--secondary);
  font-size: 13px;
  font-weight: 950;
  line-height: 1.25;
  white-space: nowrap;
}

.product-line-count {
  color: var(--muted);
}

.product-line-missing {
  color: #c2410c;
  font-size: 15px;
}

.product-line-missing.is-ready {
  color: var(--success);
}

.sku-row {
  display: grid;
  gap: 6px;
}

.sku-row {
  padding: 7px 8px;
  border-bottom: 1px solid #f0ece3;
  background: linear-gradient(180deg, #ffffff 0, #fffefa 100%);
}

.sku-row:last-child {
  border-bottom: 0;
}

.sku-name {
  min-width: 0;
  font-weight: 950;
  line-height: 1.16;
  padding-bottom: 0;
}

.sku-name-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  direction: rtl;
  white-space: nowrap;
  overflow: hidden;
}

.sku-ar,
.sku-en {
  display: inline-block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sku-ar {
  direction: rtl;
  flex: 0 1 auto;
}

.sku-en {
  direction: ltr;
  flex: 1 1 auto;
  color: var(--muted);
  font-size: 14px;
  font-weight: 850;
  text-align: right;
}

.sku-divider {
  flex: 0 0 auto;
  color: #b8b0a2;
  font-size: 11px;
  font-weight: 900;
}

.sku-nicotine {
  display: inline-flex;
  flex: 0 0 auto;
  width: fit-content;
  padding: 2px 7px;
  border: 1px solid #dfd8ca;
  border-radius: 999px;
  background: #f5f1e8;
  color: #69645c;
  font-size: 10px;
  font-weight: 900;
  line-height: 1.2;
  direction: ltr;
}


.sku-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  align-items: stretch;
}

.stock-control,
.sku-stepper {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 3px;
  align-items: stretch;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.stock-control {
  background: transparent;
}

.replenishment-control {
  background: transparent;
}

.return-control {
  background: transparent;
}

.sku-field {
  display: grid;
  gap: 3px;
  margin: 0;
  min-width: 0;
}

.sku-field span,
.sku-stepper-label {
  display: block;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  line-height: 1.15;
  text-align: center;
}

.quantity-box {
  display: grid;
  grid-template-rows: 36px 40px;
  gap: 3px;
  min-width: 0;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fffefd;
  box-shadow: none;
}

.stock-control .quantity-box {
  background: #fffefd;
}

.replenishment-control .quantity-box {
  background: #fffefd;
}

.return-control .quantity-box {
  background: #fffefd;
}

.stock-control input,
.sku-stepper input {
  width: 100%;
  height: 36px;
  min-height: 36px;
  justify-self: center;
  padding: 4px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: #ffffff;
  color: var(--primary);
  font-family: Inter, Arial, "Noto Sans Arabic", sans-serif;
  font-size: 16px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: center;
  box-shadow: inset 0 1px 2px rgba(32, 33, 36, 0.04);
}

.sku-stepper-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px;
  width: 100%;
}

.sku-stepper-actions.single-action {
  grid-template-columns: 1fr;
}

.zero-stock-button,
.sku-step-button {
  width: 100%;
  min-height: 40px;
  padding: 5px 3px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  box-shadow: none;
  touch-action: manipulation;
}

.sku-step-button {
  background: #fffefd;
  color: var(--secondary);
}

.sku-step-up {
  border-color: rgba(0, 140, 122, 0.18);
  background: var(--accent-soft);
  color: var(--accent);
}

.sku-step-down {
  background: #fffefd;
  color: var(--secondary);
}

.sku-step-button:active,
button.zero-stock-button:active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  transform: translateY(1px);
}

button.zero-stock-button {
  align-self: stretch;
  border-color: rgba(0, 140, 122, 0.18);
  background: var(--accent-soft);
  color: var(--accent);
}

.stock-control:focus-within,
.sku-stepper:focus-within {
  border-color: transparent;
}

.stock-control:focus-within .quantity-box,
.sku-stepper:focus-within .quantity-box {
  border-color: rgba(15, 111, 79, 0.34);
  box-shadow: 0 0 0 3px rgba(0, 140, 122, 0.08);
}

.collection-primary-grid,
.collection-other-grid {
  display: grid;
  gap: 7px;
}

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

.collection-other-grid {
  grid-template-columns: minmax(86px, 0.75fr) minmax(0, 1.45fr);
  margin-top: 2px;
}

.location-row {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 7px;
  align-items: end;
}

.location-row .field {
  margin-bottom: 0;
}

.location-row button {
  align-self: end;
  white-space: nowrap;
}

.location-result {
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.checklist {
  display: grid;
  gap: 6px;
}

.checklist label {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 7px 11px;
  border: 1px solid var(--button-weak-border);
  border-radius: 16px;
  background: #fffefd;
  color: var(--primary);
  font-weight: 850;
}

.checklist input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.pdf-bill-tool {
  border: 0;
}

.pdf-bill-tool summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  cursor: pointer;
  list-style: none;
}

.pdf-bill-tool summary::-webkit-details-marker {
  display: none;
}

.pdf-bill-title {
  font-size: 19px;
  font-weight: 950;
  line-height: 1.18;
}

.pdf-bill-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 12px;
  border: 1px solid var(--button-weak-border);
  border-radius: 999px;
  background: var(--button-light);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.pdf-bill-body {
  padding-top: 8px;
}

.pdf-source-text {
  min-height: 150px;
}

.pdf-bill-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

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

.pdf-note-card {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--button-weak-border);
  border-radius: 16px;
  background: #fffefd;
}

.pdf-note-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.pdf-note-header strong {
  font-size: 14px;
  font-weight: 950;
}

.pdf-note-header button {
  min-height: 34px;
  padding: 5px 14px;
  font-size: 13px;
}

.pdf-note-output {
  min-height: 132px;
  direction: ltr;
  text-align: left;
  unicode-bidi: plaintext;
}

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

.preview-toolbar button {
  min-width: 76px;
}

#generate-button {
  min-width: 88px;
}

.toolbar-status {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.toolbar-status strong {
  color: var(--primary);
}

.bottom-stock-summary {
  color: #c2410c;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.2;
}

.bottom-stock-summary.is-ready {
  color: var(--success);
}

@media (max-width: 900px) {
  .app {
    display: block;
  }

  .topbar,
  .data-status,
  .visit-status,
  #salesperson-section,
  #store-section,
  #sku-section,
  #collection-section,
  #location-section,
  #after-sales-section,
  #photo-section,
  #notes-section,
  #pdf-bill-section,
  #preview-section {
    margin-bottom: 8px;
  }

  #preview-section {
    position: static;
  }

  .preview-toolbar {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    grid-template-columns: minmax(0, 1fr) minmax(76px, auto) minmax(70px, auto);
    margin: 0;
    padding: 8px max(10px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    border-top: 1px solid var(--border);
    background: rgba(247, 246, 242, 0.95);
    box-shadow: 0 -8px 20px rgba(32, 28, 20, 0.08);
    backdrop-filter: blur(18px);
  }

  #visit-preview {
    min-height: 176px;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding-right: max(6px, env(safe-area-inset-right));
    padding-left: max(6px, env(safe-area-inset-left));
  }

  .topbar {
    margin-right: -6px;
    margin-left: -6px;
  }

  .topbar select {
    width: auto;
    min-width: 108px;
  }

  .visit-status {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .panel {
    padding: 10px;
  }

  .product-line summary {
    grid-template-columns: minmax(64px, 1fr) auto auto;
    padding: 7px 9px;
  }

  .product-line-count,
  .product-line-missing {
    padding-right: 0;
    padding-left: 0;
    min-width: 22px;
    font-size: 12px;
  }

  .product-line-missing {
    font-size: 13px;
  }

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

  .collection-other-grid {
    grid-template-columns: minmax(86px, 0.72fr) minmax(0, 1.5fr);
  }

  .pdf-note-grid {
    grid-template-columns: 1fr;
  }

  .sku-row {
    padding: 7px 5px;
  }

  .sku-name {
    font-size: 14px;
  }

  .sku-en {
    font-size: 14px;
  }

}

@media (max-width: 340px) {
  .stock-control,
  .sku-stepper {
    padding-right: 5px;
    padding-left: 5px;
  }

  .quantity-box {
    grid-template-rows: 36px auto;
    min-height: 122px;
  }

  .sku-stepper-actions {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .sku-stepper-actions.single-action {
    align-content: end;
  }

  .sku-step-button,
  .zero-stock-button {
    min-height: 40px;
  }

  .preview-toolbar {
    grid-template-columns: minmax(0, 1fr) 88px 76px;
    gap: 6px;
  }

  .preview-toolbar button {
    padding-right: 8px;
    padding-left: 8px;
  }
}
