:root {
  color-scheme: light;
  --ink: #172629;
  --muted: #637174;
  --line: #d5dddc;
  --surface: #ffffff;
  --page: #f5eeee;
  --brand: #ed1b24;
  --brand-dark: #b80f18;
  --brand-soft: #fde7e9;
  --teal: var(--brand);
  --teal-dark: var(--brand-dark);
  --green: #247a49;
  --green-bg: #e8f5ed;
  --amber: #a86108;
  --amber-bg: #fff1d7;
  --red: #a33a35;
  --shadow: 0 12px 34px rgba(21, 49, 51, 0.15);
  font-family: "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-header {
  height: 68px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand-lockup {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: block;
  border-radius: 50%;
  object-fit: cover;
}

.brand, .eyebrow {
  margin: 0;
  color: var(--teal);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.app-header h1 {
  margin: 1px 0 0;
  font-size: 20px;
  line-height: 1.1;
}

main { min-height: calc(100vh - 68px); }

.auth-view {
  min-height: calc(100vh - 68px);
  display: grid;
  place-items: center;
  padding: 22px 16px;
}

.auth-panel {
  width: min(100%, 390px);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.section-icon, .scan-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--brand);
  background: var(--brand-soft);
}

.auth-logo {
  width: 58px;
  height: 58px;
  display: block;
  border-radius: 50%;
  object-fit: cover;
}

.section-icon svg, .scan-mark svg { width: 24px; height: 24px; }
.auth-panel h2 { margin: 16px 0 6px; font-size: 23px; }
.auth-panel > p, .scan-panel > p { margin: 0 0 22px; color: var(--muted); line-height: 1.5; }

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 13px;
  font-weight: 700;
}

input, textarea {
  width: 100%;
  border: 1px solid #b9c5c4;
  border-radius: 4px;
  padding: 11px 12px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
}

input:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(237, 27, 36, 0.16);
}

textarea { resize: vertical; }

.primary-button, .secondary-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-radius: 4px;
  padding: 10px 16px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary-button {
  color: #fff;
  background: var(--teal);
}

.primary-button:hover { background: var(--teal-dark); }
.primary-button:disabled { opacity: 0.55; cursor: wait; }
.secondary-button { color: var(--ink); background: var(--surface); border-color: #aebcbb; }
.secondary-button:hover { border-color: var(--teal); color: var(--teal-dark); }
.primary-button svg, .secondary-button svg { width: 18px; height: 18px; }
.auth-panel .primary-button, .status-dialog .primary-button { width: 100%; margin-top: 20px; }

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--ink);
  background: transparent;
}

.icon-button:hover { background: #e5eceb; }
.icon-button svg { width: 20px; height: 20px; }
.icon-button.dark { color: #fff; background: var(--ink); border-radius: 4px; }

.work-view {
  width: min(100%, 860px);
  margin: 0 auto;
  padding: 0 16px 32px;
}

.user-bar {
  min-height: 43px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  border-bottom: 1px solid var(--line);
}

.connection-state { display: inline-flex; align-items: center; gap: 6px; }
.state-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }

.scan-panel {
  min-height: calc(100vh - 112px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 30px 0 70px;
}

.scan-mark { width: 76px; height: 76px; margin-bottom: 18px; }
.scan-mark svg { width: 38px; height: 38px; }
.scan-panel h2 { margin: 0 0 8px; font-size: 26px; }
.scan-panel .large { width: min(100%, 340px); min-height: 52px; }
.scan-panel > .secondary-button { width: min(100%, 340px); margin-top: 10px; }

.manual-row {
  width: min(100%, 340px);
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
  margin-top: 20px;
}

.job-panel { padding-top: 22px; }
.job-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.job-heading h2 { margin: 3px 0 0; font-size: 25px; }

.status-badge {
  flex: none;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 800;
}

.status-badge.completed { color: var(--green); background: var(--green-bg); }
.status-badge.delivered { color: #fff; background: var(--brand); }
.status-badge.pending { color: var(--amber); background: var(--amber-bg); }
.status-badge.new { color: #275c7a; background: #e5f1f7; }
.status-badge.imported, .status-badge.cancelled { color: var(--red); background: #f8e9e7; }

.job-facts {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1px;
  margin: 20px 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--line);
}

.job-facts div { min-width: 0; padding: 12px; background: var(--surface); }
.job-facts dt { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.job-facts dd { margin: 4px 0 0; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.customer-address {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  white-space: pre-line;
}
.customer-address.compact { margin-top: 0; }

.remark-block {
  padding: 12px 14px;
  border-left: 4px solid var(--amber);
  background: var(--amber-bg);
}

.remark-block span { color: var(--amber); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.remark-block p { margin: 4px 0 0; line-height: 1.45; }
.items-heading { display: flex; align-items: center; justify-content: space-between; margin: 24px 0 9px; }
.items-heading h3 { margin: 0; font-size: 16px; }
.items-heading span { color: var(--muted); font-size: 12px; }
.job-tabs { margin-top: 8px; }

.tab-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.tab-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.tab-button svg { width: 17px; height: 17px; }
.tab-button.active { color: #fff; background: var(--brand); }
.tab-panel { padding-top: 10px; }
.items-list { border-top: 1px solid var(--line); }

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 13px 2px;
  border-bottom: 1px solid var(--line);
}

.item-code { margin: 0 0 3px; color: var(--teal-dark); font-size: 11px; font-weight: 800; }
.item-description { margin: 0; overflow-wrap: anywhere; font-size: 14px; font-weight: 650; line-height: 1.35; }
.item-description + .item-description { margin-top: 2px; }
.item-remark { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.item-quantity { align-self: center; text-align: right; font-weight: 800; white-space: nowrap; }
.item-quantity span { display: block; color: var(--muted); font-size: 11px; font-weight: 500; }

.delivery-tools {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.delivery-tools .secondary-button,
.delivery-tools .primary-button { width: 100%; }

.delivery-tools label { margin: 2px 0 -4px; }

.delivery-preview {
  width: 132px;
  height: 132px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 4px;
  object-fit: cover;
  background: #fff;
}

.proof-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 16px 0 8px;
}

.proof-heading h3 { margin: 0; font-size: 15px; }
.proof-heading span, .proof-empty { color: var(--muted); font-size: 12px; }
.proof-list { display: grid; gap: 9px; }

.proof-card {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.proof-image-button {
  width: 82px;
  height: 82px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  overflow: hidden;
  background: #fff;
}

.proof-image-button:focus-visible {
  outline: 3px solid rgba(237, 27, 36, 0.28);
  outline-offset: 2px;
}

.proof-image-button img {
  width: 82px;
  height: 82px;
  display: block;
  object-fit: cover;
}

.proof-meta { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.35; }
.proof-remark { margin: 4px 0 0; font-size: 13px; font-weight: 650; line-height: 1.35; overflow-wrap: anywhere; }

.action-bar {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 8px;
  margin: 24px -16px -32px;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

dialog {
  width: min(calc(100% - 24px), 470px);
  max-height: calc(100vh - 24px);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(12, 29, 31, 0.7); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 2px 0 0; font-size: 20px; }
.camera-frame { position: relative; aspect-ratio: 3 / 4; background: #0b1719; overflow: hidden; }
.camera-frame video { width: 100%; height: 100%; object-fit: cover; }

.scan-guide {
  position: absolute;
  inset: 18% 10%;
  border: 3px solid #fff;
  border-radius: 6px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.28);
}

.camera-dialog > p { margin: 0; padding: 14px 16px; color: var(--muted); text-align: center; }
.status-dialog form { padding: 0 18px 20px; }
.status-dialog .dialog-header { margin: 0 -18px; }
.confirm-dialog form { padding: 0 18px 18px; }
.confirm-dialog .dialog-header { margin: 0 -18px; }
.confirm-message { margin: 18px 0; color: var(--muted); line-height: 1.45; }
.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.proof-viewer-dialog {
  width: 100vw;
  max-width: none;
  height: 100vh;
  max-height: none;
  border: 0;
  border-radius: 0;
  background: #0b0f10;
}

.proof-viewer-dialog::backdrop { background: rgba(0, 0, 0, 0.84); }

.proof-viewer-header {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  color: #fff;
  background: rgba(0, 0, 0, 0.84);
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

.proof-viewer-header h2 { margin: 2px 0 0; font-size: 17px; }
.proof-viewer-header .icon-button { color: #fff; background: rgba(255, 255, 255, 0.12); }

.proof-viewer-stage {
  height: calc(100vh - 126px);
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 18px;
  touch-action: pan-x pan-y;
}

.proof-viewer-stage img {
  max-width: 100%;
  max-height: 100%;
  transform-origin: center center;
  transition: transform 120ms ease;
  user-select: none;
}

.proof-viewer-actions {
  min-height: 64px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  padding: 10px max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.84);
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}

.status-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 18px 0;
  padding: 0;
  border: 0;
}

.status-choice legend { margin-bottom: 7px; font-size: 13px; font-weight: 700; }
.status-choice label { margin: 0; }
.status-choice input { position: absolute; opacity: 0; pointer-events: none; }

.status-choice span {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid #aebcbb;
  border-radius: 4px;
  color: var(--muted);
}

.status-choice span svg { width: 18px; height: 18px; }
.status-choice input:checked + span { border-color: var(--brand); color: var(--brand-dark); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }

.toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100% - 32px);
  transform: translate(-50%, 20px);
  padding: 11px 14px;
  border-radius: 4px;
  color: #fff;
  background: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); }

@media (min-width: 700px) {
  .work-view { padding-inline: 28px; }
  .job-facts { grid-template-columns: 2fr 1fr 1fr 1fr; }
  .action-bar { position: static; width: 420px; margin: 28px 0 0 auto; padding: 0; border: 0; background: transparent; }
}

@media (max-width: 380px) {
  .auth-panel { padding: 22px 18px; }
  .action-bar { grid-template-columns: 1fr; }
}
