﻿:root {
  color-scheme: light dark;
  --bg: #F2F2F7;
  --bg-elevated: #FFFFFF;
  --bg-secondary: #E5E5EA;
  --text: #000000;
  --text-secondary: #8E8E93;
  --separator: rgba(60, 60, 67, 0.16);
  --accent: #007AFF;
  --green: #34C759;
  --red: #FF3B30;
  --bubble-user: #34C759;
  --bubble-model: #E9E9EB;
  --bubble-model-text: #000000;
  --nav-bg: rgba(242, 242, 247, 0.85);
  --tab-bg: rgba(249, 249, 249, 0.94);
  --sheet-bg: #F2F2F7;
  --overlay: rgba(0, 0, 0, 0.35);
  --radius: 12px;
  --radius-lg: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tab-height: 50px;
  --toolbar-height: 56px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: #1C1C1E;
    --bg-secondary: #2C2C2E;
    --text: #FFFFFF;
    --text-secondary: #98989F;
    --separator: rgba(84, 84, 88, 0.65);
    --accent: #0A84FF;
    --green: #30D158;
    --red: #FF453A;
    --bubble-user: #30D158;
    --bubble-model: #2C2C2E;
    --bubble-model-text: #FFFFFF;
    --nav-bg: rgba(0, 0, 0, 0.78);
    --tab-bg: rgba(28, 28, 30, 0.94);
    --sheet-bg: #1C1C1E;
    --overlay: rgba(0, 0, 0, 0.5);
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { height: 100%; background: var(--bg); }
body {
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
input, select { border: none; background: transparent; outline: none; }
.hidden { display: none !important; }
.spacer { flex: 1; }

#app { min-height: 100dvh; }

.view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.nav-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: var(--safe-top);
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}
.nav-bar-inner {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  position: relative;
}
.nav-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.nav-title.large { font-size: 17px; }
.nav-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.2;
}
.nixi-nav { justify-content: center; }
.nixi-nav-title { text-align: center; }
.icon-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: var(--accent);
  border-radius: 50%;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { opacity: 0.6; }

.content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-left: max(16px, var(--safe-left));
  padding-right: max(16px, var(--safe-right));
}

/* Onboarding */
.onboarding-content {
  padding-top: 24px;
  padding-bottom: 24px;
  display: flex;
  flex-direction: column;
}
.onb-step { animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.step-title {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 24px;
  letter-spacing: -0.02em;
}
.goal-options { display: flex; flex-direction: column; gap: 12px; }
.goal-btn {
  width: 100%;
  padding: 16px;
  border-radius: 12px;
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 17px;
  font-weight: 500;
  transition: background .15s, color .15s, transform .1s;
}
.goal-btn.selected { background: var(--accent); color: #fff; }
.goal-btn:active { transform: scale(0.99); }

.form-card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  overflow: hidden;
}
.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  min-height: 44px;
  font-size: 17px;
}
.field + .field, .settings-action + .settings-action { border-top: 0.5px solid var(--separator); }
.field-label { flex: 0 0 auto; }
.field-input {
  flex: 1;
  text-align: right;
  font-size: 17px;
  color: var(--text);
  min-width: 0;
}
.field-input::placeholder { color: var(--text-secondary); }
.select-input {
  appearance: none;
  -webkit-appearance: none;
  text-align: right;
  padding-right: 0;
  color: var(--accent);
  background: transparent;
}
.row-field .field-input { width: auto; }

/* Toggle */
.toggle { position: relative; width: 51px; height: 31px; flex: 0 0 51px; display: inline-block; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
  position: absolute; inset: 0;
  background: #E9E9EB;
  border-radius: 31px;
  transition: .2s;
}
@media (prefers-color-scheme: dark) { .toggle-slider { background: #39393D; } }
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 27px; height: 27px;
  left: 2px; top: 2px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,.2);
  transition: .2s;
}
.toggle input:checked + .toggle-slider { background: var(--green); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* Stepper */
.stepper { display: flex; gap: 1px; background: var(--separator); border-radius: 8px; overflow: hidden; }
.stepper-btn {
  width: 44px; height: 32px;
  background: var(--bg-secondary);
  font-size: 20px; line-height: 1;
  color: var(--text);
}
.stepper-btn:active { opacity: 0.6; }

.onboarding-footer {
  display: flex;
  align-items: center;
  padding: 16px max(16px, var(--safe-right)) calc(16px + var(--safe-bottom)) max(16px, var(--safe-left));
  gap: 12px;
  background: var(--bg);
}
.btn-text {
  color: var(--accent);
  font-size: 17px;
  padding: 10px 4px;
}
.btn-text.bold { font-weight: 600; }
.btn-text:disabled { opacity: 0.4; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  padding: 10px 22px;
  border-radius: 10px;
}
.btn-primary:disabled { opacity: 0.45; }
.btn-primary:active:not(:disabled) { filter: brightness(0.92); }

.result-card { text-align: center; padding: 40px 16px; }
.result-title { font-size: 28px; font-weight: 700; margin-bottom: 12px; letter-spacing: -0.02em; }
.result-kcal { font-size: 48px; font-weight: 700; color: var(--accent); line-height: 1.1; margin-bottom: 12px; }
.result-sub { font-size: 17px; color: var(--text-secondary); line-height: 1.4; max-width: 320px; margin: 0 auto; }

/* Main */
.main-content {
  padding-top: 16px;
  padding-bottom: calc(16px + var(--toolbar-height) + var(--tab-height) + var(--safe-bottom));
}
.list-section { margin-bottom: 24px; }
.section-title {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 0 16px 8px;
}
.card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  overflow: hidden;
}
.calorie-card {
  padding: 24px 16px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.ring-wrap {
  position: relative;
  width: 180px;
  height: 180px;
  margin-bottom: 8px;
}
.calorie-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg {
  fill: none;
  stroke: var(--bg-secondary);
  stroke-width: 14;
}
.ring-fg {
  fill: none;
  stroke: var(--green);
  stroke-width: 14;
  stroke-linecap: round;
  stroke-dasharray: 540.35;
  stroke-dashoffset: 540.35;
  transition: stroke-dashoffset .5s ease, stroke .2s;
}
.ring-fg.over { stroke: var(--red); }
.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
}
.ring-value { font-size: 40px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.ring-label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.ring-summary { font-size: 13px; color: var(--text-secondary); text-align: center; }

.progress-card { padding: 16px; }
.progress-track {
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 10px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 4px;
  transition: width .35s ease;
}
.progress-labels {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 8px;
}
.progress-labels span { flex: 1; }
.progress-labels span:nth-child(2) { text-align: center; }
.progress-labels span:nth-child(3) { text-align: right; }
.current-weight { font-weight: 700; }
.btn-link {
  color: var(--accent);
  font-size: 17px;
  padding: 4px 0;
  text-align: left;
}
.btn-link:active { opacity: 0.6; }

.list-card .empty-row {
  padding: 14px 16px;
  color: var(--text-secondary);
  font-size: 17px;
}
.food-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  min-height: 44px;
  font-size: 17px;
  border-bottom: 0.5px solid var(--separator);
  position: relative;
  background: var(--bg-elevated);
}
.food-row:last-child { border-bottom: none; }
.food-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.food-cal { color: var(--text-secondary); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.food-delete {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(255, 59, 48, 0.12);
  color: var(--red);
  display: grid; place-items: center;
  font-size: 18px; line-height: 1;
}
.food-delete:active { opacity: 0.7; }

.bottom-toolbar {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--tab-height) + var(--safe-bottom));
  height: var(--toolbar-height);
  padding: 0 max(16px, var(--safe-right)) 0 max(16px, var(--safe-left));
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
  z-index: 15;
}
.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-size: 15px;
  padding: 8px 10px;
  border-radius: 8px;
}
.toolbar-btn:active { background: rgba(0,122,255,0.08); }
.toolbar-icon { width: 20px; height: 20px; flex-shrink: 0; }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* Tab bar */
.tab-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  display: flex;
  background: var(--tab-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
  z-index: 30;
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 500;
  padding-top: 4px;
}
.tab-btn.active { color: var(--accent); }
.tab-icon { width: 24px; height: 24px; }
.tab-btn:active { opacity: 0.7; }

/* Chat */
.chat-content {
  padding-top: 12px;
  padding-bottom: calc(12px + 88px + var(--tab-height) + var(--safe-bottom));
}
.chat-messages { display: flex; flex-direction: column; gap: 10px; }
.chat-empty {
  color: var(--text-secondary);
  font-size: 17px;
  line-height: 1.45;
  padding: 20px 4px;
}
.chat-bubble {
  max-width: min(78%, 560px);
  padding: 12px 14px;
  border-radius: 18px;
  font-size: 17px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-bubble.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.chat-bubble.model {
  align-self: flex-start;
  background: var(--bubble-model);
  color: var(--bubble-model-text);
  border-bottom-left-radius: 6px;
}
.chat-bubble.typing { color: var(--text-secondary); }
.chat-compose {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--tab-height) + var(--safe-bottom));
  padding: 8px max(16px, var(--safe-right)) 8px max(16px, var(--safe-left));
  background: var(--nav-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
  z-index: 15;
}
.chat-compose-inner {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-input {
  flex: 1;
  height: 40px;
  padding: 0 14px;
  border-radius: 20px;
  background: var(--bg-elevated);
  border: 0.5px solid var(--separator);
  font-size: 17px;
}
.chat-input::placeholder { color: var(--text-secondary); }
.send-btn {
  width: 36px; height: 36px;
  color: var(--accent);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.send-btn svg { width: 34px; height: 34px; }
.send-btn:disabled { color: var(--text-secondary); opacity: 0.5; }
.send-btn:active:not(:disabled) { transform: scale(0.94); }

/* Sheets */
.sheet-overlay, .alert-overlay, .analyzing-overlay {
  position: fixed; inset: 0;
  z-index: 100;
}
.sheet-overlay { display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop, .alert-backdrop {
  position: absolute; inset: 0;
  background: var(--overlay);
}
.sheet {
  position: relative;
  width: 100%;
  max-width: 720px;
  background: var(--sheet-bg);
  border-radius: 16px 16px 0 0;
  padding-bottom: calc(16px + var(--safe-bottom));
  max-height: calc(100dvh - 20px);
  overflow-y: auto;
  animation: sheetUp .25s ease;
}
.sheet-tall { min-height: 60vh; }
@keyframes sheetUp { from { transform: translateY(24px); opacity: 0.98; } to { transform: none; opacity: 1; } }
.sheet-handle {
  width: 36px; height: 5px;
  background: rgba(120,120,128,0.35);
  border-radius: 3px;
  margin: 8px auto 0;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  min-height: 44px;
}
.sheet-title { font-size: 17px; font-weight: 600; }
.header-spacer { width: 70px; }
.sheet-body { padding: 8px 16px 16px; }

/* Settings */
.settings-group { margin-bottom: 24px; }
.settings-group-title {
  font-size: 13px;
  color: var(--text-secondary);
  text-transform: uppercase;
  padding: 0 16px 8px;
}
.settings-footnote {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 8px 16px 0;
  line-height: 1.4;
}
.settings-action {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  font-size: 17px;
  color: var(--accent);
}
.settings-action.destructive { color: var(--red); }
.settings-action:active { background: rgba(128,128,128,0.08); }
.settings-server-url {
  font-size: 13px;
  color: var(--text-secondary);
  word-break: break-all;
  text-align: left;
}
.token-input { text-align: left !important; }

/* Alert */
.alert-overlay { display: flex; align-items: center; justify-content: center; padding: 24px; }
.alert {
  position: relative;
  width: min(270px, 100%);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 14px;
  text-align: center;
  overflow: hidden;
}
@media (prefers-color-scheme: dark) {
  .alert { background: rgba(44,44,46,0.95); }
}
.alert-title { font-size: 17px; font-weight: 600; padding: 20px 16px 4px; }
.alert-message { font-size: 13px; line-height: 1.4; padding: 0 16px 20px; color: var(--text); }
.alert-btn {
  width: 100%;
  padding: 12px 16px;
  font-size: 17px;
  font-weight: 600;
  color: var(--accent);
  border-top: 0.5px solid var(--separator);
}
.alert-btn:active { background: rgba(128,128,128,0.12); }

/* Analyzing */
.analyzing-overlay {
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  z-index: 90;
}
.analyzing-card {
  pointer-events: auto;
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 12px;
  font-size: 17px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}
@media (prefers-color-scheme: dark) {
  .analyzing-card { background: rgba(44,44,46,0.95); }
}
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--bg-secondary);
  border-top-color: var(--text-secondary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 700px) {
  .main-content, .onboarding-content, .chat-messages { max-width: 680px; margin-left: auto; margin-right: auto; width: 100%; }
  .sheet { border-radius: 16px; margin-bottom: 24px; }
  .sheet-overlay { align-items: center; padding: 24px; }
}
@supports (padding-top: env(safe-area-inset-top)) {
  body { padding-left: 0; padding-right: 0; }
}

