/* ═══════════ CalorieCore ─ 테마 토큰 ═══════════ */
:root {
  color-scheme: light;
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #898781;
  --hairline:    #e1e0d9;
  --border:      rgba(11, 11, 11, 0.10);
  --accent:      #2a78d6;   /* series-1 blue */
  --accent-soft: #cde2fb;
  --carb:        #2a78d6;   /* slot 1 */
  --protein:     #eb6834;   /* slot 2 */
  --fat:         #1baf7a;   /* slot 3 */
  --good:        #0ca30c;
  --good-text:   #006300;
  --critical:    #d03b3b;
  --track:       #f0efec;
  --shadow:      0 1px 3px rgba(11,11,11,.06), 0 4px 16px rgba(11,11,11,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page:        #0d0d0d;
    --surface:     #1a1a19;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --muted:       #898781;
    --hairline:    #2c2c2a;
    --border:      rgba(255, 255, 255, 0.10);
    --accent:      #3987e5;
    --accent-soft: #184f95;
    --carb:        #3987e5;
    --protein:     #d95926;
    --fat:         #199e70;
    --good:        #0ca30c;
    --good-text:   #0ca30c;
    --critical:    #d03b3b;
    --track:       #2c2c2a;
    --shadow:      0 1px 3px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  background: var(--page);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
}

/* ═══════════ 상단바 ═══════════ */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}
.topbar-inner {
  max-width: 860px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 8px; padding: 12px 0; }
.brand-mark { font-size: 22px; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: -0.2px; }

.nav { display: flex; gap: 2px; overflow-x: auto; }
.nav-btn {
  border: none; background: none; cursor: pointer;
  font: inherit; font-size: 14px; color: var(--ink-2);
  padding: 14px 14px 12px; border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.nav-btn:hover { color: var(--ink); }
.nav-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ═══════════ 레이아웃 ═══════════ */
.container { max-width: 860px; margin: 0 auto; padding: 20px 16px 60px; }
.view { display: none; }
.view.active { display: block; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: baseline; }
.card-title-sub { font-size: 13px; color: var(--muted); font-weight: 500; }

/* ═══════════ 날짜 이동 ═══════════ */
.date-row { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.date-label { font-weight: 600; font-size: 16px; min-width: 170px; text-align: center; }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ═══════════ 버튼 & 입력 ═══════════ */
.primary-btn {
  border: none; background: var(--accent); color: #fff;
  font: inherit; font-size: 14px; font-weight: 600;
  padding: 9px 16px; border-radius: 9px; cursor: pointer;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn.wide { width: 100%; margin-top: 14px; padding: 12px; }
.ghost-btn {
  border: 1px solid var(--border); background: none; color: var(--ink-2);
  font: inherit; font-size: 13px; padding: 8px 14px; border-radius: 9px; cursor: pointer;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }
.ghost-btn.danger:hover { border-color: var(--critical); color: var(--critical); }

.input {
  font: inherit; font-size: 14px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 9px; padding: 9px 12px; min-width: 0;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.input.wide { width: 100%; }
.input-sm { width: 92px; }
.form-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

/* ═══════════ 대시보드 히어로 ═══════════ */
.hero-card { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; justify-content: center; }
.cal-ring-wrap { position: relative; width: 190px; height: 190px; }
.cal-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--track); stroke-width: 14; }
.ring-fill {
  fill: none; stroke: var(--accent); stroke-width: 14; stroke-linecap: round;
  stroke-dasharray: 527.8; stroke-dashoffset: 527.8;
  transition: stroke-dashoffset .5s ease, stroke .3s;
}
.ring-fill.over { stroke: var(--critical); }
.cal-ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.hero-num { font-size: 38px; font-weight: 700; letter-spacing: -1px; }
.hero-sub { font-size: 13px; color: var(--muted); }

.cal-stats { display: flex; gap: 28px; }
.cal-stat-label { font-size: 12.5px; color: var(--muted); }
.cal-stat-value { font-size: 21px; font-weight: 700; margin-top: 2px; }
.cal-stat-value small { font-size: 12px; font-weight: 500; color: var(--muted); }

/* ═══════════ 매크로 미터 ═══════════ */
.macro-row { margin-bottom: 14px; }
.macro-row:last-child { margin-bottom: 0; }
.macro-head { font-size: 13.5px; color: var(--ink-2); display: flex; align-items: center; gap: 7px; margin-bottom: 6px; }
.macro-val { margin-left: auto; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dot-carb { background: var(--carb); }
.dot-protein { background: var(--protein); }
.dot-fat { background: var(--fat); }
.meter { height: 8px; background: var(--track); border-radius: 4px; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 4px; width: 0; transition: width .4s ease; }
.fill-carb { background: var(--carb); }
.fill-protein { background: var(--protein); }
.fill-fat { background: var(--fat); }

/* ═══════════ 물 ═══════════ */
.water-cups { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; min-height: 34px; }
.cup { font-size: 24px; opacity: .25; transition: opacity .2s, transform .2s; }
.cup.full { opacity: 1; transform: scale(1.05); }
.water-actions { display: flex; gap: 8px; }

/* ═══════════ 오늘의 기록 요약 ═══════════ */
.today-summary { font-size: 14px; color: var(--ink-2); }
.today-summary .sum-row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--hairline); }
.today-summary .sum-row:last-child { border-bottom: none; }
.today-summary b { color: var(--ink); font-variant-numeric: tabular-nums; }
.empty-note { color: var(--muted); font-size: 13.5px; padding: 8px 0; }

/* ═══════════ 식단 ═══════════ */
.meal-card .meal-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
}
.meal-name { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.meal-kcal { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.entry-list { list-style: none; }
.entry-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--hairline);
  font-size: 14px;
}
.entry-list li:last-child { border-bottom: none; }
.entry-main { flex: 1; min-width: 0; }
.entry-sub { font-size: 12px; color: var(--muted); }
.entry-kcal { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.entry-del {
  border: none; background: none; color: var(--muted); cursor: pointer;
  font-size: 15px; padding: 4px; border-radius: 6px;
}
.entry-del:hover { color: var(--critical); }

/* ═══════════ 주간 바 차트 ═══════════ */
.weekly-chart { width: 100%; height: 200px; display: block; }
.weekly-chart .grid-line { stroke: var(--hairline); stroke-width: 1; }
.weekly-chart .axis-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.weekly-chart .axis-strong { fill: var(--ink); font-weight: 600; }
.weekly-chart .bar { fill: var(--accent); opacity: .55; }
.weekly-chart .bar-today { opacity: 1; }
.weekly-chart .goal-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }

/* ═══════════ 체중 차트 ═══════════ */
.chart-wrap { position: relative; }
.weight-chart { width: 100%; height: 260px; display: block; }
.weight-chart .grid-line { stroke: var(--hairline); stroke-width: 1; }
.weight-chart .axis-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.weight-chart .w-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.weight-chart .w-area { fill: var(--accent); opacity: .08; }
.weight-chart .w-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.weight-chart .crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); padding: 7px 10px; font-size: 12.5px;
  transform: translate(-50%, -115%); white-space: nowrap;
}
.chart-tooltip b { font-variant-numeric: tabular-nums; }
.bmi-line { margin-top: 12px; font-size: 13.5px; color: var(--ink-2); }
.bmi-badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600; margin-left: 6px;
  background: var(--accent-soft); color: var(--ink);
}

/* ═══════════ 프로필 ═══════════ */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .profile-grid { grid-template-columns: 1fr; } }
.profile-grid label { font-size: 13px; color: var(--ink-2); display: flex; flex-direction: column; gap: 5px; }

.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.result-tile {
  background: var(--page); border: 1px solid var(--hairline);
  border-radius: 10px; padding: 14px;
}
.result-label { font-size: 12px; color: var(--muted); }
.result-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.result-value small { font-size: 12px; font-weight: 500; color: var(--muted); }

/* ═══════════ 모달 ═══════════ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  width: 100%; max-width: 480px; max-height: 85vh; overflow-y: auto; padding: 20px;
}
.modal-sm { max-width: 360px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { font-size: 16px; }

.food-results { list-style: none; margin: 12px 0; max-height: 300px; overflow-y: auto; }
.food-results li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 8px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.food-results li:hover { background: var(--track); }
.food-results .fr-sub { font-size: 12px; color: var(--muted); }
.food-results .fr-head {
  cursor: default; color: var(--muted); font-size: 11.5px; font-weight: 600;
  padding: 8px 8px 2px; text-transform: uppercase; letter-spacing: .4px;
}
.food-results .fr-head:hover { background: none; }
.food-results .fr-kcal { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.custom-food { border-top: 1px solid var(--hairline); padding-top: 12px; }
.custom-food .form-row { margin-top: 8px; }
.qty-unit { font-size: 14px; color: var(--ink-2); }

/* ═══════════ 토스트 ═══════════ */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--page);
  padding: 10px 20px; border-radius: 24px; font-size: 14px; font-weight: 500;
  z-index: 200; box-shadow: var(--shadow);
  animation: toast-in .25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

[hidden] { display: none !important; }
