:root {
  --bg: #eef5ff;
  --surface: #ffffff;
  --surface-2: #f5f9ff;
  --text: #0b1730;
  --muted: #5f7392;
  --border: #c5d7f4;
  --blue: #2f6df6;
  --green: #0b7f57;
  --yellow: #f5bf32;
  --red: #b42318;
  --shadow: 0 18px 46px rgba(18, 48, 94, 0.15);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 10% 0%, rgba(47, 109, 246, 0.17), transparent 34%),
    linear-gradient(180deg, #e8f1ff, #f8fbff 45%, var(--bg));
}

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

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 900;
}

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

.screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.panel,
.form-section,
.topbar,
.modal-box {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  width: min(100%, 520px);
  padding: 20px;
}

.assignment-message {
  margin: 18px 0;
  color: var(--muted);
  font-weight: 750;
  line-height: 1.55;
}

.panel-header,
.topbar,
.top-actions,
.buttons-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-header,
.topbar,
.buttons-row {
  justify-content: space-between;
}

.panel h1,
.topbar h1,
.eyebrow,
.muted {
  margin: 0;
}

.panel h1,
.topbar h1 {
  font-size: clamp(2rem, 7vw, 3.2rem);
  line-height: 0.98;
}

.eyebrow {
  color: #2765d8;
  font-size: 0.78rem;
  font-weight: 950;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
  font-weight: 750;
}

.app-shell {
  width: min(100%, 1120px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px;
}

.topbar {
  margin: 0 0 12px;
  padding: 16px;
  color: #eef5ff;
  background: linear-gradient(135deg, #102044, #173f95);
  border-color: rgba(255, 255, 255, 0.16);
}

.topbar .eyebrow {
  color: #8fb8ff;
}

.topbar .muted {
  color: #d3e2fb;
}

.form-section {
  margin: 0 auto;
  padding: 16px;
}

label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 950;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  padding: 0 13px;
  color: var(--text);
  background: #fbfdff;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  font-weight: 850;
}

input:disabled {
  color: #3f5575;
  background: #eef4ff;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 109, 246, 0.14);
}

textarea {
  min-height: 90px;
  padding: 10px 12px;
  resize: vertical;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--text);
  text-transform: none;
}

.check-row input {
  width: 20px;
  min-height: 20px;
  accent-color: var(--blue);
}

.primary,
.finish {
  color: white;
  background: linear-gradient(135deg, #3777ff, #2456cb);
}

.secondary,
.ghost {
  color: #12346f;
  background: #f8fbff;
  border: 1px solid var(--border);
}

.warning {
  color: #1c1605;
  background: linear-gradient(135deg, #ffd860, var(--yellow));
}

.panel button,
.buttons-row button,
.finish {
  padding: 0 14px;
}

.panel button {
  width: 100%;
  margin-top: 10px;
}

.ghost {
  width: auto !important;
  margin: 0 !important;
}

.summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 14px 0;
}

.summary div {
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.summary span {
  display: block;
  font-size: 1.55rem;
  font-weight: 950;
}

.summary small {
  color: var(--muted);
  font-weight: 850;
}

.stop-preview {
  list-style: none;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.stop-preview li {
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.stop-preview strong {
  color: #12346f;
}

.stop-preview small {
  color: var(--muted);
  font-weight: 750;
}

.finish {
  width: 100%;
  margin-top: 14px;
  background: linear-gradient(135deg, #23bf7b, var(--green));
}

.modal-bg {
  position: fixed;
  inset: 0;
  z-index: 6000;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(6, 18, 42, 0.62);
  backdrop-filter: blur(6px);
}

.modal-box {
  width: min(100%, 460px);
  padding: 18px;
}

.modal-box h2 {
  margin: 0 0 8px;
}

.d2d-modal-box {
  display: grid;
  gap: 8px;
}

.d2d-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.d2d-modal-head .eyebrow,
.d2d-modal-head h2 {
  margin: 0;
}

.d2d-camera-btn {
  min-height: 44px;
  padding: 0 14px;
  color: #fff;
  background: linear-gradient(135deg, #0f8f82, #087467);
  border-radius: 10px;
  white-space: nowrap;
}

.d2d-photo-shell {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: #eef9f7;
  border: 2px solid #9ddfd4;
  border-radius: 14px;
}

.d2d-photo-shell img {
  display: block;
  width: 100%;
  max-height: min(38dvh, 360px);
  object-fit: contain;
  background: #10282e;
  border-radius: 10px;
}

.d2d-photo-shell img[hidden] {
  display: none;
}

.d2d-photo-guide {
  margin: 0;
  color: #36545b;
  font-size: 0.82rem;
  font-weight: 850;
  line-height: 1.35;
  text-align: center;
}

.d2d-ocr-status {
  margin: 0;
  padding: 9px 11px;
  color: #36545b;
  background: #eef9f7;
  border: 1px solid #bde5de;
  border-radius: 10px;
  font-size: 0.84rem;
  font-weight: 850;
  line-height: 1.35;
}

.d2d-ocr-status[data-mode="work"] {
  color: #1359a7;
  background: #eef5ff;
  border-color: #bfd6fb;
}

.d2d-ocr-status[data-mode="success"] {
  color: #06695e;
  background: #e8fbf6;
  border-color: #9fe2d5;
}

.d2d-ocr-status[data-mode="warn"] {
  color: #8a4d00;
  background: #fff8e8;
  border-color: #f1d596;
}

.d2d-number-callout {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 14px;
  padding: 10px 12px;
  color: #173b3f;
  background: linear-gradient(135deg, #fff7d6, #e8fbf6);
  border: 2px solid #edc965;
  border-radius: 12px;
}

.d2d-number-callout > span {
  color: #73530b;
  font-size: 0.72rem;
  font-weight: 950;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.d2d-number-callout > strong {
  grid-row: 1 / 3;
  grid-column: 2;
  color: #087467;
  font-size: 2rem;
  line-height: 1;
}

.d2d-number-callout p {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1.28;
}

.d2d-ocr-details {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
}

.d2d-ocr-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.d2d-ocr-details pre {
  max-height: 120px;
  margin: 8px 0 0;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 0.72rem;
}

@media (max-width: 640px) {
  body {
    padding-bottom: 104px;
  }

  .screen,
  .app-shell {
    padding: 10px;
  }

  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    padding: 12px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .top-actions,
  .top-actions button {
    width: 100%;
  }

  .form-section {
    padding: 12px;
  }

  label {
    margin: 9px 0 5px;
  }

  input,
  select,
  textarea {
    min-height: 44px;
    padding: 0 12px;
  }

  .form-section > .buttons-row {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 20;
    display: grid;
    grid-template-columns: 0.95fr 0.75fr 1.15fr;
    gap: 8px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 18px 42px rgba(18, 48, 94, 0.22);
  }

  .form-section > .buttons-row button {
    width: 100%;
    min-height: 48px;
    padding: 0 8px;
  }

  .summary {
    margin: 12px 0;
  }

  .summary div {
    padding: 10px 12px;
  }

  .modal-box .buttons-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .modal-bg .d2d-modal-box {
    width: min(100%, 520px) !important;
    height: auto !important;
    max-height: calc(100dvh - 20px) !important;
    padding: 14px !important;
    overflow-y: auto !important;
    border-radius: 14px !important;
  }

  .d2d-modal-head {
    align-items: stretch;
    flex-direction: column;
  }

  .d2d-camera-btn {
    width: 100%;
  }
}

.milk-notice {
  position: fixed;
  left: 50%;
  bottom: max(76px, calc(env(safe-area-inset-bottom) + 76px));
  z-index: 80;
  width: min(560px, calc(100vw - 18px));
  transform: translateX(-50%);
  border: 1px solid #ffc9c9;
  border-radius: 10px;
  background: #fff4f4;
  color: #991b1b;
  box-shadow: 0 18px 42px rgba(18, 48, 94, 0.2);
  font-size: 0.9rem;
  font-weight: 900;
  padding: 12px 14px;
}

.milk-notice[data-type="info"] {
  border-color: #b7cef5;
  background: #f2f7ff;
  color: #143f8f;
}
