/* SPDX-License-Identifier: Apache-2.0
   Copyright 2026 CLSOFTLAB (씨엘소프트랩), Dr. Lee Il-guk (이일국) */

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f9;
  --text: #17202e;
  --muted: #6b7686;
  --border: #dde3ee;
  --brand: #ff5a3c;
  --brand-2: #ff8a3c;
  --accent: #3c7bff;
  --ok: #17b26a;
  --warn: #f5a524;
  --danger: #e5484d;
  --star-fill: #ffb020;
  --star-empty: #d9dee8;
  --shadow: 0 6px 20px rgba(20, 30, 55, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1218; --surface: #171d27; --surface-2: #1f2733; --text: #e8edf5;
    --muted: #9aa6b8; --border: #2a3340; --star-empty: #3a4453;
    --shadow: 0 8px 26px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0e1218; --surface: #171d27; --surface-2: #1f2733; --text: #e8edf5;
  --muted: #9aa6b8; --border: #2a3340; --star-empty: #3a4453;
  --shadow: 0 8px 26px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", sans-serif;
  line-height: 1.55; -webkit-text-size-adjust: 100%;
}
body.modal-open, body.session-open { overflow: hidden; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.3; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; margin-top: 1.4rem; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); font-weight: 400; font-size: .88em; }
.empty { color: var(--muted); text-align: center; padding: 2.5rem 1rem; }

#app { max-width: 1080px; margin: 0 auto; padding: 0 16px 3rem; }

/* 헤더 */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 0; position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { font-size: 1.9rem; }
.brand h1 { font-size: 1.25rem; margin: 0; }
.tagline { margin: 0; font-size: .8rem; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 8px; }
.credit-chip {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 999px; font-size: .85rem;
}
.credit-chip.has-credit { background: color-mix(in srgb, var(--ok) 18%, var(--surface)); border-color: var(--ok); }
.demo-chip {
  background: var(--brand); color: #fff; font-size: .68rem; font-weight: 700;
  padding: 3px 8px; border-radius: 6px; letter-spacing: .5px;
}
.icon-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  width: 38px; height: 38px; font-size: 1.1rem; color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }

/* 탭 */
.tabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 12px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 999px; white-space: nowrap; font-size: .92rem;
}
.tab.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.pill {
  background: rgba(0,0,0,.12); border-radius: 999px; padding: 0 7px; font-size: .78rem; margin-left: 3px;
}
.tab.is-active .pill { background: rgba(255,255,255,.28); }

.view { display: none; animation: fade .25s ease; }
.view.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.section-note { color: var(--muted); font-size: .9rem; margin: 0 0 1rem; }
.result-count { color: var(--muted); font-size: .85rem; margin: .2rem 0 .8rem; }

/* 필터 */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: .5rem; }
.filters input, .filters select, .field input, .field select, .field textarea {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 11px; font-size: .92rem;
}
.filters #search { flex: 1 1 200px; min-width: 140px; }
.filters select { flex: 0 1 auto; }

/* 트레이너 그리드 */
.trainer-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 620px) { .trainer-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 940px) { .trainer-grid { grid-template-columns: 1fr 1fr 1fr; } }
.trainer-card {
  display: flex; gap: 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); transition: transform .15s;
}
.trainer-card:hover, .trainer-card:focus-visible { transform: translateY(-3px); outline: none; border-color: var(--brand); }
.tc-avatar svg { display: block; border-radius: 12px; width: 84px; height: 84px; flex: none; }
.tc-body { flex: 1; min-width: 0; }
.tc-top { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tc-top h3 { margin: 0; font-size: 1.05rem; }
.gender-tag { font-size: .7rem; padding: 2px 7px; border-radius: 999px; font-weight: 600; }
.gender-tag.female { background: color-mix(in srgb, #ff5aa5 20%, var(--surface)); color: #d63384; }
.gender-tag.male { background: color-mix(in srgb, #3c7bff 20%, var(--surface)); color: #2b6ae0; }
.tc-rating { display: flex; align-items: center; gap: 5px; font-size: .9rem; margin: 3px 0; }
.tc-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 5px 0; }
.tag { background: var(--surface-2); color: var(--muted); font-size: .72rem; padding: 2px 8px; border-radius: 999px; }
.tc-intro {
  font-size: .84rem; color: var(--muted); margin: 6px 0; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tc-foot { display: flex; justify-content: space-between; align-items: baseline; margin-top: 6px; }
.price { color: var(--brand); font-weight: 800; font-size: 1rem; }
.price.big { font-size: 1.4rem; }
.stars { display: inline-flex; }
.stars svg { display: block; }

/* 버튼 */
.btn {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 16px;
  font-weight: 600; font-size: .92rem; background: var(--surface); color: var(--text);
}
.btn.sm { padding: 6px 12px; font-size: .84rem; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #e94a2e; }
.btn.secondary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* 모달 공통 */
.backdrop {
  position: fixed; inset: 0; background: rgba(10, 15, 25, .55); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 20px; overflow-y: auto;
}
.dialog {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  max-width: 640px; width: 100%; padding: 22px; position: relative; box-shadow: var(--shadow);
  margin: auto;
}
.dialog-close {
  position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1rem;
}
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 1.2rem; flex-wrap: wrap; }
.detail-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.detail-avatar svg { border-radius: 14px; width: 120px; height: 120px; }
.detail-intro { margin: 1rem 0; }
.certs { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.certs li { color: var(--muted); font-size: .9rem; }
.slot-preview { display: flex; flex-direction: column; gap: 6px; }
.slot-day { font-size: .88rem; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.slot-mini { background: var(--surface-2); padding: 2px 8px; border-radius: 6px; font-size: .8rem; }
.reviews { display: grid; gap: 10px; }
.review { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.review-head { display: flex; align-items: center; gap: 6px; font-size: .85rem; margin-bottom: 3px; }
.review p { margin: 0; font-size: .9rem; }
.inline-form { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; display: grid; gap: 8px; }

/* 필드 */
.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; }
.field > span { color: var(--muted); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
textarea { resize: vertical; font-family: inherit; }
.warn {
  background: color-mix(in srgb, var(--warn) 18%, var(--surface)); border: 1px solid var(--warn);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: .88rem; margin: .6rem 0;
}

/* 캘린더 */
.calendar { display: grid; gap: 10px; max-height: 55vh; overflow-y: auto; }
.cal-day { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; }
.cal-date { font-weight: 700; margin-bottom: 6px; font-size: .9rem; }
.cal-times { display: flex; flex-wrap: wrap; gap: 6px; }
.slot { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 12px; font-size: .85rem; }
.slot:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.slot.taken { text-decoration: line-through; opacity: .45; }

/* 이용권 */
.plan-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 620px) { .plan-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 940px) { .plan-grid { grid-template-columns: repeat(4, 1fr); } }
.plan-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; position: relative; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px;
}
.plan-badge { position: absolute; top: -8px; right: 12px; background: var(--brand-2); color: #fff; font-size: .7rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.plan-price { font-size: 1.4rem; font-weight: 800; color: var(--brand); margin: 2px 0; }
.plan-per { font-size: .8rem; }
.plan-desc { font-size: .85rem; color: var(--muted); flex: 1; margin: 6px 0 10px; }
.my-passes { display: grid; gap: 8px; }
.pass-row {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
}
.pass-row.used { opacity: .6; }
.pass-remain { font-size: .85rem; text-align: right; min-width: 140px; }
.bar { background: var(--surface-2); border-radius: 999px; height: 7px; overflow: hidden; margin-top: 4px; }
.bar span { display: block; height: 100%; background: var(--ok); border-radius: 999px; }

/* 예약 */
.booking-list { display: grid; gap: 8px; }
.booking-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
.booking-card.completed { opacity: .8; }
.booking-card.cancelled { opacity: .55; }
.bk-info { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status-tag { font-size: .7rem; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.status-tag.confirmed { background: color-mix(in srgb, var(--ok) 20%, var(--surface)); color: var(--ok); }
.status-tag.completed { background: var(--surface-2); color: var(--muted); }
.status-tag.cancelled { background: color-mix(in srgb, var(--danger) 20%, var(--surface)); color: var(--danger); }
.bk-actions { display: flex; gap: 6px; }

/* 세션 룸 */
.session-room {
  position: fixed; inset: 0; z-index: 60; background: #0b0e14; color: #eef2f8;
  display: flex; flex-direction: column;
}
.sr-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; background: #12161f; border-bottom: 1px solid #232b38; }
.sr-title { font-weight: 700; display: flex; align-items: center; gap: 8px; font-size: .95rem; }
.sr-timer { font-variant-numeric: tabular-nums; font-size: 1.4rem; font-weight: 800; letter-spacing: 1px; }
.sr-stage { display: grid; grid-template-columns: 1fr; gap: 10px; padding: 12px 16px; }
@media (min-width: 720px) { .sr-stage { grid-template-columns: 1fr 1fr; } }
.cam { position: relative; border-radius: 12px; overflow: hidden; aspect-ratio: 16/10; background: #000; }
.cam svg { width: 100%; height: 100%; display: block; }
.cam-note { position: absolute; bottom: 8px; left: 8px; font-size: .72rem; background: rgba(0,0,0,.5); padding: 3px 8px; border-radius: 6px; }
.sr-panel { flex: 1; display: grid; grid-template-columns: 1fr; gap: 14px; padding: 0 16px 16px; overflow-y: auto; }
@media (min-width: 720px) { .sr-panel { grid-template-columns: 1.4fr 1fr; } }
.sr-routine, .sr-feedback { background: #12161f; border: 1px solid #232b38; border-radius: 12px; padding: 14px; }
.sr-routine h3, .sr-feedback h3 { color: #eef2f8; }
.routine-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.rt-check { display: flex; align-items: center; gap: 10px; background: #171d28; border: 1px solid #232b38; border-radius: 10px; padding: 8px 10px; cursor: pointer; }
.rt-check input { width: 20px; height: 20px; accent-color: var(--brand); flex: none; }
.rt-check input:checked ~ .rt-info b { text-decoration: line-through; color: #8a97a8; }
.rt-art svg { width: 40px; height: 40px; display: block; flex: none; }
.rt-info { display: flex; flex-direction: column; font-size: .86rem; min-width: 0; }
.rt-cue { color: #7f8ba0; font-size: .78rem; }
.routine-progress { margin-top: 10px; font-size: .85rem; }
.routine-progress .bar { background: #232b38; }
.sr-feedback textarea { width: 100%; background: #171d28; color: #eef2f8; border: 1px solid #232b38; border-radius: 10px; padding: 10px; }
.sr-feedback .field { margin: 10px 0; }
.sr-feedback select { background: #171d28; color: #eef2f8; border: 1px solid #232b38; border-radius: 8px; padding: 8px; }

/* 요약 */
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 1rem 0; }
.sum-stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 6px; text-align: center; }
.sum-stat b { display: block; font-size: 1.4rem; color: var(--brand); }
.sum-stat span { font-size: .74rem; color: var(--muted); }
.sum-feedback { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; }
.sum-feedback p { margin: 0; font-size: .9rem; }

/* 진행상황 */
.stat-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 620px) { .stat-row { grid-template-columns: repeat(5, 1fr); } }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; text-align: center; box-shadow: var(--shadow); }
.stat-card b { display: block; font-size: 1.6rem; color: var(--brand); }
.stat-card span { font-size: .78rem; color: var(--muted); }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 10px 8px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 3px; }
.chart-bar { width: 70%; min-height: 3px; background: linear-gradient(var(--brand-2), var(--brand)); border-radius: 6px 6px 0 0; transition: height .4s; }
.chart-val { font-size: .72rem; color: var(--muted); }
.chart-label { font-size: .66rem; color: var(--muted); }
.log-list { display: grid; gap: 8px; }
.log-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.log-fb { font-size: .84rem; color: var(--muted); margin-top: 4px; }

/* 설문 */
.survey-form { display: grid; gap: 12px; max-width: 560px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.survey-form input, .survey-form select { width: 100%; }
.chips { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; }
.chips legend { color: var(--muted); font-size: .82rem; padding: 0 4px; }
.chip-check { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border-radius: 999px; padding: 4px 10px; margin: 3px; font-size: .84rem; cursor: pointer; }
.survey-result { margin-top: 1.5rem; }
.rec-list { display: grid; gap: 10px; }
.rec-card { display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; position: relative; box-shadow: var(--shadow); cursor: pointer; }
.rec-card:hover { border-color: var(--brand); }
.rec-rank { position: absolute; top: 8px; right: 12px; font-weight: 800; color: var(--brand); }
.rec-avatar svg { width: 64px; height: 64px; border-radius: 12px; flex: none; }
.rec-body { flex: 1; }
.match-score { color: var(--ok); font-weight: 700; font-size: .85rem; margin: 2px 0; }
.match-reasons { list-style: none; padding: 0; margin: 0; font-size: .8rem; color: var(--muted); }

/* 토스트 */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1c2230; color: #fff; padding: 11px 18px; border-radius: 999px; font-size: .9rem;
  z-index: 80; opacity: 0; transition: opacity .25s, transform .25s; box-shadow: var(--shadow); max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* AI 코치 */
.ai-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin: 14px 0; box-shadow: var(--shadow);
}
.ai-card h3, .ai-card h4 { margin: 0 0 6px; }
.ai-card .btn { margin-top: 10px; }
.ai-output {
  margin: 12px 0 0; padding: 12px 14px; min-height: 1.2em;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: .88rem; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; overflow-x: auto;
  font-family: inherit;
}
.ai-output:empty { display: none; }
.ai-output.streaming { border-color: var(--brand); }
.ai-output.streaming::after { content: '▍'; color: var(--brand); animation: ai-blink 1s steps(1) infinite; }
@keyframes ai-blink { 50% { opacity: 0; } }

/* 푸터 */
.app-footer { margin-top: 2.5rem; padding-top: 1.2rem; border-top: 1px solid var(--border); color: var(--muted); font-size: .8rem; }
.app-footer strong { color: var(--text); }
