:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #18212f;
  --muted: #667085;
  --line: #d8dee8;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --teal: #0f766e;
  --green-bg: #dcfce7;
  --green-ink: #166534;
  --amber-bg: #fef3c7;
  --amber-ink: #92400e;
  --red-bg: #fee2e2;
  --red-ink: #991b1b;
  --shadow: 0 12px 30px rgba(20, 30, 50, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
}

.brand,
.nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  font-weight: 800;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 0.8rem;
  letter-spacing: 0;
}

.nav {
  flex-wrap: wrap;
  justify-content: flex-end;
  font-size: 0.95rem;
  color: var(--muted);
}

.menu-toggle {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.menu-toggle span:not(.sr-only) {
  display: block;
  width: 18px;
  height: 2px;
  margin: 4px auto;
  border-radius: 999px;
  background: var(--ink);
}

.menu-toggle.open span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.menu-toggle.open span:nth-child(2) {
  opacity: 0;
}

.menu-toggle.open span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.nav a,
.link-button {
  min-height: 38px;
  padding: 8px 10px;
  border-radius: 8px;
}

.nav a:hover,
.link-button:hover {
  background: #eef2f7;
  color: var(--ink);
}

.link-button {
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.page {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

.auth-shell {
  min-height: calc(100vh - 160px);
  display: grid;
  align-items: center;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel {
  width: min(440px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 22px;
}

.dashboard-head {
  align-items: center;
}

.dashboard-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.calendar-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, auto));
  justify-content: end;
}

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

h1 {
  margin-bottom: 6px;
  font-size: clamp(2rem, 1.6rem + 1.3vw, 3rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.12rem;
  line-height: 1.2;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.flash {
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 700;
}

.flash-success {
  background: var(--green-bg);
  color: var(--green-ink);
}

.flash-error {
  background: var(--red-bg);
  color: var(--red-ink);
}

.stack {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 0.92rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid #c9d2df;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

input:focus,
select:focus {
  outline: 3px solid rgba(37, 99, 235, 0.18);
  border-color: var(--blue);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
}

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

.button.primary:hover {
  background: var(--blue-dark);
}

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

.button.secondary:hover {
  background: #f8fafc;
}

.wizard {
  padding: 24px;
}

.stepper {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 0;
  margin: 0 0 24px;
  list-style: none;
}

.stepper li {
  min-height: 38px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #eef2f7;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.stepper li.active {
  background: #dbeafe;
  color: #1e40af;
}

.wizard-step {
  display: none;
}

.wizard-step.active {
  display: grid;
  gap: 20px;
}

.two-col,
.metric-grid,
.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.wizard-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.summary-grid,
.metric-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.summary-item,
.metric {
  padding: 18px;
}

.summary-item span,
.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.summary-item strong,
.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 1.55rem;
  line-height: 1.15;
}

.metric small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.status {
  flex: 0 0 auto;
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 900;
}

.status.good {
  background: var(--green-bg);
  color: var(--green-ink);
}

.status.warn {
  background: var(--amber-bg);
  color: var(--amber-ink);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 900;
}

.badge-success {
  background: var(--green-bg);
  color: var(--green-ink);
}

.badge-fail {
  background: var(--red-bg);
  color: var(--red-ink);
}

.progress-panel {
  margin-top: 16px;
  padding: 20px;
}

.progress-copy,
.section-title {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.progress-copy strong {
  font-size: 1.5rem;
}

.progress-track {
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--blue));
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.home-summary-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

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

.chart-panel,
.today-steps-card,
.info-grid .panel,
.settings-panel {
  padding: 20px;
}

.today-steps-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.today-steps-card h2 {
  margin-bottom: 4px;
  font-size: 2.25rem;
}

.today-step-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.today-ring-wrap {
  display: grid;
  justify-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.modal {
  width: min(440px, calc(100% - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(20, 30, 50, 0.24);
  color: var(--ink);
}

.modal::backdrop {
  background: rgba(24, 33, 47, 0.42);
  backdrop-filter: blur(3px);
}

.modal[open] {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.modal-head h2 {
  margin-bottom: 0;
}

.modal-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 1.2rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  background: #f8fafc;
  color: var(--ink);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

#weightChart {
  display: block;
  width: 100%;
  min-height: 280px;
}

.steps-shell {
  padding: 20px;
  background: var(--panel);
  color: var(--ink);
}

.steps-weekdays,
.steps-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.steps-weekdays {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
  text-align: center;
}

.steps-calendar {
  gap: 10px 8px;
}

.step-cell {
  min-width: 0;
  min-height: 112px;
}

.step-cell.empty {
  opacity: 0;
}

.step-day {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 5px;
  width: 100%;
  padding: 8px 4px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.step-day:hover,
.step-day:focus-visible {
  background: #f8fafc;
  border-color: #c9d2df;
  outline: none;
}

.step-day.today {
  border-color: rgba(15, 118, 110, 0.5);
  background: #f0fdfa;
}

.step-ring {
  position: relative;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: conic-gradient(#e11d48 var(--progress), #ffe8ee 0);
  box-shadow: inset 0 0 0 1px rgba(24, 33, 47, 0.05);
}

.step-ring-inner {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--panel);
}

.step-ring-inner strong {
  font-size: 0.78rem;
}

.today-step-ring {
  width: 112px;
  height: 112px;
}

.today-step-ring .step-ring-inner {
  width: 72px;
  height: 72px;
}

.today-step-ring .step-ring-inner strong {
  font-size: 1.1rem;
}

.today-step-ring.closed {
  background: conic-gradient(#e11d48 100%, #e11d48 0);
}

.step-day.closed .step-ring {
  background: conic-gradient(#e11d48 100%, #e11d48 0);
}

.target-dot {
  position: absolute;
  top: 6px;
  right: calc(50% - 36px);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: transparent;
}

.step-day.closed .target-dot {
  background: #84cc16;
  box-shadow: 0 0 0 2px rgba(132, 204, 22, 0.16);
}

.step-date {
  font-size: 1rem;
  font-weight: 900;
}

.step-count {
  max-width: 100%;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.facts {
  display: grid;
  gap: 12px;
  margin: 0;
}

.facts div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.facts div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.facts dt {
  color: var(--muted);
  font-weight: 700;
}

.facts dd {
  margin: 0;
  font-weight: 900;
}

.info-grid {
  margin-top: 16px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

@media (max-width: 900px) {
  .summary-grid,
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid,
  .info-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    position: static;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 14px 16px;
  }

  .menu-toggle {
    display: block;
  }

  .nav {
    display: none;
    grid-column: 1 / -1;
    width: 100%;
    justify-content: stretch;
    align-items: stretch;
    padding-top: 8px;
  }

  .nav.open {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .nav a,
  .nav form,
  .link-button {
    width: 100%;
  }

  .nav a,
  .link-button {
    justify-content: flex-start;
    text-align: left;
  }

  .page {
    width: min(100% - 24px, 1160px);
    padding-top: 22px;
  }

  .page-head,
  .dashboard-head,
  .progress-copy,
  .section-title {
    display: grid;
  }

  .today-steps-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .dashboard-actions {
    display: flex;
    justify-content: flex-start;
  }

  .calendar-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .two-col,
  .summary-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

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

  .wizard-actions {
    display: grid;
  }

  .modal-actions {
    display: grid;
  }

  .button {
    width: 100%;
  }

  .today-step-actions {
    display: grid;
  }

  .today-ring-wrap {
    justify-items: center;
    align-self: center;
  }
  }

  .steps-shell {
    padding: 14px 10px;
  }

  .steps-calendar {
    gap: 8px 4px;
  }

  .step-cell {
    min-height: 88px;
  }

  .step-ring {
    width: 44px;
    height: 44px;
  }

  .step-ring-inner {
    width: 26px;
    height: 26px;
  }

  .today-step-ring {
    width: 96px;
    height: 96px;
  }

  .today-step-ring .step-ring-inner {
    width: 62px;
    height: 62px;
  }

  .today-step-ring .step-ring-inner strong {
    font-size: 1rem;
  }

  .step-count {
    display: none;
  }
}

@media (max-width: 380px) {
  .today-steps-card {
    grid-template-columns: 1fr;
  }

  .today-ring-wrap {
    justify-items: center;
  }
}
