:root {
  --bg: #0b1220;
  --bg-2: #111a2e;
  --card: #182238;
  --card-2: #1f2a44;
  --line: #2a3656;
  --text: #e8ecf5;
  --muted: #93a0bf;
  --accent: #34d399;
  --accent-2: #0ea5a4;
  --danger: #f87171;
  --warn: #fbbf24;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; overscroll-behavior-y: none; }
body { padding-bottom: calc(80px + var(--safe-bottom)); }

.app-header {
  position: sticky; top: 0; z-index: 10;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: linear-gradient(180deg, rgba(11,18,32,0.95), rgba(11,18,32,0.8));
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; font-size: 22px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.title { font-weight: 700; font-size: 20px; letter-spacing: -0.01em; }
.subtitle { color: var(--muted); font-size: 13px; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 16px; cursor: pointer;
}
.icon-btn:active { transform: scale(0.96); }

.tabs {
  display: flex; gap: 4px; padding: 8px 12px; overflow-x: auto;
  position: sticky; top: calc(65px + var(--safe-top)); z-index: 9;
  background: var(--bg); border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; padding: 8px 14px; border-radius: 999px;
  background: transparent; border: 1px solid var(--line);
  color: var(--muted); font-size: 14px; font-weight: 500;
}
.tab.active { background: var(--text); color: var(--bg); border-color: var(--text); }

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

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 16px;
}
.card h2 { margin: 0 0 10px; font-size: 15px; color: var(--muted); font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; }

.big-stat { display: flex; align-items: baseline; gap: 10px; }
.big-stat .val { font-size: 44px; font-weight: 700; letter-spacing: -0.02em; }
.big-stat .unit { font-size: 16px; color: var(--muted); }
.delta { margin-top: 6px; font-size: 13px; color: var(--muted); }
.delta.pos { color: var(--accent); }
.delta.neg { color: var(--danger); }

.progress-bar { height: 8px; background: var(--bg-2); border-radius: 999px; overflow: hidden; margin-top: 12px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.4s ease; }

.row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; padding-top: 0; }
.row:last-child { padding-bottom: 0; }
.row .lbl { color: var(--muted); font-size: 14px; }
.row .val { font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 16px; border-radius: 14px; border: 0; cursor: pointer;
  font-size: 15px; font-weight: 600; color: #06121a;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.btn:active { transform: scale(0.98); }
.btn.secondary { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn.full { width: 100%; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }

.workout-card {
  display: flex; gap: 12px; padding: 14px; border-radius: 16px;
  background: var(--card-2); border: 1px solid var(--line); align-items: center;
  text-decoration: none; color: var(--text);
}
.workout-card .wtype {
  width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center;
  background: rgba(52, 211, 153, 0.12); color: var(--accent); font-size: 22px; flex: 0 0 auto;
}
.workout-card .wbody { flex: 1 1 auto; min-width: 0; }
.workout-card .wttl { font-weight: 600; font-size: 15px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.workout-card .wmeta { font-size: 12px; color: var(--muted); }
.workout-card .wplay { color: var(--accent); font-size: 20px; }

.meal-list { display: flex; flex-direction: column; gap: 8px; }
.meal-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; background: var(--card-2); border-radius: 12px; border: 1px solid var(--line);
}
.meal-item .mn { font-size: 14px; }
.meal-item .mk { font-weight: 600; color: var(--accent); font-size: 13px; }

.input, textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  font: inherit;
}
.input:focus, textarea:focus { outline: 0; border-color: var(--accent); }

.chart { width: 100%; height: 200px; }
.chart-bg { fill: var(--bg-2); }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-target { fill: none; stroke: var(--warn); stroke-width: 1.2; stroke-dasharray: 4 4; }
.chart-dot { fill: var(--accent); }
.chart-txt { fill: var(--muted); font: 10px system-ui; }

.empty { color: var(--muted); text-align: center; padding: 24px 16px; font-size: 14px; }

.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--bg-2); border-radius: 20px 20px 0 0;
  padding: 12px 16px calc(24px + var(--safe-bottom));
  max-height: 85vh; overflow-y: auto;
  animation: sheet-in 0.25s ease;
}
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 40px; height: 4px; background: var(--line); border-radius: 2px; margin: 4px auto 16px; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(24px + var(--safe-bottom));
  background: var(--card); border: 1px solid var(--line); padding: 12px 16px; border-radius: 14px;
  z-index: 60; text-align: center; animation: toast-in 0.2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.photo-thumb {
  aspect-ratio: 1; border-radius: 12px; overflow: hidden;
  background: var(--bg-2); display: grid; place-items: center; color: var(--muted);
  border: 1px solid var(--line); position: relative;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .date { position: absolute; bottom: 4px; left: 4px; right: 4px; font-size: 10px; background: rgba(0,0,0,0.5); padding: 2px 4px; border-radius: 4px; text-align: center; }

.kcal-result { padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin-top: 12px; }
.kcal-result h3 { margin: 0 0 8px; font-size: 16px; }
.macro-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.macro { text-align: center; padding: 8px; background: var(--bg-2); border-radius: 10px; }
.macro .m-val { font-weight: 700; font-size: 16px; }
.macro .m-lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; }

.cal-event { display: flex; gap: 10px; padding: 10px; background: var(--card-2); border-radius: 12px; border: 1px solid var(--line); align-items: center; }
.cal-event .ce-icon { font-size: 20px; }
.cal-event .ce-body { flex: 1; min-width: 0; }
.cal-event .ce-ttl { font-weight: 600; font-size: 14px; }
.cal-event .ce-time { font-size: 12px; color: var(--muted); }
.cal-event .ce-badge { font-size: 11px; padding: 2px 8px; background: rgba(52,211,153,0.15); color: var(--accent); border-radius: 8px; }
