/* 하루결 — 스타일
 * 모바일 우선. 밤에 기록하는 일이 많으므로 다크 모드를 기본 지원한다. */

/* 글씨체: 조선굴림체 (저작권 (주)조선일보사, 무료 · 원본 그대로 사용 · fonts/ChosunGu-LICENSE.txt)
 * 굵기는 Regular 한 가지뿐이라 굵은 글씨는 브라우저가 굵게 만들어 보여 준다.
 * 이 글꼴에 없는 글자(✓, − 등)는 다음 글꼴로 자동으로 보인다. */
@font-face {
  font-family: "ChosunGu";
  src: url("../fonts/ChosunGu.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #F6F4EF;
  --surface: #FFFFFF;
  --surface-2: #EFECE5;
  --line: #E2DED5;
  --text: #1C1C1C;
  --muted: #5F5F5F;
  --faint: #6E6E6E;
  --primary: #141414;
  --primary-ink: #FFFFFF;
  --primary-soft: #E7E5E0;
  --warn: #B4582F;
  --warn-soft: #F7E4D9;
  --safe: #3D6FB0;
  --safe-soft: #E1EAF6;
  --safe-ink: #FFFFFF;

  --c-up: #D9952E;       /* 들뜸 */
  --c-down: #4F74B3;     /* 우울 */
  --c-mixed: #8E5CB0;    /* 혼재 */
  --c-anx: #C25E4A;      /* 불안 */
  --c-irr: #B0783A;      /* 짜증 */
  --c-ok: #4E9A7C;
  --c-energy: var(--primary);   /* 에너지 선 = 앱 강조색 (다크 모드에서는 흰색) */
  --c-focus: #7A6BB8;
  --c-sleep: #4F74B3;
  --c-bed: #CBD5E6;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 20, .06), 0 2px 10px rgba(20, 20, 20, .04);
  --font: "ChosunGu", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", "Noto Sans KR", "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212;
    --surface: #1C1C1C;
    --surface-2: #262626;
    --line: #343434;
    --text: #EBEBEB;
    --muted: #ADADAD;
    --faint: #9A9A9A;
    --primary: #EDEDED;
    --primary-ink: #121212;
    --primary-soft: #303030;
    --warn: #E59B78;
    --warn-soft: #3D2A21;
    --safe: #8DB3E8;
    --safe-soft: #1F2C3F;
    --safe-ink: #121212;
    --c-bed: #34405A;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121212;
  --surface: #1C1C1C;
  --surface-2: #262626;
  --line: #343434;
  --text: #EBEBEB;
  --muted: #ADADAD;
  --faint: #9A9A9A;
  --primary: #EDEDED;
  --primary-ink: #121212;
  --primary-soft: #303030;
  --warn: #E59B78;
  --warn-soft: #3D2A21;
  --safe: #8DB3E8;
  --safe-soft: #1F2C3F;
  --safe-ink: #121212;
  --c-bed: #34405A;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
/* 화면이 바뀔 때 화면 읽기용으로 포커스만 옮기는 제목(누를 수 없음)에는 테두리를 그리지 않는다 */
h1[tabindex="-1"]:focus-visible { outline: none; }

/* ---------- 레이아웃 ---------- */
#app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 16px calc(84px + env(safe-area-inset-bottom));
}
.view { padding-top: 8px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  margin: 0 -16px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid transparent;
}
.topbar h1 { font-size: 19px; font-weight: 700; flex: 1; }
.topbar .sub { font-size: 13px; color: var(--muted); font-weight: 400; }

.datenav { display: flex; align-items: center; gap: 4px; flex: 1; justify-content: center; }
.datenav .date { font-weight: 700; font-size: 17px; min-width: 9.5em; text-align: center; background: none; border: 0; padding: 6px 4px; border-radius: 8px; }
.datenav .date small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.iconbtn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: transparent; color: var(--muted);
  display: inline-grid; place-items: center; font-size: 20px;
}
.iconbtn:hover { background: var(--surface-2); }
.iconbtn:disabled { opacity: .3; cursor: default; background: none; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar nav { max-width: 600px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); }
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0 8px; text-decoration: none; color: var(--faint); font-size: 12px; font-weight: 600;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a[aria-current="page"] { color: var(--primary); font-weight: 800; }
.tabbar a[aria-current="page"] svg { stroke-width: 2.5; }   /* 색만으로 구분하지 않도록 굵기로도 표시 */

/* ---------- 카드 ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: 16px;
  margin: 12px 0;
}
.card > h2, .section-title { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card > h2 .right, .section-title .right { margin-left: auto; font-weight: 500; font-size: 13px; color: var(--muted); }
.card-sub { color: var(--muted); font-size: 13px; margin: 2px 0 8px; }
.card.soft { background: var(--surface-2); box-shadow: none; }
.card.notice { background: var(--primary-soft); border-color: transparent; }
.card.warn { background: var(--warn-soft); border-color: transparent; }
.card.safe { background: var(--safe-soft); border-color: transparent; }

.emoji { font-size: 18px; line-height: 1; }

/* ---------- 오늘 화면: 단계 버튼 ---------- */
.stagebar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 4px; }
.stage {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm);
  padding: 10px 6px; text-align: center; font-weight: 600; font-size: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 64px; justify-content: center;
}
.stage small { font-weight: 500; color: var(--muted); font-size: 12px; }
.stage.done { background: var(--primary-soft); border-color: transparent; }
.stage.done small { color: var(--primary); }

/* ---------- 질문 ---------- */
.q { padding: 12px 0; border-top: 1px solid var(--line); }
.q:first-of-type { border-top: 0; }
.q-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.q-label { font-weight: 650; font-size: 15px; }
.q-help { font-size: 13px; color: var(--muted); margin: -4px 0 8px; }
.q-clear { margin-left: auto; font-size: 12px; color: var(--muted); background: none; border: 0; padding: 10px 8px; margin-top: -10px; margin-bottom: -10px; }
.q-clear:hover { color: var(--text); }

.card[id], h2[id] { scroll-margin-top: 76px; }
.q-divider { display: flex; align-items: center; gap: 8px; margin: 14px 0 2px; color: var(--faint); font-size: 12px; font-weight: 600; }
.q-divider::before, .q-divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.q-divider + .q { border-top: 0; }
.sheet-foot { font-size: 12px; color: var(--muted); background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; margin-top: 12px; }
.sheet-info { font-size: 13px; color: var(--text); background: var(--primary-soft); border-radius: var(--radius-sm); padding: 8px 10px; margin: 6px 0; }
.group-action { margin-left: auto; }

/* 척도 버튼 */
.scale { display: grid; gap: 6px; grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr)); }
.scale button {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm);
  padding: 8px 2px; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: 13px; line-height: 1.2; color: var(--text);
  transition: background .12s, border-color .12s;
}
.scale button b { font-size: 16px; font-weight: 700; }
.scale button span { color: var(--muted); font-size: 12px; word-break: keep-all; }
.scale button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.scale button[aria-pressed="true"] span { color: var(--primary-ink); opacity: .9; }
.scale.tone-up button[aria-pressed="true"] { background: var(--c-up); border-color: var(--c-up); color: #1C1C1C; }
.scale.tone-down button[aria-pressed="true"] { background: var(--c-down); border-color: var(--c-down); color: #fff; }
.scale.tone-up button[aria-pressed="true"] span { color: #1C1C1C; }
.scale.tone-down button[aria-pressed="true"] span { color: #fff; }
.scale-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--faint); margin-top: 4px; }

/* 칩 (다중 선택) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.sebasis { margin: 6px 0 10px; }
.sebasis p { margin: 4px 0; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 7px 12px; font-size: 14px; min-height: 36px;
}
.chip[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--text); font-weight: 600; }
.chip.add { border-style: dashed; color: var(--muted); }

/* 예/아니오 */
.yn { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; max-width: 280px; }
.yn button { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm); min-height: 44px; font-weight: 600; }
.yn button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

/* 입력 */
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
input[type="text"], input[type="number"], input[type="time"], input[type="date"], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm);
  padding: 10px 12px; min-height: 44px; width: 100%;
}
textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
input[type="time"] { max-width: 150px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.timebox { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.timebox input { flex: 0 0 132px; }
.pill-now { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; min-height: 36px; font-variant-numeric: tabular-nums; }
.pill-now[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); }

.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.stepper button { width: 44px; height: 44px; border: 0; background: var(--surface-2); font-size: 20px; }
.stepper output { min-width: 64px; text-align: center; font-weight: 700; padding: 0 4px; }
.stepper .unit { font-weight: 500; color: var(--muted); font-size: 13px; }

/* 버튼 */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm);
  padding: 10px 16px; min-height: 44px; font-weight: 650; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  word-break: keep-all; overflow-wrap: break-word;   /* 버튼 글자는 띄어쓰기 단위로 줄바꿈 ("기록하/기"처럼 끊기지 않게) */
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
/* 강조색이 글자색과 같은 검정이라, 글자 버튼은 밑줄로 "누를 수 있음"을 보여 준다 */
.btn.ghost { background: transparent; border-color: transparent; color: var(--primary); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
/* 전체폭 글자 버튼(🤍 지금 많이 힘들어요)은 잘 보이도록 테두리 있는 버튼으로 */
.btn.ghost.block { background: var(--surface); border-color: var(--line); text-decoration: none; }
.btn.danger { color: var(--warn); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btnrow .btn { flex: 1; }

/* 모드 토글 */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 650; color: var(--muted); min-height: 32px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- 약 ---------- */
.dose {
  display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line);
}
.dose:first-of-type { border-top: 0; }
.dose .time { font-variant-numeric: tabular-nums; font-weight: 700; width: 48px; color: var(--muted); font-size: 14px; }
.dose .name { flex: 1; min-width: 0; }
.dose .name b { display: block; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dose .name small { color: var(--muted); font-size: 12px; }
.dose .take {
  min-width: 92px; min-height: 44px; border-radius: 999px; border: 1.5px solid var(--primary);
  background: transparent; color: var(--primary); font-weight: 700; font-size: 14px; padding: 0 12px;
}
.dose .take.taken { background: var(--primary); color: var(--primary-ink); }
.dose .take.skipped { border-color: var(--faint); color: var(--faint); }
.dose .more { width: 36px; height: 36px; }
/* 먹는 때(아침·자기 전) 묶음: 버튼 하나로 한꺼번에 */
.dose.group .name b { white-space: normal; }
.dose.group .cnt { color: var(--muted); font-weight: 500; font-size: 13px; margin-left: 2px; }
.dose .medlist { display: block; line-height: 1.5; margin-top: 3px; word-break: keep-all; overflow-wrap: break-word; }
.dose .medlist span + span::before { content: ' · '; color: var(--faint); }
.dose .medlist i { font-style: normal; color: var(--faint); }
.dose .medlist .off { color: var(--faint); }
.dose .name .pending { display: block; color: var(--warn); font-size: 12px; margin-top: 2px; }
.dose .medlist .todo { color: var(--warn); font-weight: 600; }
/* 묶음 고치기 시트 */
.glist { margin: 4px 0 8px; }
.gmed { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.gmed:first-child { border-top: 0; }
.gmed .gname { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 6px 0; color: inherit; }
.gmed .gname b { display: block; font-weight: 650; overflow-wrap: anywhere; }
.gmed .gname small { display: block; color: var(--muted); font-size: 12px; }
.gseg { display: inline-flex; gap: 4px; flex: none; }
.gseg button { min-height: 40px; min-width: 60px; padding: 0 10px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; font-weight: 650; font-size: 14px; }
.gseg button[data-v="taken"][aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.gseg button[data-v="skipped"][aria-pressed="true"] { background: var(--surface-2); border-color: var(--faint); color: var(--text); }
#m-slots .chip { min-height: 44px; padding: 8px 14px; }

/* ---------- 사건 목록 ---------- */
.evlist { list-style: none; margin: 0; padding: 0; }
.evlist li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.evlist li:first-child { border-top: 0; }
.evlist .at { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); width: 48px; flex: none; }
.evlist .body { flex: 1; min-width: 0; }
.evlist .body b { font-weight: 650; }
.evlist .body p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin: 2px 4px 0 0; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }

.quickadd { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.quickadd button {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm);
  min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-weight: 650; font-size: 14px;
}
.quickadd button .emoji { font-size: 20px; }

/* ---------- 시트 (하단 모달) ---------- */
.sheet-back {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 10, 10, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 600px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { font-size: 18px; margin-bottom: 4px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-back { animation: none; } }

/* ---------- 토스트 ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(10px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100% - 32px); text-align: center;
  box-shadow: 0 0 0 2px var(--bg), 0 4px 14px rgba(0, 0, 0, .2);   /* 검은 버튼 위에 떠도 경계가 보이게 */
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 알림 ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); margin: 8px 0; font-size: 14px; }
.alert .emoji { margin-top: 1px; }
.alert.warn { background: var(--warn-soft); }
.alert.safe { background: var(--safe-soft); }
.alert b { display: block; margin-bottom: 2px; }
.alert .act { margin-top: 6px; }

.crisis { line-height: 1.7; }
.crisis a { font-weight: 700; text-decoration: none; }
.crisis .num { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.crisis .num:first-of-type { border-top: 0; }
.crisis .num a { background: var(--safe); color: var(--safe-ink); border-radius: 999px; padding: 6px 14px; font-size: 15px; }

/* ---------- 달력 ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .wd { text-align: center; font-size: 12px; color: var(--faint); font-weight: 600; padding: 4px 0; }
.cal button {
  min-width: 0; min-height: 58px; border: 1px solid transparent; background: var(--surface); border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding: 4px 0 2px; gap: 2px; font-size: 13px; font-weight: 600;
  position: relative;
}
.cal button.out { visibility: hidden; }
.cal button.today { border-color: var(--primary); }
.cal button.empty { background: transparent; color: var(--faint); font-weight: 500; }
.cal button:disabled { opacity: .35; pointer-events: none; }   /* 아직 오지 않은 날 위에서 밀어도 달력이 받게 */
/* 좌우로 밀어 달 넘기기: 위아래 스크롤은 그대로, 미는 동안 달력이 따라오고 넘기면 그쪽에서 들어온다 */
.calcard { touch-action: pan-y pinch-zoom; overflow: hidden; }
.vv-zoomed .calcard { touch-action: auto; }   /* 확대해 둔 동안에는 옆으로 밀면 화면이 움직이게 */
.calcard .cal { transition: transform .2s ease; }
.calcard .cal.dragging { transition: none; }
.cal.in-r { animation: cal-in-r .22s ease-out; }
.cal.in-l { animation: cal-in-l .22s ease-out; }
@keyframes cal-in-r { from { transform: translateX(36px); opacity: .3; } }
@keyframes cal-in-l { from { transform: translateX(-36px); opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .calcard .cal { transition: none; } .cal.in-r, .cal.in-l { animation: none; } }
.cal .bar { width: 6px; border-radius: 3px; }
.cal .mini { display: flex; gap: 2px; align-items: flex-end; height: 22px; }
.cal .mood-up { background: var(--c-up); }
.cal .mood-down { background: var(--c-down); }
.cal .mood-mixed { background: var(--c-mixed); }
.cal .mood-mixed-soft { background: var(--c-mixed); opacity: .45; }
.cal .mood-ok { background: var(--c-ok); height: 4px !important; }
.cal .dotrow { display: flex; gap: 2px; }
.cal .dotrow i { width: 5px; height: 5px; border-radius: 50%; display: block; }
.cal .i-panic { background: var(--c-anx); }
.cal .i-visit { background: var(--primary); }
.cal .i-chg { background: var(--c-mixed); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* ---------- 요약 수치 ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 8px 0; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 20px; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.stat .d { font-size: 12px; color: var(--faint); }
/* 마음 안전: 다른 카드와 같은 크기. 더 볼 내용이 있으면 테두리(크기는 그대로) + 카드들 아래에 한 줄씩 */
.stat.sfstat .d { word-break: keep-all; overflow-wrap: anywhere; }
.stat.sfwarn { outline: 1.5px solid var(--warn); outline-offset: -1.5px; }
.report .sfmore { border: 1.5px solid var(--warn); border-radius: var(--radius-sm); padding: 8px 12px; margin: 8px 0; font-size: 13px; line-height: 1.45; word-break: keep-all; overflow-wrap: anywhere; break-inside: avoid; }
.report .sfmore ul { list-style: none; margin: 4px 0 0; padding: 0; color: var(--muted); }
.report .sfmore li { margin: 1px 0; padding-left: 10px; text-indent: -10px; }
.report .sfmore li::before { content: '·'; display: inline-block; width: 10px; text-indent: 0; }
.report .sfmore li.b { color: var(--text); font-weight: 700; }
.report .sfnote { margin: 4px 0 0; font-size: 12px; color: var(--faint); word-break: keep-all; overflow-wrap: anywhere; }
.report .sfmore .sfnote { margin-top: 6px; }

/* ---------- 리스트/설정 ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .grow small { display: block; color: var(--muted); font-size: 13px; }
.listhead { margin: 12px 0 0; font-size: 13px; font-weight: 700; color: var(--muted); }
/* 사용자가 쓴 줄바꿈을 그대로 보여 주기 (진료 메모 등) */
.keepbr { white-space: pre-line; overflow-wrap: anywhere; }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .15s; }
.switch span::after { content: ''; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(20px); background: var(--primary-ink); }   /* 다크 모드: 흰 바탕 위에서도 보이게 */

details.more { margin-top: 8px; }
details.more > summary { cursor: pointer; color: var(--primary); font-weight: 650; font-size: 14px; padding: 8px 0; list-style: none; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: '＋ '; }
details.more[open] > summary::before { content: '－ '; }

/* ---------- 차트 ---------- */
.chart { display: block; overflow: visible; font-family: var(--font); }
.chart .ax { font-size: 10px; fill: var(--faint); }
.chart .lbl { font-size: 11px; fill: var(--muted); font-weight: 600; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--faint); stroke-width: 1; }
.chart .ref { stroke: var(--c-ok); stroke-width: 1; stroke-dasharray: 4 3; }
.chart .wkend { fill: var(--surface-2); opacity: .7; }
.chart .future { fill: var(--line); opacity: .35; }
.chart .mark { stroke: var(--primary); stroke-width: 1.5; stroke-dasharray: 3 2; }
.chart .mark.chg { stroke: var(--c-mixed); }
.chart .b-up { fill: var(--c-up); }
.chart .b-down { fill: var(--c-down); }
.chart .b-mixed { fill: var(--c-mixed); }
.chart .b-mixed-soft { fill: var(--c-mixed); opacity: .4; }
.chart .dot-ok { fill: var(--c-ok); }
.chart .ln { stroke-width: 2; stroke: var(--primary); stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--primary); }
.chart .ln.c-energy { stroke: var(--c-energy); } .chart .pt.c-energy { fill: var(--c-energy); }
.chart .ln.c-focus { stroke: var(--c-focus); } .chart .pt.c-focus { fill: var(--c-focus); }
.chart .ln.c-anx { stroke: var(--c-anx); } .chart .pt.c-anx { fill: var(--c-anx); }
.chart .ln.c-irr { stroke: var(--c-irr); } .chart .pt.c-irr { fill: var(--c-irr); }
.chart .ln.c-sleep { stroke: var(--c-sleep); } .chart .pt.c-sleep { fill: var(--c-sleep); }
.chart .ln.c-up { stroke: var(--c-up); } .chart .pt.c-up { fill: var(--c-up); }
.chart .ln.c-down { stroke: var(--c-down); } .chart .pt.c-down { fill: var(--c-down); }
.chart .s-bed { fill: var(--c-bed); }
.chart .s-sleep { fill: var(--c-sleep); }
.chart .s-med { fill: var(--c-up); stroke: var(--surface); stroke-width: 1; }
.chart .s-clip { fill: var(--text); opacity: .65; }   /* 22시 전부터·12시 넘어서까지 이어진 잠 */
.chart .g-taken { fill: var(--c-ok); }
.chart .g-late { fill: var(--c-up); }
.chart .g-skip { stroke: var(--warn); stroke-width: 2; stroke-linecap: round; }
.chart .g-none { fill: var(--faint); }
.chart .g-yes { fill: var(--c-anx); }
.chart .g-int { fill: var(--c-anx); }
.chart .b-count { fill: var(--c-anx); }
.chart .b-prn { fill: var(--c-mixed); }
.chart-block { margin: 10px 0 4px; }
.chart-block h3 { font-size: 14px; font-weight: 700; margin-bottom: 2px; }
.chart-block .cap { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.chart-legend { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); margin: 2px 0 4px; }   /* 한 줄에 하나씩 */
.chart-legend i { display: inline-block; width: 12px; height: 4px; border-radius: 2px; vertical-align: 3px; margin-right: 4px; }
.chart-legend i.sw { height: 0; border-top: 4px solid currentColor; border-radius: 0; background: none; }
.legend i { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

/* ---------- 리포트 ---------- */
.report h2 { font-size: 16px; margin: 0 0 6px; padding-bottom: 4px; border-bottom: 2px solid var(--text); }
.report section { margin: 18px 0; }
.report h2, .report h3 { break-after: avoid; }
.report .chart-block, .report .stats, .report table, .report .head { break-inside: avoid; }
.report table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report th, .report td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.report th { font-weight: 700; color: var(--muted); font-size: 12px; }
.report td.num, .report th.num { text-align: right; font-variant-numeric: tabular-nums; }
/* 한 행을 한 줄로 (약 복용 표). 아주 좁은 화면에서는 줄바꿈 대신 옆으로 밀어 보기 */
.report .tscroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.report table.oneline th, .report table.oneline td { white-space: nowrap; padding-left: 4px; padding-right: 4px; }
.report table.oneline td:first-child { width: 100%; }
.report table.oneline tr.grp th { color: var(--text); font-size: 13px; padding-top: 10px; }
.chart .lbl.grp { fill: var(--text); font-weight: 700; }
.report .head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; border-bottom: 3px solid var(--primary); padding-bottom: 8px; margin-bottom: 8px; }
.report ul { padding-left: 20px; margin: 4px 0; }
.report-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
/* 진료 때 말할 것: 말로 읽기 쉽게 한 줄씩 넉넉히 */
.talk ul { margin: 8px 0 0; padding-left: 20px; }
.talk li { margin: 0 0 8px; line-height: 1.6; font-size: 15px; }
.talk li:last-child { margin-bottom: 0; }
.report .head-meta { text-align: left; }
.report-controls select, .report-controls input { width: auto; }

.empty-state { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty-state .emoji { font-size: 32px; display: block; margin-bottom: 8px; }

.onboard h2 { font-size: 22px; margin: 8px 0; }
.onboard p { color: var(--muted); }

/* ---------- 인쇄 ---------- */
@media print {
  :root, :root:not([data-theme="light"]), :root[data-theme="dark"] {
    --bg: #fff; --surface: #fff; --surface-2: #F3F3F1; --line: #D8D8D4; --text: #111; --muted: #444; --faint: #777;
    --primary: #141414; --primary-ink: #FFFFFF; --primary-soft: #EEEEEE; --warn: #A3461F; --warn-soft: #FBEDE6; --c-bed: #CBD5E6;
    color-scheme: light;
  }
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 12px; }
  #app { max-width: none; padding: 0; }
  .tabbar, .topbar, .no-print, #toast { display: none !important; }
  .card { box-shadow: none; border: 0; padding: 0; margin: 0; }
  .report section { margin: 10px 0; }
  .report .pagebreak { break-before: page; }
  .chart .wkend { fill: #F1F1EE; }
  a { color: inherit; text-decoration: none; }
  .report .tscroll { overflow: visible; }   /* 인쇄·PDF에서는 옆으로 밀기 없이 전부 */
  .report table.oneline td:first-child { white-space: normal; }   /* 종이 폭을 넘는 아주 긴 이름만 줄바꿈 */
}

@media screen and (max-width: 640px) {
  .report .chart-block { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .report .chart-block .cap, .report .chart-block h3, .report .chart-block .chart-legend { position: sticky; left: 0; }
}
.chart, .chart * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

/* 기록 탭 '이번 달 기록': 줄 전체가 버튼. 날짜 한 줄 + 요약(수면·상태·약) 한 줄 (요약이 길면 글자를 줄임: history.js fitOneLine) */
.monthlist li { padding: 0; }
.monthlist .dayrow { display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 0; background: none; border: 0; text-align: left; color: inherit; min-height: 52px; }
.monthlist .body { flex: 1; min-width: 0; display: block; }
.monthlist .at { display: block; width: auto; white-space: nowrap; font-size: 14px; font-weight: 700; color: var(--text); }
.monthlist .at .faint { font-weight: 500; }
.monthlist .fit1 { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; margin-top: 2px; }
.monthlist .body b.fit1 { font-weight: 600; }
.monthlist .extra { color: var(--muted); font-weight: 600; }
.monthlist .body b.fit1:empty { display: none; }
.monthlist .note { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; }
.monthlist .tags { display: block; margin-top: 4px; }
.monthlist .chev { flex: none; color: var(--faint); font-size: 22px; line-height: 1; }

/* 홈 화면 바로가기로 약을 기록했을 때 크게 보여 주는 시각 */
.quick-big { font-size: 28px; font-weight: 800; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }

/* 동기화 코드: 크게, 고정폭으로 */
.sync-code { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 20px; font-weight: 700; letter-spacing: .5px; text-align: center; background: var(--surface-2); border-radius: var(--radius-sm); padding: 14px 8px; margin: 10px 0; word-break: break-all; user-select: all; }

/* 차트 설명을 항목마다 한 줄씩 (색 견본과 함께) */
.cap-list { list-style: none; margin: 2px 0 6px; padding: 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.cap-list li { display: flex; gap: 6px; align-items: baseline; padding: 1px 0; word-break: keep-all; }
/* 긴 설명 한 줄: 둘째 줄은 이름 아래부터 이어 써서 폭을 넓게 쓴다 (두 줄 안에 끝나게) */
.cap-list li.flow { display: block; padding-left: 16px; text-indent: -16px; line-height: 18px; }
.cap-list li.flow .sw { display: inline-block; margin: 0 6px 0 0; vertical-align: -1px; }
.cap-list li.flow b { display: inline-block; text-indent: 0; margin-right: 6px; }
.cap-list li b { flex: none; color: var(--text); font-weight: 650; min-width: 4.6em; }
.cap-list .sw { flex: none; display: inline-block; width: 10px; height: 10px; border-radius: 2px; align-self: flex-start; margin-top: 4px; }
.cap-list .sw.dot { border-radius: 50%; width: 7px; height: 7px; margin: 6px 1.5px 0; }
.cap-list .sw.x { width: auto; height: auto; color: var(--warn); font-style: normal; font-size: 11px; line-height: 1; margin-top: 3px; background: none; }
.cap-list .sw.dot.small { width: 4px; height: 4px; margin: 7px 3px 0; }
.cap-list .sw.dash { height: 0; border-top: 2px dashed var(--primary); border-radius: 0; margin-top: 9px; }
.report .chart-block .cap-list { position: sticky; left: 0; }
@media print { .cap-list .sw { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

/* 필요시 약 표: 칸 제목·약 이름은 한 줄, 이유는 항목마다 한 줄 */
.report table.prntable th { white-space: nowrap; }
.report table.prntable td.pname { white-space: nowrap; font-size: 12px; }
.report table.prntable td:nth-child(3) { width: 100%; }
.report table.prntable .rsn { display: block; line-height: 1.45; }
.report table.prntable .rsn b { font-weight: 650; white-space: nowrap; }

/* 리포트 '이 기간의 약 변경' 목록: 표 글자 크기에 맞춰 작게 */
.report ul.chglist { font-size: 13px; line-height: 1.6; margin: 4px 0; padding-left: 18px; }
@media print { .report ul.chglist { font-size: 11px; } }
/* 공황 기록 표: 칸 제목은 한 줄 */
.report table.paniclist th { white-space: nowrap; }
.report table.paniclist td:first-child, .report table.paniclist td:nth-child(2) { white-space: nowrap; }
/* 표 칸 안의 항목: 한 줄에 하나씩 (대처는 항목이 끊기지 않게) */
.report .cell-line { display: block; line-height: 1.45; }
/* 공황 기록: 한 건마다 위 줄(날짜·시각·강도·지속) + 아래에 상황·유발 / 대처를 항목마다 한 줄씩 */
.report table.paniclist tr:not(.sub) td { border-bottom: 0; padding-bottom: 0; }
.report table.paniclist tr.sub td { padding-top: 4px; }
.report table.paniclist .kv { display: flex; gap: 10px; font-size: 12px; margin: 2px 0; }
.report table.paniclist .kv > b { flex: none; width: 5.2em; color: var(--muted); font-weight: 650; }
.report table.paniclist .kv .cell-line { white-space: nowrap; }
/* 신호 그래프: 줄 이름을 그래프 위 한 줄로 (설명 문구처럼) */
.report .chart-block .row-cap { font-size: 12px; color: var(--muted); font-weight: 400; margin: 6px 0 0; position: sticky; left: 0; }
/* 차트 제목 옆 작은 설명 (설명 문구와 같은 크기) */
.chart-block h3 .h3-note { font-size: 12px; font-weight: 400; color: var(--muted); }
