/* AxionStat — Neumorphism design system (mobile-first) */

:root {
  --color-primary: #006666;
  --color-primary-dark: #004d4d;
  --color-secondary: #F1F2F5;
  --color-success: #00A63D;
  --color-warning: #FE9900;
  --color-danger: #FF2157;
  --color-info: #006666;
  --color-surface: #E7E5E4;
  --color-text: #1E2938;
  --color-text-muted: #64748b;
  --color-shadow-dark: #c8c6c5;
  --color-shadow-light: #ffffff;

  --font-primary: "Space Mono", "JetBrains Mono", ui-monospace, monospace;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 999px;

  --shadow-raised: 6px 6px 14px var(--color-shadow-dark), -6px -6px 14px var(--color-shadow-light);
  --shadow-raised-sm: 4px 4px 10px var(--color-shadow-dark), -4px -4px 10px var(--color-shadow-light);
  --shadow-inset: inset 4px 4px 10px var(--color-shadow-dark), inset -4px -4px 10px var(--color-shadow-light);
  --shadow-pressed: inset 2px 2px 6px var(--color-shadow-dark), inset -2px -2px 6px var(--color-shadow-light);
  /* Soft elevation without white neumorphism halo */
  --shadow-lift: 0 4px 14px rgba(30, 41, 56, 0.1), 0 1px 3px rgba(30, 41, 56, 0.06);
  --shadow-lift-sm: 0 2px 10px rgba(30, 41, 56, 0.09), 0 1px 2px rgba(30, 41, 56, 0.05);

  --header-h: 64px;
  --nav-h: 72px;
  --sidebar-w: 240px;
  --touch-min: 44px;
  --content-max: 1200px;
  --layout-max: 1400px;
  --breakpoint-desktop: 900px;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  overflow-x: hidden;
  width: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-primary);
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-surface);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

.app-frame {
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  overflow-x: hidden;
}

aside.side-nav {
  margin: 0;
}

.content-wrap {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  min-width: 0;
}

.page-section {
  width: 100%;
  min-width: 0;
  overflow-x: hidden;
}

canvas {
  display: block;
  max-width: 100%;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: rgba(0, 102, 102, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

/* Neumorphism surfaces */
.neu-raised { box-shadow: var(--shadow-raised); }
.neu-raised-sm { box-shadow: var(--shadow-raised-sm); }
.neu-inset { box-shadow: var(--shadow-inset); }

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  background: var(--color-surface);
  overflow-x: hidden;
}

.side-nav[hidden] {
  display: none !important;
}

.bottom-nav[hidden] {
  display: none !important;
}

@media (max-width: 899px) {
  .side-nav:not([hidden]) {
    display: none;
  }
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: var(--space-3) var(--space-4);
  padding-top: max(var(--space-3), env(safe-area-inset-top));
  background: var(--color-surface);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex: 1;
}

.brand > div {
  min-width: 0;
}

.brand-logo-wrap {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  box-sizing: border-box;
}

.brand-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
}

.brand-logo-wrap--mobile {
  width: 40px;
  height: 40px;
  padding: 3px;
}

.brand-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 0;
  font-size: 11px;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-main {
  flex: 1;
  width: 100%;
  min-width: 0;
  padding-top: var(--space-3);
  padding-left: max(var(--space-3), env(safe-area-inset-left));
  padding-right: max(var(--space-3), env(safe-area-inset-right));
  padding-bottom: calc(var(--nav-h) + var(--space-6) + env(safe-area-inset-bottom));
}

.app-main .content-wrap {
  padding: 0;
}

.app-shell:has(.bottom-nav[hidden]) .app-main {
  padding-bottom: calc(var(--space-8) + env(safe-area-inset-bottom));
}

/* Bottom navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  padding: var(--space-2) var(--space-4);
  padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
  background: var(--color-surface);
  border-top: 1px solid rgba(30, 41, 56, 0.06);
  z-index: 30;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  padding: var(--space-2);
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 10px;
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: color 0.15s, background 0.15s;
}

.nav-item svg { width: 22px; height: 22px; }

.nav-item.active {
  color: var(--color-primary);
  background: rgba(0, 102, 102, 0.08);
  box-shadow: none;
}

.nav-item:focus-visible {
  color: var(--color-primary);
  background: rgba(0, 102, 102, 0.06);
  box-shadow: none;
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Typography */
.page-title {
  margin: 0 0 var(--space-2);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.page-lead {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 13px;
}

.section-head { margin-bottom: var(--space-6); }

/* Auth */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: calc(100dvh - var(--header-h) - var(--space-8));
}

.auth-card {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

body[data-page="login"] .app-main,
body[data-page="register"] .app-main {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-bottom: max(var(--space-6), env(safe-area-inset-bottom));
}

body[data-page="login"] .app-main .content-wrap,
body[data-page="register"] .app-main .content-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

body[data-page="login"] .bottom-nav,
body[data-page="register"] .bottom-nav {
  display: none !important;
}

.stack-form { display: flex; flex-direction: column; gap: var(--space-4); margin-top: var(--space-6); }

.field { display: flex; flex-direction: column; gap: var(--space-2); }

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input {
  width: 100%;
  min-height: var(--touch-min);
  padding: var(--space-3) var(--space-4);
  border: none;
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-family: inherit;
  font-size: 15px;
  color: var(--color-text);
}

.input:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.input::placeholder { color: #94a3b8; }

.form-error {
  margin: 0;
  color: var(--color-danger);
  font-size: 13px;
}

.auth-switch {
  margin: var(--space-6) 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--color-text-muted);
}

.link-btn {
  padding: 0;
  border: none;
  background: none;
  color: var(--color-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.link-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.auth-oauth {
  margin-top: var(--space-4);
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-4) 0;
  color: var(--color-text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(30, 41, 56, 0.1);
}

.btn-yandex {
  width: 100%;
  gap: var(--space-2);
  background: transparent;
  color: var(--color-text);
  border: 2px solid #fc3f1d;
  box-shadow: none;
}

.btn.btn-yandex {
  border: 2px solid #fc3f1d;
}

.btn-yandex:hover,
.btn.btn-yandex:hover {
  background: rgba(252, 63, 29, 0.06);
  border-color: #fc3f1d;
  color: var(--color-text);
}

.btn-yandex-icon {
  flex-shrink: 0;
  display: block;
}

.vk-auth-root {
  width: 100%;
  margin-top: var(--space-3);
}

.auth-oauth .btn-yandex + .vk-auth-root {
  margin-top: var(--space-3);
}

.auth-oauth .vk-auth-root:first-child {
  margin-top: 0;
}

.verify-code-input {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.35em;
  text-align: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-min);
  padding: var(--space-3) var(--space-5);
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s;
  text-decoration: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
  box-shadow: var(--shadow-pressed);
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-raised-sm);
}

.btn-primary:hover { background: var(--color-primary-dark); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  box-shadow: none;
  margin-top: var(--space-2);
  width: 100%;
}

.btn-icon {
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  padding: var(--space-2);
  border: none;
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
}

.btn-icon:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Dashboard & charts */
.period-tabs,
.metric-tabs {
  background: transparent;
}

.period-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.period-tab {
  flex-shrink: 0;
  min-height: 40px;
  padding: var(--space-2) var(--space-4);
  border: 1px solid rgba(30, 41, 56, 0.08);
  border-radius: var(--radius-full);
  background: rgba(30, 41, 56, 0.04);
  box-shadow: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.period-tab:hover {
  color: var(--color-text);
  background: rgba(30, 41, 56, 0.07);
}

.period-tab.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-raised-sm);
}

.dashboard-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.dashboard-primary,
.dashboard-aside {
  min-width: 0;
  overflow: visible;
}

.dashboard-primary .metric-tabs {
  max-width: 100%;
}

.metric-tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  overflow-x: auto;
  overflow-y: visible;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 6px 4px;
}

.metric-tabs::-webkit-scrollbar {
  display: none;
}

.metric-tab {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: var(--space-2) var(--space-4);
  border: 1px solid rgba(30, 41, 56, 0.08);
  border-radius: var(--radius-full);
  background: rgba(30, 41, 56, 0.04);
  box-shadow: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: visible;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.metric-tab[data-metric="weight_kg"] { --tab-color: #006666; }
.metric-tab[data-metric="body_fat_pct"] { --tab-color: #FF2157; }
.metric-tab[data-metric="muscle_mass_kg"] { --tab-color: #00A63D; }
.metric-tab[data-metric="bmi"] { --tab-color: #FE9900; }
.metric-tab[data-metric="body_water_l"] { --tab-color: #0891b2; }
.metric-tab[data-metric="visceral_fat_level"] { --tab-color: #9333ea; }

.metric-tab-swatch {
  width: 8px;
  height: 16px;
  border-radius: 2px;
  flex-shrink: 0;
  background: var(--tab-color, #64748b);
}

.metric-tab.active .metric-tab-swatch {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.45);
}

.metric-tab:hover {
  color: var(--color-text);
  background: rgba(30, 41, 56, 0.07);
}

.metric-tab.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
  box-shadow: none;
}

#dashboard-content .dashboard-main-chart,
#dashboard-content .sparkline-card {
  box-shadow: var(--shadow-lift-sm);
}

#dashboard-content .dashboard-main-chart {
  margin-top: var(--space-1);
}

#dashboard-content .sparkline-card.active {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-lift);
}

.page-section,
.dashboard-grid,
.dashboard-primary,
.dashboard-aside {
  overflow: visible;
}

.section-subtitle {
  margin: 0 0 var(--space-3);
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chart-card {
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  margin-bottom: var(--space-5);
  width: 100%;
  min-width: 0;
  overflow: visible;
}

.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.chart-metric-label {
  margin: 0;
  font-size: 11px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chart-metric-value {
  margin: var(--space-1) 0 0;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}

.chart-delta-wrap {
  text-align: right;
}

.chart-delta {
  display: block;
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font-mono);
}

.chart-delta-caption {
  display: block;
  font-size: 10px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.chart-delta.good { color: var(--color-success); }
.chart-delta.bad { color: var(--color-danger); }
.chart-delta.neutral { color: var(--color-text-muted); }

.chart-canvas-wrap {
  position: relative;
  height: 220px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.chart-canvas-wrap--tall {
  height: 240px;
}

.chart-canvas-wrap--segment {
  height: 200px;
}

.chart-canvas-wrap--doughnut {
  height: 220px;
}

.chart-stats-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid rgba(30, 41, 56, 0.06);
}

.chart-stat {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  text-align: left;
}

.chart-stat-label {
  display: block;
  font-size: 10px;
  color: var(--color-text-muted);
  text-transform: uppercase;
}

.chart-stat-value {
  display: block;
  margin-top: 0;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-mono);
}

.chart-legend-inline {
  margin: var(--space-1) 0 0;
  font-size: 10px;
  color: var(--color-text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  align-items: center;
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot-color);
  margin-right: 4px;
  vertical-align: middle;
}

.sparkline-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.dashboard-aside {
  min-width: 0;
  overflow: visible;
}

.sparkline-card {
  display: block;
  width: 100%;
  min-width: 0;
  padding: var(--space-3);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  background: var(--color-surface);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
}

.sparkline-card:active {
  transform: scale(0.98);
}

.sparkline-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
}

.sparkline-label {
  font-size: 10px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sparkline-delta {
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 600;
}

.sparkline-delta.good { color: var(--color-success); }
.sparkline-delta.bad { color: var(--color-danger); }
.sparkline-delta.neutral { color: var(--color-text-muted); }

.sparkline-value {
  margin: var(--space-2) 0 0;
  font-size: 16px;
  font-weight: 700;
}

.sparkline-value small {
  font-size: 11px;
  font-weight: 400;
  color: var(--color-text-muted);
}

.sparkline-canvas-wrap {
  position: relative;
  height: 44px;
  width: 100%;
  overflow: visible;
  padding: 2px 0;
}


/* Upload */
.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  min-height: 200px;
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  cursor: pointer;
  transition: outline 0.15s;
  text-align: center;
}

.upload-zone:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.upload-zone.dragover {
  outline: 2px dashed var(--color-primary);
}

.upload-icon { color: var(--color-primary); opacity: 0.8; }

.upload-title {
  margin: 0;
  font-weight: 700;
  font-size: 15px;
}

.upload-hint {
  margin: 0;
  font-size: 12px;
  color: var(--color-text-muted);
}

.preview-card,
.success-card {
  margin-top: var(--space-5);
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.preview-label,
.success-title {
  margin: 0 0 var(--space-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.preview-name {
  margin: 0 0 var(--space-5);
  font-size: 15px;
  font-weight: 600;
  word-break: break-all;
}

.success-title { font-size: 16px; color: var(--color-success); text-transform: none; }

.success-text {
  margin: 0 0 var(--space-5);
  color: var(--color-text-muted);
}

/* History */
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.history-item {
  display: block;
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  border: none;
  box-shadow: var(--shadow-lift-sm);
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s, transform 0.1s;
}

.history-item:hover {
  box-shadow: var(--shadow-lift);
}

.history-item:active {
  transform: scale(0.995);
  box-shadow: var(--shadow-pressed);
}

#history-content .chart-card {
  box-shadow: var(--shadow-lift-sm);
}

.history-date {
  margin: 0 0 var(--space-3);
  font-size: 15px;
  font-weight: 700;
}

.history-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

.history-metric-label {
  font-size: 10px;
  color: var(--color-text-muted);
  text-transform: uppercase;
}

.history-metric-value {
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-mono);
}

/* Measurement detail */
.back-link {
  display: inline-block;
  margin-bottom: var(--space-4);
  font-size: 13px;
  font-weight: 600;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

.detail-card {
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-lift-sm);
  min-width: 0;
  overflow-wrap: anywhere;
}

.detail-card.wide { grid-column: 1 / -1; }

.detail-label {
  margin: 0 0 var(--space-1);
  font-size: 10px;
  color: var(--color-text-muted);
  text-transform: uppercase;
}

.detail-value {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  word-break: break-word;
}

.detail-value-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.metric-delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.metric-delta-icon {
  flex-shrink: 0;
}

.metric-delta.good { color: var(--color-success); }
.metric-delta.bad { color: var(--color-danger); }
.metric-delta.neutral { color: var(--color-text-muted); }

.detail-range {
  margin: var(--space-2) 0 0;
  font-size: 11px;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
}

.composition-grid {
  margin-bottom: var(--space-6);
}

.goals-grid {
  margin-bottom: var(--space-6);
}

/* Measurement page — single elevation layer, no neumorphism halos */
#measurement-detail .chart-card,
#measurement-detail .detail-card {
  box-shadow: var(--shadow-lift-sm);
}

#measurement-detail .detail-card {
  background: var(--color-surface);
}

/* Body diagram */
.body-diagram-card {
  margin-bottom: var(--space-6);
  padding: var(--space-3);
}

.body-diagram-split {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  min-width: 0;
}

.body-diagram-divider {
  width: 2px;
  margin: 0 var(--space-2);
  background: rgba(100, 116, 139, 0.35);
  border-radius: 1px;
  align-self: stretch;
}

.body-diagram-half {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.body-diagram-half-head {
  text-align: center;
}

.body-diagram-half--muscle .body-diagram-half-head {
  text-align: left;
}

.body-diagram-half--fat .body-diagram-half-head {
  text-align: right;
}

.body-diagram-title {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.body-diagram-total {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}

.body-diagram-total-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.body-diagram-half--muscle .body-diagram-total-row {
  justify-content: flex-start;
}

.body-diagram-half--fat .body-diagram-total-row {
  justify-content: flex-end;
}

.body-diagram-half-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2);
  align-items: center;
  min-width: 0;
}

.body-diagram-half-body--mirror {
  grid-template-columns: auto minmax(0, 1fr);
}

.body-diagram-half-body--mirror .body-diagram-labels {
  order: 2;
}

.body-diagram-half-body--mirror .body-diagram-figure {
  order: 1;
}

.body-diagram-figure {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--space-1) 0;
  min-height: 180px;
  min-width: 0;
}

.body-diagram-figure--loading {
  font-size: 13px;
  color: var(--color-text-muted);
}

.body-figure {
  width: min(100%, 130px);
  height: auto;
  display: block;
  margin: 0 auto;
}

.body-figure:not(svg) {
  object-fit: contain;
}

svg.body-figure {
  max-height: 280px;
}

.body-diagram-labels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.seg-label-btn--trunk {
  grid-column: 1 / -1;
}

.seg-label-btn {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-left: 3px solid var(--color-primary);
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  background: transparent;
  min-width: 0;
}

.seg-label:not(.seg-label-btn) {
  border-left: 3px solid var(--color-primary);
}

.seg-label-btn:hover:not(:disabled) {
  background: rgba(30, 41, 56, 0.05);
}

.seg-label-btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.seg-label-btn:disabled {
  cursor: default;
  opacity: 0.7;
}

.seg-label--above { border-left-color: var(--color-danger); }
.seg-label--below { border-left-color: var(--color-warning); }
.seg-label-btn.seg-label--above { border-left-color: var(--color-danger); }
.seg-label-btn.seg-label--below { border-left-color: var(--color-warning); }

.seg-label-name {
  display: block;
  font-size: 10px;
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

.seg-label-name-line {
  display: block;
  line-height: 1.25;
}

.seg-label-name-line:first-child {
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.seg-label-name-line--part {
  text-transform: capitalize;
  font-weight: 500;
}

.seg-label-mass {
  display: block;
  font-size: 15px;
  font-weight: 700;
  margin-top: 2px;
}

.seg-label-value-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  margin-top: 2px;
}

.seg-label-value-row .seg-label-mass {
  display: inline;
  margin-top: 0;
}

.seg-label-pct {
  display: block;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  margin-top: 2px;
}

.seg-label .status-badge {
  margin-top: var(--space-1);
}

/* Modal */
.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(30, 41, 56, 0.45);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 360px;
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  max-height: calc(100dvh - var(--space-8));
  overflow-y: auto;
}

.modal-card--chart {
  max-width: 520px;
}

.modal-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.modal-card-head-text {
  min-width: 0;
  flex: 1;
}

.modal-card-head .modal-title {
  margin: 0 0 var(--space-1);
}

.modal-card-head .modal-text {
  margin: 0;
}

.modal-close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: var(--radius-md);
  background: rgba(30, 41, 56, 0.06);
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.modal-close:hover {
  background: rgba(30, 41, 56, 0.1);
  color: var(--color-text);
}

.modal-close:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.modal-card--chart .segment-trend-periods {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  padding-bottom: 2px;
}

.modal-card--chart .segment-trend-periods::-webkit-scrollbar {
  display: none;
}

.modal-card--chart .segment-trend-periods .period-tab {
  flex-shrink: 0;
}

.modal-card--chart .chart-canvas-wrap--modal {
  height: 220px;
  overflow: visible;
}

.modal-card--chart .chart-stats-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: var(--space-4);
}

.modal-title {
  margin: 0 0 var(--space-2);
  font-size: 18px;
  font-weight: 700;
}

.modal-text {
  margin: 0 0 var(--space-5);
  font-size: 14px;
  color: var(--color-text-muted);
}

.modal-actions {
  display: flex;
  gap: var(--space-3);
}

.modal-btn {
  flex: 1;
  margin: 0;
}

.modal-btn.btn-ghost {
  width: auto;
}

.status-badge {
  display: inline-block;
  margin-top: var(--space-1);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 600;
}

.status-badge.normal { background: rgba(0, 166, 61, 0.15); color: var(--color-success); }
.status-badge.above { background: rgba(255, 33, 87, 0.12); color: var(--color-danger); }
.status-badge.below { background: rgba(254, 153, 0, 0.15); color: var(--color-warning); }

.segment-section { margin-top: var(--space-5); }

.segment-chart-card {
  margin-bottom: var(--space-4);
}

.key-metrics-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.key-metric {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.key-metric-label {
  display: block;
  font-size: 10px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.key-metric-value {
  display: block;
  margin-top: var(--space-1);
  font-size: 20px;
  font-weight: 700;
}

.measurement-charts-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.segment-section h2 {
  margin: 0 0 var(--space-3);
  font-size: 14px;
}

.segment-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  box-shadow: var(--shadow-raised-sm);
  font-size: 13px;
}

/* Empty / loading states */
.empty-state,
.loading-state {
  padding: var(--space-8) var(--space-5);
  border-radius: var(--radius-lg);
  text-align: center;
  background: var(--color-surface);
}

.empty-title {
  margin: 0 0 var(--space-2);
  font-size: 16px;
  font-weight: 700;
}

.empty-text {
  margin: 0 0 var(--space-5);
  color: var(--color-text-muted);
  font-size: 13px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--space-4) + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  max-width: min(420px, calc(100% - var(--space-8)));
  width: calc(100% - var(--space-8));
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-text);
  color: #fff;
  font-size: 13px;
  text-align: center;
  z-index: 100;
  transition: transform 0.25s ease;
  pointer-events: none;
  display: none;
}

.toast.show {
  display: block;
  transform: translateX(-50%) translateY(0);
}

body[data-page="login"] .toast,
body[data-page="register"] .toast {
  bottom: max(var(--space-4), env(safe-area-inset-bottom));
}

/* Mobile — compact layout, no horizontal overflow */
@media (max-width: 599px) {
  :root {
    --shadow-raised: 3px 3px 10px var(--color-shadow-dark), -3px -3px 10px var(--color-shadow-light);
    --shadow-raised-sm: 2px 2px 6px var(--color-shadow-dark), -2px -2px 6px var(--color-shadow-light);
  }

  .page-title {
    font-size: 20px;
    line-height: 1.2;
    word-break: break-word;
  }

  .page-lead {
    font-size: 12px;
    line-height: 1.45;
  }

  .section-head {
    margin-bottom: var(--space-4);
  }

  .chart-head {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }

  .chart-delta-wrap {
    text-align: left;
  }

  .chart-metric-value {
    font-size: 24px;
  }

  .chart-stats-row {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }

  .sparkline-grid {
    gap: var(--space-2);
  }

  .detail-grid,
  .composition-grid,
  .goals-grid {
    grid-template-columns: 1fr;
  }

  .history-metric-value {
    font-size: 13px;
  }

  .period-tabs,
  .metric-tabs {
    gap: var(--space-1);
  }

  .period-tab,
  .metric-tab {
    font-size: 12px;
    padding: var(--space-2) var(--space-3);
    min-height: 36px;
  }

  .auth-card {
    padding: var(--space-4);
  }

  .upload-zone {
    min-height: 160px;
    padding: var(--space-4);
  }

  .seg-label-mass {
    font-size: 14px;
  }

  .header-inner {
    gap: var(--space-2);
  }

  .brand-title {
    font-size: 14px;
  }
}

@media (min-width: 480px) {
  .chart-stats-row {
    grid-template-columns: repeat(3, 1fr);
  }

  .chart-stat {
    flex-direction: column;
    text-align: center;
  }

  .chart-stat-value {
    margin-top: 2px;
  }

  .history-metrics {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-2);
  }
}

/* Tablet */
@media (min-width: 600px) {
  .app-main {
    padding-top: var(--space-6);
    padding-left: max(var(--space-6), env(safe-area-inset-left));
    padding-right: max(var(--space-6), env(safe-area-inset-right));
    padding-bottom: calc(var(--nav-h) + var(--space-8) + env(safe-area-inset-bottom));
  }

  .detail-grid,
  .composition-grid,
  .goals-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .key-metrics-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .history-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
  }

  .history-list > li {
    list-style: none;
  }
}

@media (min-width: 768px) {
  .key-metrics-row {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Desktop */
@media (min-width: 900px) {
  body {
    font-size: 16px;
    background: #ddd9d7;
  }

  .app-frame {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    align-items: start;
    align-content: start;
    gap: var(--space-4);
    padding: var(--space-4);
    box-sizing: border-box;
    max-width: var(--layout-max);
    margin: 0 auto;
    overflow: visible;
  }

  .app-frame:has(.side-nav[hidden]) {
    grid-template-columns: minmax(0, 1fr);
    max-width: min(920px, calc(100% - 2 * var(--space-4)));
  }

  .app-frame:has(.side-nav[hidden]) .app-shell {
    grid-column: 1;
    width: 100%;
  }

  .side-nav {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    margin: 0;
    padding: var(--space-5);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-lift);
    position: sticky;
    top: var(--space-4);
    height: calc(100dvh - 2 * var(--space-4));
    min-height: calc(100dvh - 2 * var(--space-4));
    max-height: calc(100dvh - 2 * var(--space-4));
    overflow: hidden;
    grid-row: 1;
    grid-column: 1;
  }

  .side-nav-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-8);
    padding-bottom: var(--space-5);
    border-bottom: 1px solid rgba(30, 41, 56, 0.06);
  }

  .side-nav-links {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    flex: 1;
  }

  .side-nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 48px;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
  }

  .side-nav-item svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
  }

  .side-nav-item:hover {
    color: var(--color-text);
    background: rgba(0, 102, 102, 0.06);
  }

  .side-nav-item.active {
    color: var(--color-primary);
    background: var(--color-surface);
    box-shadow: var(--shadow-inset);
  }

  .app-shell {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lift);
    overflow: hidden;
    flex: none;
    width: auto;
    min-width: 0;
    min-height: calc(100dvh - 2 * var(--space-4));
    background: var(--color-surface);
    margin: 0;
    grid-row: 1;
    grid-column: 2;
  }

  .app-header {
    background: var(--color-surface);
    box-shadow: none;
    border-bottom: none;
    padding: var(--space-5) var(--space-8) var(--space-4);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .brand-logo-wrap--mobile,
  .brand-title--header {
    display: none;
  }

  .header-greeting {
    font-size: clamp(20px, 2.2vw, 26px);
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.02em;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
  }

  .brand--header > div {
    min-width: 0;
  }

  .bottom-nav {
    display: none !important;
  }

  .app-main {
    padding: 0 var(--space-8) var(--space-8);
  }

  .app-shell:has(.bottom-nav[hidden]) .app-main,
  .app-shell .app-main {
    padding-bottom: var(--space-8);
  }

  body[data-page="login"] .app-main,
  body[data-page="register"] .app-main {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: calc(100dvh - 2 * var(--space-4));
  }

  .page-title {
    font-size: 32px;
  }

  .page-lead {
    font-size: 15px;
  }

  .chart-metric-value {
    font-size: 36px;
  }

  .chart-canvas-wrap {
    height: clamp(220px, 35vw, 360px);
  }

  .chart-canvas-wrap--tall {
    height: clamp(260px, 40vw, 400px);
  }

  .chart-canvas-wrap--segment {
    height: 180px;
  }

  .chart-card {
    padding: var(--space-4);
  }

  .detail-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .detail-value {
    font-size: 18px;
  }

  .detail-card {
    padding: var(--space-4);
  }

  .body-diagram-card {
    padding: var(--space-5);
  }

  .dashboard-grid {
    display: grid;
    grid-template-columns: 1.35fr 1fr;
    gap: var(--space-6);
    align-items: start;
  }

  .dashboard-aside .sparkline-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .history-list {
    grid-template-columns: repeat(2, 1fr);
  }

  .upload-zone {
    min-height: 280px;
  }

  .toast {
    bottom: var(--space-6);
  }

  #history-content .chart-card + .section-subtitle {
    margin-top: var(--space-2);
  }

  .measurement-charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
  }

  .measurement-charts-grid .chart-card:first-child {
    grid-column: 1 / -1;
    max-width: 520px;
  }

  .body-diagram-divider {
    margin: 0 var(--space-4);
  }

  .body-diagram-total {
    font-size: 22px;
  }

  .body-figure {
    width: min(100%, 160px);
  }

  svg.body-figure {
    max-height: 320px;
  }
}

@media (max-width: 899px) {
  .body-diagram-split {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .body-diagram-divider {
    width: 100%;
    height: 2px;
    margin: var(--space-4) 0;
  }

  .body-diagram-half-head,
  .body-diagram-half--muscle .body-diagram-half-head,
  .body-diagram-half--fat .body-diagram-half-head {
    text-align: center;
  }

  .body-diagram-half-body,
  .body-diagram-half-body--mirror {
    grid-template-columns: 1fr;
  }

  .body-diagram-half-body .body-diagram-figure,
  .body-diagram-half-body--mirror .body-diagram-figure {
    order: 1;
  }

  .body-diagram-half-body .body-diagram-labels,
  .body-diagram-half-body--mirror .body-diagram-labels {
    order: 2;
  }
}

@media (min-width: 1200px) {
  .dashboard-grid {
    grid-template-columns: 1.5fr 1fr;
  }

  .dashboard-aside .sparkline-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-list {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
