/* Habit detail */
.habit-header {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 2px;
}

.habit-header h1 {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

.stat-row {
  display: flex;
  gap: 28px;
  margin: 16px 0 22px;
}

.stat {
  text-align: left;
}

.stat .value {
  font-size: 26px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat .label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 1px;
}

.heatmap-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px 16px 12px;
  box-shadow: var(--shadow-sm);
}

.heatmap-scroll {
  overflow-x: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}

.heatmap-inner {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
}

.heatmap-months {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 18px;
  gap: 3px;
  padding-left: 29px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  height: 16px;
}

.heatmap-body {
  display: flex;
  gap: 3px;
}

.heatmap-daylabels {
  display: grid;
  grid-template-rows: repeat(7, 18px);
  gap: 3px;
  font-size: 10px;
  color: var(--text-muted);
  width: 26px;
  text-align: right;
  padding-right: 4px;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface-1);
  flex: none;
}

.heatmap-daylabels span {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 18px;
}

.heatmap-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 18px;
  grid-template-rows: repeat(7, 18px);
  gap: 3px;
}

.heatmap-cell {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--cell-empty);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.12s ease;
}

.heatmap-cell:not(:disabled):hover {
  transform: scale(1.18);
}

.heatmap-cell:disabled {
  cursor: default;
  pointer-events: none;
}

/* Datoer uden for den viste periode skjules; fremtidige dage vises svagt. */
.heatmap-cell.is-outside {
  opacity: 0;
}

.heatmap-cell.is-future {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--gridline);
  opacity: 0.8;
}

.heatmap-cell.is-today {
  box-shadow: 0 0 0 2px var(--text-primary) inset;
}

.heatmap-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 14px;
}

.legend-cell {
  width: 14px;
  height: 14px;
  border-radius: 4px;
}

.date-readout {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  min-height: 18px;
  margin-top: 10px;
}

.danger-zone {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--gridline);
}

.link-danger {
  background: none;
  border: none;
  color: var(--danger-ink);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 0;
  cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(6px);
  background: var(--text-primary);
  color: var(--surface-1);
  padding: 11px 20px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Valg af heatmap-periode: 3 måneder / hele året */
.range-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  margin-bottom: 10px;
  border-radius: 10px;
  background: var(--surface-3);
}

.range-toggle button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.range-toggle button.active {
  background: var(--surface-1);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Guld-markering: dagen, milepælen kan nås (hvis man ticker hver dag fra nu) */
:root {
  --gold: #d4a017;
  --gold-fill: rgba(212, 160, 23, 0.28);
  --gold-glow: rgba(212, 160, 23, 0.55);
}

.heatmap-cell.is-target {
  box-shadow: 0 0 0 2px var(--gold), 0 0 10px 2px var(--gold-glow);
  position: relative;
  z-index: 1;
}

.heatmap-cell.is-target:disabled {
  opacity: 1;
  background: var(--gold-fill);
  box-shadow: 0 0 0 2px var(--gold), 0 0 10px 2px var(--gold-glow);
}

.legend-target {
  box-shadow: 0 0 0 2px var(--gold);
  background: var(--gold-fill);
  margin-left: 10px;
}

.target-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Heatmap fylder hele kortets bredde: felterne vokser med pladsen (aldrig under 22–26 px; ellers sidelæns scroll). */
.heatmap-inner {
  --cell: 26px;
  --gap: 5px;
  display: flex;
  width: 100%;
  min-width: calc(34px + var(--weeks) * (var(--cell) + var(--gap)));
  max-width: calc(34px + var(--weeks) * 64px);
  gap: 8px;
}

@media (max-width: 520px) {
  .heatmap-inner {
    --cell: 22px;
    --gap: 4px;
  }
}

.heatmap-inner .heatmap-months {
  grid-auto-flow: row;
  grid-template-columns: repeat(var(--weeks), minmax(var(--cell), 1fr));
  grid-auto-columns: auto;
  gap: var(--gap);
  padding-left: 33px;
  height: 18px;
  font-size: 12px;
  white-space: nowrap;
}

.heatmap-inner .heatmap-body {
  gap: var(--gap);
  align-items: stretch;
}

.heatmap-inner .heatmap-daylabels {
  grid-template-rows: repeat(7, 1fr);
  gap: var(--gap);
  width: 28px;
  font-size: 11px;
}

.heatmap-inner .heatmap-daylabels span {
  height: auto;
}

.heatmap-inner .heatmap-grid {
  flex: 1;
  grid-template-columns: repeat(var(--weeks), minmax(var(--cell), 1fr));
  grid-template-rows: repeat(7, auto);
  grid-auto-columns: auto;
  gap: var(--gap);
}

.heatmap-inner .heatmap-cell {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border-radius: 8px;
}

/* Dage uden for vanens valgte ugedage: svagere, men kan stadig tickes */
.heatmap-cell.is-off:not([data-done="1"]) {
  opacity: 0.35;
}

/* Milepælens værdi som lille tal i guldcellen (flere milepæle kan kendes fra hinanden) */
.heatmap-cell.is-target::after {
  content: attr(data-target);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
  pointer-events: none;
}

/* Rytme "hver N. dag": hviledage i egen farve, fristen markeret */
:root {
  --rest: #5b83d6;
  --rest-fill: rgba(91, 131, 214, 0.28);
}

.heatmap-cell.is-rest:not([data-done="1"]) {
  background: var(--rest-fill);
}

.heatmap-cell.is-due:not([data-done="1"]) {
  box-shadow: inset 0 0 0 2px var(--rest);
}

.heatmap-cell.is-future.is-rest {
  background: var(--rest-fill);
  box-shadow: none;
}

.heatmap-cell.is-future.is-due {
  box-shadow: inset 0 0 0 2px var(--rest);
}

.heatmap-cell.is-future.is-target {
  box-shadow: 0 0 0 2px var(--gold), 0 0 10px 2px var(--gold-glow);
}

.legend-rest {
  background: var(--rest-fill);
  margin-left: 10px;
}

.legend-due {
  box-shadow: inset 0 0 0 2px var(--rest);
  margin-left: 10px;
}

.rhythm-badge {
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--rest-fill);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* Frisk start: arkiverede dage før startdatoen */
.heatmap-cell.is-archived {
  opacity: 0.25;
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--gridline);
}

/* Planlagte ugedage: rød boks (guld for milepæle vinder på samme celle) */
:root {
  --planned: #d64545;
  --planned-fill: rgba(214, 69, 69, 0.18);
  --planned-glow: rgba(214, 69, 69, 0.5);
}

.heatmap-cell.is-planned:not(.is-target) {
  box-shadow: 0 0 0 2px var(--planned), 0 0 8px 1px var(--planned-glow);
  position: relative;
  z-index: 1;
}

.heatmap-cell.is-planned.is-today:not(.is-target) {
  box-shadow: 0 0 0 2px var(--planned), 0 0 8px 1px var(--planned-glow), inset 0 0 0 2px var(--text-primary);
}

.heatmap-cell.is-planned.is-future:not(.is-target) {
  background: var(--planned-fill);
}

.legend-planned {
  box-shadow: 0 0 0 2px var(--planned);
  background: var(--planned-fill);
  margin-left: 10px;
}

.planned-badge {
  background: var(--planned-fill);
}
