body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
}

.sticky-header {
  position: static;
  top: auto;
  z-index: 1000;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  max-width: 480px;
  margin: 0 auto;
  padding: 0.5em 1em;
  border-bottom: 1px solid #ddd;
}

@media (min-width: 769px) {
  .sticky-header {
    position: sticky;
    top: 0;
  }
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #eee;
  flex-wrap: wrap;
  padding: 0.5em 0;
  gap: 0.5em;
  flex-direction: column;
}

@media (min-width: 601px) {
  .header-top {
    flex-direction: row;
  }
}

.header-top h1 {
  font-size: 1.3rem;
  font-weight: 600;
  color: #333;
  margin: 0;
}

.header-top button,
button {
  padding: 0.4em 1em;
  font-size: 0.9rem;
  background-color: #e53935;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.header-top button:hover,
button:hover {
  background-color: #c62828;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

button:active {
  background-color: #b71c1c;
}

.summary {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: #f4f4f4;
  padding: 0.6em 0.8em;
  font-weight: 700;
  gap: 0.5em;
  flex-wrap: wrap;
  text-align: center;
  max-width: 480px;
  margin: 0.6em auto 0;
}

@media (max-width: 600px) {
  .summary {
    max-width: 100%;
    gap: 1rem;
    padding: 0.5em;
    flex-direction: row;
    justify-content: space-between;
  }
}

.summary > div {
  flex: 1 1 30%;
  min-width: 100px;
  text-align: center;
}

@media (max-width: 600px) {
  .summary > div {
    flex: 1 1 100px;
  }
}

.yearly {
  font-size: 0.8rem;
  color: #555;
  display: block;
  margin-top: 0.25em;
}

section {
  padding: 1em;
  max-width: 480px;
  margin: 1em auto 2em;
}

input[type="number"],
input[type="text"] {
  width: 100%;
  max-width: 120px;
  text-align: right;
  padding: 0.3em 0.4em;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 0.95rem;
}


#chart {
  display: block;
  margin: 1em auto;
  max-width: 90vw;
  max-height: 250px;
  height: auto !important;
}

@media (max-width: 600px) {
  #chart {
    max-width: 100%;
  }
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1em;
}

.income-table td,
.expense-table td {
  padding: 0.4em 0;
  vertical-align: middle;
}

.income-table td:nth-child(2),
.expense-table td:nth-child(2) {
  text-align: right;
}

.income-table td input,
.expense-table td input {
  max-width: 120px;
  width: 100%;
  text-align: right;
  padding: 0.3em 0.4em;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
}


/* Mobil layout: td bliver flex-container */
@media (max-width: 600px) {
  .income-table td,
  .expense-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1em;
  }

  .income-table td input,
  .expense-table td input {
    width: auto;
    max-width: 120px;
    margin-left: auto;
  }
}


legend {
  font-weight: 700;
  padding: 0 0.5em;
}

.expense-category {
  margin-bottom: 2em;
  border-top: 1px solid #ddd;
  padding-top: 1em;
}

.add-expense {
  margin-top: 0.5em;
  background-color: #1976d2;
  color: #fff;
  border: none;
  padding: 0.5em 1em;
  border-radius: 6px;
  cursor: pointer;
  width: 100%;
  max-width: 300px;
  transition: background-color 0.2s ease;
}

@media (max-width: 600px) {
  .add-expense {
    max-width: 100%;
  }
}

.add-expense:hover {
  background-color: #1565c0;
}

@media (max-width: 600px) {
  .income-table td,
  .expense-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1em;
    flex-wrap: nowrap;
  }

  .income-table td::before,
  .expense-table td::before {
    flex: 1 1 auto;
    white-space: nowrap;
  }

  .income-table td input,
  .expense-table td input {
    flex-shrink: 0;
    max-width: 120px;
  }
}
@media (min-width: 601px) {
  .income-table td,
  .expense-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1em;
  }

  .income-table td span,
  .expense-table td span {
    flex: 1 1 auto;
  }

  .income-table td input,
  .expense-table td input {
    flex-shrink: 0;
    max-width: 120px;
    margin-left: auto;
    text-align: right;
  }
}

.info-mark {
  position: relative;
}

.input-with-info {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 120px;
}


.input-with-info input {
  flex: 1;
}

.info-mark {
  margin-left: 8px;
  cursor: pointer;
  position: relative;
}

.input-with-info {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-info input {
  flex: 1;
  padding-right: 2em; /* giver plads til infomærket */
}

.info-mark {
  position: absolute;
  right: 125px;
  cursor: pointer;
  font-size: 1.1em;
  color: #555;
}

.info-mark::after {
  content: attr(aria-label);
  position: absolute;
  bottom: 125%;
  left: 50%;                  /* Start midt på info-ikonet */
  transform: translateX(-50%); /* Træk tooltippen tilbage, så den bliver centreret */
  background: #333;
  color: #fff;
  padding: 5px 8px;
  border-radius: 4px;
  white-space: normal;
  min-width: 250px;           /* Minimum bredde for plads til ca. 30 tegn */
  max-width: 350px;           /* Maks bredde */
  word-wrap: break-word;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  font-size: 0.8em;
  z-index: 10;
  box-sizing: border-box;
}



.info-mark:hover::after,
.info-mark:focus::after {
  opacity: 1;
}





/* Fjern sticky fra .sticky-header */
.sticky-header {
  position: static; /* Ikke sticky længere */
  z-index: auto;
  box-shadow: none;
  border-bottom: none;
}


/* Gør KUN .summary sticky */
.sticky-summary {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: #f4f4f4;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  border-bottom: 1px solid #ccc;
}



#customTaxPercent {
  width: 100%;
  max-width: 120px;
  box-sizing: border-box;
  font-size: 0.95rem;
  padding: 0.3em 0.4em;
  text-align: right;
  border: 1px solid #ccc;
  border-radius: 4px;
  /* Sørg for at den ikke får margin eller padding der skrumper den */
  margin: 0;
}

td {
  display: flex;
  justify-content: space-between; /* label helt til venstre, input helt til højre */
  align-items: center;
  gap: 1em;
  padding: 0.5em 1em; /* valgfrit, lidt luft i cellen */
}

td label {
  flex-shrink: 0; /* label fylder kun det nødvendige */
}

.input-with-info {
  display: flex;
  align-items: center;
  gap: 0.5em;
  flex-shrink: 0; /* forhindrer input i at krympe */
}

.input-with-info input {
  width: 100px; /* fast bredde på input, så de er ens */
  text-align: right; /* tal til højre i input */
}

/* Hele rækken */
.extra-field tr td {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5em 0;
}

/* Label */
.extra-field label {
  flex: 1;
  font-weight: 600;
}

/* Container til input og info-ikon */
.input-with-info {
  display: flex;
  align-items: center;
  gap: 0.4em;
}

/* Inputfeltet */
.input-with-info input {
  width: 100px;
  text-align: right;
}

/* Inddel td i flex */
#housing-section td {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5em 0;
}

/* Label venstre */
#housing-section label {
  flex: 1;
  font-weight: 600;
}

/* Input + ikon højre */
.input-with-info {
  display: flex;
  align-items: center;
  gap: 0.4em;
}

.input-with-info input {
  width: 100px;
  text-align: right;
}

.toggleable {
  display: none;
}


.chart-row {
  display:flex;
  align-items:center;
  gap:8px;
  font-family:sans-serif;
}

.chart-row .color-box {
  width:16px; height:16px;
  border-radius:3px;
  flex-shrink:0;
}

.chart-row .cat-name   { flex:1; }
.chart-row .cat-value  { text-align:right; min-width:80px; }

.chart-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  max-width: 480px;
  margin: 1em auto;
}

#chart {
  max-width: 250px;
  max-height: 250px;
  width: 100%;
  height: auto !important;
  flex-shrink: 0;
}

.chart-list {
  display: flex;
  flex-direction: column;
  gap: 2px;           /* Mindre afstand mellem linjer */
  font-family: Arial, sans-serif;
  font-size: 0.95rem;
  margin-top: 0;      /* Kan justeres efter behov */
  padding: 0;
  max-width: 250px;   /* Kan ændres efter behov */
}

.chart-list > * {
  margin: 0;          /* Fjern margin på børn for at mindske afstand */
  padding: 0 4px;     /* Lidt vandret padding for luft, kan justeres */
  display: flex;
  align-items: center;
}

.chart-list .color-box {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
  margin-right: 6px;  /* Lille afstand til teksten */
}

.chart-list .cat-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart-list .cat-value {
  min-width: 60px;
  text-align: right;
  font-weight: 600;
}


.chart-list {
  display: flex !important;
  flex-direction: column;
  gap: 1px;
  font-family: Arial, sans-serif;
  font-size: 0.95rem;
  margin-top: 0;
  padding: 0;
  max-width: 250px;
  visibility: visible !important;
  opacity: 1 !important;
}