:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-weight: #2a78d6;
  --series-goal: #898781;
  --good: #006300;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-weight: #3987e5;
    --series-goal: #898781;
    --good: #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-weight: #3987e5;
  --series-goal: #898781;
  --good: #0ca30c;
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

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

.header h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.header .sub {
  font-size: 13px;
  color: var(--text-muted);
}

.theme-toggle {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 12px;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.12) inset, 0 2px 6px -2px rgba(0, 0, 0, 0.25);
}

.theme-toggle::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 55%);
  pointer-events: none;
  z-index: -1;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 12px 28px -16px rgba(0, 0, 0, 0.45);
}

/* Note: no overflow:hidden here — #chart-tooltip is an absolutely
   positioned child that can sit above the chart and must not get clipped. */
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0) 45%);
  pointer-events: none;
  z-index: -1;
}

.hero {
  text-align: center;
  padding: 32px 24px;
  overflow-wrap: break-word;
}

.hero .value {
  font-size: clamp(32px, 9vw, 56px);
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.hero .value.good {
  color: var(--good);
}

.hero .label {
  margin-top: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}

.hero .goal-line {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.kpi {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 14px;
  text-align: center;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 8px 18px -12px rgba(0, 0, 0, 0.4);
}

.kpi::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0) 50%);
  pointer-events: none;
  z-index: -1;
}

.kpi .kpi-value {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.kpi .kpi-label {
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.3;
}

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

.card h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 2px;
}

.card .card-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

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

.chart-head-actions {
  display: flex;
  gap: 14px;
  flex-shrink: 0;
}

.chart-head .toggle-link {
  margin-top: 2px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Full-width chart mode — breaks the card out of .wrap's max-width so the
   chart can use the full browser window, independent of the rest of the
   (intentionally narrow) page. */
.card.chart-expanded {
  max-width: 100vw;
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
}

.card.chart-expanded #chart-container {
  max-width: 1400px;
  margin: 0 auto;
}

.chart-legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.chart-legend .swatch-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

#chart-container {
  position: relative;
}

#chart-container svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--surface);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.1s;
  top: 0;
  left: 0;
}

.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.log-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 2px 8px;
  padding: 9px 0;
  border-top: 1px solid var(--gridline);
  font-size: 13.5px;
}

.log-list li:first-child {
  border-top: none;
}

.log-list .log-date {
  color: var(--text-secondary);
  width: 40%;
}

.log-list .log-weight {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.log-list .log-delta {
  font-size: 12px;
  margin-left: 6px;
  font-variant-numeric: tabular-nums;
}

.log-list .log-delta.down {
  color: var(--good);
}

.log-list .log-steps {
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.toggle-link {
  display: inline-block;
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  font-family: inherit;
}

.toggle-link:hover {
  color: var(--text-primary);
}

table.full-log {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  margin-top: 16px;
  font-variant-numeric: tabular-nums;
}

table.full-log th {
  text-align: right;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 6px 8px;
  border-bottom: 1px solid var(--gridline);
}

table.full-log th:first-child,
table.full-log td:first-child {
  text-align: left;
}

table.full-log td {
  text-align: right;
  padding: 6px 8px;
  border-bottom: 1px solid var(--gridline);
}

.footer-stats {
  display: flex;
  justify-content: center;
  gap: 28px;
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
}

.footer-stats strong {
  color: var(--text-secondary);
  font-weight: 600;
}

.hidden {
  display: none;
}

/* Auth / settings forms */

.wrap.narrow {
  max-width: 420px;
  padding-top: 64px;
}

.form-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 18px;
}

.form-subtitle {
  font-size: 14px;
  font-weight: 600;
  margin: 22px 0 2px;
}

.form-errors {
  list-style: none;
  margin: 0 0 16px;
  padding: 10px 14px;
  background: rgba(211, 59, 59, 0.1);
  border: 1px solid rgba(211, 59, 59, 0.3);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 13px;
}

.form-errors li + li {
  margin-top: 4px;
}

form label {
  display: block;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

form .form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

form input[type="text"],
form input[type="email"],
form input[type="password"],
form input[type="date"],
form input[type="number"] {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-sizing: border-box;
}

form select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 8px;
}

form .optional {
  color: var(--text-muted);
  font-weight: 400;
}

.btn-primary {
  position: relative;
  overflow: hidden;
  display: inline-block;
  width: 100%;
  padding: 11px 16px;
  margin-top: 6px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  color: var(--page);
  background: var(--text-primary);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset, 0 6px 16px -6px rgba(0, 0, 0, 0.5);
  transition: filter 0.15s, transform 0.1s, box-shadow 0.1s;
}

.btn-primary::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 55%);
  pointer-events: none;
  z-index: -1;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-primary:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 2px 6px -2px rgba(0, 0, 0, 0.4);
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  row-gap: 10px;
  margin: 14px 0 22px;
  flex-wrap: wrap;
}

.settings-actions form {
  margin: 0;
}

.btn-secondary {
  display: inline-block;
  width: auto;
  padding: 11px 16px;
  margin-top: 0;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  background: transparent;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  color: var(--text-primary);
  border: 1px solid var(--border);
  transition: background 0.15s, border-color 0.15s;
}

.btn-secondary:hover {
  background: var(--page);
}

.btn-danger {
  position: relative;
  overflow: hidden;
  display: inline-block;
  width: auto;
  padding: 11px 20px;
  margin-top: 0;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: #d9541f;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset, 0 6px 16px -6px rgba(0, 0, 0, 0.5);
  transition: filter 0.15s, transform 0.1s, box-shadow 0.1s;
}

.btn-danger::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 55%);
  pointer-events: none;
  z-index: -1;
}

.btn-danger:hover {
  filter: brightness(1.08);
}

.btn-danger:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset, 0 2px 6px -2px rgba(0, 0, 0, 0.4);
}

.log-form {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}

.log-form .btn-primary {
  width: auto;
  padding: 9px 20px;
  margin-top: 0;
}

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

.form-footnote {
  margin-top: 16px;
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
}

.form-footnote a {
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.text-link {
  font-size: 12.5px;
  color: var(--text-secondary);
  text-decoration: none;
}

.text-link:hover {
  color: var(--text-primary);
}

.text-link-btn {
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  cursor: pointer;
}

.inline-form {
  display: inline;
}

.flash {
  padding: 14px 20px;
  font-size: 13.5px;
  color: var(--text-primary);
}

/* Color swatch picker (settings page) */

.color-field {
  margin-bottom: 16px;
}

.color-field-label {
  display: block;
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.swatch-picker {
  display: flex;
  gap: 10px;
}

.swatch-picker input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.swatch-picker .swatch {
  display: inline-block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--swatch-color);
  cursor: pointer;
  box-shadow: inset 0 0 0 2px var(--surface);
  outline: 2px solid transparent;
  outline-offset: 2px;
}

.swatch-picker input[type="radio"]:checked + .swatch {
  outline-color: var(--text-primary);
}

.swatch-picker input[type="radio"]:focus-visible + .swatch {
  outline-color: var(--text-primary);
}
