:root {
  color-scheme: light;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #ecfdf5;
  --blue: #2563eb;
  --orange: #d97706;
  --red: #dc2626;
  --ink: #17202f;
  --muted: #64748b;
  --line: #e2e8f0;
  --surface: #ffffff;
  --background: #f4f7f7;
  --shadow: 0 8px 28px rgba(15, 76, 70, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--background);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 100% 0, rgba(15, 118, 110, 0.1), transparent 32%),
    var(--background);
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding:
    max(18px, env(safe-area-inset-top))
    18px
    calc(100px + env(safe-area-inset-bottom));
}

.app-header,
.section-heading,
.page-title,
.dialog-header,
.card-heading,
.measurement-main,
.profile-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-header {
  margin-bottom: 22px;
}

.app-header h1,
.page-title h2,
.section-heading h2,
.dialog-header h2 {
  margin: 0;
}

.app-header h1 {
  font-size: 30px;
  letter-spacing: -0.04em;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 16px;
  color: white;
  background: var(--primary);
  box-shadow: 0 8px 20px rgba(15, 118, 110, 0.24);
  font-size: 27px;
}

.update-banner,
.backup-reminder {
  width: 100%;
  border-radius: 15px;
  text-align: left;
}

.update-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -7px 0 16px;
  padding: 12px 14px;
  border: 0;
  color: white;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}

.update-banner strong,
.update-banner small,
.backup-reminder strong,
.backup-reminder small {
  display: block;
}

.update-banner small {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.78);
}

.backup-reminder {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #fde68a;
  color: #92400e;
  background: #fffbeb;
}

.backup-reminder small {
  margin-top: 2px;
  color: #b45309;
}

.page {
  display: none;
}

.page.active {
  display: block;
  animation: page-in 160ms ease-out;
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 27px;
}

.summary-card,
.profile-card,
.measurement-card,
.settings-card,
.chart-card,
.analysis-card,
.empty-state {
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 19px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.summary-card {
  min-width: 0;
  padding: 16px 12px;
}

.summary-card strong {
  display: block;
  overflow: hidden;
  margin-bottom: 3px;
  font-size: clamp(20px, 6vw, 27px);
  letter-spacing: -0.04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-card span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-card.primary {
  color: white;
  border-color: transparent;
  background: linear-gradient(145deg, #0f766e, #14b8a6);
}

.summary-card.primary span {
  color: rgba(255, 255, 255, 0.78);
}

.section-heading,
.page-title {
  align-items: flex-end;
  margin: 24px 2px 12px;
}

.page-title {
  align-items: center;
  margin-top: 0;
  margin-bottom: 18px;
}

.section-heading h2,
.page-title h2 {
  font-size: 20px;
}

.section-heading p,
.page-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.text-button {
  padding: 8px;
  border: 0;
  color: var(--primary);
  background: transparent;
}

.primary,
.secondary,
.danger-button {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 13px;
  font-weight: 650;
}

.primary {
  border: 1px solid var(--primary);
  color: white;
  background: var(--primary);
}

.primary:active {
  background: var(--primary-dark);
}

.secondary {
  border: 1px solid var(--line);
  color: var(--ink);
  background: white;
}

.danger-button {
  border: 1px solid #fecaca;
  color: var(--red);
  background: #fff5f5;
}

.small {
  min-height: 38px;
  padding: 8px 13px;
  font-size: 14px;
}

.full {
  width: 100%;
}

.card-list {
  display: grid;
  min-width: 0;
  gap: 11px;
}

.profile-card,
.measurement-card {
  padding: 16px;
}

.profile-main,
.measurement-main {
  align-items: flex-start;
}

.profile-card h3,
.measurement-card h3,
.settings-card h3,
.chart-card h3,
.analysis-card h3 {
  margin: 0;
  font-size: 17px;
}

.profile-card p,
.measurement-card p,
.settings-card p,
.chart-card p,
.analysis-card p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.latest-value {
  flex: 0 0 auto;
  text-align: right;
}

.latest-value strong {
  display: block;
  color: var(--primary);
  font-size: 21px;
}

.latest-value span {
  color: var(--muted);
  font-size: 11px;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.metric {
  min-width: 0;
  padding: 10px;
  border-radius: 13px;
  background: #f8fafc;
}

.metric strong,
.metric span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric strong {
  font-size: 15px;
}

.metric span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.card-actions,
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.card-actions button {
  min-height: 37px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: white;
  font-size: 13px;
}

.card-actions button.action-primary {
  border-color: #99f6e4;
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.card-actions button.action-danger {
  color: var(--red);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 650;
}

.badge.warning {
  color: #92400e;
  background: #fffbeb;
}

.badge.muted {
  color: #475569;
  background: #f1f5f9;
}

.filter-row,
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.filter-row {
  margin-bottom: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  margin-top: 7px;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  color: var(--ink);
  background: white;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

textarea {
  resize: vertical;
}

.field-select {
  margin: 0 0 14px;
}

label {
  display: block;
  margin-bottom: 15px;
  color: #334155;
  font-size: 13px;
  font-weight: 600;
}

.form-hint,
.status-text {
  padding: 10px 12px;
  border-radius: 12px;
  color: #475569;
  background: #f8fafc;
  font-size: 12px;
  line-height: 1.55;
}

.settings-card,
.chart-card,
.analysis-card {
  display: grid;
  gap: 12px;
  margin-bottom: 13px;
  padding: 17px;
}

.settings-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 12px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-weight: 750;
}

.source-list {
  display: grid;
  gap: 10px;
}

.source-item {
  padding: 11px;
  border-radius: 12px;
  background: #f8fafc;
}

.source-item strong,
.source-item small {
  display: block;
}

.source-item small {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.45;
}

.source-item a {
  color: var(--primary);
}

.chart-wrap {
  overflow-x: auto;
  margin-top: 4px;
}

.chart {
  display: block;
  width: 100%;
  min-width: 560px;
  height: auto;
}

.chart-grid {
  stroke: #e2e8f0;
  stroke-width: 1;
}

.chart-axis-label,
.chart-label {
  fill: #64748b;
  font-size: 10px;
}

.chart-line {
  fill: none;
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.chart-line.weight {
  stroke: var(--blue);
}

.chart-line.bmi {
  stroke: var(--orange);
}

.chart-reference {
  fill: none;
  stroke: #94a3b8;
  stroke-dasharray: 5 5;
  stroke-width: 1.2;
}

.chart-dot {
  fill: white;
  stroke: var(--primary);
  stroke-width: 3;
}

.chart-dot.weight {
  stroke: var(--blue);
}

.chart-dot.bmi {
  stroke: var(--orange);
}

.analysis-result {
  padding: 13px;
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  background: #f8fafc;
}

.analysis-result.warning {
  border-left-color: var(--orange);
}

.analysis-result strong,
.analysis-result span {
  display: block;
}

.analysis-result span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.standard-switch {
  margin: 12px 0;
  padding: 10px 12px;
  border: 1px solid #bfdbfe;
  border-radius: 12px;
  color: #1e40af;
  background: #eff6ff;
  font-size: 12px;
  line-height: 1.5;
}

.empty-state {
  padding: 30px 18px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  display: block;
  margin-bottom: 5px;
  color: var(--ink);
}

.trash-list {
  display: grid;
  gap: 8px;
}

.trash-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: #f8fafc;
}

.trash-item button {
  flex: 0 0 auto;
}

.bottom-nav {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  width: min(100%, 760px);
  margin: 0 auto;
  padding:
    8px
    10px
    calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(226, 232, 240, 0.9);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.06);
  backdrop-filter: blur(18px);
}

.nav-item {
  display: grid;
  min-width: 0;
  min-height: 54px;
  padding: 5px 2px;
  place-items: center;
  border: 0;
  border-radius: 13px;
  color: #64748b;
  background: transparent;
}

.nav-item span {
  font-size: 19px;
}

.nav-item small {
  font-size: 10px;
}

.nav-item.active {
  color: var(--primary);
  background: var(--primary-soft);
}

.nav-item.quick-action {
  color: white;
  background: var(--primary);
}

dialog {
  width: min(calc(100% - 28px), 560px);
  max-height: min(86vh, 800px);
  padding: 20px;
  overflow-y: auto;
  border: 0;
  border-radius: 22px;
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.3);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(3px);
}

.dialog-header {
  margin-bottom: 20px;
}

.dialog-close {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 12px;
  color: var(--muted);
  background: #f1f5f9;
  font-size: 23px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.detail-cell {
  padding: 12px;
  border-radius: 12px;
  background: #f8fafc;
}

.detail-cell strong,
.detail-cell span {
  display: block;
}

.detail-cell span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 18px;
  bottom: calc(92px + env(safe-area-inset-bottom));
  left: 18px;
  width: fit-content;
  max-width: min(520px, calc(100% - 36px));
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 14px;
  color: white;
  background: #17202f;
  box-shadow: 0 12px 35px rgba(15, 23, 42, 0.28);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 520px) {
  .app-shell {
    padding-right: 14px;
    padding-left: 14px;
  }

  .summary-grid {
    gap: 7px;
  }

  .summary-card {
    padding: 14px 9px;
  }

  .form-grid,
  .filter-row {
    grid-template-columns: 1fr;
  }

  .metric-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .bottom-nav {
    padding-right: 5px;
    padding-left: 5px;
  }
}
