:root {
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
  --dark: #424749;
  --ink: #1f2a2e;
  --muted: #758187;
  --line: #d7dde0;
  --soft: #f3f6f7;
  --accent: #dce95a;
  --blue: #2384c6;
  --danger: #c73535;
  --ok: #22a447;
}

* {
  box-sizing: border-box;
}

html {
  background: #eef2f3;
  height: 100%;
  overscroll-behavior: none;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

body {
  background: #eef2f3;
  color: var(--ink);
  height: 100%;
  margin: 0;
  min-height: 100dvh;
  overscroll-behavior: none;
  overflow: hidden;
  position: fixed;
  width: 100%;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
}

.app-header {
  align-items: center;
  background: var(--dark);
  border-bottom: 4px solid #f4f6f7;
  color: #ffffff;
  display: flex;
  gap: 16px;
  min-height: calc(56px + env(safe-area-inset-top));
  justify-content: space-between;
  padding: env(safe-area-inset-top) calc(20px + env(safe-area-inset-right)) 0 calc(20px + env(safe-area-inset-left));
}

.app-header strong {
  font-size: 20px;
  font-weight: 400;
}

.header-status {
  align-items: center;
  display: flex;
  gap: 12px;
}

.api-dot {
  background: #989fa3;
  border-radius: 999px;
  display: inline-block;
  height: 18px;
  width: 18px;
}

.api-dot.online {
  background: #20bb43;
}

.api-dot.offline {
  background: #d74747;
}

.icon-button {
  align-items: center;
  background: transparent;
  border: 0;
  color: inherit;
  display: inline-flex;
  height: 44px;
  justify-content: center;
  padding: 0;
  width: 44px;
}

.icon-button svg {
  fill: none;
  height: 28px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 28px;
}

.screen {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 18px calc(18px + env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
}

.loading-card {
  background: #ffffff;
  border: 1px solid var(--line);
  padding: 20px;
}

.login-screen {
  align-items: center;
  display: flex;
  justify-content: flex-end;
  padding-right: clamp(28px, 8vw, 96px);
}

.pin-panel {
  display: grid;
  gap: 20px;
  justify-items: center;
  max-width: 360px;
  width: min(360px, 100%);
}

.pin-text,
.pin-dots {
  color: #0f2028;
  font-size: 15px;
  line-height: 1.35;
  min-height: 42px;
  text-align: center;
  width: 100%;
}

.pin-dots {
  font-size: 30px;
  letter-spacing: 8px;
}

.pin-grid {
  display: grid;
  gap: 22px 34px;
  grid-template-columns: repeat(3, 64px);
  justify-content: center;
}

.pin-grid button {
  align-items: center;
  background: transparent;
  border: 0;
  color: #10212a;
  display: flex;
  font-size: 38px;
  font-weight: 300;
  height: 64px;
  justify-content: center;
  padding: 0;
  width: 64px;
}

.pin-grid-spacer {
  height: 64px;
  width: 64px;
}

.pin-grid svg {
  fill: none;
  height: 46px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
  width: 46px;
}

.login-error {
  color: var(--danger);
  margin: 0;
  min-height: 20px;
  text-align: center;
}

.portal-screen {
  display: grid;
  gap: 16px;
}

.summary-card,
.portal-section,
.portal-grid article {
  background: #ffffff;
  border: 1px solid var(--line);
}

.summary-card {
  display: grid;
  gap: 4px;
  padding: 18px;
}

.summary-card span,
.summary-card small {
  color: var(--muted);
}

.summary-card strong {
  font-size: 28px;
  font-weight: 400;
}

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

.portal-section h2,
.portal-grid h3,
.task-dialog h2,
.stock-product-dialog h2,
.unknown-product-card h3 {
  font-size: 18px;
  margin: 0;
}

.text-button {
  background: transparent;
  border: 0;
  color: var(--blue);
  padding: 8px;
}

.task-list {
  display: grid;
}

.task-card {
  align-items: center;
  background: #ffffff;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: inherit;
  display: grid;
  gap: 4px;
  grid-template-columns: 1fr auto;
  min-height: 76px;
  padding: 12px 14px;
  text-align: left;
  width: 100%;
}

.task-card strong {
  font-size: 16px;
}

.task-card small {
  color: var(--muted);
}

.task-card .status-pill {
  background: var(--soft);
  border-radius: 999px;
  color: var(--muted);
  padding: 5px 10px;
}

.task-card.available .status-pill {
  background: #e2f4e7;
  color: #187034;
}

.empty-state {
  color: var(--muted);
  padding: 18px 14px;
}

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

.portal-grid article {
  padding: 16px;
}

.portal-grid p {
  color: var(--muted);
  margin: 10px 0 0;
}

.stock-product-section {
  margin-top: 16px;
}

.stock-product-header {
  cursor: pointer;
  position: relative;
}

.stock-product-section header small {
  color: var(--muted);
}

.stock-product-card {
  padding: 14px;
}

.stock-barcode-row {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.stock-barcode-row .button {
  min-height: 40px;
  padding: 7px 10px;
  white-space: nowrap;
}

.stock-photo-field {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) 38px;
}

.stock-photo-clear {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-size: 24px;
  height: 38px;
  justify-content: center;
  padding: 0;
  width: 38px;
}

.stock-photo-preview {
  border: 1px solid var(--line);
  display: block;
  height: 96px;
  margin-top: 8px;
  overflow: hidden;
  width: 96px;
}

.stock-photo-preview[hidden] {
  display: none;
}

.stock-photo-preview img {
  display: block;
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.stock-packaging-block {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  padding-top: 12px;
}

.task-dialog,
.stock-product-dialog,
.barcode-scanner-dialog,
.unknown-product-dialog,
.line-comment-dialog,
.line-action-dialog {
  border: 0;
  margin: auto;
  max-width: min(720px, calc(100vw - 24px));
  padding: 0;
  width: 720px;
}

.task-dialog,
.stock-product-dialog {
  height: 100dvh;
  max-height: 100dvh;
  max-width: 100vw;
  position: relative;
  width: 100vw;
}

.unknown-product-dialog,
.line-comment-dialog,
.line-action-dialog {
  max-width: min(520px, calc(100vw - 24px));
  width: 520px;
}

.task-dialog::backdrop,
.stock-product-dialog::backdrop,
.barcode-scanner-dialog::backdrop,
.unknown-product-dialog::backdrop,
.line-comment-dialog::backdrop,
.line-action-dialog::backdrop {
  background: rgb(0 0 0 / 45%);
}

.task-dialog form,
.stock-product-dialog form,
.barcode-scanner-dialog form,
.unknown-product-dialog form,
.line-comment-dialog form,
.line-action-dialog form {
  background: #ffffff;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  max-height: calc(100dvh - 24px);
}

.task-dialog form,
.stock-product-dialog form {
  height: 100dvh;
  max-height: 100dvh;
  position: relative;
}

.task-dialog header,
.stock-product-dialog header,
.barcode-scanner-dialog header,
.unknown-product-dialog header,
.line-comment-dialog header,
.line-action-dialog header {
  align-items: start;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: calc(18px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right)) 18px calc(18px + env(safe-area-inset-left));
}

.task-dialog header,
.stock-product-dialog header {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.stock-product-dialog header {
  align-items: center;
}

.stock-product-dialog header small {
  color: var(--muted);
  grid-column: 1;
}

.task-dialog header p {
  color: var(--muted);
  margin: 4px 0 0;
}

.task-dialog-heading {
  align-items: center;
  display: grid;
  gap: 6px 10px;
  grid-template-columns: minmax(0, 1fr) auto;
  min-width: 0;
}

.task-dialog-heading h2 {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  grid-column: 1;
  grid-row: 1;
  margin: 0;
}

.task-dialog-heading h2,
.task-show-deleted-toggle {
  min-width: 0;
}

.task-info-button {
  align-items: center;
  background: transparent;
  border: 1px solid #9aa6ab;
  border-radius: 999px;
  color: #4f5a60;
  display: inline-flex;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  height: 24px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 24px;
}

.task-show-deleted-toggle {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  gap: 8px;
  grid-column: 1 / -1;
  grid-row: 2;
  justify-self: start;
  min-height: 34px;
  white-space: nowrap;
}

.task-sync-status {
  color: var(--muted);
  font-size: 12px;
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  min-width: 120px;
  text-align: right;
  white-space: nowrap;
}

.task-show-deleted-toggle input {
  height: 18px;
  min-height: 18px;
  width: 18px;
}

.task-dialog header > button,
.stock-product-dialog header > button,
.barcode-scanner-dialog header > button,
.unknown-product-dialog header > button,
.line-comment-dialog header > button,
.line-action-dialog header > button {
  background: transparent;
  border: 0;
  color: #68747a;
  font-size: 34px;
  line-height: 1;
}

.task-info-card {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.task-info-card div {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 4px;
  padding-bottom: 10px;
}

.task-info-card span {
  color: var(--muted);
  font-size: 13px;
}

.task-info-card strong {
  font-weight: 500;
}

.task-info-overlay {
  inset: 0;
  position: absolute;
  z-index: 80;
}

.task-info-overlay-backdrop {
  background: rgb(0 0 0 / 45%);
  border: 0;
  inset: 0;
  padding: 0;
  position: absolute;
}

.task-info-panel {
  background: #ffffff;
  box-shadow: 0 16px 40px rgb(0 0 0 / 24%);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  left: 50%;
  max-height: min(620px, calc(100dvh - 32px));
  max-width: min(520px, calc(100vw - 24px));
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 520px;
}

.task-info-panel header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 16px 18px;
}

.task-info-panel header h2 {
  font-size: 18px;
  margin: 0;
}

.task-info-panel header button {
  background: transparent;
  border: 0;
  color: #68747a;
  font-size: 34px;
  line-height: 1;
}

.task-info-subtitle {
  background: var(--soft);
  margin: 0;
  padding: 10px 12px;
}

.task-dialog-body,
.stock-product-dialog-body {
  display: grid;
  gap: 16px;
  grid-auto-rows: max-content;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 18px calc(18px + env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
}

.barcode-scanner-dialog {
  max-width: min(620px, calc(100vw - 24px));
  width: 620px;
}

.barcode-scanner-dialog form {
  gap: 12px;
  grid-template-rows: auto auto auto;
  padding-bottom: 16px;
}

.barcode-scanner-view {
  background: #111;
  display: grid;
  margin: 0 16px;
  min-height: min(70vw, 420px);
  overflow: hidden;
  position: relative;
}

.barcode-scanner-view video {
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.barcode-scanner-frame {
  border: 2px solid #dce86b;
  inset: 26% 10%;
  pointer-events: none;
  position: absolute;
}

.barcode-scanner-dialog p {
  margin: 0;
  padding: 0 16px;
}

.task-dialog dl {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
}

.task-dialog dl div {
  background: var(--soft);
  padding: 12px;
}

.task-dialog dt {
  color: var(--muted);
  font-size: 12px;
}

.task-dialog dd {
  margin: 4px 0 0;
}

.unknown-product-card,
.line-comment-card,
.line-action-card {
  border: 1px solid var(--line);
  display: grid;
  gap: 10px;
  padding: 14px;
}

.unknown-quantity-unit-row {
  display: grid;
  gap: 8px;
  grid-template-columns: 2fr 1fr;
}

.inventory-entry-card {
  background: #ffffff;
  border: 0;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  padding: 14px;
  position: sticky;
  top: 0;
  z-index: 8;
}

.inventory-entry-card h3 {
  font-size: 18px;
  margin: 0;
}

.inventory-entry-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 220px) auto;
  align-items: end;
}

.inventory-entry-grid label,
.product-search-field {
  color: var(--muted);
  display: grid;
  gap: 5px;
  font-size: 13px;
  min-width: 0;
}

.inventory-quantity-unit-row {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: 2fr 1fr;
  min-width: 0;
}

.inventory-entry-grid input,
.inventory-entry-grid select {
  border: 1px solid var(--line);
  min-height: 42px;
  padding: 8px 10px;
  width: 100%;
}

.product-search-field {
  position: relative;
}

.product-suggestions {
  background: #ffffff;
  border: 1px solid #b9c5ca;
  box-shadow: 0 14px 34px rgb(0 0 0 / 18%);
  display: grid;
  left: 0;
  max-height: 260px;
  overflow: auto;
  position: absolute;
  right: 0;
  top: calc(100% + 2px);
  z-index: 18;
}

.product-suggestions button {
  background: #ffffff;
  border: 0;
  border-bottom: 1px solid #edf0f1;
  display: grid;
  gap: 3px;
  min-height: 48px;
  padding: 7px 10px;
  text-align: left;
}

.product-suggestions button.active,
.product-suggestions button:focus {
  background: #dfeaf0;
  outline: 0;
}

.product-suggestions span {
  color: var(--ink);
  font-size: 14px;
}

.product-suggestions small,
.selected-product,
.counted-lines small {
  color: var(--muted);
}

.unknown-suggestion span {
  color: var(--blue);
}

.selected-product {
  background: var(--soft);
  padding: 8px 10px;
}

.counted-lines {
  display: grid;
  gap: 4px;
  max-height: min(44vh, 420px);
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
}

.counted-lines::-webkit-scrollbar {
  display: none;
}

.counted-line {
  align-items: center;
  border: 0;
  background: #f8fafb;
  color: inherit;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto auto;
  min-height: 34px;
  overflow: hidden;
  padding: 6px 8px;
  position: relative;
  text-align: left;
  touch-action: pan-y;
  user-select: none;
  width: 100%;
}

.counted-line::before {
  align-items: center;
  background: #dff3df;
  color: #1f5f1f;
  content: '\041A\043E\043C\043C\0435\043D\0442\0430\0440\0438\0439';
  display: flex;
  font-size: 12px;
  font-weight: 700;
  inset: 0 auto 0 0;
  justify-content: center;
  min-width: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  position: absolute;
  transition: opacity 120ms ease;
  width: var(--swipe-progress, 0);
  z-index: 2;
}

.counted-line.swiping-comment::before {
  opacity: 1;
}

.counted-line.swiping-delete::before {
  background: #ffdede;
  color: #9f1f1f;
  content: '\0423\0434\0430\043B\0438\0442\044C';
  inset: 0 0 0 auto;
  opacity: 1;
}

.counted-line > * {
  position: relative;
  z-index: 1;
}

.counted-line span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.counted-line.synced small {
  color: var(--ok);
}

.counted-line.pending small {
  color: #b47400;
}

.counted-line.deleted {
  background: #fff0f0;
  color: #8f3131;
  text-decoration: line-through;
}

.counted-line.deleted small {
  color: #b33a3a;
  text-decoration: none;
}

.counted-line-comment-link {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.unknown-product-card p {
  color: var(--muted);
  margin: 0;
}

.unknown-product-card label {
  color: var(--muted);
  display: grid;
  gap: 5px;
  font-size: 13px;
}

.unknown-product-card input,
.unknown-product-card select,
.unknown-product-card textarea,
.line-comment-card textarea {
  border: 1px solid var(--line);
  min-height: 40px;
  padding: 8px 10px;
  width: 100%;
}

.line-comment-card textarea {
  min-height: 132px;
  resize: vertical;
}

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

.button {
  background: var(--blue);
  border: 0;
  color: #ffffff;
  min-height: 42px;
  padding: 10px 14px;
}

.portal-toast {
  background: #2f3436;
  bottom: calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 12px 34px rgb(0 0 0 / 24%);
  color: #ffffff;
  left: 50%;
  max-width: min(520px, calc(100vw - 32px));
  padding: 14px 18px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 1000;
}

@media (max-width: 720px) {
  .app-header {
    padding: env(safe-area-inset-top) calc(14px + env(safe-area-inset-right)) 0 calc(14px + env(safe-area-inset-left));
  }

  .login-screen {
    justify-content: center;
    padding-right: 18px;
  }

  .task-dialog,
  .stock-product-dialog,
  .barcode-scanner-dialog,
  .unknown-product-dialog,
  .line-comment-dialog,
  .line-action-dialog {
    max-width: calc(100vw - 12px);
    width: calc(100vw - 12px);
  }

  .task-dialog {
    height: 100dvh;
    max-width: 100vw;
    width: 100vw;
  }

  .stock-product-dialog {
    height: 100dvh;
    max-width: 100vw;
    width: 100vw;
  }

  .task-dialog form,
  .stock-product-dialog form,
  .barcode-scanner-dialog form,
  .unknown-product-dialog form,
  .line-comment-dialog form,
  .line-action-dialog form {
    height: 100%;
    max-height: 100%;
  }

  .portal-grid,
  .inventory-entry-grid {
    grid-template-columns: 1fr;
  }

  .task-dialog-body,
  .stock-product-dialog-body {
    padding: 12px;
  }
}
