/* 분양정보 엑셀 전환 화면. 화면설계서 V0.4 4,5,6,7절 기준. 토큰은 tokens.css에서 가져온다. */

* { box-sizing: border-box; }

/* HTML hidden 속성 보호. 같은 우선순위(0,1,0)인 클래스 display 규칙이 나중에 와서 hidden을 덮어쓰는 것을 막는다.
   #offline-overlay,#steps,#chosen-file-row 등 display:flex를 쓰는 요소가 hidden일 때도 실제로 숨어야 한다. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: var(--fs-body);
  font-weight: var(--fw-body);
  line-height: var(--lh-body);
}

.tabular-nums { font-variant-numeric: tabular-nums; }

/* ---------- 공통 레이아웃 (4절) ---------- */

.shell-header {
  height: var(--shell-header-h);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-default);
}
.shell-logo { height: 28px; }

.page {
  max-width: var(--bp-desktop);
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-16);
}

.page-header {
  /* 2026-11-20 정을용 결정(원문 "추천안대로"). 카드와 같은 폭,정렬로 세로줄을 맞춘다. */
  max-width: var(--screen-card-max-width);
  width: 100%;
  margin: 0 auto;
}
.page-header h1 {
  font-size: var(--fs-h1);
  font-weight: var(--fw-h1);
  line-height: var(--lh-h1);
  margin: 0;
}
.page-header .page-subtitle {
  margin: var(--space-2) 0 var(--space-8);
  color: var(--text-secondary);
  font-size: var(--fs-body);
}

.screen-stack {
  display: grid;
  /* 묵시적 열 트랙(auto)은 내용의 max-content로 잡혀 좁은 화면에서 트랙이 컨테이너 폭을 넘긴다(grid blowout).
     minmax(0, 1fr)로 열을 명시해 트랙이 컨테이너 폭 안으로 줄어들게 한다. 넓은 표는 .table-scroll이 가로로 스크롤한다. */
  grid-template-columns: minmax(0, 1fr);
}
.screen-stack > .screen {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-normal) var(--ease-out);
}
.screen-stack > .screen.is-active {
  opacity: 1;
  pointer-events: auto;
}

.card {
  max-width: var(--screen-card-max-width);
  width: 100%;
  margin: 0 auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-5) var(--space-6);
}
.card-title {
  font-size: var(--fs-h3);
  font-weight: var(--fw-h3);
  line-height: var(--lh-h3);
  margin: 0 0 var(--space-4);
}
.example-note {
  margin: calc(var(--space-4) * -1) 0 var(--space-3);
  font-size: var(--fs-micro);
  color: var(--text-quaternary);
}

/* ---------- 버튼 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 40px;
  min-height: var(--min-click-target);
  padding: 0 var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-family: var(--font-primary);
  font-size: var(--fs-button);
  font-weight: var(--fw-button);
  line-height: var(--lh-button);
  cursor: pointer;
  transition:
    background var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out),
    transform var(--duration-instant) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn .icon { width: 16px; height: 16px; }

.btn-primary { background: var(--shinhan-blue); color: var(--text-inverse); }
.btn-primary:hover:not(:disabled) { background: var(--shinhan-blue-dark); }
.btn-primary:disabled { background: var(--border-strong); color: var(--text-quaternary); cursor: not-allowed; }

.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border-default); }
.btn-secondary:hover { border-color: var(--border-strong); background: var(--bg-secondary); }

.btn-ghost {
  background: transparent;
  color: var(--text-tertiary);
  padding: 0;
  width: 32px;
  height: 32px;
  justify-content: center;
}
.btn-ghost:hover { background: var(--bg-secondary); }

.button-row {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.button-row-center { justify-content: center; }

/* ---------- SCN-A03-01 파일 올리기 ---------- */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out);
}
.dropzone:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.dropzone.is-dragover {
  border-color: var(--shinhan-blue);
  background: var(--shinhan-blue-50);
}
.dropzone-icon { width: 32px; height: 32px; color: var(--text-tertiary); }
.dropzone-text { margin: 0; color: var(--text-secondary); }
.dropzone-or { margin: 0; color: var(--text-quaternary); font-size: var(--fs-caption); }
.dropzone-hint { margin: var(--space-2) 0 0; color: var(--text-quaternary); font-size: var(--fs-caption); }

.file-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  animation: rowEnter var(--duration-normal) var(--ease-out);
}
.file-row .icon { width: 18px; height: 18px; color: var(--text-tertiary); flex-shrink: 0; }
.file-row .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .file-size { color: var(--text-quaternary); font-size: var(--fs-caption); flex-shrink: 0; }
.file-row-compact { justify-content: center; background: none; border: none; }

.field-error { color: var(--danger); font-size: var(--fs-body-sm); margin: 0; }

.info-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  color: var(--text-tertiary);
  font-size: var(--fs-body-sm);
}
.info-row .icon { width: 16px; height: 16px; flex-shrink: 0; }

/* ---------- SCN-A03-02 변환 중 ---------- */

.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
}
.progress-head .card-title { display: flex; align-items: center; gap: var(--space-2); margin: 0; }
.progress-head .icon { width: 18px; height: 18px; color: var(--text-tertiary); }
.elapsed { color: var(--text-tertiary); font-size: var(--fs-body-sm); }

.steps {
  display: flex;
  align-items: flex-start;
  margin-bottom: var(--space-5);
}
.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  flex: 0 0 auto;
  width: 96px;
}
.step-icon {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.step-icon > * { display: none; }
.step[data-state="pending"] .step-icon-pending {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
}
.step[data-state="active"] .step-icon-active { display: block; }
.step[data-state="done"] .step-icon-done {
  display: block;
  width: 24px;
  height: 24px;
  color: var(--success);
  animation: stepDone var(--duration-fast) var(--ease-out);
}
.step-label { font-size: var(--fs-body-sm); text-align: center; }
.step[data-state="pending"] .step-label { color: var(--text-tertiary); }
.step[data-state="active"] .step-label { color: var(--text-brand); font-weight: var(--fw-medium); }
.step[data-state="done"] .step-label { color: var(--text-primary); }

.step-line {
  flex: 1 1 auto;
  height: 2px;
  margin-top: 19px;
  background: var(--border-strong);
}
.step-line[data-filled="true"] {
  background: var(--shinhan-blue);
  transition: background var(--duration-normal) var(--ease-out);
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--shinhan-blue-100);
  border-top-color: var(--shinhan-blue);
  animation: spin 800ms linear infinite;
}
.spinner-sm { width: 20px; height: 20px; }

.spinner-only-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
  color: var(--text-primary);
}

/* ---------- SCN-A03-03 변환 결과 ---------- */

.result-summary-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  animation: rowEnter var(--duration-normal) var(--ease-out);
}
.result-icon { width: 24px; height: 24px; flex-shrink: 0; }
.result-icon.is-success { color: var(--success); }
.result-icon.is-danger { color: var(--danger); }
.result-summary-text { font-size: var(--fs-h3); font-weight: var(--fw-h3); flex: 1; }
.result-warning-line {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-3) 0 0;
  color: var(--warning);
  font-size: var(--fs-body-sm);
}
.result-warning-line .icon { width: 16px; height: 16px; flex-shrink: 0; }
.result-summary .button-row { margin-top: var(--space-4); }
.result-chip-row { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }

/* 버튼 옆 안내(M-12, 고른 표 자르기 범위 오류). 화면설계서 V0.4 5.3절 2번 */
.field-hint { margin: 0; align-self: center; color: var(--text-tertiary); font-size: var(--fs-body-sm); }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.card-head .card-title { margin: 0; }

/* 글자 Button ghost("전체 고르기","되돌리기","{page}쪽"). 아이콘 전용 .btn-ghost의 32px 폭을 풀어 준다 */
.btn-ghost.btn-ghost-text {
  width: auto;
  padding: 0 var(--space-2);
  color: var(--text-brand);
  font-size: var(--fs-body-sm);
}

/* 고르기 칸. 디자인 시스템 Checkbox(B-5, tokens/components.css .sh-check) 모양을 토큰으로 옮겼다(화면설계서 V0.4 5.3절 4,7번) */
.check {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  user-select: none;
  color: var(--text-primary);
  font-size: var(--fs-body-sm);
}
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check-box {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-inverse);
  transition: background var(--duration-fast) var(--ease-out), border-color var(--duration-fast) var(--ease-out);
}
.check-box .icon { width: 12px; height: 12px; opacity: 0; }
.check:hover .check-box { border-color: var(--shinhan-blue); }
.check input:checked + .check-box,
.check input:indeterminate + .check-box { background: var(--shinhan-blue); border-color: var(--shinhan-blue); }
.check input:checked + .check-box .icon { opacity: 1; }
.check input:indeterminate + .check-box::after { content: ""; width: 8px; height: 2px; background: var(--text-inverse); }
.check input:focus-visible + .check-box { box-shadow: var(--focus-ring); }
.data-grid th.is-check, .data-grid td.is-check { width: 40px; }
.data-grid td .chip + .chip { margin-left: var(--space-1); }
.data-grid td.is-muted { color: var(--text-tertiary); }
/* 표 목록의 표 이름 칸. 다른 칸은 한 줄(nowrap)이지만 이름은 길 수 있어 칸 안에서 줄을 바꾼다.
   한 줄로 두면 표가 카드보다 넓어져 원문 열(쪽 버튼)이 가로 스크롤 밖으로 밀린다(지시서 S2 구현 기록 14).
   한글은 낱말 단위로 바꾸고(keep-all), 띄어쓰기 없이 긴 글은 아무 데서나 바꾼다. */
.data-grid td.is-name { white-space: normal; word-break: keep-all; overflow-wrap: anywhere; min-width: 10rem; }

/* 7번 자르기 줄. 숫자 입력은 디자인 시스템 Input(B-2, .sh-input)을 작은 크기로 토큰으로 옮겼다 */
.crop-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-3);
  font-size: var(--fs-body-sm);
}
.crop-label { font-weight: var(--fw-medium); }
.crop-group { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.crop-group-label, .crop-sep { color: var(--text-secondary); }
.crop-columns { display: inline-flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); }
.number-input {
  width: 72px;
  height: 32px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-light);
  text-align: right;
  transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
.number-input:hover:not(:disabled) { border-color: var(--border-strong); }
.number-input:focus { outline: none; border-color: var(--border-focus); box-shadow: var(--focus-ring); }
.number-input:disabled { background: var(--bg-tertiary); color: var(--text-quaternary); cursor: not-allowed; }
.number-input.is-error { border-color: var(--danger); }
#crop-error { margin-bottom: var(--space-3); }

/* 5번 미리보기는 자르기를 바꿀 때마다 다시 그려서 행마다 늦게 나타나는 움직임을 끄고,
   표 목록 행을 눌렀을 때만 내용 투명도 0 -> 1(화면설계서 V0.4 7절 미리보기)로 보인다 */
.data-grid.data-grid-static tbody tr { opacity: 1; animation: none; }
.table-scroll.is-entering { animation: fadeIn var(--duration-fast) var(--ease-out); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: var(--fs-caption);
  font-weight: var(--fw-caption);
  white-space: nowrap;
}
.chip-success { background: var(--success-bg); color: var(--success); }
.chip-warning { background: var(--warning-bg); color: var(--warning); }
.chip-danger { background: var(--danger-bg); color: var(--danger); }
.chip-info { background: var(--info-bg); color: var(--info); }

.table-scroll { overflow-x: auto; }
.data-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-body-sm);
}
.data-grid th, .data-grid td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-table);
  text-align: left;
  white-space: nowrap;
}
.data-grid th {
  background: var(--bg-table-head);
  color: var(--text-secondary);
  font-weight: var(--fw-caption);
  text-transform: uppercase;
  font-size: var(--fs-caption);
}
.data-grid tbody tr { cursor: default; opacity: 0; animation: rowEnter var(--duration-fast) var(--ease-out) forwards; }
.data-grid tbody tr.is-clickable { cursor: pointer; }
.data-grid tbody tr.is-clickable:hover { background: var(--bg-table-row-hover); }
.data-grid tbody tr.is-selected { background: var(--bg-table-row-selected); }
.data-grid td.is-numeric { text-align: right; font-variant-numeric: tabular-nums; }

.issues-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.issues-list li {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--fs-body-sm);
}
.issues-list .icon { width: 16px; height: 16px; color: var(--warning); flex-shrink: 0; margin-top: 2px; }

/* ---------- SCN-A03-04 변환 실패 ---------- */

.failure-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  text-align: center;
  padding: var(--space-8) var(--space-6);
  animation: fadeIn var(--duration-normal) var(--ease-out);
}
.failure-icon { width: 48px; height: 48px; color: var(--danger); }
.failure-title { font-size: var(--fs-h3); font-weight: var(--fw-h3); margin: 0; }
.failure-body { margin: 0; color: var(--text-secondary); }
.failure-card .button-row { margin-top: var(--space-3); }

/* ---------- 오프라인 화면 ---------- */

.offline-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  background: var(--bg-primary);
  text-align: center;
  padding: var(--space-6);
}
.offline-icon { width: 48px; height: 48px; color: var(--warning); }
.offline-title { margin: 0; font-size: var(--fs-h3); font-weight: var(--fw-h3); }
.offline-body { margin: 0; color: var(--text-secondary); }

/* ---------- 토스트 ---------- */

.toast-root {
  position: fixed;
  left: 50%;
  bottom: var(--space-8);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 10;
}
.toast {
  background: var(--shinhan-navy);
  color: var(--text-inverse);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--fs-body-sm);
  box-shadow: var(--shadow-md);
  animation: toastIn var(--duration-normal) var(--ease-out);
}

/* ---------- 소개 움직임 (3초, 처음 들어올 때만. 화면설계서 V0.4 5.1,7절) ---------- */

.intro {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
  background: var(--bg-primary);
}
.intro-logo { height: 40px; opacity: 0; animation: fadeIn var(--duration-slow) var(--ease-out) 0ms forwards; }
.intro-title {
  margin: 0;
  font-size: var(--fs-h1);
  font-weight: var(--fw-h1);
  opacity: 0;
  transform: translateY(8px);
  animation: slideUp var(--duration-slow) var(--ease-out) 400ms forwards;
}
.intro-subtitle {
  margin: 0;
  color: var(--text-secondary);
  opacity: 0;
  transform: translateY(8px);
  animation: slideUp var(--duration-slow) var(--ease-out) 600ms forwards;
}
.intro-steps { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-4); }
.intro-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  opacity: 0;
  transform: scale(0.8);
  animation: introStepIn var(--duration-normal) var(--ease-out) forwards;
}
.intro-step[data-intro-step="0"] { animation-delay: 1200ms; }
.intro-step[data-intro-step="1"] { animation-delay: 1700ms; }
.intro-step[data-intro-step="2"] { animation-delay: 2200ms; }
.intro-step-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--shinhan-blue-50);
  color: var(--text-brand);
  display: flex;
  align-items: center;
  justify-content: center;
}
.intro-step-icon .icon { width: 20px; height: 20px; }
.intro-step-label { font-size: var(--fs-body-sm); color: var(--text-secondary); }
.intro-line { width: 48px; height: 2px; background: var(--border-strong); margin-top: 19px; overflow: hidden; position: relative; }
.intro-line::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--shinhan-blue);
  transform: scaleX(0);
  transform-origin: left;
  animation: lineFill var(--duration-normal) var(--ease-out) forwards;
}
.intro-line[data-intro-line="0"]::after { animation-delay: 1450ms; }
.intro-line[data-intro-line="1"]::after { animation-delay: 1950ms; }
.intro.is-leaving { animation: fadeOut var(--duration-normal) var(--ease-out) 2700ms forwards; }
.intro.is-hidden { display: none; }

/* ---------- 애니메이션 키프레임 ---------- */

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes rowEnter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes introStepIn { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }
@keyframes lineFill { to { transform: scaleX(1); } }
@keyframes stepDone { from { transform: scale(0.8); } to { transform: scale(1); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- 반응형 (4절. 640px 이하는 넷 다 (용용이 생각) 후보) ---------- */

@media (max-width: 768px) {
  .page { padding: var(--space-6) var(--space-4) var(--space-12); }
}

@media (max-width: 640px) {
  .page { padding: var(--space-4) var(--space-4) var(--space-12); }
  .dropzone-text, .dropzone-or { display: none; }
  /* 주 버튼(Button primary)을 맨 위에 둔다(화면설계서 V0.4 4절 3번). DOM 순서는 화면마다 달라
     (SCN-01은 보조,주 / SCN-03은 주,보조) column-reverse 대신 order로 주 버튼만 항상 앞으로 뺀다. */
  .button-row { flex-direction: column; align-items: stretch; }
  .button-row .btn { width: 100%; justify-content: center; }
  .button-row .btn-primary { order: -1; }
  .button-row-center { flex-direction: column; }
  .progress-head { flex-direction: column; align-items: flex-start; gap: var(--space-2); }
}

/* ---------- 움직임 줄이기 ---------- */

@media (prefers-reduced-motion: reduce) {
  .intro { display: none; }
  * {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.001ms !important;
  }
  .spinner { animation-duration: 800ms !important; }
}
