:root {
  color-scheme: dark;
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #263449;
  --bg-input: #0b1120;
  --border: #334155;
  --text: #f8fafc;
  --text-sub: #94a3b8;
  --accent: #f59e0b;
  --accent-soft: rgba(245, 158, 11, 0.16);
  --meal: #fbbf24;
  --meal-soft: rgba(251, 191, 36, 0.16);
  --water: #38bdf8;
  --water-soft: rgba(56, 189, 248, 0.16);
  --strength: #818cf8;
  --strength-soft: rgba(129, 140, 248, 0.18);
  --cardio: #f472b6;
  --cardio-soft: rgba(244, 114, 182, 0.18);
  --body: #34d399;
  --body-soft: rgba(52, 211, 153, 0.16);
  --danger: #f87171;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 520px;
  margin-inline: auto;
  padding-bottom: 92px;
  min-height: 100vh;
}

button, input, select, textarea { font-family: inherit; color: inherit; }
button { touch-action: manipulation; }

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-avatar {
  width: 38px; height: 38px; border-radius: 12px;
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.brand-name { font-weight: 800; font-size: 16px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--accent); font-weight: 600; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.offline-pill { display: none; font-size: 11px; color: var(--danger); font-weight: 700; margin-top: 2px; }

.member-switch {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}
.m-btn {
  border: none; background: transparent; color: var(--text-sub);
  padding: 5px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.m-btn.active { background: var(--accent); color: #0f172a; }

.container {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Active Timer Banner */
.timer-banner {
  background: linear-gradient(135deg, rgba(129, 140, 248, 0.24), rgba(244, 114, 182, 0.18));
  border: 1px solid var(--strength);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: pulseBorder 2.5s infinite ease-in-out;
}
@keyframes pulseBorder {
  0%, 100% { border-color: rgba(129, 140, 248, 0.9); }
  50% { border-color: rgba(244, 114, 182, 0.9); }
}
.timer-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.timer-label { font-size: 14px; font-weight: 800; display: flex; align-items: center; gap: 6px; }
.timer-clock { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; color: #fff; }
.timer-actions { display: flex; gap: 8px; }
.btn-timer { flex: 1; padding: 9px 10px; border-radius: 10px; border: none; font-weight: 800; font-size: 13px; cursor: pointer; }
.btn-timer-stop { background: #22c55e; color: #052e16; }
.btn-timer-pause { background: var(--accent); color: #0f172a; }
.btn-timer-cancel { background: rgba(255,255,255,0.1); color: var(--text-sub); flex: 0 0 auto; }

/* Rest Countdown Strip */
.rest-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  background: rgba(15, 23, 42, 0.55); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px; padding: 6px 10px; font-size: 12px;
}
.rest-chips { display: flex; gap: 4px; }
.rest-chip {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 8px; font-size: 11px; font-weight: 700; cursor: pointer;
}
.rest-chip.active { background: var(--water); color: #0f172a; border-color: var(--water); }

/* Status Dashboard */
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hero-card {
  grid-column: 1 / -1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.hero-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 8px; }
.hero-kcal { font-size: 24px; font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }
.hero-kcal span { font-size: 13px; font-weight: 600; color: var(--text-sub); }
.hero-rem { font-size: 12px; font-weight: 700; color: var(--accent); text-align: right; }
.hero-rem.over { color: var(--danger); }

.prog-track { width: 100%; height: 9px; border-radius: 999px; background: var(--bg-input); overflow: hidden; border: 1px solid rgba(255,255,255,0.05); }
.prog-fill { height: 100%; border-radius: 999px; transition: width 0.35s ease; }

.macro-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.macro-box { background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px; padding: 8px; }
.macro-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-sub); font-weight: 700; margin-bottom: 4px; }
.macro-val { font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; margin-bottom: 5px; }
.macro-track { height: 5px; border-radius: 999px; background: var(--bg-card); overflow: hidden; }
.macro-fill { height: 100%; border-radius: 999px; }

.status-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 11px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.sc-head { font-size: 11px; color: var(--text-sub); font-weight: 700; }
.sc-main { font-size: 16px; font-weight: 800; line-height: 1.2; }
.sc-sub { font-size: 11px; color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Card & Quick Log */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.card-title {
  font-size: 13px; font-weight: 700; color: var(--text-sub);
  margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center;
}

.water-bar {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.water-top { display: flex; justify-content: space-between; align-items: center; }
.water-val { font-size: 20px; font-weight: 900; color: var(--water); }
.step-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.step-btn {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 0; font-size: 12px; font-weight: 700; cursor: pointer;
}
.step-btn:active { transform: scale(0.96); }

.submit-row-2 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 8px; }
.btn-water {
  background: var(--water); color: #082f49; border: none; border-radius: 10px;
  padding: 10px; font-size: 13px; font-weight: 800; cursor: pointer;
}
.btn-weight-quick {
  background: var(--body-soft); color: #6ee7b7; border: 1px solid rgba(52, 211, 153, 0.4);
  border-radius: 10px; padding: 10px 8px; font-size: 13px; font-weight: 700; cursor: pointer;
}

.quick-row-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-bottom: 10px; }
.quick-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.q-btn {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 4px; display: flex; flex-direction: column; align-items: center;
  gap: 4px; cursor: pointer; font-size: 12px; font-weight: 700;
}
.q-btn:active { transform: scale(0.96); background: var(--bg-card-hover); }
.q-btn .icon { font-size: 18px; }
.q-btn.meal-btn { border-color: rgba(251, 191, 36, 0.35); }
.q-btn.str-btn { border-color: rgba(129, 140, 248, 0.45); background: var(--strength-soft); }
.q-btn.cardio-btn { border-color: rgba(244, 114, 182, 0.45); background: var(--cardio-soft); }
.q-btn.active { box-shadow: inset 0 0 0 2px var(--accent); }

.preset-strip {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-top: 4px;
}
.preset-chip {
  flex: 0 0 auto; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 11px; font-size: 11.5px; font-weight: 600;
  color: var(--text-sub); cursor: pointer; white-space: nowrap;
}
.preset-chip:active { border-color: var(--accent); color: var(--accent); }

/* Segmented Switch & Date Nav */
.seg {
  display: flex; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 10px; padding: 3px; gap: 3px; margin-bottom: 10px;
}
.seg button {
  flex: 1; border: none; background: transparent; color: var(--text-sub);
  border-radius: 7px; padding: 7px 6px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.seg button.active { background: var(--accent); color: #0f172a; }

.date-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.date-btn {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px;
  padding: 7px 11px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.date-input {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px;
  padding: 7px 10px; font-size: 13px; font-weight: 700; text-align: center; flex: 1; min-width: 0;
}

.summary-chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.summary-chips.two-col { grid-template-columns: repeat(2, 1fr); }
.s-chip { background: var(--bg-input); border: 1px solid var(--border); border-radius: 12px; padding: 9px 8px; text-align: center; }
.s-chip-label { font-size: 11px; color: var(--text-sub); margin-bottom: 3px; }
.s-chip-val { font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* 24h Rhythm Bar */
.rhythm-track {
  position: relative; height: 18px; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin-top: 6px;
}
.rhythm-block { position: absolute; top: 2px; bottom: 2px; border-radius: 999px; }
.rhythm-dot { position: absolute; top: 3px; width: 6px; height: 10px; border-radius: 4px; transform: translateX(-50%); }
.rhythm-hours { display: flex; justify-content: space-between; font-size: 10px; color: var(--text-sub); margin-top: 4px; }

/* Timeline */
.timeline-list { display: flex; flex-direction: column; gap: 8px; }
.tl-item {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px; cursor: pointer;
}
.tl-item:active { background: var(--bg-card-hover); }
.tl-left { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.tl-icon {
  width: 36px; height: 36px; border-radius: 10px; display: flex;
  align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0;
}
.tl-time { font-size: 11px; color: var(--text-sub); font-weight: 600; }
.tl-title { font-size: 13.5px; font-weight: 700; margin-top: 2px; line-height: 1.3; }
.tl-sub { font-size: 11.5px; color: var(--text-sub); margin-top: 2px; }
.tl-memo { font-size: 11.5px; color: var(--accent); margin-top: 3px; word-break: break-word; }
.tl-right { font-size: 11px; font-weight: 700; color: var(--text-sub); flex-shrink: 0; text-align: right; }

.tl-day { border: 1px solid var(--border); border-radius: 12px; background: var(--bg-input); overflow: hidden; }
.tl-day-head { padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; cursor: pointer; font-size: 12.5px; font-weight: 700; }
.tl-day-body { padding: 0 8px 8px; display: flex; flex-direction: column; gap: 6px; }
.wk-row { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 8px; margin-bottom: 6px; cursor: pointer; }
.wk-lbl { font-size: 11px; color: var(--text-sub); font-weight: 700; }

/* Charts */
.bar-row { display: grid; grid-template-columns: 46px 1fr 64px; align-items: center; gap: 8px; margin-bottom: 7px; font-size: 11.5px; }
.bar-track { height: 14px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; position: relative; }
.bar-fill { height: 100%; border-radius: 999px; }
.bar-goal-line { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(248, 250, 252, 0.7); }
.bar-val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.svg-chart { width: 100%; height: 170px; display: block; }

/* Chat */
.chat-list {
  display: flex; flex-direction: column; gap: 10px;
  max-height: 52vh; min-height: 220px; overflow-y: auto; padding: 4px 2px;
}
.chat-bubble {
  max-width: 86%; padding: 10px 13px; border-radius: 14px;
  font-size: 13.5px; line-height: 1.5; word-break: break-word;
}
.chat-bubble > div:first-child { white-space: pre-wrap; }
.chat-bubble.user { align-self: flex-end; background: var(--accent); color: #0f172a; font-weight: 600; border-bottom-right-radius: 4px; }
.chat-bubble.assistant { align-self: flex-start; background: var(--bg-input); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 4px; }
.chat-meta { font-size: 10px; opacity: 0.75; margin-bottom: 3px; font-weight: 700; }
.chat-tools { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.tool-badge {
  font-size: 10px; background: rgba(52, 211, 153, 0.16); color: var(--body);
  border: 1px solid rgba(52, 211, 153, 0.35); border-radius: 6px; padding: 2px 6px; font-weight: 700;
}
.prompt-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 6px; }
.prompt-chip {
  flex: 0 0 auto; background: var(--bg-input); border: 1px solid var(--border); color: var(--text-sub);
  border-radius: 999px; padding: 7px 12px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.chat-input-bar { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.chat-input {
  flex: 1; background: var(--bg-input); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 11px 13px; font-size: 14.5px; outline: none; min-width: 0;
}
.chat-send-btn {
  min-width: 64px; height: 44px; padding: 0 12px; background: var(--accent); color: #0f172a;
  border: none; border-radius: 12px; font-size: 14px; font-weight: 800; cursor: pointer; white-space: nowrap;
}
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-attach-btn {
  flex: 0 0 42px; height: 44px; background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; font-size: 19px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.chat-attach-tray { display: none; gap: 10px; margin-top: 10px; overflow-x: auto; padding-top: 6px; }
.attach-chip { position: relative; flex: 0 0 56px; width: 56px; height: 56px; }
.attach-chip img, .attach-chip video { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
.attach-x {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg-input); color: var(--text); font-size: 12px; cursor: pointer;
}
.chat-media-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chat-media { width: 130px; height: 130px; object-fit: cover; border-radius: 10px; display: block; }
.chat-progress { font-size: 12px; color: var(--text-sub); margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chat-progress[hidden] { display: none; }
.chat-progress button { background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; font-size: 11px; cursor: pointer; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 23, 0.78);
  z-index: 60; display: none; align-items: flex-end; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal-sheet {
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  background: var(--bg-card); border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0; padding: 18px 16px 26px;
  display: flex; flex-direction: column; gap: 12px;
}
.form-row { display: flex; flex-direction: column; gap: 5px; }
.form-row label { font-size: 12px; font-weight: 700; color: var(--text-sub); }
.form-input {
  width: 100%; background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font-size: 14px; outline: none;
}
.form-input:focus { border-color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.set-row { display: grid; grid-template-columns: 1.7fr 1fr 0.8fr 0.8fr 28px; gap: 5px; align-items: center; margin-bottom: 6px; }
.set-row input { padding: 8px 6px; font-size: 12.5px; }
.set-del { background: transparent; border: none; color: var(--danger); font-size: 16px; cursor: pointer; }

.modal-btns { display: flex; gap: 8px; margin-top: 6px; }
.btn-close { flex: 1; background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px; padding: 11px; font-weight: 700; cursor: pointer; }
.btn-delete { background: rgba(248, 113, 113, 0.16); color: var(--danger); border: 1px solid rgba(248, 113, 113, 0.35); border-radius: 10px; padding: 11px 14px; font-weight: 700; cursor: pointer; }
.btn-save { flex: 1.5; background: var(--accent); color: #0f172a; border: none; border-radius: 10px; padding: 11px; font-weight: 800; cursor: pointer; }

/* PIN Lock Keypad Overlay */
.pin-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(15, 23, 42, 0.98);
  display: none; flex-direction: column; align-items: center; justify-content: center; padding: 24px;
}
.pin-overlay.open { display: flex; }
.pin-card { width: 100%; max-width: 320px; text-align: center; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 20px 0; }
.pin-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); background: transparent; transition: all 0.15s; }
.pin-dot.filled { background: var(--accent); border-color: var(--accent); transform: scale(1.1); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-key {
  height: 56px; border-radius: 14px; border: 1px solid var(--border); background: var(--bg-card);
  font-size: 20px; font-weight: 800; cursor: pointer;
}
.pin-key:active { background: var(--accent); color: #0f172a; }
.pin-msg { font-size: 13px; color: var(--text-sub); min-height: 20px; }
.pin-msg.error { color: var(--danger); font-weight: 700; }

/* Bottom Nav & Toast */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px; z-index: 40;
  background: rgba(15, 23, 42, 0.95); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 4px calc(8px + env(safe-area-inset-bottom));
}
.nav-tab {
  background: transparent; border: none; color: var(--text-sub);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; font-weight: 700; cursor: pointer; padding: 4px 0;
}
.nav-tab.active { color: var(--accent); }

.toast {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: var(--text); border: 1px solid var(--accent);
  border-radius: 999px; padding: 10px 16px; font-size: 13px; font-weight: 700;
  z-index: 80; display: none; align-items: center; gap: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); max-width: 92vw;
}
.toast.error { border-color: var(--danger); color: #fecaca; }
.toast-undo { background: var(--accent); color: #0f172a; border: none; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 800; cursor: pointer; }
