/* ══════════════════════════════════════════════════════════════
   Workout Tracker — iOS 네이티브 감각의 PWA 스타일 (요구사항 §5)
   ══════════════════════════════════════════════════════════════ */

/* DR-110: 시스템 폰트(SF Pro) 우선 / DR-111: 다크 모드 자동 대응 */
:root {
  --bg:            #f2f2f7;
  --bg-elevated:   #ffffff;
  --bg-input:      #ffffff;
  --separator:     rgba(60, 60, 67, 0.16);
  --label:         #000000;
  --label-2:       #3c3c43;
  --label-3:       rgba(60, 60, 67, 0.6);
  --tint:          #007aff;
  --tint-press:    #0062cc;
  --green:         #248a3d;
  --red:           #d70015;
  --orange:        #c93400;
  --fill:          rgba(120, 120, 128, 0.12);
  --fill-strong:   rgba(120, 120, 128, 0.2);
  --tabbar-bg:     rgba(249, 249, 249, 0.94);
  --radius:        14px;
  --safe-top:      env(safe-area-inset-top, 0px);
  --safe-bottom:   env(safe-area-inset-bottom, 0px);
  --safe-left:     env(safe-area-inset-left, 0px);
  --safe-right:    env(safe-area-inset-right, 0px);
  --tabbar-h:      52px;
  --actionbar-h:   76px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #000000;
    --bg-elevated: #1c1c1e;
    --bg-input:    #2c2c2e;
    --separator:   rgba(84, 84, 88, 0.6);
    --label:       #ffffff;
    --label-2:     #ebebf5;
    --label-3:     rgba(235, 235, 245, 0.6);
    --tint:        #0a84ff;
    --tint-press:  #409cff;
    --green:       #30d158;
    --red:         #ff453a;
    --orange:      #ff9f0a;
    --fill:        rgba(120, 120, 128, 0.24);
    --fill-strong: rgba(120, 120, 128, 0.36);
    --tabbar-bg:   rgba(22, 22, 24, 0.94);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--label);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Apple SD Gothic Neo",
               "Pretendard", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  /* DR-120: 당겨서 새로고침 오발동 방지 */
  overscroll-behavior-y: none;
}

body { overflow: hidden; }

/* ── 화면 전환 ────────────────────────────────────────────── */
.screen { position: fixed; inset: 0; display: none; flex-direction: column; }
.screen.is-active { display: flex; }

.scroll {
  flex: 1; overflow-y: auto;
  /* DR-120: 관성 스크롤 */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  /* 하단 고정 바 + 탭바에 가리지 않게 여백 확보 (DR-102) */
  padding-bottom: calc(var(--actionbar-h) + var(--tabbar-h) + var(--safe-bottom) + 16px);
}

/* ── 큰 제목 (DR-104) ─────────────────────────────────────── */
.titlebar { padding: 12px 20px 4px; }
.titlebar .eyebrow {
  margin: 0 0 2px; font-size: 13px; font-weight: 600;
  color: var(--label-3); letter-spacing: 0.02em;
}
.titlebar h1 {
  margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -0.022em;
}

.content { padding: 8px 20px 20px; }

/* ── 카드 ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

.pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  background: var(--fill); color: var(--label-2);
  font-size: 12px; font-weight: 600;
}

.card h2 { margin: 8px 0 0; font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }

/* 목표 중량 — 화면에서 가장 중요한 숫자 */
.target {
  margin: 12px 0 8px;
  font-size: 30px; font-weight: 700; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.target .x { color: var(--label-3); font-weight: 500; font-size: 22px; margin: 0 4px; }

.reason { margin: 0; font-size: 14px; color: var(--label-3); line-height: 1.5; }

.summary {
  background: var(--bg-elevated); border-radius: var(--radius);
  padding: 18px 16px; margin-bottom: 16px;
}
.summary .groups { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.summary p { margin: 0; font-size: 15px; color: var(--label-2); line-height: 1.55; }

/* 주의사항 배너 (FR-504) */
.caution {
  display: flex; gap: 10px; align-items: flex-start;
  background: color-mix(in srgb, var(--orange) 12%, var(--bg-elevated));
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px;
  font-size: 14px; color: var(--label); line-height: 1.5;
}
.caution svg { flex: 0 0 20px; width: 20px; height: 20px; stroke: var(--orange); margin-top: 1px; }

.source-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--label-3); margin-top: 14px;
}
.source-tag .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }

/* ── 폼 ───────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field > label {
  display: block; margin-bottom: 7px;
  font-size: 13px; font-weight: 600; color: var(--label-3);
}
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

/* DR-108: 16px 이상 → iOS 포커스 시 자동 확대 방지 */
input[type="text"], input[type="date"], input[type="number"], textarea, select {
  width: 100%; font-size: 17px; font-family: inherit; color: var(--label);
  background: var(--bg-input); border: none; border-radius: 10px;
  padding: 13px 14px; min-height: 48px;
  appearance: none; -webkit-appearance: none;
}
textarea { resize: none; line-height: 1.5; min-height: 96px; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--tint); outline-offset: -2px;
}
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%238e8e93' stroke-width='1.8' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 12px;
  padding-right: 38px;
}
.hint { margin: 7px 2px 0; font-size: 12.5px; color: var(--label-3); line-height: 1.45; }

/* ── 스테퍼 (DR-105 44pt / DR-106 우선 입력수단) ──────────── */
.set-row {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 0; border-top: 0.5px solid var(--separator);
}
.set-row:first-child { border-top: none; }
.set-no {
  flex: 0 0 26px; font-size: 13px; font-weight: 600;
  color: var(--label-3); padding-bottom: 14px; font-variant-numeric: tabular-nums;
}
.stepper-group { flex: 1; min-width: 0; }
.stepper-group > span {
  display: block; margin-bottom: 5px; font-size: 12px; font-weight: 600; color: var(--label-3);
}
.stepper { display: flex; align-items: stretch; background: var(--fill); border-radius: 10px; }
.stepper button {
  flex: 0 0 44px; min-height: 44px;      /* DR-105 */
  border: none; background: transparent; color: var(--tint);
  font-size: 22px; font-weight: 400; cursor: pointer;
  border-radius: 10px; transition: background 90ms;
}
/* DR-118: 지연 없는 눌림 표시 */
.stepper button:active { background: var(--fill-strong); }
.stepper input {
  flex: 1; min-width: 0; text-align: center;
  background: transparent; border: none; border-radius: 0;
  font-size: 18px; font-weight: 650; padding: 0;
  font-variant-numeric: tabular-nums; min-height: 44px;
}
.set-del {
  flex: 0 0 36px; min-height: 44px; border: none; background: transparent;
  color: var(--red); font-size: 20px; cursor: pointer; border-radius: 8px;
}
.set-del:active { background: var(--fill); }

.entry-head { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.entry-head select { flex: 1; }
.entry-remove {
  flex: 0 0 44px; height: 44px; border: none; border-radius: 10px;
  background: var(--fill); color: var(--red); font-size: 17px; cursor: pointer;
}
.entry-remove:active { background: var(--fill-strong); }

/* ── 버튼 ─────────────────────────────────────────────────── */
.btn {
  display: flex; align-items: center; justify-content: center;
  width: 100%; min-height: 50px;          /* DR-105 */
  border: none; border-radius: 12px;
  font-family: inherit; font-size: 17px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: opacity 90ms, background 90ms, transform 90ms;
}
.btn-primary { background: var(--tint); color: #fff; }
.btn-primary:active:not(:disabled) { background: var(--tint-press); transform: scale(0.985); }
.btn-primary:disabled { opacity: 0.4; cursor: default; }
.btn-ghost { background: var(--fill); color: var(--tint); }
.btn-ghost:active { background: var(--fill-strong); }
.btn.is-busy { opacity: 0.65; pointer-events: none; }

/* 카드 안 보조 버튼 */
.row-actions { display: flex; gap: 8px; margin-top: 14px; }
.mini {
  flex: 1; min-height: 44px; border: none; border-radius: 10px;
  background: var(--fill); color: var(--label-2);
  font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.mini:active { background: var(--fill-strong); }
.mini.danger { color: var(--red); }

/* ── 하단 고정 액션 바 (DR-102) ───────────────────────────── */
.actionbar {
  position: absolute; left: 0; right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 10px calc(20px + var(--safe-left)) 12px calc(20px + var(--safe-right));
  background: linear-gradient(to bottom, transparent, var(--bg) 28%);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}

/* ── 하단 탭바 ────────────────────────────────────────────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);          /* DR-102: 홈 인디케이터 회피 */
  display: flex;
  background: var(--tabbar-bg);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
  z-index: 20;
}
.tab {
  flex: 1; min-height: 44px;               /* DR-105 */
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: none; background: transparent; cursor: pointer;
  color: var(--label-3); font-family: inherit; font-size: 10px; font-weight: 550;
  transition: color 90ms;
}
.tab svg {
  width: 24px; height: 24px; fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
.tab.is-selected { color: var(--tint); }
.tab:active { opacity: 0.55; }

/* ── 하단 시트 ────────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 30;
  animation: fade 180ms ease;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-height: 92vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 14px 14px 0 0;
  padding-bottom: var(--safe-bottom);
  animation: slide-up 260ms cubic-bezier(0.32, 0.72, 0, 1);
}
.sheet-grabber {
  width: 36px; height: 5px; border-radius: 3px; background: var(--fill-strong);
  margin: 6px auto 2px;
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px 12px; border-bottom: 0.5px solid var(--separator);
}
.sheet-head h2 { margin: 0; font-size: 17px; font-weight: 650; }
.sheet-cancel, .sheet-done {
  min-width: 56px; min-height: 44px; border: none; background: transparent;
  color: var(--tint); font-family: inherit; font-size: 17px; cursor: pointer;
}
.sheet-cancel { text-align: left; }
.sheet-done { text-align: right; font-weight: 650; }
.sheet-body { overflow-y: auto; padding: 18px 20px 24px; -webkit-overflow-scrolling: touch; }

/* 스위치 */
.switch { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.switch > span:first-child { font-size: 17px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  width: 51px; height: 31px; border-radius: 999px; background: var(--fill-strong);
  position: relative; transition: background 200ms; flex: 0 0 51px;
}
.switch-knob {
  position: absolute; top: 2px; left: 2px; width: 27px; height: 27px;
  border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  transition: transform 200ms cubic-bezier(0.32, 0.72, 0, 1);
}
.switch input:checked + .switch-track { background: var(--green); }
.switch input:checked + .switch-track .switch-knob { transform: translateX(20px); }

/* ── 히스토리 ─────────────────────────────────────────────── */
.hist-date { font-size: 15px; font-weight: 650; }
.hist-note {
  margin: 8px 0 0; padding: 10px 12px; border-radius: 10px;
  background: var(--fill); font-size: 14px; color: var(--label-2); line-height: 1.5;
}
.hist-line {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 9px 0; border-top: 0.5px solid var(--separator); font-size: 14.5px;
}
.hist-line b { font-weight: 600; }
.hist-line span { color: var(--label-3); font-variant-numeric: tabular-nums; text-align: right; }

/* 종목 관리 행 */
.ex-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-elevated); border-radius: var(--radius);
  padding: 13px 16px; margin-bottom: 8px; min-height: 60px;
}
.ex-row .info { flex: 1; min-width: 0; }
.ex-row .info b { display: block; font-size: 16px; font-weight: 600; }
.ex-row .info small { color: var(--label-3); font-size: 12.5px; }
.ex-row .edit {
  flex: 0 0 auto; min-height: 44px; padding: 0 14px; border: none; border-radius: 9px;
  background: var(--fill); color: var(--tint); font-family: inherit;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.ex-row .edit:active { background: var(--fill-strong); }
.group-label {
  margin: 20px 2px 8px; font-size: 13px; font-weight: 650;
  color: var(--label-3); letter-spacing: 0.02em;
}
.group-label:first-child { margin-top: 4px; }

/* ── 상태 표시 (DR-119, DR-121) ───────────────────────────── */
.skeleton-stack { display: flex; flex-direction: column; gap: 12px; }
.skeleton {
  height: 92px; border-radius: var(--radius); background: var(--fill);
  animation: pulse 1.4s ease-in-out infinite;
}
.empty { text-align: center; padding: 56px 24px; color: var(--label-3); font-size: 15px; line-height: 1.6; }
.empty strong { display: block; color: var(--label-2); font-size: 17px; font-weight: 600; margin-bottom: 6px; }

.toast {
  position: fixed; left: 50%; transform: translate(-50%, 20px);
  bottom: calc(var(--tabbar-h) + var(--actionbar-h) + var(--safe-bottom) + 8px);
  max-width: calc(100vw - 40px);
  padding: 12px 20px; border-radius: 12px;
  background: rgba(28, 28, 30, 0.95); color: #fff;
  font-size: 14.5px; font-weight: 550; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity 220ms, transform 220ms; z-index: 40;
}
.toast.is-shown { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--red); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
