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

html {
  color-scheme: dark;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-family);
  font-feature-settings: var(--num);
  line-height: 1.45;
  padding-bottom: 96px;
}

button {
  font-family: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-xs);
}

:root {
  --content-width: 720px;
}

/* ---------- Topbar ---------- */
.topbar {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 24px var(--space) 8px;
}

.brand {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.2px;
}

.brand-sub {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 400;
  letter-spacing: 0.01em;
}

main {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 8px var(--space);
}

.tab-panel {
  animation: fade-in 0.25s ease;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space);
  margin-bottom: 16px;
}

.card-title {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 12px;
}

/* ---------- Home ---------- */
.hero {
  text-align: center;
  padding: 28px var(--space) 24px;
  background-image: radial-gradient(
      60% 80% at 50% 0%,
      var(--accent-soft),
      transparent 70%
    ),
    linear-gradient(180deg, var(--accent-soft), transparent 40%),
    var(--surface);
}

.hero-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0 0 6px;
}

.trend-big {
  font-size: 3.75rem;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -1px;
  margin: 0;
}

.trend-unit {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 4px;
}

.delta-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.9375rem;
  font-weight: 600;
}

.delta-badge.loss {
  background: var(--success-soft);
  color: var(--success);
}

.delta-badge.gain {
  background: var(--danger-soft);
  color: var(--danger);
}

.delta-badge.flat {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.sparkline {
  margin-top: 20px;
  width: 100%;
  height: 64px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 560px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
}

.kpi-sub {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin: 2px 0 0;
}

/* ---------- IMC ---------- */
.imc-tag {
  display: inline-flex;
  align-items: center;
  margin: 6px 0 0;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.imc-low {
  background: var(--warn-soft);
  color: var(--warn);
}

.imc-normal {
  background: var(--success-soft);
  color: var(--success);
}

.imc-high {
  background: var(--warn-soft);
  color: var(--warn);
}

.imc-obese {
  background: var(--danger-soft);
  color: var(--danger);
}

.progress-track {
  height: 12px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 999px;
  width: 0;
  transition: width 0.5s ease;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin-top: 8px;
}

.milestone-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.milestone-flag {
  display: inline-flex;
  color: var(--accent-hover);
}

.milestone-flag svg {
  width: 22px;
  height: 22px;
}

/* ---------- Chart ---------- */
.range-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.range-btn {
  min-height: 44px;
  min-width: 48px;
  padding: 8px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  transition: transform 0.06s ease, background 0.15s ease, color 0.15s ease;
}

.range-btn.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.range-btn:active {
  transform: scale(0.96);
}

.chart-box {
  position: relative;
  min-height: 320px;
  touch-action: pan-y;
}

.chart-box svg {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.8125rem;
  transform: translate(-50%, -110%);
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 2;
}

.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 12px;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 12px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}

.swatch-dashed {
  background-image: linear-gradient(
    90deg,
    var(--forecast) 40%,
    transparent 40%,
    transparent 60%,
    var(--forecast) 60%,
    var(--forecast) 100%
  );
}

.swatch-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* ---------- Journal ---------- */
.journal-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.journal-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.journal-item:last-child {
  border-bottom: none;
}

.journal-date {
  flex: 1;
  font-size: 0.9375rem;
}

.journal-weight {
  font-weight: 700;
  font-size: 1.0625rem;
}

.journal-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  transition: transform 0.06s ease, color 0.15s ease;
}

.icon-btn:hover {
  color: var(--text);
}

.icon-btn:active {
  transform: scale(0.92);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* ---------- Milestones ---------- */
.milestone-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
}

.milestone-item.reached .milestone-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px var(--success-soft);
}

.milestone-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.milestone-info {
  flex: 1;
}

.milestone-name {
  font-weight: 600;
  font-size: 0.9375rem;
}

.milestone-sub {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

/* ---------- Settings ---------- */
.field {
  display: block;
  margin-bottom: 16px;
}

.field > span {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="date"],
input[type="number"],
input[type="text"] {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}

input:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.settings-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ---------- Buttons ---------- */
.btn {
  min-height: 48px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 600;
  transition: transform 0.06s ease, background 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

.btn-danger {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: 96px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 30px rgba(124, 108, 255, 0.35);
  z-index: 10;
  transition: transform 0.1s ease, background 0.15s ease;
}

.fab svg {
  width: 26px;
  height: 26px;
}

.fab:hover {
  background: var(--accent-hover);
}

.fab:active {
  transform: scale(0.92);
}

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(7, 8, 11, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
  z-index: 20;
}

.tab-btn {
  flex: 1;
  max-width: 120px;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.6875rem;
  font-weight: 600;
  transition: transform 0.06s ease, color 0.15s ease;
}

.tab-btn svg {
  width: 22px;
  height: 22px;
}

.tab-btn.is-active {
  color: var(--accent-hover);
}

.tab-btn:active {
  transform: scale(0.94);
}

/* ---------- Modal ---------- */
.modal {
  border: none;
  background: transparent;
  padding: 0;
  max-width: none;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  overflow-y: auto;
}

.modal::backdrop {
  background: rgba(3, 4, 6, 0.72);
  backdrop-filter: blur(4px);
}

.modal-card {
  max-width: 420px;
  margin: 12vh auto 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0;
}

.modal-help {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin: 0 0 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

.import-result {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin: 0 0 4px;
}

.import-result.ok {
  background: var(--success-soft);
  color: var(--success);
}

.import-result.err {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------- Stepper ---------- */
.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.step-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.75rem;
  line-height: 1;
  transition: transform 0.06s ease, border-color 0.15s ease;
  flex-shrink: 0;
}

.step-btn:hover {
  border-color: var(--accent);
}

.step-btn:active {
  transform: scale(0.9);
}

.stepper-value {
  flex: 1;
  min-width: 0;
  font-size: 2.25rem;
  font-weight: 700;
  text-align: center;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 0;
  min-height: 0;
  -moz-appearance: textfield;
}

.stepper-value::-webkit-outer-spin-button,
.stepper-value::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 0.875rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  z-index: 30;
}

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 32px 0;
}

.hidden {
  display: none;
}

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