:root {
  --bg: #09090b;
  --bg-elevated: #18181b;
  --bg-card: #141416;
  --bg-inset: #101012;
  --tab-bar-bg: rgba(24, 24, 27, 0.52);
  --sheet-shadow: 0 -12px 40px rgba(0, 0, 0, 0.28);
  --backdrop: rgba(0, 0, 0, 0.55);
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #fafafa;
  --muted: #a1a1aa;
  --accent: #818cf8;
  --accent-solid: #6366f1;
  --accent-dim: rgba(99, 102, 241, 0.14);
  --calories: #f59e0b;
  --water: #22d3ee;
  --weight: #34d399;
  --danger: #f87171;
  --danger-dim: rgba(248, 113, 113, 0.1);
  --radius: 16px;
  --radius-lg: 20px;
  --radius-sm: 10px;
  --app-max: 440px;
  --app-pad: 16px;
  --tab-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --ring: 201;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.32);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f4f5;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --bg-inset: #f0f0f2;
    --tab-bar-bg: rgba(255, 255, 255, 0.5);
    --sheet-shadow: 0 -8px 32px rgba(0, 0, 0, 0.1);
    --backdrop: rgba(0, 0, 0, 0.35);
    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.14);
    --text: #18181b;
    --muted: #71717a;
    --accent-dim: rgba(99, 102, 241, 0.12);
    --danger-dim: rgba(248, 113, 113, 0.12);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.08);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

*::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html {
  overflow-x: hidden;
}

body {
  overflow-x: hidden;
}

body.has-app {
  padding-bottom: 0;
}

body.is-offline #app-shell,
body.is-offline #auth,
body.is-offline #loading {
  display: none;
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
  background: var(--bg);
}

.loading.hidden {
  display: none;
}

.loading p {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.loading span {
  color: var(--muted);
  font-size: 0.95rem;
}

#app-shell.hidden,
#auth.hidden {
  display: none;
}

.auth {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-content: center;
  padding: 24px;
  background: var(--bg);
}

.auth-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 60% at 50% -20%, rgba(99, 102, 241, 0.12), transparent 70%);
  pointer-events: none;
}



.auth-card {
  position: relative;
  width: min(100%, 380px);
  display: grid;
  gap: 14px;
  padding: 28px 22px 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.auth-logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #fff;
  background: var(--accent-solid);
}

.auth-title {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.035em;
}

.auth-tagline {
  margin: -8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.auth-version-line {
  margin: 4px 0 2px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
  letter-spacing: 0.02em;
}

.auth-sso-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  text-align: center;
}

.auth-sso-hint strong {
  color: var(--text);
  font-weight: 600;
}

.auth-status {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.field-hint {
  font-style: normal;
  font-weight: 400;
  opacity: 0.75;
}

.field.hidden {
  display: none;
}

.auth-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 1rem;
  background: var(--bg-card);
  color: var(--text);
  color-scheme: light dark;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

html[data-theme="light"] .auth-input,
html[data-theme="light"] .setting-input input {
  background: var(--bg-inset);
  color: var(--text);
  border-color: var(--border-strong);
}

html[data-theme="light"] .auth-input:-webkit-autofill,
html[data-theme="light"] .setting-input input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--bg-inset) inset;
  -webkit-text-fill-color: var(--text);
}

.auth-input:focus {
  outline: none;
  border-color: var(--accent-solid);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.pwd-wrap {
  position: relative;
  display: block;
}

.pwd-wrap .auth-input {
  padding-right: 5.75rem;
}

.pwd-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  border-radius: 10px;
  padding: 7px 10px;
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-elevated);
  cursor: pointer;
}

.pwd-toggle[aria-pressed="true"] {
  color: var(--accent-solid);
}

.auth-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.88rem;
  line-height: 1.4;
}

.auth-error.hidden {
  display: none;
}

.log-panel.hidden {
  display: none;
}

.log-panel,
.log-panel-settings {
  margin-top: 4px;
}

.log-title,
.log-panel-settings .panel-section-title {
  margin: 0 0 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-transform: none;
  color: var(--text);
}

.log-body {
  margin: 0;
  max-height: 140px;
  overflow: auto;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.log-panel-settings .log-body,
.diagnostics-panel .log-body {
  max-height: 200px;
  margin: 0 18px 12px;
}

.diagnostics-panel {
  padding: 0 0 12px;
}

.diagnostics-summary {
  padding: 14px 18px;
  cursor: pointer;
  list-style: none;
}

.diagnostics-summary::-webkit-details-marker {
  display: none;
}

.log-actions {
  display: flex;
  gap: 8px;
  padding: 0 18px 14px;
}

.log-actions .btn {
  flex: 1;
  padding: 10px;
  font-size: 0.85rem;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.full {
  width: 100%;
  margin-top: 4px;
}

.offline {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
  background: var(--bg);
  padding: 24px;
}

.offline.hidden {
  display: none;
}

.offline p {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
}

.offline span {
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 280px;
  line-height: 1.45;
}

.offline-retry {
  margin-top: 20px;
  min-width: 160px;
  flex: 0 0 auto;
}

.bg-glow {
  position: fixed;
  inset: -30% -20% auto;
  height: 50vh;
  background: radial-gradient(ellipse 70% 55% at 50% 0%, rgba(99, 102, 241, 0.08), transparent 72%);
  pointer-events: none;
  z-index: 0;
}

html[data-theme="light"] .bg-glow {
  background: radial-gradient(ellipse 70% 55% at 50% 0%, rgba(99, 102, 241, 0.06), transparent 72%);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .bg-glow {
    background: radial-gradient(ellipse 70% 55% at 50% 0%, rgba(99, 102, 241, 0.06), transparent 72%);
  }
}

.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.user-badge {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--accent-solid);
  background: var(--accent-dim);
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  transition: transform 0.15s ease, background 0.15s ease;
}

.user-badge:active {
  transform: scale(0.96);
}

.user-badge.hidden {
  display: none;
}

.boot-loading {
  position: fixed;
  inset: 0;
  z-index: 96;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 10px;
  background: var(--bg);
}

.boot-loading.hidden {
  display: none !important;
}

.boot-loading p {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.boot-loading span {
  color: var(--muted);
  font-size: 0.9rem;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: var(--app-max);
  height: 100dvh;
  height: 100vh;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 8px) var(--app-pad) 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#app {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  position: relative;
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 20px);
}

#app[data-pull="1"]::before {
  content: 'Отпустите для синхронизации';
  position: sticky;
  top: 0;
  z-index: 2;
  display: block;
  padding: 10px 0 6px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--accent-solid);
}

@media (display-mode: standalone) {
  .hero .eyebrow {
    display: none;
  }
}

.view {
  display: none;
  padding-bottom: 16px;
  animation: fadeIn 0.35s ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.hero {
  padding: 8px 0 16px;
}

@media (display-mode: standalone) {
  .hero {
    padding-top: 4px;
  }
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
}

.hero h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1.15;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 400;
  text-transform: capitalize;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.metric-card.flash {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 1px var(--accent-dim);
}

.metric-card.wide {
  grid-column: 1 / -1;
}

.metric-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
}

.chip::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.metric-card[data-type="calories"] .chip::before { background: var(--calories); }
.metric-card[data-type="water"] .chip::before { background: var(--water); }
.metric-card[data-type="weight"] .chip::before { background: var(--weight); }

.ring-wrap {
  position: relative;
  width: 88px;
  height: 88px;
  flex-shrink: 0;
}

.ring-svg {
  width: 88px;
  height: 88px;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 4;
}

.ring-progress {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: var(--ring);
  stroke-dashoffset: var(--ring);
  transition: stroke-dashoffset 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.ring-progress.calories { stroke: var(--calories); }
.ring-progress.water { stroke: var(--water); }

.ring-progress.ring-complete.calories {
  filter: drop-shadow(0 0 6px rgba(249, 115, 22, 0.5));
  animation: ring-goal-pop 0.65s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.ring-progress.ring-complete.water {
  filter: drop-shadow(0 0 6px rgba(59, 130, 246, 0.5));
  animation: ring-goal-pop 0.65s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes ring-goal-pop {
  0% { stroke-width: 4; opacity: 0.85; }
  45% { stroke-width: 6; opacity: 1; }
  100% { stroke-width: 4; opacity: 1; }
}

.auth-welcome-user {
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-weight: 600;
}

#auth-welcome .btn.ghost {
  margin-top: 8px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.ring-pct {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.metric-value {
  font-size: 1.75rem;
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.metric-value.small {
  font-size: 1.5rem;
  margin: 8px 0;
}

.metric-value small {
  font-size: 0.85rem;
  color: var(--muted);
  margin-left: 4px;
}

.metric-goal {
  margin: 4px 0 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--muted);
}

.cal-calc {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.cal-calc-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.cal-calc-field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.cal-calc-field span {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.cal-calc-field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 8px;
  font-size: 0.85rem;
  text-align: center;
  background: var(--bg-elevated);
  color: var(--text);
}

.cal-calc-field input:focus {
  outline: none;
  border-color: var(--calories);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.15);
}

.cal-calc-add {
  width: 100%;
  color: var(--calories);
}

.cal-calc-add:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.quick-add {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 10px;
}

.quick-add-weight {
  grid-template-columns: 1fr;
}

.quick-btn {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 6px;
  background: transparent;
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
}

.quick-btn:hover {
  background: var(--bg-inset);
  border-color: var(--border-strong);
}

.quick-btn:active {
  transform: scale(0.96);
}

.quick-add[data-type="water"] .quick-btn {
  color: var(--water);
}

.quick-weight-log {
  color: var(--weight);
  padding: 10px 12px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.stats-range {
  margin: -8px 0 14px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
}

.summary-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.summary-row-3 {
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.today-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.today-summary.hidden { display: none !important; }

.today-summary-item {
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.today-summary-item span {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.today-summary-item strong {
  display: block;
  margin-top: 4px;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}

.today-summary-item em {
  font-size: 0.72rem;
  color: var(--muted);
  font-style: normal;
}

.summary-row-3 .summary-card {
  padding: 12px 10px;
}

.summary-row-3 .summary-card strong {
  font-size: 1rem;
}

.summary-delta {
  display: block;
  margin-top: 4px;
  font-size: 0.68rem;
  font-style: normal;
  color: var(--muted);
  line-height: 1.3;
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.summary-card span {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.summary-card strong {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.panel-weight {
  padding-bottom: 14px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.panel-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.chart-host {
  width: 100%;
}

.chart-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  margin: 0 -2px;
  padding-bottom: 2px;
}

.chart-scroll-static {
  overflow-x: hidden;
}

.chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 120px;
}

.chart.week {
  width: 100%;
}

.chart.week .bar-wrap {
  flex: 1;
  min-width: 0;
}

.chart.month {
  gap: 3px;
  flex-shrink: 0;
}

.chart.month .bar-wrap {
  flex: 0 0 11px;
  width: 11px;
}

.chart.quarter {
  gap: 2px;
  flex-shrink: 0;
}

.chart.quarter .bar-wrap {
  flex: 0 0 4px;
  width: 4px;
}

.chart.quarter .bar {
  max-width: 4px;
  border-radius: 3px 3px 1px 1px;
}

.chart.quarter .bar-label {
  font-size: 0.5rem;
}

.bar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  height: 100%;
  justify-content: flex-end;
}

.bar {
  width: 100%;
  max-width: 24px;
  min-height: 4px;
  border-radius: 6px 6px 2px 2px;
  transition: height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.chart.month .bar {
  max-width: 11px;
  border-radius: 4px 4px 2px 2px;
}

.bar.at-goal {
  box-shadow: 0 0 0 1px var(--border-strong);
}

.bar-label {
  font-size: 0.62rem;
  color: var(--muted);
  line-height: 1;
  white-space: nowrap;
}

.chart.month .bar-label {
  font-size: 0.55rem;
}

.bar-label-empty {
  visibility: hidden;
}

.weight-chart {
  position: relative;
  margin-top: 4px;
}

.weight-chart.hidden {
  display: none;
}

.weight-chart-inner {
  display: block;
}

.weight-chart-inner.week {
  width: 100%;
}

.weight-chart-svg {
  display: block;
  width: 100%;
  height: 120px;
}

.weight-chart-inner.month .weight-chart-svg {
  width: 100%;
  min-width: 100%;
}

.weight-line {
  fill: none;
  stroke: var(--weight);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.weight-dot {
  fill: var(--weight);
  stroke: var(--bg-elevated);
  stroke-width: 2;
}

.weight-goal-line {
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 5 4;
  opacity: 0.45;
}

.weight-labels {
  margin-top: 6px;
  min-height: 16px;
}

.weight-labels-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.weight-labels-week .weight-label-tick {
  text-align: center;
  font-size: 0.62rem;
  color: var(--muted);
}

.weight-labels-month {
  position: relative;
  height: 18px;
}

.weight-labels-month .weight-label-tick,
.weight-labels-quarter .weight-label-tick {
  position: absolute;
  transform: translateX(-50%);
  font-size: 0.55rem;
  color: var(--muted);
  white-space: nowrap;
}

.weight-labels-quarter {
  position: relative;
  height: 18px;
}

.weight-chart-inner.quarter .weight-chart-svg {
  width: 100%;
  min-width: 100%;
}

.weight-empty {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

.weight-empty.hidden {
  display: none;
}

.panel-section-title {
  margin: 0;
  padding: 14px 18px 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-transform: none;
  color: var(--text);
}

.panel-section-title.danger {
  color: var(--danger);
}

.account-panel {
  padding: 16px 18px;
  display: grid;
  gap: 12px;
}

.account-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.account-avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent-solid);
}

.account-label {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.account-name {
  margin: 2px 0 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.danger-panel {
  padding: 0 0 16px;
  border-color: rgba(248, 113, 113, 0.18);
  background: var(--danger-dim);
}

.danger-hint {
  margin: 0 18px 12px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

.delete-warning {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.panel.settings {
  padding: 0 0 8px;
}

.panel.settings .panel-hint {
  margin: 0 18px 14px;
}

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.setting:last-child {
  border-bottom: none;
}

.setting-input {
  display: flex;
  align-items: center;
  gap: 8px;
}

.setting-input input {
  width: 88px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 1rem;
  text-align: right;
  background: var(--bg-elevated);
  color: var(--text);
}

.setting-input em {
  font-style: normal;
  font-size: 0.8rem;
  color: var(--muted);
}

.footnote {
  margin: 8px 0 4px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
  text-align: center;
}

.version-tag {
  margin: 0 0 4px;
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
  letter-spacing: 0.04em;
  opacity: 0.7;
}

.tab-bar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 50;
  width: 100%;
  max-width: var(--app-max);
  margin: 0;
  padding: 0 var(--app-pad) calc(var(--safe-bottom) + 10px);
  background: transparent;
  border: none;
  pointer-events: none;
}

.tab-bar-inner {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  min-height: var(--tab-h);
  padding: 5px 6px;
  background: var(--tab-bar-bg);
  backdrop-filter: blur(22px) saturate(1.4);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 28px rgba(0, 0, 0, 0.18);
  pointer-events: auto;
}

.stats-segmented {
  grid-template-columns: repeat(3, 1fr);
}

.tab {
  border: none;
  background: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.625rem;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  padding: 6px 4px;
  border-radius: 12px;
  transition: color 0.15s ease, background 0.15s ease;
}

.tab svg {
  width: 20px;
  height: 20px;
  stroke-width: 1.75;
}

.tab.active {
  color: var(--accent-solid);
  background: var(--accent-dim);
}

dialog.sheet {
  border: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 0;
  width: 100%;
  max-width: var(--app-max);
  margin: auto auto 0;
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--sheet-shadow);
  z-index: 200;
}

dialog.sheet::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#modal-form {
  padding: 12px 24px calc(24px + var(--safe-bottom));
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 99px;
  background: var(--border);
  margin: 0 auto 20px;
}

#modal-form h2 {
  margin: 0 0 20px;
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
  font-size: 2.2rem;
  font-weight: 300;
  background: var(--bg-card);
  color: var(--text);
  margin-bottom: 12px;
}

.modal-note {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 1rem;
  background: var(--bg-card);
  color: var(--text);
  margin-bottom: 12px;
}

.quick-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.quick-row button {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.btn {
  flex: 1;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.12s ease;
}

.btn.primary {
  background: var(--accent-solid);
  color: #fff;
}

.btn.primary:active {
  transform: scale(0.98);
  opacity: 0.92;
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.ghost:active {
  background: var(--bg);
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.btn.danger:active {
  transform: scale(0.98);
}

.rotate-lock {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background: var(--bg);
  color: var(--text);
}

.rotate-lock p {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.rotate-lock span {
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 280px;
  line-height: 1.45;
}

.rotate-lock svg {
  width: 48px;
  height: 48px;
  color: var(--accent);
}

@media (orientation: landscape) and (max-width: 900px) {
  .rotate-lock {
    display: flex;
  }

  body.landscape-locked #app-shell,
  body.landscape-locked #auth {
    display: none !important;
  }
}

body.landscape-locked {
  overflow: hidden;
}

.update-banner {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 10px;
  padding: 12px 14px;
  background: var(--accent-dim);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}

.update-banner.hidden {
  display: none !important;
}

.update-banner-text {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--text);
}

.update-banner-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn.compact {
  flex: 0 0 auto;
  padding: 8px 12px;
  font-size: 0.82rem;
}

.status-panel .status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-panel .panel-section-title {
  margin: 0 0 4px;
}

.status-text {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.sync-badge {
  min-width: 42px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.04em;
}

.sync-badge.ok {
  color: #4ade80;
  background: rgba(74, 222, 128, 0.12);
  border: 1px solid rgba(74, 222, 128, 0.25);
}

.sync-badge.saving {
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(167, 139, 250, 0.25);
}

.sync-badge.error {
  color: var(--danger);
  background: var(--danger-dim);
  border: 1px solid rgba(248, 113, 113, 0.25);
}

.sync-badge.offline {
  color: var(--muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.panel-hint {
  margin: 0 0 12px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--muted);
}

.data-panel .btn + .btn {
  margin-top: 8px;
}

.water-remind-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 12px;
  padding: 12px 14px;
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.2);
  border-radius: var(--radius);
}

.water-remind-banner.hidden {
  display: none !important;
}

.water-remind-banner p {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--text);
}

.import-label {
  display: block;
  margin-top: 8px;
}

.import-mode-seg {
  margin-bottom: 10px;
}

.export-scope-field,
.restore-field {
  margin-bottom: 10px;
}

.push-hours-label {
  margin-top: 4px;
}

.push-hours {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.hour-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
}

.hour-chip input {
  accent-color: var(--accent);
}

.import-status {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.import-status.error {
  color: var(--danger);
}

.import-status.hidden {
  display: none;
}

.backup-info {
  margin-top: 12px;
}

.today-journal {
  margin-top: 18px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.journal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.journal-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.journal-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.journal-refresh {
  min-width: 40px;
  padding: 8px 10px;
}

.entry-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.entry-list:empty {
  display: none;
}

.entry-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.entry-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.entry-dot.calories { background: var(--calories); }
.entry-dot.water { background: var(--water); }
.entry-dot.weight { background: var(--weight); }

.entry-main {
  flex: 1;
  min-width: 0;
}

.entry-label {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.35;
}

.entry-meta {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.entry-delete {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}

.entry-delete:active {
  background: var(--danger-dim);
  color: var(--danger);
}

.entry-empty {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted);
  text-align: center;
  padding: 8px 0 4px;
}

.entry-empty.hidden {
  display: none;
}

.cal-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.cal-preset-btn {
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  padding: 6px 10px;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 500;
  cursor: pointer;
}

.cal-preset-btn:active {
  background: var(--accent-dim);
  color: var(--text);
}

.cal-preset-btn.saved {
  border-style: solid;
  color: var(--calories);
  border-color: rgba(245, 158, 11, 0.35);
}

.profile-sheet {
  padding: 8px 20px calc(20px + var(--safe-bottom));
  max-height: 92dvh;
  overflow-y: auto;
}

.profile-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}

.profile-header-main {
  flex: 1;
  min-width: 0;
}

.profile-close {
  flex-shrink: 0;
  min-width: 40px;
  padding: 8px 10px;
}

.profile-version {
  margin: 4px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.profile-sync,
.profile-password,
.profile-danger {
  margin-bottom: 14px;
  padding: 14px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.profile-danger .panel-section-title {
  padding: 0 0 8px;
}

.profile-danger .danger-hint {
  margin: 0 0 12px;
}

.profile-sync .panel-section-title,
.profile-password .panel-section-title {
  padding: 0 0 8px;
}

.profile-sync .status-row {
  margin-bottom: 10px;
}

.profile-password .field {
  margin-bottom: 10px;
}

.profile-actions {
  display: grid;
  gap: 8px;
  position: sticky;
  bottom: 0;
  padding-top: 8px;
  background: linear-gradient(to top, var(--bg-elevated) 85%, transparent);
}

#app.pull-ready {
  transition: transform 0.15s ease;
}

.pull-indicator {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
  padding: 8px 14px;
  font-size: 0.75rem;
  color: var(--muted);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.pull-indicator.visible {
  opacity: 1;
}

.toggle-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toggle-setting input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.theme-panel .theme-segmented {
  margin: 4px 18px 14px;
  grid-template-columns: repeat(3, 1fr);
}

.theme-panel .panel-section-title {
  padding-bottom: 4px;
}

.status-panel {
  padding: 14px 18px;
}

.data-panel {
  padding: 0 18px 16px;
}

.data-panel .panel-section-title {
  padding-left: 0;
  padding-right: 0;
}

.data-panel .panel-hint {
  margin-bottom: 10px;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f4f5;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-inset: #f0f0f2;
  --tab-bar-bg: rgba(255, 255, 255, 0.5);
  --sheet-shadow: 0 -8px 32px rgba(0, 0, 0, 0.1);
  --backdrop: rgba(0, 0, 0, 0.35);
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --text: #18181b;
  --muted: #71717a;
  --accent-dim: rgba(99, 102, 241, 0.12);
  --danger-dim: rgba(248, 113, 113, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.08);
}

html[data-theme="light"] body,
html[data-theme="light"] #app,
html[data-theme="light"] .app-shell {
  background: var(--bg);
  color: var(--text);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #09090b;
  --bg-elevated: #18181b;
  --bg-card: #141416;
  --bg-inset: #101012;
  --tab-bar-bg: rgba(24, 24, 27, 0.52);
  --sheet-shadow: 0 -12px 40px rgba(0, 0, 0, 0.28);
  --backdrop: rgba(0, 0, 0, 0.55);
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #fafafa;
  --muted: #a1a1aa;
  --accent-dim: rgba(99, 102, 241, 0.14);
  --danger-dim: rgba(248, 113, 113, 0.1);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.32);
}