:root {
  --page: #f4f7fb;
  --ink: #172033;
  --muted: #657085;
  --line: #d8dfeb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --nav: #111827;
  --nav-soft: #1f2937;
  --teal: #0f766e;
  --teal-soft: #dff5f1;
  --blue: #2563eb;
  --blue-soft: #e7efff;
  --amber: #b45309;
  --amber-soft: #fff3d6;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --green: #15803d;
  --green-soft: #dcfce7;
  --shadow: 0 18px 50px rgba(23, 32, 51, 0.12);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 56px);
  line-height: 1.04;
}

h2 {
  margin-bottom: 0;
  font-size: 24px;
  line-height: 1.2;
}

h3 {
  margin-bottom: 10px;
  font-size: 18px;
}

.overline {
  margin-bottom: 6px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hint,
.muted {
  color: var(--muted);
}

.auth-page {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, 480px);
  min-height: 100dvh;
  padding: 28px;
  gap: 24px;
}

.auth-intro {
  display: flex;
  min-height: calc(100dvh - 56px);
  border-radius: 18px;
  padding: 34px;
  flex-direction: column;
  justify-content: space-between;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.92), rgba(37, 99, 235, 0.84)),
    #0f172a;
  color: #fff;
  overflow: hidden;
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 850;
}

.brand-symbol {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: #fff;
  color: var(--teal);
  font-weight: 900;
}

.intro-copy {
  max-width: 780px;
}

.intro-copy .overline {
  color: #c7fff4;
}

.intro-copy p:not(.overline) {
  max-width: 680px;
  margin-top: 18px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 18px;
}

.intro-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.intro-grid div {
  min-height: 112px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 14px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.12);
}

.intro-grid strong,
.intro-grid span {
  display: block;
}

.intro-grid span {
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.76);
  font-size: 14px;
}

.auth-card {
  align-self: center;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.invite-page {
  min-height: 100vh;
  place-items: center;
}

.invite-card {
  max-width: 520px;
}

.invite-summary {
  margin: 18px 0;
}

.invite-detail-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.invite-detail-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.invite-detail-list dt {
  color: var(--muted);
}

.invite-detail-list dd {
  margin: 0;
  font-weight: 760;
  text-align: right;
}

.auth-card-head {
  margin-bottom: 18px;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 18px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
}

.mode-button,
.filter-pill {
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 760;
}

.mode-button.active,
.filter-pill.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 5px rgba(23, 32, 51, 0.1);
}

.auth-form,
.create-form,
.field-grid {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 760;
}

.field-help {
  color: var(--muted);
  font-size: 12px;
  font-weight: 560;
  line-height: 1.4;
}

.field-note {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.weekday-field {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.weekday-field legend {
  padding: 0 4px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 760;
}

.weekday-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.weekday-grid label,
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.weekday-grid input,
.check-row input {
  width: 18px;
  min-height: 18px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  background: var(--surface);
  color: var(--ink);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 2px;
}

.form-error {
  min-height: 22px;
  margin: 0;
  color: var(--red);
  font-size: 14px;
  font-weight: 760;
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 820;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.button:active,
.icon-button:active,
.side-nav-item:active,
.scenario-card:active {
  transform: scale(0.98);
}

.button.primary {
  background: var(--ink);
  color: #fff;
}

.button.primary:hover {
  background: #0f172a;
}

.button.subtle {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.button.small {
  min-height: 36px;
  padding: 7px 10px;
}

.button.full {
  width: 100%;
}

.icon-button {
  width: 44px;
  padding: 0;
  background: var(--surface-2);
  color: var(--ink);
}

.app-frame {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100dvh;
  padding: 22px;
  flex-direction: column;
  background: var(--nav);
  color: #fff;
}

.app-brand {
  margin-bottom: 32px;
}

.app-brand .brand-symbol {
  background: var(--teal);
  color: #fff;
}

.side-nav {
  display: grid;
  gap: 8px;
}

.side-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 12px;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  text-align: left;
  font-weight: 780;
}

.side-nav-item.active {
  background: var(--nav-soft);
  color: #fff;
}

.nav-glyph {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 12px;
}

.account-card {
  display: grid;
  gap: 14px;
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.08);
}

.account-label {
  display: block;
  color: rgba(255, 255, 255, 0.64);
  font-size: 12px;
}

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

.main-shell {
  padding: 24px;
}

.app-header,
.section-title-row,
.dialog-header,
.dialog-actions,
.card-head,
.plan-title-row,
.record-row,
.family-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.app-header {
  margin-bottom: 18px;
}

.summary-strip,
.flow-section,
.content-panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 8px 26px rgba(23, 32, 51, 0.06);
}

.summary-strip,
.flow-section {
  margin-bottom: 16px;
  padding: 16px;
}

.content-panel {
  padding: 16px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  min-height: 88px;
  border-radius: 14px;
  padding: 14px;
  background: var(--surface-2);
}

.metric-value {
  font-size: 28px;
  font-weight: 900;
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-pill {
  border: 1px solid var(--line);
  padding: 8px 11px;
  background: var(--surface);
}

.quick-start {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  background: var(--surface-2);
}

.quick-start strong {
  display: block;
  margin-bottom: 4px;
}

.quick-start p {
  margin-bottom: 0;
  color: var(--muted);
}

.form-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.form-section-head h3 {
  margin-bottom: 4px;
}

.step-draft-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.draft-loop-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: var(--surface-2);
}

.draft-loop-tools > div {
  display: grid;
  gap: 2px;
}

.draft-loop-tools strong {
  font-size: 14px;
}

.draft-loop-tools span,
.loop-block-meta {
  color: var(--muted);
  font-size: 13px;
}

.draft-loop-tools label,
.loop-block-controls label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.draft-loop-tools input,
.loop-block-controls input {
  width: 72px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  background: #fff;
}

.draft-empty {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 12px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 14px;
}

.draft-step {
  display: grid;
  grid-template-columns: 24px 28px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: var(--surface-2);
}

.draft-step-select {
  display: inline-grid;
  place-items: center;
}

.draft-step-select input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.draft-step.compact {
  background: var(--surface);
}

.draft-step.editing {
  border-color: rgba(15, 118, 110, 0.5);
  background: var(--teal-soft);
}

.draft-step-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.draft-step > span,
.step-progress-row > span {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 13px;
  font-weight: 900;
}

.draft-step p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.exercise-meta {
  margin: 4px 0 0;
  color: var(--teal);
  font-size: 13px;
  font-weight: 760;
}

.tag-row,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  background: #eef2f7;
  color: #344154;
  font-size: 13px;
  font-weight: 800;
}

.tag.medication {
  background: var(--blue-soft);
  color: #1d4ed8;
}

.tag.exercise {
  background: #ede9fe;
  color: #5b21b6;
}

.tag.family {
  background: var(--amber-soft);
  color: var(--amber);
}

.tag.success {
  background: var(--green-soft);
  color: var(--green);
}

.tag.warning {
  background: var(--amber-soft);
  color: var(--amber);
}

.tag.danger {
  background: var(--red-soft);
  color: var(--red);
}

.card-list,
.record-grid {
  display: grid;
  gap: 12px;
}

.action-card,
.plan-card,
.summary-card,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: var(--surface);
}

.action-card.needs_attention,
.action-card.issue {
  border-color: rgba(185, 28, 28, 0.28);
  background: #fff8f8;
}

.meta-line,
.item-meta {
  color: var(--muted);
  font-size: 14px;
}

.item-meta {
  margin: 4px 0 0;
}

.loop-preview,
.step-progress {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.loop-block,
.repeat-block {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: var(--surface-2);
}

.draft-loop-block,
.progress-loop-block,
.progress-repeat-block {
  border-color: rgba(91, 33, 182, 0.24);
  background: #fbfaff;
}

.loop-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.loop-block-head strong {
  min-width: 0;
  color: var(--ink);
  font-size: 14px;
}

.loop-block-head span {
  flex: 0 0 auto;
  color: #5b21b6;
  font-size: 12px;
  font-weight: 840;
}

.loop-block-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.loop-block-meta {
  margin: 0;
}

.loop-round-preview,
.loop-step-list {
  display: grid;
  gap: 6px;
}

.loop-round-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.loop-round-strip span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 820;
}

.loop-round-strip span.done {
  border-color: rgba(22, 163, 74, 0.28);
  background: var(--green-soft);
  color: var(--green);
}

.loop-round-strip span.active {
  border-color: rgba(15, 118, 110, 0.32);
  background: var(--teal-soft);
  color: var(--teal);
}

.loop-round {
  display: grid;
  gap: 6px;
}

.loop-round-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 820;
}

.loop-inline-items {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.loop-inline-items span,
.loop-single {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.summary-loop-block {
  padding: 8px;
}

.workout-session {
  display: grid;
  gap: 10px;
  margin: 12px 0;
  border: 1px solid rgba(15, 118, 110, 0.3);
  border-radius: 14px;
  padding: 12px;
  background: var(--teal-soft);
}

.workout-session-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.workout-session-head span {
  color: var(--teal);
  font-size: 13px;
  font-weight: 850;
}

.workout-session-head strong {
  color: var(--ink);
  font-size: 38px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.workout-timer-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.16);
  overflow: hidden;
}

.workout-timer-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 240ms linear;
}

.workout-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.workout-note {
  margin: 0;
  color: #0f766e;
  font-size: 13px;
  font-weight: 760;
}

.completion-note {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(21, 128, 61, 0.24);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--green-soft);
  color: var(--green);
  text-align: center;
  font-weight: 840;
}

.completed-actions {
  display: grid;
  width: 100%;
  gap: 8px;
}

.step-progress-head {
  color: var(--ink);
  font-size: 13px;
  font-weight: 820;
}

.step-progress-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px;
  color: var(--muted);
  font-size: 13px;
}

.step-progress-row.active {
  border-color: rgba(15, 118, 110, 0.45);
  background: var(--teal-soft);
  color: var(--ink);
}

.step-progress-row.done {
  background: var(--green-soft);
  color: var(--green);
}

.step-progress-row em {
  font-style: normal;
  font-weight: 820;
}

.step-progress-row strong {
  display: grid;
  gap: 2px;
}

.step-progress-row small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.action-body {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 14px;
  margin: 14px 0;
}

.media-tile {
  min-height: 108px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  overflow: hidden;
}

.media-preview {
  display: grid;
  place-items: center;
  min-height: 108px;
  padding: 12px;
  color: #1d4ed8;
  text-align: center;
  font-size: 13px;
  font-weight: 820;
}

.media-preview.video {
  background: linear-gradient(135deg, #eef2ff, #e0f2fe);
  color: #3730a3;
}

.status-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 128px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.status-button.primary {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.status-button.warn {
  border-color: #f6d98f;
  background: var(--amber-soft);
  color: var(--amber);
}

.status-button.danger {
  border-color: #fecaca;
  background: var(--red-soft);
  color: var(--red);
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.group-section + .group-section {
  margin-top: 18px;
}

.group-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.group-header h3 {
  margin-bottom: 0;
}

.group-header span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.record-row,
.family-row {
  min-height: 58px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 12px;
}

.empty-state {
  color: var(--muted);
}

.mobile-nav {
  position: fixed;
  left: 50%;
  bottom: 12px;
  z-index: 10;
  display: none;
  grid-template-columns: repeat(4, 1fr);
  width: min(520px, calc(100% - 24px));
  min-height: 62px;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.mobile-nav-item {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 820;
}

.mobile-nav-item.active {
  background: var(--teal-soft);
  color: var(--teal);
}

.create-dialog {
  width: min(820px, calc(100% - 24px));
  max-height: calc(100dvh - 32px);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.create-dialog::backdrop {
  background: rgba(15, 23, 42, 0.54);
}

.create-form {
  padding: 20px;
}

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

.form-section {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check-row input {
  width: 20px;
  min-height: 20px;
}

.dialog-actions {
  margin-top: 18px;
}

@media (max-width: 1180px) {
  .auth-page {
    grid-template-columns: 1fr;
  }

  .auth-intro {
    min-height: auto;
  }

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

@media (max-width: 900px) {
  body {
    padding-bottom: 80px;
  }

  .app-frame {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px 16px;
  }

  .side-nav {
    display: none;
  }

  .account-card {
    display: none;
  }

  .main-shell {
    padding: 14px;
  }

  .mobile-nav {
    display: grid;
  }

  .app-header,
  .section-title-row {
    align-items: stretch;
    flex-direction: column;
  }

  .metric-grid,
  .plan-grid {
    grid-template-columns: 1fr;
  }

  .weekday-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .auth-page {
    padding: 12px;
  }

  .auth-intro,
  .auth-card {
    border-radius: 16px;
    padding: 20px;
  }

  .intro-grid,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .quick-start {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-pills {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-pill:first-child {
    grid-column: 1 / -1;
  }

  .action-body {
    grid-template-columns: 1fr;
  }

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

  .form-section-head,
  .draft-step,
  .loop-block-head {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .inline-actions {
    justify-content: stretch;
  }

  .inline-actions .button {
    flex: 1 1 180px;
  }

  .app-header .button,
  .dialog-actions .button {
    width: 100%;
  }
}
