/*
 * styles.css — G HUB METER
 * 토큰 출처: 02_화면설계_시각화_v1.md §2 (컬러/타이포/스페이싱/모션)
 * 품질 기준: 12px 미만 폰트 0, 4px 그리드, 섹션 간격 48px 이상, 대비 4.5:1 이상,
 *            색 단독 전달 금지(색+텍스트+아이콘 3중), prefers-reduced-motion 대응, 가로스크롤 0.
 */

/* ── 0. 리셋 ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { overflow-x: hidden; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
ul { margin: 0; padding: 0; list-style: none; }
a { color: inherit; }
h1, h2, h3, h4, h5, h6, p { margin: 0; } /* 브라우저 기본 마진 제거 — 간격은 space 토큰으로만 제어(4px 그리드) */

/* ── 1. 디자인 토큰 ──────────────────────────────────────── */
:root {
  /* 컬러 */
  --color-bg-base: #0B0E14;
  --color-bg-surface: #131722;
  --color-bg-surface-2: #1B2130;
  --color-border-default: #232B3D;
  --color-text-primary: #E8ECF4;
  --color-text-secondary: #9AA5B8;
  --color-text-disabled: #5C6478;
  --color-brand-primary: #5B8CFF;
  --color-brand-accent: #29D3FF;
  --color-state-good: #35D07F;
  --color-state-warn: #FFB020;
  --color-state-bad: #FF4D5E;

  /* 타이포 */
  --font-family: Pretendard, -apple-system, BlinkMacSystemFont, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;

  /* 스페이싱(4px 그리드) */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px; --space-5: 20px;
  --space-6: 24px; --space-7: 32px; --space-8: 40px; --space-9: 48px; --space-10: 64px;

  /* 라운드 */
  --radius-sm: 4px; --radius-md: 8px; --radius-lg: 12px; --radius-pill: 999px;

  /* 모션 */
  --motion-fast: 120ms ease-out;
  --motion-base: 200ms ease-in-out;
  --motion-slow: 400ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --motion-fast: 40ms linear;
    --motion-base: 40ms linear;
    --motion-slow: 40ms linear;
  }
}

/* ── 2. 기본 타이포·배경 ─────────────────────────────────── */
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-family);
  background: var(--color-bg-base);
  color: var(--color-text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  min-height: 100vh;
}

.t-display { font-size: 40px; line-height: 48px; font-weight: 700; }
.t-h1 { font-size: 28px; line-height: 36px; font-weight: 700; }
.t-h2 { font-size: 20px; line-height: 28px; font-weight: 600; }
.t-h3 { font-size: 16px; line-height: 24px; font-weight: 600; }
.t-body-l { font-size: 16px; line-height: 24px; font-weight: 400; }
.t-body-m { font-size: 14px; line-height: 20px; font-weight: 400; }
.t-caption { font-size: 12px; line-height: 16px; font-weight: 500; } /* 최소 허용치 — 이 아래 금지 */

.text-secondary { color: var(--color-text-secondary); }
.text-disabled { color: var(--color-text-disabled); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── 3. 포커스 표시(접근성) ──────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--color-brand-accent);
  outline-offset: 2px;
}
button:focus:not(:focus-visible) { outline: none; }

/* ── 4. 앱 셸 / 상단 내비게이션 ──────────────────────────── */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.nav-bar {
  height: 56px; min-height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--space-6);
  background: var(--color-bg-surface);
  border-bottom: 1px solid var(--color-border-default);
  position: sticky; top: 0; z-index: 40;
}
.nav-brand { font-size: 16px; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
.nav-tabs { display: flex; gap: var(--space-2); }
.nav-tab {
  height: 40px; padding: 0 var(--space-4);
  display: inline-flex; align-items: center; gap: var(--space-1);
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-md);
  color: var(--color-text-secondary); font-size: 14px; font-weight: 600; cursor: pointer;
  min-width: 44px; min-height: 40px;
}
.nav-tab[aria-current="page"] {
  background: var(--color-bg-surface-2); color: var(--color-text-primary); border-color: var(--color-border-default);
}
.nav-right { display: flex; align-items: center; gap: var(--space-2); }
.icon-btn {
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--color-border-default); border-radius: var(--radius-md);
  color: var(--color-text-secondary); cursor: pointer; font-size: 18px;
}
.icon-btn:hover { color: var(--color-text-primary); border-color: var(--color-brand-primary); }

.view-main { flex: 1; width: 100%; }
.container {
  max-width: 960px; margin: 0 auto; padding: var(--space-9) var(--space-6) var(--space-10);
}

[hidden] { display: none !important; }

/* ── 5. 공통 카드/섹션 ───────────────────────────────────── */
.section { margin-top: var(--space-9); } /* 섹션 간 최소 48px */
.section:first-child { margin-top: 0; }

.card {
  background: var(--color-bg-surface);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}
.card + .card { margin-top: var(--space-6); }

.card-title { margin: 0 0 var(--space-4); }

.meta-row { color: var(--color-text-secondary); font-size: 14px; }

/* ── 6. 버튼 ─────────────────────────────────────────────── */
.btn {
  min-height: 44px; min-width: 44px;
  padding: 0 var(--space-6);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 16px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  transition: transform var(--motion-fast), background var(--motion-base), opacity var(--motion-base);
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--color-brand-primary); color: #06101F; height: 48px; }
.btn-primary:hover:not(:disabled) { background: #7099FF; }

.btn-secondary {
  background: transparent; color: var(--color-text-primary);
  border-color: var(--color-border-default); height: 44px;
}
.btn-secondary:hover { border-color: var(--color-brand-primary); }

.btn-ghost {
  background: transparent; color: var(--color-text-secondary); border: none; height: 40px; padding: 0 var(--space-3);
}
.btn-ghost:hover { color: var(--color-text-primary); }

.btn-danger { background: transparent; border-color: var(--color-state-bad); color: var(--color-state-bad); height: 44px; }

.btn-block { width: 100%; }

/* ── 7. 입력/토글/칩 ─────────────────────────────────────── */
.field-group { margin-bottom: var(--space-6); }
.field-label { display: block; margin-bottom: var(--space-3); font-weight: 600; }

.segmented {
  display: inline-flex; background: var(--color-bg-surface-2); border-radius: var(--radius-md);
  border: 1px solid var(--color-border-default); padding: 2px;
}
.segmented button {
  height: 36px; padding: 0 var(--space-4); border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--color-text-secondary); font-size: 14px; font-weight: 600; cursor: pointer;
  min-width: 44px;
}
.segmented button[aria-pressed="true"] { background: var(--color-brand-primary); color: #06101F; }

.num-input-row { display: flex; align-items: center; gap: var(--space-4); margin-top: var(--space-4); flex-wrap: wrap; }
.num-input {
  width: 140px; height: 48px; padding: 0 var(--space-4);
  background: var(--color-bg-surface-2); border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md); color: var(--color-text-primary); font-size: 20px; font-weight: 700;
}
.num-input.is-invalid { border-color: var(--color-state-bad); }
.convert-hint { color: var(--color-text-secondary); font-size: 14px; }

.chip-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.chip {
  height: 40px; padding: 0 var(--space-4); border-radius: var(--radius-pill);
  border: 1px solid var(--color-border-default); background: var(--color-bg-surface-2);
  color: var(--color-text-secondary); font-size: 14px; font-weight: 600; cursor: pointer; min-width: 44px;
}
.chip[aria-pressed="true"] { background: var(--color-brand-primary); color: #06101F; border-color: var(--color-brand-primary); }

.select-input {
  height: 44px; padding: 0 var(--space-4); background: var(--color-bg-surface-2);
  border: 1px solid var(--color-border-default); border-radius: var(--radius-md); color: var(--color-text-primary);
  font-size: 14px; min-width: 220px;
}

.inline-error { display: flex; align-items: center; gap: var(--space-1); color: var(--color-state-bad); font-size: 12px; margin-top: var(--space-2); }

.banner {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-4); border-radius: var(--radius-md); border: 1px solid var(--color-border-default);
  background: var(--color-bg-surface-2); font-size: 14px;
}
.banner-warn { border-color: var(--color-state-warn); }
.banner-bad { border-color: var(--color-state-bad); }
.banner-good { border-color: var(--color-state-good); }
.banner-info { border-color: var(--color-brand-primary); }
.banner-icon { flex: none; font-size: 14px; line-height: 20px; }

/* ── 8. 상태 배지(색+텍스트+아이콘 3중 표기) ─────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: var(--radius-pill); font-size: 12px; font-weight: 600;
  white-space: nowrap;
}
.badge-good { background: rgba(53,208,127,0.14); color: var(--color-state-good); }
.badge-warn { background: rgba(255,176,32,0.14); color: var(--color-state-warn); }
.badge-bad { background: rgba(255,77,94,0.14); color: var(--color-state-bad); }
.badge-info { background: rgba(91,140,255,0.14); color: var(--color-brand-primary); }
.badge-neutral { background: var(--color-bg-surface-2); color: var(--color-text-secondary); border: 1px solid var(--color-border-default); }
.badge-provisional { background: rgba(255,176,32,0.10); color: var(--color-state-warn); border: 1px dashed var(--color-state-warn); }

/* ── 9. 측정 준비 화면 ───────────────────────────────────── */
.mobile-block-banner { display: none; } /* 기본 숨김 — <768px 미디어쿼리에서만 노출(반응형 §15) */
.setup-header { margin-bottom: var(--space-9); }
.setup-header p { margin: var(--space-2) 0 0; }

.setup-actions { display: flex; flex-direction: column; align-items: center; gap: var(--space-4); margin-top: var(--space-9); }
.setup-actions .btn-primary { width: 260px; }

/* ── 10. 실시간 측정 화면 ────────────────────────────────── */
.hud-header {
  display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: var(--space-3);
  padding-bottom: var(--space-4); border-bottom: 1px solid var(--color-border-default); margin-bottom: var(--space-6);
}
.hud-elapsed { font-size: 40px; line-height: 48px; font-weight: 700; }
.hud-target { color: var(--color-text-secondary); font-size: 14px; }

.hud-grid {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-6);
}
.hud-side { flex: 1 1 0; display: flex; flex-direction: column; gap: var(--space-6); min-width: 0; }
.hud-center { flex: none; order: 0; }
.hud-cell { display: flex; flex-direction: column; gap: var(--space-2); }
.hud-cell.align-end { align-items: flex-end; text-align: right; }
.hud-side.align-end { align-items: flex-end; }
.hud-num { font-size: 40px; line-height: 48px; font-weight: 700; }
.hud-unit { font-size: 14px; color: var(--color-text-secondary); }

.click-target-wrap { position: relative; width: 260px; height: 260px; margin: 0 auto; }
.click-target {
  position: absolute; inset: 0; margin: auto; width: 220px; height: 220px; border-radius: 50%;
  background: var(--color-bg-surface-2); border: 2px solid var(--color-brand-accent);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  user-select: none; touch-action: manipulation;
  transition: transform var(--motion-fast);
}
.click-target:active { transform: scale(0.94); }
.click-target-label { font-size: 14px; color: var(--color-text-secondary); text-align: center; padding: 0 var(--space-4); }
.click-target-flash {
  position: absolute; inset: 0; margin: auto; width: 220px; height: 220px; border-radius: 50%;
  background: var(--color-brand-accent); opacity: 0; pointer-events: none;
}
.click-target-flash.is-flashing { animation: ghm-flash 200ms ease-out; }
@media (prefers-reduced-motion: reduce) {
  .click-target { transition: none; }
  .click-target-flash.is-flashing { animation: ghm-flash-reduced 40ms linear; }
}
@keyframes ghm-flash { 0% { opacity: 0; } 40% { opacity: 0.35; } 100% { opacity: 0; } }
@keyframes ghm-flash-reduced { 0% { opacity: 0; } 50% { opacity: 0.35; } 100% { opacity: 0; } }

.ring-gauge-svg { position: absolute; inset: 0; }

.hud-sparkline-row {
  margin-top: var(--space-9); padding-top: var(--space-6); border-top: 1px solid var(--color-border-default);
}
.hud-sparkline-label { margin-bottom: var(--space-2); }

.hud-stop-row { display: flex; justify-content: center; margin-top: var(--space-9); }

.countdown-overlay, .pause-overlay {
  position: fixed; inset: 0; background: rgba(11,14,20,0.9); z-index: 60;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-6); text-align: center; padding: var(--space-6);
}
.countdown-num { font-size: 96px; font-weight: 700; }

/* ── 11. 결과 요약 화면 ──────────────────────────────────── */
.result-header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-2); }
#result-interrupted, #result-low-sample { margin-top: var(--space-2); color: var(--color-state-warn); }
.hud-notice { margin-top: var(--space-2); color: var(--color-state-warn); }

.gauge-hero { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); text-align: center; }
.gauge-hero svg { max-width: 360px; }

.linear-gauge-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-6); }
.linear-gauge-block { display: flex; flex-direction: column; gap: var(--space-2); }
.linear-gauge-toprow { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); flex-wrap: wrap; }

.compare-block { display: flex; flex-direction: column; gap: var(--space-4); }
.compare-row { display: flex; align-items: center; gap: var(--space-4); }
.compare-row-label { flex: 0 0 128px; white-space: nowrap; }
.compare-row-bar { flex: 1 1 auto; min-width: 0; }

.feedback-card { border-left: 4px solid var(--color-brand-primary); }
.feedback-card.sev-bad { border-left-color: var(--color-state-bad); }
.feedback-card.sev-warn { border-left-color: var(--color-state-warn); }
.feedback-card.sev-good { border-left-color: var(--color-state-good); }
.feedback-card.sev-info { border-left-color: var(--color-brand-primary); }
.feedback-title { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); }
.feedback-ghub { margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px dashed var(--color-border-default); color: var(--color-text-secondary); font-size: 14px; }
.feedback-extra { margin-top: var(--space-4); }
.feedback-extra summary { cursor: pointer; color: var(--color-text-secondary); font-size: 14px; }

.result-actions { display: flex; justify-content: center; gap: var(--space-4); margin-top: var(--space-9); flex-wrap: wrap; align-items: center; }

.diag-detail-list { display: flex; flex-direction: column; gap: var(--space-4); }
.diag-detail-item { padding: var(--space-4); border: 1px solid var(--color-border-default); border-radius: var(--radius-md); background: var(--color-bg-surface-2); }
.diag-detail-item .badge { margin-bottom: var(--space-2); }

/* ── 12. 환경진단 + 통계 화면 ────────────────────────────── */
.env-card-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }
.env-card { padding: var(--space-4); background: var(--color-bg-surface-2); border: 1px solid var(--color-border-default); border-radius: var(--radius-md); display: flex; flex-direction: column; gap: var(--space-2); }
.env-card-label { color: var(--color-text-secondary); }
.env-card-value { font-size: 20px; font-weight: 700; }

.diag-result-list { display: flex; flex-direction: column; gap: var(--space-3); }
.diag-result-item { display: flex; gap: var(--space-2); align-items: flex-start; }

.rec-table, .history-table, .stats-table {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
.rec-table th, .rec-table td, .history-table th, .history-table td, .stats-table th, .stats-table td {
  text-align: left; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border-default);
  white-space: nowrap; /* 좁은 화면에서 줄바꿈 대신 가로 스크롤(반응형 §표는 가로 스크롤) */
}
.rec-table th, .history-table th, .stats-table th { color: var(--color-text-secondary); font-weight: 600; font-size: 12px; }
.table-scroll { overflow-x: auto; }
.table-scroll .rec-table, .table-scroll .history-table, .table-scroll .stats-table { min-width: 560px; }
.history-row { cursor: pointer; }
.history-row:hover { background: var(--color-bg-surface-2); }
.history-row td:first-child, .history-row th:first-child { padding-left: var(--space-4); }

.pagination { display: flex; gap: var(--space-2); justify-content: center; margin-top: var(--space-4); }
.pagination button { min-width: 40px; height: 40px; border-radius: var(--radius-md); border: 1px solid var(--color-border-default); background: var(--color-bg-surface-2); }
.pagination button[aria-current="true"] { background: var(--color-brand-primary); color: #06101F; }

.empty-state { text-align: center; padding: var(--space-9) var(--space-4); color: var(--color-text-secondary); }
.empty-state .btn { margin-top: var(--space-4); }

.stats-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }

/* ── 13. 모달(설정/피드백) ───────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 70;
  display: flex; align-items: center; justify-content: center; padding: var(--space-4);
}
.modal-box {
  width: 100%; max-width: 440px; background: var(--color-bg-surface); border: 1px solid var(--color-border-default);
  border-radius: var(--radius-lg); padding: var(--space-6); max-height: calc(100vh - 32px); overflow-y: auto;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-4); }
.modal-row { display: flex; justify-content: space-between; align-items: center; padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border-default); gap: var(--space-4); }
.modal-row:last-of-type { border-bottom: none; }

.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track {
  position: absolute; inset: 0; background: var(--color-bg-surface-2); border: 1px solid var(--color-border-default);
  border-radius: var(--radius-pill); transition: background var(--motion-base); cursor: pointer;
}
.switch-track::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px; background: var(--color-text-secondary);
  border-radius: 50%; transition: transform var(--motion-base), background var(--motion-base);
}
.switch input:checked + .switch-track { background: rgba(91,140,255,0.35); border-color: var(--color-brand-primary); }
.switch input:checked + .switch-track::before { transform: translateX(20px); background: var(--color-brand-primary); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--color-brand-accent); outline-offset: 2px; }

.textarea-input {
  width: 100%; min-height: 120px; padding: var(--space-3); background: var(--color-bg-surface-2);
  border: 1px solid var(--color-border-default); border-radius: var(--radius-md); color: var(--color-text-primary); resize: vertical;
}
.text-input {
  width: 100%; height: 44px; padding: 0 var(--space-3); background: var(--color-bg-surface-2);
  border: 1px solid var(--color-border-default); border-radius: var(--radius-md); color: var(--color-text-primary);
}
.char-count { text-align: right; color: var(--color-text-secondary); }

.fab-feedback {
  position: fixed; right: var(--space-6); bottom: var(--space-6); z-index: 30;
  height: 48px; padding: 0 var(--space-5); border-radius: var(--radius-pill);
  background: var(--color-brand-primary); color: #06101F; border: none; font-weight: 700; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

/* ── 14. 고지 배너 ───────────────────────────────────────── */
.consent-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
  background: var(--color-bg-surface); border-top: 1px solid var(--color-border-default);
  padding: var(--space-4) var(--space-6); display: flex; gap: var(--space-4); align-items: center; flex-wrap: wrap;
}
.consent-banner p { margin: 0; flex: 1 1 320px; font-size: 14px; color: var(--color-text-secondary); }
.consent-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: var(--space-9); transform: translateX(-50%);
  background: var(--color-bg-surface-2); border: 1px solid var(--color-border-default); color: var(--color-text-primary);
  padding: var(--space-3) var(--space-5); border-radius: var(--radius-md); z-index: 90; font-size: 14px;
}

/* ── 15. 반응형(모바일 <768px) ───────────────────────────── */
@media (max-width: 768px) {
  .container { padding: var(--space-6) var(--space-4) var(--space-9); }
  .nav-bar { padding: 0 var(--space-4); }
  .nav-brand { font-size: 14px; }
  .nav-tab { padding: 0 var(--space-2); font-size: 13px; }

  .hud-grid { flex-direction: column; align-items: stretch; }
  .hud-side { flex-direction: row; justify-content: space-between; order: 1; }
  .hud-side.align-end { align-items: stretch; }
  .hud-cell.align-end { align-items: flex-start; text-align: left; }
  .hud-center { order: -1; align-self: center; }

  .linear-gauge-pair { grid-template-columns: 1fr; }
  .env-card-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-cards { grid-template-columns: 1fr; }

  .num-input-row { flex-direction: column; align-items: stretch; }
  .num-input-row .num-input { width: 100%; }
  #duration-chips.chip-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-2); }
  #duration-chips .chip { width: 100%; }

  .mobile-block-banner { display: flex; }
  .setup-form { display: none; } /* 모바일에서는 측정 진입 자체를 차단 — 폼 대신 안내 배너만 노출 */
}

/* ── 16. 게이지/차트 컨테이너 ────────────────────────────── */
.gauge-box, .chart-box { width: 100%; }
.chart-box { min-height: 160px; }
