/**
 * [우문현답] 공용 컴포넌트 & 모바일 규칙 CSS (components.css)
 * 
 * 명세: specs/SPEC_디자인_대개편.md 5.4, 5.7
 */

/* ==========================================================================
   1. 버튼 & 링크 (.btn-primary, .btn-secondary, .text-action)
   ========================================================================== */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background-color: var(--green);
  color: #fffdf8;
  border: 1px solid var(--green);
  border-radius: 12px;
  font-family: var(--sans);
  font-size: 15.5px;
  font-weight: 600;
  min-height: 48px;
  padding: 0 24px;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background-color 0.2s ease;
  box-shadow: 0 2px 8px rgba(54, 91, 70, 0.18);
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover {
  opacity: 0.95;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background-color: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-family: var(--sans);
  font-size: 14.5px;
  font-weight: 500;
  min-height: 44px;
  padding: 0 18px;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-secondary:hover {
  background-color: var(--sage);
  border-color: var(--muted);
}

.btn-secondary:active {
  transform: scale(0.98);
}

/* 글자 링크 (터치 영역 44px 이상 확보) */
.text-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--green);
  font-size: 14.5px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 4px;
  min-height: 44px;
  padding: 0 8px;
  background: none;
  border: none;
  cursor: pointer;
  transition: color 0.2s ease, opacity 0.2s ease;
}

.text-action:hover {
  opacity: 0.8;
}

/* ==========================================================================
   2. 하단 고정 바 (.cta-dock)
   모바일(≤ 768px)에서 화면 아래 고정. 키보드 오픈 시 숨김.
   ========================================================================== */

.cta-dock {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 24px;
}

@media (max-width: 768px) {
  .cta-dock {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background-color: var(--surface);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(41, 61, 51, 0.08);
    z-index: 100;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  .cta-dock .btn-primary {
    width: 100%;
  }

  /* 키보드가 올라오면 하단 바 숨김 (ui-core.js에서 제어) */
  body.keyboard-open .cta-dock {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
  }
}

/* ==========================================================================
   3. 단계 표시 (.step-dots)
   점 4개(또는 5개). 현재 점만 --green.
   ========================================================================== */

.step-dots {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
}

.step-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background-color: var(--line);
  transition: background-color 0.25s ease, transform 0.25s ease;
}

.step-dot.active {
  background-color: var(--green);
  transform: scale(1.25);
}

.step-dot.completed {
  background-color: var(--muted);
}

/* ==========================================================================
   4. 접힌 요약 (.step-summary)
   끝난 단계를 한 줄로 간결히 요약하고 클릭 시 되돌아가기
   ========================================================================== */

.step-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  background-color: var(--sage);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13.5px;
  color: var(--ink);
  margin-bottom: 16px;
  animation: fadeIn 0.25s ease-out;
}

.step-summary .summary-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.step-summary .step-summary-edit,
.step-summary .summary-edit-btn {
  background: none;
  border: none;
  color: var(--green);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  text-decoration: underline;
  text-underline-offset: 3px;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ==========================================================================
   5. 용어 말풍선 (.term)
   글자 옆 작은 '?' 표시. hover/click/focus로 팝업. Esc/Outside 닫힘.
   ========================================================================== */

.term {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  padding: 0 2px;
  margin: 0;
  font: inherit;
  color: inherit;
  font-weight: 600;
  text-decoration: underline dotted var(--muted);
  text-underline-offset: 3px;
  cursor: help;
  vertical-align: baseline;
}

.term::after {
  content: "?";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  font-size: 10.5px;
  font-weight: 700;
  border-radius: 50%;
  background-color: var(--sage);
  color: var(--green);
  border: 1px solid var(--line);
}

.term-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 260px;
  padding: 10px 14px;
  background-color: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.6;
  text-decoration: none;
  box-shadow: var(--shadow-float);
  z-index: 1000;
  pointer-events: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.term-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--line);
}

.term.tooltip-open .term-tooltip,
.term:focus-visible .term-tooltip {
  opacity: 1;
  visibility: visible;
}

/* ==========================================================================
   6. 도구 서랍 (.tools-drawer)
   모바일: 바텀 시트, 데스크톱: 우측 슬라이드 패널
   ========================================================================== */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 900;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.drawer-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.tools-drawer {
  position: fixed;
  z-index: 1000;
  background-color: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-float);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.3s ease;
  display: flex;
  flex-direction: column;
  visibility: hidden;
  pointer-events: none;
}

.tools-drawer.open {
  visibility: visible;
  pointer-events: auto;
}

/* 데스크톱: 우측 슬라이드 패널 */
@media (min-width: 769px) {
  .tools-drawer {
    top: 0;
    right: 0;
    bottom: 0;
    width: 360px;
    max-width: 90vw;
    border-right: none;
    transform: translateX(100%);
  }

  .tools-drawer.open {
    transform: translateX(0);
  }
}

/* 모바일: 바텀 시트 */
@media (max-width: 768px) {
  .tools-drawer {
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 85vh;
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    transform: translateY(100%);
  }

  .tools-drawer.open {
    transform: translateY(0);
  }
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.drawer-title {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  color: var(--ink);
}

.drawer-close-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--muted);
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.drawer-content {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ==========================================================================
   7. 5.7 모바일 공통 요구사항 & 폼 필드
   ========================================================================== */

/* iOS 줌 방지 (16px 이상) */
textarea,
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
select {
  font-family: var(--sans);
  font-size: 16px !important;
  color: var(--ink);
  background-color: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  line-height: 1.6;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 0.2s ease, outline-color 0.2s ease;
}

textarea:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 1px;
  border-color: var(--green);
}

textarea::placeholder,
input::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

/* 텍스트 줄바꿈: 한글 단어가 어색하게 끊기지 않도록 */
h1, h2, h3, h4, h5, p, button, label, .term-tooltip {
  word-break: keep-all;
  overflow-wrap: break-word;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
