/* ===== 디자인 토큰 ===== */
:root {
  --accent: #5b7cfa;
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --accent-softer: color-mix(in srgb, var(--accent) 8%, transparent);
  --bg: #f6f6f4;
  --card: #ffffff;
  --text: #22252a;
  --muted: #8a8f98;
  --faint: #b9bdc4;
  --line: #ececea;
  --chip: #f0f0ee;
  --shadow: 0 1px 2px rgba(20, 22, 26, 0.04), 0 4px 16px rgba(20, 22, 26, 0.04);
  --radius: 18px;
  --radius-s: 12px;
  --gap: 16px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #121316;
    --card: #1b1d21;
    --text: #e9eaec;
    --muted: #8d929b;
    --faint: #5a5f68;
    --line: #2a2d33;
    --chip: #25282d;
    --shadow: none;
    --accent-soft: color-mix(in srgb, var(--accent) 22%, transparent);
    --accent-softer: color-mix(in srgb, var(--accent) 12%, transparent);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #121316;
  --card: #1b1d21;
  --text: #e9eaec;
  --muted: #8d929b;
  --faint: #5a5f68;
  --line: #2a2d33;
  --chip: #25282d;
  --shadow: none;
  --accent-soft: color-mix(in srgb, var(--accent) 22%, transparent);
  --accent-softer: color-mix(in srgb, var(--accent) 12%, transparent);
  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: contain;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
h3 { font-size: 17px; font-weight: 650; }
[hidden] { display: none !important; }

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) var(--gap) calc(var(--tabbar-h) + var(--safe-b) + 96px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ===== 레이아웃 도우미 ===== */
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; }
.row.gap-s { gap: 6px; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.center { align-items: center; }
.row.baseline { align-items: baseline; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.divider { height: 1px; background: var(--line); margin: 4px 0; }

/* ===== 카드 ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card.pad { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card.list > * + * { border-top: 1px solid var(--line); }

.group { display: flex; flex-direction: column; gap: 8px; }
.group-title { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0 4px; }
.group-toggle {
  display: inline-flex; align-items: center; gap: 4px;
  background: none; border: 0; padding: 4px; color: var(--muted); font-size: 13px; font-weight: 600;
}

.page-head { display: flex; align-items: center; gap: 10px; min-height: 44px; padding-right: 44px; }
.page-head h1 { flex: 1; }
.editor-head h1 { flex: 0; }
.today-head { padding: 4px 4px 6px; padding-right: 44px; }
.today-head p { font-size: 14px; }

.settings-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 18px);
  right: max(var(--gap), calc((100vw - 640px) / 2 + var(--gap)));
  z-index: 20;
}
body[data-route='settings'] .settings-btn,
body[data-route='docs-edit'] .settings-btn { display: none; }
body[data-route='docs-edit'] .page-head,
body[data-route='settings'] .page-head { padding-right: 0; }

.empty { color: var(--muted); text-align: center; padding: 28px 12px; font-size: 14px; }
.empty.inline-empty { text-align: left; padding: 6px 4px; }

.banner {
  position: sticky; top: 0; z-index: 30;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 13px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 16px 8px;
  text-align: center;
}

/* ===== 버튼 ===== */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 12px;
  border: 0; background: transparent; color: var(--muted);
  flex-shrink: 0;
}
.icon-btn:active { background: var(--chip); }
.icon-btn.tiny { width: 28px; height: 28px; }
.icon { display: inline-flex; line-height: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 10px 16px;
  font-weight: 600; font-size: 15px;
  background: var(--chip); color: var(--text);
  white-space: nowrap;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: var(--chip); }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; align-self: flex-start; }
.btn:active { opacity: 0.8; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: 13px; font-weight: 600; }

.pill {
  border: 0; border-radius: 999px; padding: 4px 10px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  background: var(--accent-soft); color: var(--accent);
}

.chips { display: flex; gap: 6px; }
.chips.wrap { flex-wrap: wrap; }
.chips.scroll { overflow-x: auto; scrollbar-width: none; margin: 0 calc(var(--gap) * -1); padding: 0 var(--gap); }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 7px 13px;
  background: var(--chip); color: var(--text);
  font-size: 14px; white-space: nowrap; flex-shrink: 0;
}
.chip.on { background: var(--accent); color: #fff; }
.chip.ghost { background: transparent; color: var(--muted); border: 1px dashed var(--line); }
.chip .count { font-size: 12px; opacity: 0.75; }
.chip.food { background: var(--card); border: 1px solid var(--line); }
.chip.food .kcal { color: var(--muted); font-size: 12px; }
.chip.tag-chip.on { background: color-mix(in srgb, var(--tag) 22%, var(--card)); color: var(--text); }

.soft-badge {
  font-size: 12px; font-weight: 600; color: var(--accent);
  background: var(--accent-softer); padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}

.seg { display: inline-flex; background: var(--chip); border-radius: 12px; padding: 3px; gap: 2px; }
.seg.full { display: flex; }
.seg.full button { flex: 1; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot.big { width: 12px; height: 12px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; outline: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--text); }

/* ===== 입력 ===== */
.field {
  width: 100%; min-width: 0;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); padding: 10px 12px;
  outline: none;
}
.field:focus { border-color: var(--accent); }
textarea.field { resize: vertical; }
.field.search { background: var(--card); }
.add-bar .field { border-style: dashed; }

/* 텍스트처럼 보이는 입력칸 (보기 = 수정) */
.inline {
  border: 0; background: transparent; padding: 0; margin: 0;
  outline: none; width: 100%; min-width: 0; resize: none;
  line-height: 1.45; display: block; overflow: hidden;
}
.inline::placeholder { color: var(--faint); }

/* ===== 할 일 ===== */
.todo { display: flex; align-items: flex-start; gap: 10px; padding: 12px 8px 12px 14px; transition: opacity 0.3s; }
.todo .check {
  width: 24px; height: 24px; margin-top: 0; flex-shrink: 0;
  border-radius: 50%; border: 1.8px solid var(--faint); background: transparent;
  display: inline-flex; align-items: center; justify-content: center; color: transparent;
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.2s;
}
.todo.done .check, .todo.just-done .check { background: var(--accent); border-color: var(--accent); color: #fff; }
.todo.just-done .check { transform: scale(1.12); }
.todo.just-done { opacity: 0.5; }
.todo.done .todo-title { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--faint); }
.todo-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; padding-top: 1px; }
.todo-title { font-size: 15.5px; }
.todo-meta { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12.5px; color: var(--muted); align-items: center; }
.meta-tag { display: inline-flex; align-items: center; gap: 4px; }
.meta-due.past { color: var(--muted); font-style: italic; }
.todo .postpone { margin-top: 1px; }
.todo .more, .todo .icon-btn { margin-top: -6px; }
.todo-children { padding: 0 12px 10px 48px; display: flex; flex-direction: column; }
.todo-children .todo { padding: 8px 4px 8px 0; }
.todo-children .todo .check { width: 20px; height: 20px; }
.todo-children > * + * { border-top: 1px solid var(--line); }
.todo-memo { font-size: 13.5px; color: var(--muted); padding: 2px 0 8px; }
.sub-add { padding: 9px 0; font-size: 14px; color: var(--text); }

/* ===== 문서 ===== */
.doc-row { display: flex; align-items: center; gap: 8px; padding: 12px 8px 12px 16px; cursor: pointer; }
.doc-row-main { flex: 1; min-width: 0; }
.doc-row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-row-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-btn { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; background: var(--chip); border-radius: 12px; padding: 12px 14px; }
.list-btn.on { background: var(--accent-soft); }

.doc-sheet { padding: 20px 18px 16px; display: flex; flex-direction: column; gap: 10px; min-height: 60vh; }
.doc-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.doc-editor { position: relative; flex: 1; }
.doc-mirror, .doc-body {
  font-family: var(--font); font-size: 16px; line-height: 1.7;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;
  padding: 0; margin: 0; border: 0; letter-spacing: normal; tab-size: 4;
}
.doc-mirror { visibility: hidden; min-height: 40vh; color: var(--text); }
.doc-mirror.tint { visibility: visible; }
.doc-mirror .sym { color: var(--faint); }
.doc-body {
  position: absolute; inset: 0; width: 100%; height: 100%;
  background: transparent; outline: none; resize: none; overflow: hidden;
  color: var(--text);
}
.doc-body.tint { color: transparent; caret-color: var(--text); -webkit-text-fill-color: transparent; }
.doc-body::placeholder { color: var(--faint); -webkit-text-fill-color: var(--faint); }
.doc-body.tint::selection { background: var(--accent-soft); }
.doc-foot { padding-top: 8px; }
.save-status { font-size: 12px; color: var(--muted); min-width: 40px; text-align: right; }

/* ===== 식단 ===== */
.date-nav { display: flex; align-items: center; justify-content: space-between; background: var(--card); border-radius: 14px; padding: 4px; box-shadow: var(--shadow); }
.date-label { border: 0; background: none; font-weight: 600; font-size: 15px; }
.diet-summary { display: flex; flex-direction: column; gap: 8px; }
.diet-summary .eaten { font-size: 15px; color: var(--muted); }
.diet-summary .eaten b { font-size: 22px; color: var(--text); font-weight: 700; }
.bar { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.4s; }
.diet-summary.over .bar-fill { background: color-mix(in srgb, var(--accent) 55%, var(--muted)); }
.remain-big { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 4px 0 6px; }
.remain-big .label { font-size: 14px; color: var(--accent); font-weight: 600; }
.remain-big .num { font-size: 40px; font-weight: 750; letter-spacing: -0.03em; line-height: 1.1; }
.remain-big .num small { font-size: 16px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.remain-big .target { font-size: 14px; color: var(--muted); }
.emph-card { box-shadow: inset 0 0 0 1.5px var(--accent-soft), var(--shadow); }
.quiet-note { margin-top: -2px; }
.detect-card { background: var(--accent-softer); box-shadow: none; }
.detect-card p { font-size: 15px; }
.freq { margin-top: 2px; }

.meal-row { display: flex; align-items: center; gap: 8px; padding: 10px 6px 10px 16px; }
.kcal-edit { display: inline-flex; align-items: baseline; gap: 2px; }
.num-input { width: 56px; text-align: right; font-variant-numeric: tabular-nums; }
.kcal-edit .unit { font-size: 12px; color: var(--muted); }
.kcal-field { width: 84px; flex-shrink: 0; }

/* ===== 달력 ===== */
.cal { padding: 10px 8px 12px; }
.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-week span { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0 8px; }
.cal-cell {
  position: relative; border: 0; background: transparent;
  height: 50px; padding: 4px 0 0;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.cal-cell.empty { pointer-events: none; }
.cal-num {
  width: 30px; height: 30px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14.5px; font-variant-numeric: tabular-nums; position: relative; z-index: 1;
}
.cal-cell.sun .cal-num { color: var(--muted); }
.cal-cell.today .cal-num { background: var(--accent); color: #fff; font-weight: 700; }
.cal-cell.sel:not(.today) .cal-num { box-shadow: inset 0 0 0 1.5px var(--accent); }
.cal-dots { display: flex; gap: 3px; height: 6px; }
.cal-dots i { width: 5px; height: 5px; border-radius: 50%; display: block; }
/* 강조 기간: 날짜 뒤로 연한 띠 */
.cal-cell.emph::before {
  content: ''; position: absolute; left: 0; right: 0; top: 4px; height: 30px;
  background: var(--accent-soft);
}
.cal-cell.emph-start::before { left: 4px; border-top-left-radius: 15px; border-bottom-left-radius: 15px; }
.cal-cell.emph-end::before { right: 4px; border-top-right-radius: 15px; border-bottom-right-radius: 15px; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; padding-top: 10px; font-size: 12px; color: var(--muted); }
.cal-legend span { display: inline-flex; align-items: center; gap: 5px; }
.cal-legend i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.cal-legend i.band { width: 16px; height: 8px; border-radius: 4px; background: var(--accent-soft); }

.day-summary { display: flex; flex-direction: column; gap: 12px; padding-top: 4px; }
.event-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; font-size: 15px; }
.bar-mark { width: 4px; align-self: stretch; border-radius: 4px; min-height: 18px; }
.simple-row { display: flex; align-items: center; gap: 10px; padding: 11px 14px; font-size: 15px; }
.link-row { cursor: pointer; }
.tag-w { width: 30px; flex-shrink: 0; }

/* ===== 설정 ===== */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px; }
.set-label { display: flex; flex-direction: column; font-size: 15px; }
.set-label small { color: var(--muted); font-size: 12.5px; }
.set-ctrl { display: inline-flex; align-items: center; gap: 6px; }
.field.num { width: 84px; text-align: right; padding: 7px 10px; }
.switch {
  appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 99px;
  background: var(--chip); position: relative; flex-shrink: 0; transition: background 0.2s; margin: 0;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); transition: transform 0.2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

/* ===== 하단 탭 / + 버튼 ===== */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1; max-width: 128px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--faint); font-size: 11px; font-weight: 600;
}
.tab.on { color: var(--text); }
.tab.on .icon { color: var(--accent); }
.fab {
  position: fixed; z-index: 41;
  right: max(var(--gap), calc((100vw - 640px) / 2 + var(--gap)));
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  width: 56px; height: 56px; border-radius: 20px; border: 0;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 35%, transparent);
}
.fab:active { transform: scale(0.95); }
body[data-route='docs-edit'] .fab, body[data-route='settings'] .fab { display: none; }

/* ===== 바텀시트 ===== */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(10, 12, 16, 0); transition: background 0.2s;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-wrap.open { background: rgba(10, 12, 16, 0.32); }
.sheet {
  width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(18px + var(--safe-b));
  transform: translateY(100%); transition: transform 0.22s ease-out;
}
.sheet-wrap.open .sheet { transform: none; }
.sheet-grip { width: 36px; height: 4px; border-radius: 4px; background: var(--line); margin: 2px auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-body { display: flex; flex-direction: column; gap: 12px; }
.confirm-msg { font-size: 15px; padding: 6px 2px 4px; }

/* ===== ... 메뉴 ===== */
.menu {
  position: fixed; z-index: 70; min-width: 180px;
  background: var(--card); border-radius: 14px; padding: 6px;
  box-shadow: 0 8px 30px rgba(10, 12, 16, 0.16); border: 1px solid var(--line);
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  border: 0; background: transparent; padding: 10px 12px; border-radius: 10px;
  text-align: left; font-size: 15px;
}
.menu-item .icon { color: var(--muted); }
.menu-item:active { background: var(--chip); }
.menu-item.muted { color: var(--muted); }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }

/* ===== 토스트 ===== */
.toast {
  position: fixed; left: 50%; z-index: 80;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 84px);
  transform: translate(-50%, 10px); opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  background: var(--text); color: var(--bg);
  border-radius: 14px; padding: 10px 14px;
  display: flex; align-items: center; gap: 14px;
  font-size: 14px; max-width: calc(100vw - 32px); width: max-content;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast button { border: 0; background: none; color: var(--accent); font-weight: 700; padding: 0; filter: brightness(1.25); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
