/* Look of the Fixkosten site. One file, no third-party packages. */

:root {
  /* Calm green on a pale green-grey page; white surfaces. */
  --bg: #eef3ef;
  --surface: #ffffff;
  --text: #17322a;
  --text-muted: #4f6a61;
  --line: #d6e2dc;
  --accent: #1f5c46;
  --accent-text: #ffffff;
  --accent-light: #dcebe3;
  --good: #1a7f4b;
  --good-light: #e4f5ec;
  --warn: #8a5a00;
  --warn-light: #fdf3d8;
  --danger: #b3261e;
  --danger-light: #fbe9e7;
  --radius: 22px;
  --radius-small: 14px;
  --font: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Colours of the categories in the chart and in the list. Fixed per
     category, chosen separately for light and dark and checked for being
     distinguishable (also with colour vision deficiency). More than eight
     colours can no longer be told apart reliably; "other" is therefore grey. */
  --cat-housing: #2a78d6;
  --cat-heating: #eb6834;
  --cat-internet: #1baf7a;
  --cat-electricity: #eda100;
  --cat-mobile: #e87ba4;
  --cat-insurance: #008300;
  --cat-subscription: #6250d6;
  --cat-mobility: #e34948;
  --cat-other: #898781;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1714;
    --surface: #18221e;
    --text: #e6efea;
    --text-muted: #a2b5ad;
    --line: #2b3a33;
    --accent: #7fcfa8;
    --accent-text: #0b2018;
    --accent-light: #1d3429;
    --good: #6fd3a0;
    --good-light: #173326;
    --warn: #f0c060;
    --warn-light: #3a2e12;
    --danger: #ff8a80;
    --danger-light: #40201d;

    --cat-housing: #3987e5;
    --cat-heating: #d95926;
    --cat-internet: #199e70;
    --cat-electricity: #c98500;
    --cat-mobile: #d55181;
    --cat-insurance: #008300;
    --cat-subscription: #9085e9;
    --cat-mobility: #e66767;
    --cat-other: #898781;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 var(--font);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }

h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 0.75rem; }
h2 { font-size: 1.15rem; line-height: 1.3; margin: 0 0 0.5rem; }
p { margin: 0 0 0.9rem; }

[hidden] { display: none !important; }

/* --- Header --- */

.header {
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  max-width: 46rem;
  margin: 0 auto;
  padding: 0.6rem max(1rem, env(safe-area-inset-right)) 0.6rem max(1rem, env(safe-area-inset-left));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 1rem;
}

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--accent);
  text-decoration: none;
  padding: 0.4rem 0;
}

.menu {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}

.menu a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 1rem;
  font-size: 0.95rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 999px;
}
.menu a:hover { color: var(--text); background: var(--surface); }
.menu a[aria-current="page"] { color: var(--accent-text); background: var(--accent); font-weight: 600; }

.menu form { margin: 0; }

/* --- Content --- */

.content {
  flex: 1;
  width: 100%;
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.25rem max(1rem, env(safe-area-inset-right)) 2rem max(1rem, env(safe-area-inset-left));
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.4rem 1.4rem 0.6rem;
  margin: 0 0 1rem;
}

p.card { padding-bottom: 1.1rem; }

.card.narrow { max-width: 28rem; margin-left: auto; margin-right: auto; }

.card.highlighted { background: var(--accent-light); }

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

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding-bottom: 1.1rem;
}

.row > div:first-child { flex: 1 1 14rem; min-width: 0; overflow-wrap: anywhere; }
.row .hint { margin: 0.15rem 0 0; }

/* --- Forms --- */

form { margin: 0 0 0.9rem; }

.field { margin: 0 0 0.9rem; }

label { display: block; font-weight: 600; margin-bottom: 0.3rem; }

input[type="text"], input[type="email"], input[type="number"], input[type="date"], select, textarea {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-size: 17px; /* below 16px the iPhone zooms in on tap */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--text-muted);
  border-radius: var(--radius-small);
}

textarea { min-height: 6rem; resize: vertical; }

/* Otherwise Safari shows date fields narrow and centred. */
input[type="date"] { -webkit-appearance: none; appearance: none; text-align: left; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }

input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.code-input {
  font-size: 1.6rem !important;
  letter-spacing: 0.3em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  padding: 0.7rem 1.4rem;
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  color: var(--accent-text);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-small);
  cursor: pointer;
}

.button.secondary { color: var(--accent); background: transparent; }
.button.danger { background: var(--danger); border-color: var(--danger); color: var(--surface); }

.link-button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 0.6rem;
  font: inherit;
  color: var(--accent);
  background: none;
  border: none;
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
}

.link-button.danger { color: var(--danger); }

.button-row { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; margin-left: -0.6rem; }
.button-row form { margin: 0; }
/* Several real buttons side by side (stacked on the phone). */
.button-group { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }

@media (min-width: 40rem) {
  .button { width: auto; }
  .card.narrow .button { width: 100%; }
  .form-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 0 0.75rem; align-items: end; }
  .form-row .button { margin-bottom: 0.9rem; }
  .field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.75rem; align-items: start; }
  .facts { grid-template-columns: 1fr 1fr; }
}

.or-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  margin: 1.1rem 0;
}
.or-divider::before, .or-divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* --- Hints and messages --- */

.hint { color: var(--text-muted); font-size: 0.92rem; }

.form-error { color: var(--danger); font-weight: 600; }
p.form-error { margin: 0.35rem 0 0.9rem; }

.messages { margin: 0 0 1rem; }

.message {
  margin: 0 0 0.5rem;
  padding: 0.8rem 1.1rem;
  border-radius: var(--radius-small);
  background: var(--surface);
}
.message.success { background: var(--surface); color: var(--good); border-color: transparent; box-shadow: inset 4px 0 0 var(--good); }
.message.warning { background: var(--warn-light); color: var(--warn); border-color: transparent; }
.message.error { background: var(--danger-light); color: var(--danger); border-color: transparent; }

.badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 999px;
  background: var(--accent-light);
  color: var(--accent);
  vertical-align: 0.1em;
}
.badge.active { background: var(--good-light); color: var(--good); }
.badge.invited { background: var(--warn-light); color: var(--warn); }
.badge.blocked { background: var(--danger-light); color: var(--danger); }

.mail-text {
  margin: 0 0 0.9rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 0.95rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.badge.pricier { background: var(--warn-light); color: var(--warn); }
.badge.first { margin-left: 0; }

/* --- Contract forms --- */

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

.field-pair.compact { display: grid; grid-template-columns: 6rem 1fr; gap: 0 0.75rem; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.button-bar { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 0 0 1rem; }

h3 { font-size: 1rem; line-height: 1.3; margin: 1.2rem 0 0.3rem; }

.back { margin: 0 0 0.4rem; }
.back a { text-decoration: none; }

/* --- Figures, categories and colours (overview and contract page) --- */

.category-line { display: flex; align-items: center; gap: 0.5rem; color: var(--text-muted); margin: 0 0 0.3rem; }

.swatch {
  flex: none;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 3px;
  background: var(--cat-other);
}
.cat-housing { background: var(--cat-housing); }
.cat-electricity { background: var(--cat-electricity); }
.cat-heating { background: var(--cat-heating); }
.cat-internet { background: var(--cat-internet); }
.cat-mobile { background: var(--cat-mobile); }
.cat-insurance { background: var(--cat-insurance); }
.cat-subscription { background: var(--cat-subscription); }
.cat-mobility { background: var(--cat-mobility); }
.cat-other { background: var(--cat-other); }

/* Two figures side by side: what gets debited and what it effectively costs. */
.figures { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin: 0.4rem 0 0.8rem; }
.figure {
  display: block;
  min-width: 0;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  color: var(--text);
  text-decoration: none;
}
.figure > * { display: block; margin: 0; }
.figure-name { font-size: 0.92rem; font-weight: 600; color: var(--text-muted); }
.figure-value { font-size: 1.5rem; font-weight: 700; line-height: 1.25; white-space: nowrap; }
.figure .hint { font-size: 0.85rem; }
@media (min-width: 40rem) { .figure-value { font-size: 1.9rem; } }

.price-change { margin: 0 0 0.35rem; }
.card > .price-change { font-size: 1rem; color: var(--text); }

/* --- Overview (start page and "Verträge von …") --- */

/* Top: ring chart with the total in the middle, a sentence, the view switch. */
.hero {
  display: grid;
  gap: 1.2rem 2rem;
  align-items: center;
  justify-items: center;
  background: var(--surface);
  border-radius: 28px;
  padding: 1.6rem 1.4rem;
  margin: 0 0 1rem;
}
.hero-text { justify-self: stretch; }
.hero h1, .hero h2 { font-size: 1.45rem; font-weight: 400; line-height: 1.35; margin: 0 0 0.5rem; }
.hero h1 strong, .hero h2 strong { font-weight: 700; white-space: nowrap; }
.hero-text > .hint { margin: 0 0 1rem; }

.ring { position: relative; width: 13rem; max-width: 100%; }
.ring canvas { display: block; }
.ring-centre {
  position: absolute;
  inset: 22%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}
.ring-label { font-size: 0.85rem; color: var(--text-muted); overflow-wrap: anywhere; line-height: 1.25; }
.ring-value { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart-hint { text-align: center; margin: 0.5rem 0 0; font-size: 0.85rem; }

/* The two figures are the switch between the views. */
.switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
  width: 100%;
  max-width: 24rem;
  padding: 0.3rem;
  background: var(--bg);
  border-radius: 999px;
}
.switch a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0.35rem 0.5rem;
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.95rem;
  text-align: center;
  text-decoration: none;
  line-height: 1.25;
}
.switch a .switch-value { font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.switch a[aria-current="true"] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(23, 50, 42, 0.18);
}

/* Shares of shared contracts: one sentence, the details fold out. */
.balance {
  background: var(--accent-light);
  border-radius: var(--radius-small);
  padding: 0.9rem 1.1rem;
  margin: 0 0 1rem;
}
.balance > p { margin: 0; }
.balance details { margin: 0.4rem 0 0; }
.balance summary { cursor: pointer; color: var(--accent); font-weight: 600; min-height: 44px; display: flex; align-items: center; gap: 0.4rem; list-style: none; }
.balance summary::-webkit-details-marker { display: none; }
.balance summary::before { content: "▸"; }
.balance details[open] summary::before { content: "▾"; }
.balance details[open] summary { margin-bottom: 0.3rem; }
.balance details p { margin: 0 0 0.35rem; }
.balance details .hint { margin: 0.35rem 0 0; }
.transfers { list-style: none; margin: 0 0 0.5rem; padding: 0; }
.transfers li { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.15rem 0 0.15rem 1rem; }
.transfers li span:first-child { min-width: 0; overflow-wrap: anywhere; }
.net-title { padding-top: 0.45rem; border-top: 1px solid var(--line); }
.net-balances li { font-weight: 600; }
.net-balances .netting { display: block; margin: 0; font-weight: normal; }

.section-title { font-size: 1rem; color: var(--text-muted); margin: 1.6rem 0.4rem 0.2rem; }
.section-hint { margin: 0 0.4rem 0.6rem; }

/* The list: one white surface, one row per category, the largest on top. */
.categories {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
}
.category {
  display: grid;
  grid-template-columns: 0.85rem minmax(0, 1fr);
  column-gap: 1rem;
  padding: 1rem 1.2rem 0.8rem;
  border-top: 1px solid var(--line);
}
.category:first-child { border-top: none; }
.category > .swatch { width: 0.85rem; height: auto; min-height: 2.6rem; border-radius: 999px; grid-row: 1 / span 2; align-self: stretch; }
.category-head { display: flex; align-items: baseline; gap: 0.6rem; font-weight: 600; }
.category-name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.category-percent { color: var(--text-muted); font-weight: 400; font-size: 0.9rem; white-space: nowrap; }
.category-head .amount { font-size: 1.15rem; }
.category.largest { padding-top: 1.3rem; padding-bottom: 1.1rem; }
.category.largest .category-head .amount { font-size: 1.5rem; }
/* Pointing at a slice in the chart highlights the matching row. */
.category.selected { background: var(--accent-light); }

.amount { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }

.category-contracts { list-style: none; margin: 0.15rem 0 0; padding: 0; }
.category-contracts li { padding: 0.05rem 0; }
.category-contracts .hint { margin: 0 0 0.25rem; }
.category-contracts .amount { color: var(--text-muted); }

.contract-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.contract-row a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  min-width: 0;
  overflow-wrap: anywhere;
}
.share-row .contract-name { display: inline-flex; align-items: center; min-height: 40px; min-width: 0; overflow-wrap: anywhere; }

.assisting { margin: 0 0 1rem; padding: 0.9rem 1.2rem; }
.assisting p { margin: 0; }

@media (min-width: 40rem) {
  .hero { grid-template-columns: 13rem 1fr; justify-items: start; padding: 1.8rem 2rem; }
  .hero h1, .hero h2 { font-size: 1.6rem; }
}

/* --- Contract page --- */

.calculation { margin: 0.4rem 0 0.9rem; }
.calculation summary, .collapsible summary { cursor: pointer; color: var(--accent); min-height: 44px; display: flex; align-items: center; gap: 0.5rem; }
.calc-table { width: 100%; border-collapse: collapse; margin: 0 0 0.5rem; }
.calc-table th { text-align: left; font-weight: 400; padding: 0.25rem 0.5rem 0.25rem 0; }
.calc-table td { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; padding: 0.25rem 0; }
.calc-table .total th, .calc-table .total td { border-top: 1px solid var(--line); }

.collapsible { padding-bottom: 0.4rem; }
.collapsible summary { color: var(--text); margin-bottom: 0.4rem; list-style: none; }
.collapsible summary h2 { margin: 0; }
.collapsible summary::before { content: "▸"; color: var(--accent); }
.collapsible[open] summary::before { content: "▾"; }
.collapsible summary::-webkit-details-marker { display: none; }

.checkbox { display: flex; align-items: flex-start; gap: 0.6rem; font-weight: 400; margin: 0 0 0.9rem; min-height: 44px; }
.checkbox input { flex: none; width: 1.35rem; height: 1.35rem; margin: 0.15rem 0 0; accent-color: var(--accent); }

/* A choice of several (radio buttons), e.g. "Wenn du nicht kündigst". */
fieldset.choices { border: 0; padding: 0; margin: 0 0 0.9rem; min-width: 0; }
fieldset.choices legend { font-weight: 600; padding: 0; margin: 0 0 0.4rem; }
fieldset.choices .checkbox { margin: 0 0 0.3rem; align-items: center; }
fieldset.choices .checkbox input { margin: 0; }
.field.nested { margin: 0 0 0.6rem 1.95rem; max-width: 12rem; }


.history { list-style: none; margin: 0 0 1rem; padding: 0; }
.history-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding: 0.55rem 0;
  border-top: 1px solid var(--line);
}
.history-row:first-child { border-top: none; }
.history-row .hint { margin: 0.1rem 0 0; }
.history-row form { margin: 0; }
.history-row:not(.current) strong { font-weight: 600; }

.facts { display: grid; gap: 0.6rem 1.5rem; margin: 0 0 0.9rem; }
.facts dt { color: var(--text-muted); font-size: 0.92rem; }
.facts dd { margin: 0; }
.facts .wide { grid-column: 1 / -1; }
.facts dd .hint { display: block; margin: 0.1rem 0 0; }

/* --- PDF upload and receipts --- */

input[type="file"] { display: block; width: 100%; min-height: 48px; padding: 0.6rem 0; font: inherit; color: var(--text); }
.checks { margin: 0 0 0.9rem; padding-left: 1.2rem; }
.checks li { margin: 0 0 0.3rem; }
#extras .checkbox span { line-height: 1.45; }

/* --- Deadlines --- */

.deadline { font-size: 1.1rem; }
.due-soon .history-row a { font-weight: 600; }
.due-soon .badge { margin-left: 0; white-space: nowrap; }
.note { white-space: pre-wrap; overflow-wrap: anywhere; }

/* --- Shared contracts and helpers --- */

.helper-hint {
  margin: -0.4rem 0 1rem;
  padding: 0.5rem 0.75rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-light);
  border-radius: 0 8px 8px 0;
  color: var(--text);
}

.sharing-list { margin: 0 0 0.6rem; }
.sharing-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.2rem 0;
  border-top: 1px solid var(--line);
}
.sharing-row:first-child { border-top: none; }
.sharing-name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; margin: 0; align-items: center; }
.sharing-row .checkbox { margin: 0; }
.sharing-row .checkbox input { margin: 0; }
input.shares-input { width: 5rem; text-align: right; }

.shares-table th[scope="col"] { font-size: 0.85rem; color: var(--text-muted); font-weight: 600; text-align: right; padding: 0.25rem 0 0.25rem 0.6rem; }
.shares-table th[scope="col"]:first-child { text-align: left; padding-left: 0; }
.shares-table td { padding-left: 0.6rem; }

/* --- Footer --- */

.footer {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 0.8rem max(1rem, env(safe-area-inset-right)) calc(0.8rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}
