/* Shared colors, typography and page chrome are in design-system.css. */
:root { --bar-h: 76px; }

*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* 키보드로 이동할 때 고정 하단 버튼에 가려지지 않게 */
  scroll-padding-bottom: calc(var(--bar-h) + 16px + env(safe-area-inset-bottom));
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.page {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px calc(var(--bar-h) + 24px + env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

/* ---------- header ---------- */
.hero { padding: 32px 2px 24px; }
.eyebrow { margin: 0 0 6px; font-size: 12px; font-weight: 700; letter-spacing: 0.12em; color: var(--primary-text); }
.hero h1 { margin: 0; font-size: 30px; line-height: 1.3; letter-spacing: -0.02em; }
.lead { margin: 10px 0 0; color: var(--text-2); font-size: 16px; line-height: 1.65; }

/* ---------- card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 22px;
  margin-bottom: 16px;
}
.card h2 {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 14px;
  font-size: 18px; letter-spacing: -0.02em;
}
.step {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 8px;
  background: var(--primary-soft); color: var(--primary-text);
  font-size: 12px; font-weight: 800;
}
.req { margin-left: auto; font-size: 13px; font-weight: 600; color: var(--text-3); }

/* ---------- form fields ---------- */
.field + .field { margin-top: 18px; }
.label { display: block; margin-bottom: 6px; font-size: 14px; font-weight: 600; color: var(--text-2); }

.input {
  display: block;
  width: 100%;
  height: 52px;
  padding: 0 14px;
  border: 1.5px solid var(--control-border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* iOS 자동 확대 방지 */
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.input::placeholder { color: var(--text-3); }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input[readonly] { background: var(--surface-2); cursor: pointer; }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.input + .error + .input,
.input-group + .error + .input,
.error + .input { margin-top: 8px; }
.input-mono { font-variant-numeric: tabular-nums; letter-spacing: 0.04em; font-weight: 600; }

.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; min-width: 0; }
.input-group .btn { flex: none; }
.field-address #address1, .field-address #address2 { margin-top: 10px; }

.hint { margin: 9px 0 0; font-size: 14px; color: var(--text-3); line-height: 1.45; }
.status { margin: 6px 0 0; font-size: 14px; font-weight: 600; }
.status:empty, .error:empty { margin: 0; } /* 숨기지 않아야 화면낭독기가 내용 변경을 읽는다 */
.status.ok { color: var(--ok); }
.status.pending { color: var(--text-3); font-weight: 500; }
.error { margin: 6px 0 0; font-size: 14px; font-weight: 600; color: var(--danger); }
.error:not(:empty)::before { content: "! "; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 52px;
  padding: 0 18px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit; font-size: 16px; font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s, transform 0.08s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:active:not(:disabled) { background: var(--primary-press); }
.btn-dark { background: var(--dark); color: var(--on-dark); padding: 0 16px; }
.btn-outline { background: var(--surface); border-color: var(--line-strong); color: var(--text); }
.btn-block { width: 100%; }
.btn-link {
  border: 0; background: none; padding: 8px 4px; margin: -8px -4px;
  color: var(--primary-text); font: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
}
.btn:focus-visible, .btn-link:focus-visible, .icon-btn:focus-visible,
.file-btn:focus-within, summary:focus-visible {
  outline: 3px solid var(--primary); outline-offset: 2px;
}

/* ---------- photo ---------- */
.photo-empty .hint { margin: 0 0 12px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.file-btn { position: relative; padding: 0 10px; font-size: 15px; }
.photo-loading {
  display: flex; align-items: center; gap: 10px;
  height: 120px; justify-content: center;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 14px;
}
.photo-preview { margin: 0; }
.photo-preview img {
  display: block; width: 100%; max-height: 360px; object-fit: contain;
  background: var(--surface-2); border-radius: var(--radius-sm); border: 1px solid var(--line);
}
.photo-preview figcaption { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.photo-preview figcaption .hint { margin: 0; }
.card.has-error { box-shadow: 0 0 0 1.5px var(--danger); }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- consent ---------- */
.consent + .consent { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.check { display: flex; align-items: flex-start; gap: 10px; min-height: 44px; padding: 8px 0; cursor: pointer; }
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check .box {
  flex: none; width: 24px; height: 24px; margin-top: 0;
  border: 2px solid var(--control-border); border-radius: 7px; background: var(--surface);
  display: grid; place-items: center; transition: background-color 0.15s, border-color 0.15s;
}
.check .box::after {
  content: ""; width: 12px; height: 7px; margin-top: -3px;
  border-left: 2.5px solid var(--on-primary); border-bottom: 2.5px solid var(--on-primary);
  transform: rotate(-45deg) scale(0); transition: transform 0.12s;
}
.check input:checked + .box { background: var(--primary); border-color: var(--primary); }
.check input:checked + .box::after { transform: rotate(-45deg) scale(1); }
.check input:focus-visible + .box { outline: 3px solid var(--primary); outline-offset: 2px; }
.check input[aria-invalid="true"] + .box { border-color: var(--danger); }
.check-text { font-size: 15px; font-weight: 600; line-height: 1.5; padding-top: 1px; }
.check-text strong { color: var(--primary-text); font-weight: 700; }

.terms {
  margin: 4px 0 0 34px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 14px; color: var(--text-2); line-height: 1.6;
}
.terms p { margin: 0; }
.terms p + p { margin-top: 6px; }
.terms b { color: var(--text); font-weight: 700; }
details.terms summary { cursor: pointer; font-weight: 700; color: var(--text-2); list-style: none; }
details.terms summary::-webkit-details-marker { display: none; }
details.terms summary::after { content: " ▾"; }
details.terms[open] summary::after { content: " ▴"; }
details.terms[open] summary { margin-bottom: 8px; }
.terms-list { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 8px; }
.terms-list dt { font-weight: 700; color: var(--text); }
.terms-list dd { margin: 0; }

/* ---------- bottom bar ---------- */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 12px max(16px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.bottom-bar .btn { display: flex; max-width: 608px; margin: 0 auto; min-height: 54px; font-size: 17px; }

/* ---------- summary list ---------- */
.summary { margin: 0; display: grid; grid-template-columns: 84px 1fr; gap: 10px 12px; font-size: 15px; }
.summary dt { color: var(--text-3); font-weight: 600; }
.summary dd { margin: 0; font-weight: 600; }
.summary dd.mono { font-variant-numeric: tabular-nums; letter-spacing: 0.03em; }
.summary dd.empty { color: var(--warn-text); }

/* ---------- confirm sheet ---------- */
.sheet {
  width: 100%; max-width: 640px; max-height: 92dvh;
  margin: auto auto 0; padding: 0;
  border: 0; border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--text);
  overflow: auto; overscroll-behavior: contain;
}
.sheet::backdrop { background: rgb(24 39 29 / 0.45); }
.sheet[open] { animation: sheet-up 0.22s ease-out; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet-inner { padding: 10px 20px calc(20px + env(safe-area-inset-bottom)); }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 0 auto 14px; }
.sheet h2 { margin: 0 0 8px; font-size: 19px; }
.warn {
  margin: 0 0 14px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--warn-bg); color: var(--warn-text); font-size: 14px; font-weight: 600;
}
.confirm-photo img {
  display: block; width: 100%; max-height: 180px; object-fit: contain;
  background: var(--surface-2); border-radius: var(--radius-sm); margin-bottom: 16px;
}
.sheet-actions { display: grid; grid-template-columns: 1fr 1.6fr; gap: 8px; margin-top: 20px; }

/* ---------- done ---------- */
.done { padding-top: 40px; text-align: center; }
.hero h1:focus { outline: none; }
.done h1 { margin: 18px 0 0; font-size: 23px; letter-spacing: -0.02em; outline: none; }
.done-icon { width: 64px; height: 64px; margin: 0 auto; border-radius: 50%; background: var(--primary); display: grid; place-items: center; }
.done-icon svg { width: 34px; height: 34px; fill: none; stroke: var(--on-primary); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.done .summary { text-align: left; margin: 24px 0 0; padding: 24px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.notice { margin: 16px 0 24px; font-size: 14px; color: var(--text-2); text-align: left; }

/* ---------- postcode layer ---------- */
.postcode-layer {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column;
  background: var(--surface);
  padding-top: env(safe-area-inset-top);
}
.postcode-head {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 8px 0 16px; border-bottom: 1px solid var(--line); flex: none;
}
.postcode-head h2 { margin: 0; font-size: 17px; }
.icon-btn { width: 44px; height: 44px; border: 0; background: none; color: var(--text); display: grid; place-items: center; cursor: pointer; border-radius: 10px; }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.postcode-container { flex: 1; min-height: 0; position: relative; padding-bottom: env(safe-area-inset-bottom); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; z-index: 100;
  bottom: calc(var(--bar-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 32px);
  padding: 12px 16px; border-radius: 12px;
  background: var(--dark); color: var(--on-dark);
  font-size: 14px; font-weight: 600; text-align: center;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.2);
  visibility: hidden; /* display:none이 아니라서 aria-live 영역이 접근성 트리에 남는다 */
}
.toast.show { visibility: visible; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- 신청 내역 조회 ---------- */
.page-plain { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
.lookup-btn { margin-top: 20px; }
.lookup-message { margin: 4px 4px 12px; font-size: 14px; font-weight: 600; }
.lookup-message:empty { margin: 0; }
.lookup-message.warn {
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--warn-bg); color: var(--warn-text);
}
.badge-ok {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-text); font-size: 12px; font-weight: 800;
}
#lookup-result:focus { outline: none; }
#lookup-result .hint { margin-top: 14px; }
.page-link { margin: 16px 4px; font-size: 14px; }
.page-link a, .lead a { color: var(--primary-text); font-weight: 700; text-decoration: none; }
.page-link a:hover, .lead a:hover { text-decoration: underline; }
.lookup-link { display: block; margin-top: 10px; font-size: 21px; }
.delivery-access { margin: 0 0 20px; padding: 18px 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--primary-soft); }
.delivery-access-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--primary-text); font-size: 14px; }
#delivery-access-time { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .03em; }
#delivery-access-message { margin: 8px 0 0; font-size: 14px; color: var(--text-2); line-height: 1.6; }
.delivery-access[data-state="expired"], .delivery-access[data-state="closed"], .delivery-access[data-state="unavailable"] { border-color: var(--warn-text); background: var(--warn-bg); }
.delivery-access-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin-top: 14px; }
.delivery-access-actions a { color: var(--primary-text); font-size: 14px; font-weight: 700; }
.notice a { color: var(--primary-text); font-weight: 700; text-decoration: none; }

/* ---------- 설정 반영(영수증 안내·중복 도움말·마감·완료 안내) ---------- */
.guide {
  margin: 8px 0 0; padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--primary-soft); color: var(--primary-text); font-size: 14px; font-weight: 600;
}
.dup-help {
  margin: 8px 0 0; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--warn-bg); color: var(--warn-text); font-size: 14px; line-height: 1.55;
}
.dup-help a, .closed-message + .hint a { color: inherit; font-weight: 800; }
.closed-message { margin: 0 0 8px; font-size: 17px; font-weight: 700; }
.done-updated {
  margin: 16px 0 0; padding: 10px 12px; border-radius: var(--radius-sm); text-align: left;
  background: var(--warn-bg); color: var(--warn-text); font-size: 14px; font-weight: 600;
}

/* A single calm column for lookup, completion and closed states. */
.page-lookup { max-width: 640px; }
.page-lookup .hero { padding-bottom: 28px; }
#lookup-form { padding: 28px; }
#lookup-form .field + .field { margin-top: 22px; }
#lookup-result { margin-top: 20px; }
#lookup-result .summary { grid-template-columns: 92px minmax(0, 1fr); }
.page-plain, #done-view { padding-bottom: 40px; }
body > .site-footer { margin-top: auto; }
#form-view:not([hidden]) ~ .site-footer { margin-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom)); }
.summary dd { min-width: 0; overflow-wrap: anywhere; }

@media (min-width: 960px) {
  #form-view { max-width: 1120px; padding: 0 24px 24px; }
  #form-view .hero { padding: 32px 0 24px; }
  #form-view .hero h1 { font-size: 34px; }
  #form-view .lead { display: flex; align-items: baseline; justify-content: space-between; gap: 24px; }
  #form-view .lookup-link { flex: none; margin: 0; }
  .delivery-access { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 0 28px; align-items: center; }
  #delivery-access-message { margin: 0; }
  .delivery-access-actions { grid-column: 1 / -1; }
  #form {
    display: grid;
    grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
    grid-template-areas: "photo recipient" "receipt recipient" "consent consent" "submit submit";
    gap: 18px;
    align-items: stretch;
  }
  #form > .card { margin: 0; min-width: 0; padding: 24px; }
  .card-photo { grid-area: photo; }
  .card-receipt { grid-area: receipt; }
  .card-recipient {
    grid-area: recipient;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0 16px;
    align-content: start;
  }
  .card-recipient h2, .card-recipient .field-address { grid-column: 1 / -1; }
  .card-recipient .field { min-width: 0; }
  .card-recipient .field + .field { margin-top: 0; }
  .card-recipient .field-address { margin-top: 20px !important; }
  .photo-preview img { max-height: 240px; }
  .card-consent {
    grid-area: consent;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0 24px;
    align-items: start;
  }
  .card-consent h2 { grid-column: 1 / -1; }
  .card-consent .consent + .consent { margin: 0; padding: 0 0 0 24px; border-top: 0; border-left: 1px solid var(--line); }
  #form .bottom-bar { grid-area: submit; position: static; padding: 6px 0 0; background: none; display: flex; justify-content: flex-end; }
  #form .bottom-bar .btn { width: 320px; min-height: 56px; margin: 0; }
  #form-view:not([hidden]) ~ .site-footer { margin-bottom: 0; }
  .sheet { max-width: 680px; max-height: calc(100dvh - 64px); }
  .sheet-inner { padding: 28px; }
  .sheet-handle { display: none; }
  .sheet h2 { font-size: 24px; }
  .postcode-layer { inset: 6vh auto 6vh 50%; transform: translateX(-50%); width: 600px; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; box-shadow: 0 0 0 100vmax rgb(24 39 29 / .45); }
}

@media (max-width: 599px) {
  .hero h1 { font-size: 27px; }
  .card { padding: 22px 18px; }
  #lookup-form { padding: 24px 20px; }
  .delivery-access { padding: 16px 18px; }
  .check-text { font-size: 14px; }
  .terms { margin-left: 0; }
  .lookup-link { line-height: 1.45; }
}
/* Keep the initial FHD form and its primary action in a single viewport. */
@media (min-width: 960px) {
  #form-view .hero { padding: 24px 0 16px; }
  .delivery-access { padding: 12px 20px; margin-bottom: 16px; }
  #form { gap: 14px; }
  #form > .card { padding: 20px; }
  #form .card h2 { margin-bottom: 12px; }
  #form .card-consent h2 { margin-bottom: 8px; }
  #form .card-consent .terms { margin-left: 0; padding: 10px 12px; }
}
