:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --card: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --border: #e4e7ec;
  --primary: #1d4ed8;
  --positive: #15803d;
  --neutral: #9333ea;
  --danger: #b91c1c;
  --warning: #b45309;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", "SF Pro Text", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.app {
  display: flex;
  flex-direction: column;
  gap: 32px;
  padding: 24px 16px 48px;
  max-width: 1100px;
  margin: 0 auto;
}

.app.auth {
  min-height: 100vh;
  justify-content: center;
}

.topbar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.topbar-actions form {
  margin: 0;
}

.user-pill {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(29, 78, 216, 0.08);
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
}

.eyebrow {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 8px;
}

h1 {
  font-size: clamp(28px, 5vw, 42px);
  line-height: 1.1;
}

.lead {
  font-size: 16px;
  line-height: 1.7;
  color: var(--muted);
}

.hero {
  display: grid;
  gap: 24px;
}

.hero-card {
  background: var(--card);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.label {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.hero-value {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 40px;
  font-weight: 700;
}

.hero-value small {
  font-size: 18px;
  color: var(--muted);
}

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

.pill {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  width: fit-content;
}

.positive {
  color: var(--positive);
  background: rgba(21, 128, 61, 0.1);
}

.neutral {
  color: var(--neutral);
  background: rgba(147, 51, 234, 0.08);
}

.warning {
  color: var(--warning);
  background: rgba(180, 83, 9, 0.12);
}

.section-title {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.section-title h2 {
  font-size: 22px;
}

.subtle {
  color: var(--muted);
  font-size: 14px;
}

.measurement-grid {
  display: grid;
  gap: 16px;
}

.measurement-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
}

.measurement-card summary {
  list-style: none;
}

.measurement-card summary::-webkit-details-marker {
  display: none;
}

.card-summary {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  cursor: pointer;
}

.card-summary-main {
  display: grid;
  gap: 10px;
}

.summary-toggle {
  font-size: 13px;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.summary-toggle::before {
  content: "Vis";
  font-weight: 600;
  color: var(--primary);
  margin-right: 4px;
}

.measurement-card[open] .summary-toggle {
  color: var(--primary);
}

.measurement-card[open] .summary-toggle::before {
  content: "Skjul";
}

.card-details {
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.unit {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.card-value {
  font-size: 32px;
  font-weight: 700;
}

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

.delta {
  font-size: 14px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 10px;
  width: fit-content;
}

.chart {
  width: 100%;
  height: 120px;
  fill: none;
  stroke: #1f2937;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  background: #f8fafc;
  border-radius: 14px;
  padding: 12px;
}

.chart-grid line {
  stroke: rgba(148, 163, 184, 0.35);
  stroke-width: 1;
  stroke-dasharray: 4 6;
}

.chart-points circle {
  fill: #1f2937;
  stroke: #fff;
  stroke-width: 1;
}

.chart-last {
  fill: #1f2937;
  stroke: #fff;
  stroke-width: 1.5;
}

.chart text {
  fill: var(--muted);
  font-size: 12px;
}

.chart circle {
  fill: #1f2937;
}

.primary,
.ghost,
.secondary {
  border: none;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 999px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.danger {
  background: var(--danger);
  color: #fff;
}

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

.secondary {
  background: #eef2ff;
  color: var(--primary);
}

.ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid rgba(29, 78, 216, 0.2);
}

.registration,
.insight,
.trend,
.motivation,
.measurement-detail {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.registration.compact {
  padding: 16px 18px;
}

.entry-form {
  display: grid;
  gap: 12px;
}

.entry-form.compact-form {
  grid-template-columns: 1fr;
  gap: 10px;
}

.entry-form.compact-form .primary {
  justify-self: start;
}

.entry-form label {
  display: grid;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}

.entry-form .checkbox {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
}

.entry-form .checkbox input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.entry-form input:not([type="checkbox"]),
.entry-form select {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 15px;
  color: var(--ink);
  background: #fff;
}

.insight-grid {
  display: grid;
  gap: 12px;
}

.trend-grid {
  display: grid;
  gap: 12px;
}

.trend-card {
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 16px;
  display: grid;
  gap: 10px;
}

.ai-debug {
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 12px;
  background: #f8fafc;
  display: grid;
  gap: 12px;
}

.ai-debug summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--primary);
}

.ai-debug-grid {
  display: grid;
  gap: 12px;
}

.ai-debug-meta {
  list-style: none;
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.ai-debug pre {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow: auto;
}

.trend-summary {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}

.trend-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.motivation-grid {
  display: grid;
  gap: 16px;
}

.progress-card {
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 16px;
  display: grid;
  gap: 10px;
}

.progress-value {
  font-size: 20px;
  font-weight: 700;
}

.progress-bar {
  background: #eef2ff;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
}

.badge-wall {
  display: grid;
  gap: 12px;
}

.badge-card {
  border-radius: 14px;
  border: 1px solid var(--border);
  padding: 14px;
  display: grid;
  gap: 6px;
  background: #f9fafb;
}

.badge-card.earned {
  border-color: rgba(21, 128, 61, 0.4);
  background: rgba(21, 128, 61, 0.08);
}

.badge-title {
  font-weight: 700;
}

.badge-detail {
  color: var(--muted);
  font-size: 13px;
}

.badge-status {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.insight-card {
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 16px;
  display: grid;
  gap: 6px;
}

.insight-value {
  font-size: 24px;
  font-weight: 700;
}

.insight-meta {
  color: var(--muted);
  font-size: 13px;
}

.alert {
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 600;
}

.alert-details {
  margin: 8px 0 0;
  padding-left: 18px;
  font-weight: 500;
  font-size: 13px;
  color: inherit;
  display: grid;
  gap: 4px;
}

.alert.success {
  background: rgba(21, 128, 61, 0.12);
  color: var(--positive);
}

.alert.error {
  background: rgba(185, 28, 28, 0.12);
  color: var(--danger);
}

.auth-card {
  background: var(--card);
  border-radius: 20px;
  padding: 32px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.empty-card {
  padding: 20px;
  border-radius: 16px;
  border: 1px dashed var(--border);
  color: var(--muted);
}

.measurement-detail {
  gap: 24px;
}

.chart-large {
  background: #f8fafc;
  border-radius: 18px;
  padding: 16px;
}

.chart-large svg {
  width: 100%;
  height: 180px;
  fill: none;
  stroke: #1f2937;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-large text {
  fill: var(--muted);
  font-size: 14px;
}

.chart-large .chart-label {
  fill: var(--muted);
  font-size: 12px;
}

.chart-large circle {
  fill: #1f2937;
}


.chart-large .chart-area {
  fill: url(#chartFill);
  stroke: none;
}

.chart-large .chart-trend {
  stroke: #7c3aed;
  stroke-width: 2;
  stroke-dasharray: 7 6;
}

.chart-large .chart-average {
  stroke: rgba(29, 78, 216, 0.45);
  stroke-width: 1.5;
  stroke-dasharray: 5 5;
}

.range-tabs {
  display: inline-flex;
  gap: 8px;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f8fafc;
}

.range-tab {
  text-decoration: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
}

.range-tab.active {
  color: #fff;
  background: var(--primary);
}

.detail-stats {
  display: grid;
  gap: 10px;
}

.detail-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 4px;
  background: #fcfdff;
}

.detail-card strong {
  font-size: 18px;
}

.detail-card span {
  color: var(--muted);
  font-size: 13px;
}

.entry-list ul {
  list-style: none;
  display: grid;
  gap: 8px;
}

.entry-list li {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
}

.entry-surface {
  display: flex;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  transition: transform 0.2s ease;
}

.entry-row.dragging .entry-surface {
  transition: none;
}

.entry-row.is-revealed .entry-surface,
.entry-row:focus-within .entry-surface {
  transform: translateX(-84px);
}

.entry-delete {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  display: flex;
  align-items: center;
  padding-right: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.entry-row.is-revealed .entry-delete,
.entry-row:focus-within .entry-delete {
  opacity: 1;
  pointer-events: auto;
}

.entry-delete button {
  padding: 8px 14px;
  border-radius: 999px;
}

@media (min-width: 720px) {
  .app {
    padding: 40px 24px 64px;
    gap: 40px;
  }

  .topbar {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .hero {
    grid-template-columns: 1.2fr 0.8fr;
    align-items: center;
  }

  .section-title {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

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

  .registration,
  .insight,
  .trend,
  .motivation {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 32px;
  }

  .entry-form {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: end;
  }

  .entry-form.compact-form {
    grid-template-columns: minmax(0, 260px) auto;
    align-items: end;
  }

  .entry-form input[type="text"] {
    min-width: 240px;
  }

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

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

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

  .badge-wall {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .measurement-detail {
    flex-direction: row;
    align-items: flex-start;
  }

  .measurement-detail > * {
    flex: 1;
  }

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