/* ============================================================
   style.css — 건강일지 앱 스타일
   수정 포인트: :root 변수만 바꾸면 전체 색상 테마 변경
   ============================================================ */

/* ----------------------------------------------------------
   색상 변수 — 여기서 테마 수정
   ---------------------------------------------------------- */
:root {
  --c-bg:        #f5f5f7;
  --c-surface:   #ffffff;
  --c-border:    rgba(0,0,0,0.08);
  --c-border-md: rgba(0,0,0,0.15);
  --c-text:      #1c1c1e;
  --c-text-2:    #48484a;
  --c-text-3:    #8e8e93;
  --c-accent:    #007aff;
  --c-accent-bg: rgba(0,122,255,0.08);
  --c-ok:        #34c759;
  --c-ok-bg:     rgba(52,199,89,0.1);
  --c-warn:      #ff9500;
  --c-warn-bg:   rgba(255,149,0,0.1);
  --c-danger:    #ff3b30;
  --c-danger-bg: rgba(255,59,48,0.1);
  --c-ai:        #5856d6;
  --c-ai-bg:     rgba(88,86,214,0.08);
  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   16px;
  --radius-xl:   20px;
}

/* 다크모드 — 자동 적용 */
@media (prefers-color-scheme: dark) {
  :root {
    --c-bg:        #000000;
    --c-surface:   #1c1c1e;
    --c-border:    rgba(255,255,255,0.08);
    --c-border-md: rgba(255,255,255,0.15);
    --c-text:      #ffffff;
    --c-text-2:    #ebebf5cc;
    --c-text-3:    #ebebf599;
    --c-accent:    #0a84ff;
    --c-accent-bg: rgba(10,132,255,0.15);
    --c-ok:        #30d158;
    --c-ok-bg:     rgba(48,209,88,0.15);
    --c-warn:      #ff9f0a;
    --c-warn-bg:   rgba(255,159,10,0.15);
    --c-danger:    #ff453a;
    --c-danger-bg: rgba(255,69,58,0.15);
    --c-ai:        #7d7aff;
    --c-ai-bg:     rgba(125,122,255,0.12);
  }
}

/* ----------------------------------------------------------
   기본 리셋
   ---------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Noto Sans KR', sans-serif;
  font-size: 14px;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
}
input, button, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  outline: none;
  border: none;
  background: none;
}
button { cursor: pointer; }

/* ----------------------------------------------------------
   앱 레이아웃
   ---------------------------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;   /* 모바일 최대 너비 */
  margin: 0 auto;
  background: var(--c-bg);
  position: relative;
  overflow: hidden;
}

/* 화면 영역 */
.screen {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* 개별 페이지 */
.page {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  display: none;
  flex-direction: column;
  background: var(--c-bg);
  -webkit-overflow-scrolling: touch;
}
.page.on { display: flex; }

/* 스크롤 바디 */
.scroll-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

/* ----------------------------------------------------------
   탑바
   ---------------------------------------------------------- */
.topbar {
  background: var(--c-surface);
  padding: 14px 16px 12px;
  border-bottom: 0.5px solid var(--c-border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--c-text);
  flex: 1;
}
.back-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-accent);
  font-size: 20px;
}
.back-btn:active { background: var(--c-border); }
.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-text-3);
  font-size: 22px;
}
.icon-btn:active { background: var(--c-border); }

/* 홈 탑바 (인사말) */
.topbar-home {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 4px;
}
.home-greeting { font-size: 13px; color: var(--c-text-3); }
.home-name { font-size: 20px; font-weight: 700; color: var(--c-text); }

/* ----------------------------------------------------------
   하단 탭 네비게이션
   ---------------------------------------------------------- */
.bottom-nav {
  background: var(--c-surface);
  border-top: 0.5px solid var(--c-border);
  display: flex;
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px); /* iPhone 홈바 대응 */
}
.nt {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px 6px;
  gap: 3px;
  color: var(--c-text-3);
  border-top: 2px solid transparent;
  transition: color 0.15s;
}
.nt.on {
  color: var(--c-accent);
  border-top-color: var(--c-accent);
}
.nt-icon { font-size: 22px; line-height: 1; }
.nt-label { font-size: 10px; font-weight: 500; }
.nt:active { opacity: 0.7; }

/* ----------------------------------------------------------
   공통 카드
   ---------------------------------------------------------- */
.card {
  background: var(--c-surface);
  border: 0.5px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 14px;
}
.card.tap { cursor: pointer; }
.card.tap:active { transform: scale(0.98); opacity: 0.9; }
.tap:active { transform: scale(0.98); opacity: 0.9; }

.ct {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-3);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ct-l { display: flex; align-items: center; gap: 6px; }
.link-btn {
  font-size: 12px;
  color: var(--c-accent);
  background: none;
  border: none;
  cursor: pointer;
}

/* ----------------------------------------------------------
   이상신호 배너
   ---------------------------------------------------------- */
.alert-banner {
  background: var(--c-warn-bg);
  border: 0.5px solid var(--c-warn);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--c-warn);
  cursor: pointer;
}
.alert-banner i:first-child { font-size: 20px; flex-shrink: 0; }
.alert-text { flex: 1; font-size: 13px; line-height: 1.5; }
.alert-arrow { font-size: 16px; flex-shrink: 0; }

/* ----------------------------------------------------------
   수치 카드 2x2 그리드
   ---------------------------------------------------------- */
.metric-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.mc {
  background: var(--c-surface);
  border: 0.5px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 14px;
  cursor: pointer;
}
.ml { font-size: 11px; color: var(--c-text-3); margin-bottom: 4px; }
.mv { font-size: 22px; font-weight: 600; color: var(--c-text); }
.ms { font-size: 11px; margin-top: 3px; }

/* ----------------------------------------------------------
   AI 박스
   ---------------------------------------------------------- */
.ai-box {
  background: var(--c-ai-bg);
  border: 0.5px solid rgba(88,86,214,0.2);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  cursor: pointer;
}
.ai-av {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--c-ai);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.ai-txt { font-size: 13px; color: var(--c-ai); line-height: 1.6; flex: 1; }

/* ----------------------------------------------------------
   방문 목록 아이템
   ---------------------------------------------------------- */
.vi {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 0.5px solid var(--c-border);
  cursor: pointer;
}
.vi:last-child { border-bottom: none; }
.vi:active { opacity: 0.7; }
.vdot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.vinfo { flex: 1; min-width: 0; }
.vname { font-size: 13px; font-weight: 600; color: var(--c-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vdiag { font-size: 11px; color: var(--c-text-3); margin-top: 2px; }
.vright { text-align: right; flex-shrink: 0; }
.vdate { font-size: 11px; color: var(--c-text-3); }
.vnext { font-size: 10px; color: var(--c-accent); margin-top: 2px; }

/* ----------------------------------------------------------
   식습관 카드
   ---------------------------------------------------------- */
.food-cell {
  background: var(--c-surface);
  border: 0.5px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 14px;
  cursor: pointer;
}
.food-cell:active { transform: scale(0.98); }
.food-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.food-meal { font-size: 12px; font-weight: 600; color: var(--c-text-3); display: flex; align-items: center; gap: 6px; }
.food-items { font-size: 14px; color: var(--c-text); line-height: 1.6; }
.food-items.empty { color: var(--c-text-3); font-style: italic; }

/* 수분 */
.water-cups { display: flex; gap: 5px; margin-bottom: 8px; }
.water-cup { flex: 1; height: 20px; border-radius: 4px; background: var(--c-border); cursor: pointer; transition: background 0.15s; }
.water-cup.filled { background: var(--c-accent); }
.prog-bar-track { height: 6px; background: var(--c-border); border-radius: 3px; overflow: hidden; }
.prog-bar-fill { height: 100%; background: var(--c-accent); border-radius: 3px; transition: width 0.3s; }
.prog-label { font-size: 11px; color: var(--c-text-3); margin-top: 6px; }

/* ----------------------------------------------------------
   날짜 선택
   ---------------------------------------------------------- */
.date-selector {
  background: var(--c-surface);
  border: 0.5px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--c-text);
  cursor: pointer;
}

/* ----------------------------------------------------------
   통계 행
   ---------------------------------------------------------- */
.stat-row {
  display: flex;
  gap: 12px;
}
.stat-item { flex: 1; }
.stat-label { font-size: 10px; color: var(--c-text-3); margin-bottom: 2px; }
.stat-val { font-size: 14px; font-weight: 600; color: var(--c-text); }
.record-sub { font-size: 11px; color: var(--c-text-3); margin-top: 6px; }

/* 미니 통계 */
.mini-stats { display: grid; grid-template-columns: repeat(2,1fr); gap: 8px; }
.mini-stat { background: var(--c-surface); border: 0.5px solid var(--c-border); border-radius: var(--radius-md); padding: 12px; }
.mini-label { font-size: 11px; color: var(--c-text-3); margin-bottom: 4px; }
.mini-val { font-size: 22px; font-weight: 600; color: var(--c-text); }

/* ----------------------------------------------------------
   추가 버튼
   ---------------------------------------------------------- */
.add-btn {
  width: 100%;
  background: var(--c-accent-bg);
  border: 1px dashed var(--c-accent);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--c-accent);
  cursor: pointer;
}
.add-btn:active { opacity: 0.8; }

/* ----------------------------------------------------------
   빈 상태
   ---------------------------------------------------------- */
.empty-msg {
  text-align: center;
  color: var(--c-text-3);
  font-size: 14px;
  padding: 40px 20px;
}
.empty-card {
  background: var(--c-surface);
  border: 1px dashed var(--c-border-md);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--c-text-3);
  font-size: 14px;
  cursor: pointer;
}
.empty-card i { font-size: 22px; color: var(--c-accent); }
.list-label { font-size: 12px; color: var(--c-text-3); padding: 0 2px; }

/* ----------------------------------------------------------
   폼 스타일
   ---------------------------------------------------------- */
.form-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.form-group {
  background: var(--c-surface);
  border: 0.5px solid var(--c-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.form-row {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 0.5px solid var(--c-border);
  gap: 12px;
}
.form-row:last-child { border-bottom: none; }
.form-label {
  font-size: 13px;
  color: var(--c-text-2);
  width: 90px;
  flex-shrink: 0;
}
.form-input {
  flex: 1;
  font-size: 14px;
  color: var(--c-text);
  text-align: right;
  background: none;
  border: none;
  outline: none;
}
.form-input::placeholder { color: var(--c-text-3); }
.form-select {
  flex: 1;
  font-size: 14px;
  color: var(--c-text);
  text-align: right;
  background: none;
  border: none;
  outline: none;
  -webkit-appearance: none;
}
.form-textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 14px;
  color: var(--c-text);
  background: none;
  border: none;
  outline: none;
  resize: none;
  min-height: 80px;
}
.form-section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-3);
  padding: 0 2px;
  margin-top: 4px;
}
.submit-btn {
  width: 100%;
  padding: 16px;
  background: var(--c-accent);
  color: #fff;
  border-radius: var(--radius-lg);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
}
.submit-btn:active { opacity: 0.85; }

/* ----------------------------------------------------------
   AI 채팅
   ---------------------------------------------------------- */
.chat-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.cmsg { display: flex; gap: 8px; align-items: flex-start; }
.cmsg.u { flex-direction: row-reverse; }
.cbubble {
  max-width: 80%;
  padding: 10px 13px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
}
.cmsg.a .cbubble {
  background: var(--c-surface);
  color: var(--c-text);
  border: 0.5px solid var(--c-border);
}
.cmsg.u .cbubble {
  background: var(--c-accent);
  color: #fff;
}
.cav {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--c-ai);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  margin-top: 2px;
}
.cav.u { background: var(--c-border); color: var(--c-text-3); }
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: var(--c-surface);
  border-top: 0.5px solid var(--c-border);
  padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
}
#chat-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 99px;
  background: var(--c-bg);
  border: 0.5px solid var(--c-border-md);
  font-size: 14px;
  color: var(--c-text);
}
.send-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--c-accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.send-btn:active { opacity: 0.8; }
.typing { letter-spacing: 3px; animation: blink 1s step-end infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.3} }

/* ----------------------------------------------------------
   배지
   ---------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 500;
}
.badge-b { background: var(--c-accent-bg); color: var(--c-accent); }
.badge-ok { background: var(--c-ok-bg); color: var(--c-ok); }
.badge-warn { background: var(--c-warn-bg); color: var(--c-warn); }
.badge-danger { background: var(--c-danger-bg); color: var(--c-danger); }

/* ----------------------------------------------------------
   상세 정보 행
   ---------------------------------------------------------- */
.dp-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 0;
  border-bottom: 0.5px solid var(--c-border);
  font-size: 14px;
}
.dp-row:last-child { border-bottom: none; }
.dp-key { color: var(--c-text-2); }
.dp-val { font-weight: 600; color: var(--c-text); }

/* 큰 숫자 */
.big-num {
  font-size: 40px;
  font-weight: 700;
  color: var(--c-text);
  text-align: center;
  line-height: 1.1;
}

/* ----------------------------------------------------------
   로딩
   ---------------------------------------------------------- */
.loading-spinner {
  display: flex;
  justify-content: center;
  padding: 40px;
}
.loading-spinner::after {
  content: '';
  width: 24px;
  height: 24px;
  border: 2px solid var(--c-border-md);
  border-top-color: var(--c-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------
   토스트 알림
   ---------------------------------------------------------- */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 999;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { background: rgba(52,199,89,0.9); }
.toast-error   { background: rgba(255,59,48,0.9); }
