:root {
  color-scheme: light dark;
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #13201e;
  --muted: #5b6a67;
  --line: #e1e7e5;
  --brand: #0f5f59;
  --brand-strong: #0b4a45;
  --on-brand: #ffffff;
  --on-brand-muted: rgb(255 255 255 / 0.78);
  --borrow: #b45309;
  --borrow-soft: #fdf1e3;
  --repay: #15803d;
  --repay-soft: #e5f5ea;
  --danger: #c0262d;
  --shadow: 0 1px 2px rgb(16 32 30 / 0.06), 0 4px 16px rgb(16 32 30 / 0.06);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1110;
    --surface: #141c1b;
    --surface-2: #1c2625;
    --text: #e6eeec;
    --muted: #93a3a0;
    --line: #253230;
    --brand: #0c4d48;
    --brand-strong: #0f5f59;
    --borrow: #f5a524;
    --borrow-soft: #33240f;
    --repay: #4ade80;
    --repay-soft: #12301d;
    --danger: #f87171;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
  }
}

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

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Kopfbereich mit Kontostand ---------- */

.top {
  background: var(--brand);
  color: var(--on-brand);
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 20px) 64px calc(var(--safe-left) + 20px);
  text-align: center;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
  min-height: 44px;
}

.top-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-right: -10px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
}

.icon-btn:active {
  background: rgb(255 255 255 / 0.15);
}

.icon-btn svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.balance-label {
  margin: 20px 0 2px;
  font-size: 16px;
  color: var(--on-brand-muted);
}

.balance-amount {
  margin: 0;
  font-size: clamp(40px, 13vw, 56px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.balance-totals {
  margin: 10px 0 0;
  font-size: 14px;
  color: var(--on-brand-muted);
  font-variant-numeric: tabular-nums;
}

.balance-totals:empty {
  display: none;
}

/* ---------- Inhalt ---------- */

.content {
  max-width: 560px;
  margin: -44px auto 0;
  padding: 0 calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 32px) calc(var(--safe-left) + 16px);
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.action {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
  padding: 14px 16px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: left;
  transition: transform 0.1s ease;
}

.action:active {
  transform: scale(0.97);
}

.action-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 24px;
  font-weight: 600;
  line-height: 1;
}

.action-borrow .action-icon {
  background: var(--borrow-soft);
  color: var(--borrow);
}

.action-repay .action-icon {
  background: var(--repay-soft);
  color: var(--repay);
}

.action-text {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
}

.action-title {
  font-size: 17px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-sub {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.install-hint {
  margin-top: 16px;
  padding: 14px 16px;
}

.install-hint p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.install-hint-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.share-icon {
  display: inline-block;
  width: 1.1em;
  height: 1.1em;
  vertical-align: -0.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.section-title {
  margin: 28px 4px 8px;
  font-size: 20px;
  font-weight: 700;
}

.month {
  margin-bottom: 16px;
}

.month-head {
  margin: 0 4px 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.entries {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.entries li + li {
  border-top: 1px solid var(--line);
}

.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  background: transparent;
  text-align: left;
}

.entry:active {
  background: var(--surface-2);
}

.entry-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.entry.borrow .entry-dot {
  background: var(--borrow);
}

.entry.repay .entry-dot {
  background: var(--repay);
}

.entry-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.entry-note {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.entry-right {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-variant-numeric: tabular-nums;
}

.entry-amount {
  font-weight: 600;
}

.entry.borrow .entry-amount {
  color: var(--borrow);
}

.entry.repay .entry-amount {
  color: var(--repay);
}

.entry-running {
  font-size: 12px;
  color: var(--muted);
}

.empty {
  margin: 8px 4px;
  padding: 28px 20px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  font-weight: 600;
}

.btn:active {
  opacity: 0.8;
}

.btn-small {
  min-height: 36px;
  padding: 0 14px;
  font-size: 15px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--brand-strong);
  color: var(--on-brand);
}

.btn-secondary {
  background: var(--surface-2);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1.5px solid currentColor;
}

.link-btn {
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--brand-strong);
}

.link-btn-strong {
  font-weight: 600;
}

@media (prefers-color-scheme: dark) {
  .link-btn,
  .btn-primary {
    color: #fff;
  }

  .link-btn {
    color: #5eead4;
  }
}

/* ---------- Bottom-Sheets ---------- */

dialog.sheet {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - var(--safe-top) - 24px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
  overflow-y: auto;
  overscroll-behavior: contain;
}

dialog.sheet[open] {
  animation: sheet-in 0.22s ease-out;
}

dialog.sheet::backdrop {
  background: rgb(0 0 0 / 0.45);
}

@keyframes sheet-in {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}

@media (min-width: 600px) {
  dialog.sheet {
    margin: auto;
    border-radius: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  dialog.sheet[open] {
    animation: none;
  }
}

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.sheet-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}

.sheet-head > :first-child {
  justify-self: start;
}

.sheet-head > :last-child {
  justify-self: end;
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 16px calc(var(--safe-bottom) + 20px);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 0;
  padding: 4px;
  border: 0;
  border-radius: 12px;
  background: var(--surface-2);
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  padding: 9px 8px;
  border-radius: 9px;
  text-align: center;
  font-weight: 600;
  color: var(--muted);
}

.segmented input:checked + span {
  background: var(--surface);
  box-shadow: var(--shadow);
}

.segmented input[value="borrow"]:checked + span {
  color: var(--borrow);
}

.segmented input[value="repay"]:checked + span {
  color: var(--repay);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--brand-strong);
  outline-offset: 1px;
}

.dir-hint {
  margin: -8px 4px 0;
  font-size: 14px;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 14px;
  font-weight: 600;
}

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

.field input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 17px; /* >= 16px, damit iOS nicht hineinzoomt */
  -webkit-appearance: none;
  appearance: none;
}

.field input:focus {
  outline: none;
  border-color: var(--brand-strong);
}

.field input[aria-invalid="true"] {
  border-color: var(--danger);
}

.amount-input {
  position: relative;
  display: block;
}

.amount-input input {
  padding-right: 40px;
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.amount-suffix {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 22px;
  font-weight: 600;
  color: var(--muted);
  pointer-events: none;
}

.field-error {
  font-size: 14px;
  color: var(--danger);
}

.group-title {
  margin: 8px 0 -8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.small {
  margin: 0;
  font-size: 14px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 16px);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 10px 10px 18px;
  border-radius: 14px;
  background: #1f2a28;
  color: #fff;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.25);
  transform: translateX(-50%);
  font-size: 15px;
}

.toast-action {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: rgb(255 255 255 / 0.12);
  color: #5eead4;
  font-weight: 600;
}
