:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #dfe5ee;
  --soft: #f8fafc;
  --primary: #2457d6;
  --primary-strong: #1e40af;
  --danger: #b42318;
  --danger-bg: #fff4f2;
  --success-bg: #ecfdf3;
  --success-text: #047857;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

.page-shell {
  width: 100%;
  min-height: 100vh;
  padding: calc(22px + env(safe-area-inset-top)) 14px calc(42px + env(safe-area-inset-bottom));
}

.document-shell {
  width: min(980px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 2px 18px;
}

.topbar h1,
.headline-group h2,
.section-title h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.2;
}

.headline-group {
  display: grid;
  gap: 6px;
}

.headline-group h2 {
  font-size: clamp(20px, 3vw, 26px);
  line-height: 1.28;
}

.eyebrow {
  margin: 0;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.muted {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.status-pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #eef4ff;
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.ready {
  background: var(--success-bg);
  color: var(--success-text);
}

.status-pill.error {
  background: var(--danger-bg);
  color: var(--danger);
}

.panel {
  width: 100%;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
}

.panel + .panel,
#documentView .panel + .panel {
  margin-top: 14px;
}

.hidden {
  display: none !important;
}

#loadingView {
  display: flex;
  align-items: center;
  gap: 12px;
}

.loader {
  width: 22px;
  height: 22px;
  border: 3px solid #dbeafe;
  border-top-color: var(--primary);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

.summary-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.summary-grid div {
  min-width: 0;
  padding: 12px;
  background: var(--soft);
  border: 1px solid #edf1f7;
  border-radius: var(--radius);
}

.summary-grid dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.summary-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.password-form {
  margin-top: 18px;
}

.password-form label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 800;
}

.password-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 10px;
}

.password-row input {
  min-width: 0;
  height: 48px;
  border: 1px solid #cfd7e3;
  border-radius: var(--radius);
  padding: 0 14px;
  background: #fff;
  color: var(--text);
  font-size: 18px;
}

.password-row input:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(36, 87, 214, 0.14);
}

.password-row button {
  height: 48px;
  border: 0;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

.password-row button:disabled {
  background: #94a3b8;
  cursor: wait;
}

.error-message {
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 800;
}

.document-header {
  display: grid;
  gap: 8px;
}

.note-block {
  margin-top: 4px;
  padding: 14px;
  background: #fffdf7;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
}

.note-block span {
  display: block;
  margin-bottom: 4px;
  color: #92400e;
  font-size: 12px;
  font-weight: 900;
}

.note-block p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.65;
}

.section-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-title h3 {
  font-size: 19px;
}

.amount-notice {
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 1px solid #d9e8ff;
  border-radius: var(--radius);
  background: #f5f9ff;
  color: #31506f;
  line-height: 1.6;
  font-size: 13px;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8fafc;
  color: #475467;
  font-size: 12px;
  font-weight: 900;
}

tr:last-child td {
  border-bottom: 0;
}

td {
  line-height: 1.5;
}

.item-name {
  font-weight: 850;
}

.amount {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 760px) {
  .page-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .status-pill {
    align-self: flex-start;
  }

  .panel {
    padding: 16px;
  }

  .summary-grid,
  .summary-grid.compact {
    grid-template-columns: 1fr;
  }

  .password-row {
    grid-template-columns: 1fr;
  }

  .password-row button {
    width: 100%;
  }

  .section-title {
    display: block;
  }

  .section-title .muted {
    margin-top: 4px;
  }

  .table-wrap {
    border: 0;
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 10px;
    background: #fff;
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr);
    gap: 10px;
    border-bottom: 1px solid #edf1f7;
    padding: 11px 12px;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
  }

  td:last-child {
    border-bottom: 0;
  }
}
