/* Material-inspired dark theme: charcoal surfaces, restrained gold accent.
   Gold is reserved for primary actions + the balance "hero" accent — used
   everywhere it would drown out the green/red that actually carries meaning
   (positive/negative amounts always win the color argument, on purpose). */
:root {
  --bg: #121214;
  --bg-alt: #18181b;
  --card: #1c1c20;
  --card-2: #232328;
  --text: #f3efe7;
  --text-muted: #9c968d;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);

  --gold: #cda13a;
  --gold-light: #e6c66c;
  --gold-dark: #a3801f;
  --gold-tint: rgba(205, 161, 58, 0.14);
  --on-gold: #201804;

  --primary: var(--gold);
  --primary-tint: var(--gold-tint);

  --green: #4bb884;
  --green-tint: rgba(75, 184, 132, 0.14);
  --green-fill: #247a52; /* darker — white text on top needs this, not --green (fails AA) */
  --red: #e2685a;
  --red-tint: rgba(226, 104, 90, 0.14);
  --red-fill: #b83f34; /* darker — white text on top needs this, not --red (fails AA) */

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 28px -10px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 20px 48px -12px rgba(0, 0, 0, 0.65), 0 8px 20px -8px rgba(0, 0, 0, 0.5);
  --radius: 20px;
  --radius-sm: 13px;

  /* Spacing scale — one rhythm used everywhere instead of ad-hoc inline
     margins. Slightly more generous than a typical utility app: a page
     handling real money reads calmer/more deliberate with room to breathe. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
}

/* Light variant kept for prefers-color-scheme:light / explicit toggle —
   same gold-on-neutral language, just inverted, still restrained. */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f2ec;
    --bg-alt: #ece7dc;
    --card: #ffffff;
    --card-2: #ffffff;
    --text: #211d15;
    --text-muted: #6f6a5f;
    --border: rgba(33, 29, 21, 0.1);
    --border-strong: rgba(33, 29, 21, 0.18);

    --gold: #a3801f;
    --gold-light: #cda13a;
    --gold-dark: #715714;
    --gold-tint: rgba(163, 128, 31, 0.12);
    --on-gold: #211804;

    --green: #116e46;
    --green-tint: rgba(17, 110, 70, 0.12);
    --green-fill: var(--green); /* already passes with white text on this theme */
    --red: #ad3327;
    --red-tint: rgba(173, 51, 39, 0.1);
    --red-fill: var(--red); /* already passes with white text on this theme */

    --shadow-sm: 0 1px 2px rgba(33, 29, 21, 0.06);
    --shadow: 0 1px 2px rgba(33, 29, 21, 0.05), 0 8px 24px -10px rgba(33, 29, 21, 0.18);
    --shadow-lg: 0 16px 40px -12px rgba(33, 29, 21, 0.28), 0 6px 16px -6px rgba(33, 29, 21, 0.18);
  }

  /* --gold on light backgrounds falls just under AA for normal-size text
     (checked: 3.71:1) — small link-style text needs the darker shade here,
     unlike dark mode where --gold alone already clears 6.5:1+. */
  .link-btn, .back-link:hover { color: var(--gold-dark); }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

@keyframes riseIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.94) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes rippleAnim {
  to { transform: scale(1); opacity: 0; }
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  background-image: radial-gradient(900px 420px at 50% -10%, var(--gold-tint), transparent 60%);
  background-repeat: no-repeat;
  background-attachment: fixed;
}

::selection { background: var(--gold); color: var(--on-gold); }

.app {
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
  padding: var(--space-5) var(--space-4) var(--space-6);
  flex: 1;
  animation: riseIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding: 4px 2px;
}

header.topbar h1 {
  font-size: 1.2rem;
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 999px;
  transition: background 0.15s ease, color 0.15s ease;
  position: relative;
  overflow: hidden;
}
.icon-btn:hover { background: var(--card-2); color: var(--text); }
.icon-btn:active { transform: scale(0.96); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}

.balance-card {
  text-align: center;
  padding: var(--space-6) var(--space-5);
  position: relative;
  overflow: hidden;
  border-top: 2px solid transparent;
  border-image: linear-gradient(90deg, transparent, var(--gold), transparent) 1;
}
.balance-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(220px 120px at 50% -20%, var(--gold-tint), transparent 70%);
  pointer-events: none;
}

.balance-card .label {
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
  margin-bottom: 8px;
  position: relative;
}

.balance-card .amount {
  font-size: 2.75rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  position: relative;
}

.amount, .tx-amount, .balance-badge, .overview-total { font-variant-numeric: tabular-nums; }

.positive { color: var(--green); }
.negative { color: var(--red); }
.zero { color: var(--text); }

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

.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 6px;
  margin: 0 -6px;
  border-bottom: 1px solid var(--border);
  border-radius: 12px;
  transition: background 0.15s ease;
}
.tx-item:hover { background: var(--bg-alt); }
.tx-item:last-child { border-bottom: none; }

.tx-icon {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.tx-info { flex: 1; min-width: 0; }
.tx-reason { font-weight: 600; font-size: 0.95rem; }
.tx-meta { color: var(--text-muted); font-size: 0.8rem; margin-top: 2px; }
.tx-amount { font-weight: 700; white-space: nowrap; }

.tx-action {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
  position: relative;
  overflow: hidden;
}
.tx-action:hover { background: var(--bg-alt); color: var(--text); }
.tx-action:active { transform: scale(0.92); }
.tx-action-delete:hover { background: var(--red-tint); color: var(--red); }

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

label { font-size: 0.85rem; color: var(--text-muted); font-weight: 600; }

/* Layout utilities — replace one-off inline styles so spacing stays on the
   shared scale instead of drifting per-element. */
.section-label {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.section-label.with-gap { margin-bottom: var(--space-3); }
.dialog-title {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-4);
}
.row-between { display: flex; justify-content: space-between; align-items: center; }
.row-between.tight { margin-bottom: var(--space-3); }
.btn-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.full-width { width: 100%; }

input[type="text"], input[type="password"], input[type="number"], select {
  width: 100%;
  padding: 14px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-tint);
}

button.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  color: var(--on-gold);
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.15s ease;
  position: relative;
  overflow: hidden;
}
button.btn:hover { filter: brightness(1.06); }
button.btn:active { transform: scale(0.98); }
button.btn.secondary {
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  box-shadow: none;
}
button.btn.secondary:active { transform: scale(0.98); }
button.btn.danger {
  background: linear-gradient(135deg, #ea7b6e, var(--red));
  color: #fff;
}
button.btn.small { padding: 9px 14px; font-size: 0.85rem; border-radius: 10px; }
button.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border-strong);
  background: var(--bg-alt);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
  position: relative;
  overflow: hidden;
}
.chip:hover { border-color: var(--gold); }
.chip:active { transform: scale(0.96); }
.chip.active {
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  border-color: transparent;
  color: var(--on-gold);
  box-shadow: var(--shadow-sm);
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 8px;
  margin: 0 -8px;
  border-bottom: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s ease;
  position: relative;
  overflow: hidden;
}
.user-row:hover { background: var(--bg-alt); }
.user-row:last-child { border-bottom: none; }
.user-name { font-weight: 700; }
.user-id { color: var(--text-muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.balance-badge { font-weight: 700; }

.error { color: var(--red); font-size: 0.88rem; margin-top: 2px; font-weight: 600; }
.hint { color: var(--text-muted); font-size: 0.8rem; margin-top: 10px; text-align: center; line-height: 1.4; }

.center-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.center-screen .card {
  width: 100%;
  max-width: 380px;
  animation: popIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.logo {
  font-size: 2.6rem;
  text-align: center;
  margin-bottom: 8px;
  filter: drop-shadow(0 6px 14px rgba(205, 161, 58, 0.35));
}
.title { text-align: center; font-size: 1.4rem; font-weight: 800; letter-spacing: -0.01em; margin-bottom: 4px; }
.subtitle { text-align: center; color: var(--text-muted); font-size: 0.9rem; margin-bottom: 22px; }

.back-link { color: var(--text-muted); text-decoration: none; font-size: 0.85rem; font-weight: 600; transition: color 0.15s ease; }
.back-link:hover { color: var(--gold); }

dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: min(420px, 92vw);
  max-height: min(640px, 86dvh);
  overflow: hidden;
  background: var(--card-2);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  animation: popIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
dialog::backdrop {
  background: rgba(5, 5, 6, 0.6);
  backdrop-filter: blur(2px);
}
/* Dialogs still using the plain .card wrapper directly (confirm, QR — short,
   fixed content, no header/footer pinning needed) keep their own scroll
   since `dialog` itself is `overflow: hidden` for the .dialog-shell ones. */
dialog > .card { box-shadow: none; margin: 0; border: none; background: transparent; max-height: inherit; overflow-y: auto; }

/* Dialog skeleton — pinned title + pinned action row, only the middle
   scrolls. Keeps "Buchen"/"Abbrechen" reachable without hunting through a
   long form (the split dialog in particular can get tall). */
.dialog-shell {
  display: flex;
  flex-direction: column;
  max-height: min(640px, 86dvh);
}
.dialog-header {
  flex-shrink: 0;
  padding: var(--space-5) var(--space-5) var(--space-4);
}
.dialog-header .dialog-title { margin-bottom: 0; }
.dialog-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--space-5) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.dialog-footer {
  flex-shrink: 0;
  padding: var(--space-4) var(--space-5);
  padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background: var(--card-2);
}

.overview-total { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.01em; }

/* Confirm dialog */
.confirm-card { text-align: center; padding: 26px 22px 22px; }
.confirm-icon { font-size: 2.4rem; margin-bottom: 10px; }
.confirm-title { font-size: 1.15rem; font-weight: 800; margin-bottom: 8px; }
.confirm-message { color: var(--text-muted); font-size: 0.92rem; line-height: 1.5; margin-bottom: 20px; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn { flex: 1; margin: 0; }

/* Split dialog helpers */
.split-equal-box {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.split-equal-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.split-equal-row input { padding: 12px; }
.split-equal-sublabel { font-size: 0.75rem; margin-bottom: 4px; display: block; }

.split-participant-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}
.split-participant-row:last-child { border-bottom: none; }
.split-participant-label {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  font-weight: 600;
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
}
.split-participant-label input[type="checkbox"], .split-participant-label input[type="radio"] {
  width: 20px;
  height: 20px;
  accent-color: var(--gold);
  cursor: pointer;
}

/* Auto-computed € (from the shares math) renders dimmed/borderless — a hand-
   typed override switches to normal input styling. Otherwise there's no way
   to tell what the system filled in vs. what the admin actually typed. */
.split-row-extra input[type="number"]:not(.split-shares-input).auto-computed {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  font-style: italic;
}

.hint-toggle-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  flex-shrink: 0;
}
.hint-toggle-btn:hover { color: var(--gold); }
.static-note {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
}
.split-row-extra {
  display: flex;
  align-items: center;
  gap: 6px;
}
.split-shares-input {
  width: 46px !important;
  padding: 10px 4px !important;
  text-align: center;
}
.split-row-extra input[type="number"]:not(.split-shares-input) {
  width: 88px;
  padding: 10px 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Material switch (e.g. the "Teilen" toggle) */
.md-switch {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}
.md-switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.md-switch-track {
  flex-shrink: 0;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--bg-alt);
  border: 1px solid var(--border-strong);
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.md-switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 0.18s cubic-bezier(0.4, 0, 0.2, 1), background 0.15s ease;
}
.md-switch input:checked ~ .md-switch-track {
  background: var(--gold-tint);
  border-color: var(--gold);
}
.md-switch input:checked ~ .md-switch-track .md-switch-thumb {
  transform: translateX(18px);
  background: var(--gold);
}
.md-switch input:focus-visible ~ .md-switch-track {
  box-shadow: 0 0 0 3px var(--gold-tint);
}
.md-switch-label {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
}

/* Custom scrollbar, webkit only — subtle */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Ausgabe/Einnahme toggle */
.amount-type-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-alt);
}
.amount-type-btn {
  flex: 1;
  border: none;
  background: none;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 12px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
/* Solid fill (not a tinted background) — reads as "this pill is chosen",
   the same selected-state language as .chip.active, instead of pattern-
   matching to a red validation/error banner at a glance. */
.amount-type-btn.expense.active { background: var(--red-fill); color: #fff; }
.amount-type-btn.income.active { background: var(--green-fill); color: #fff; }

/* Success-styled inline notice (reuses .error's slot, different color) */
.notice-success { color: var(--green) !important; }

/* Plain link-style button (e.g. "🔄 Gleichmäßig" reset) */
.link-btn {
  background: none;
  border: none;
  color: var(--gold);
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 4px 0;
}
.link-btn:hover { text-decoration: underline; }

/* Dismissible hints — shown until explicitly closed, remembered via localStorage */
.dismissible-hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 10px 10px 12px;
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.4;
}
.dismissible-hint span { flex: 1; }
.hint-dismiss {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 4px;
  line-height: 1;
  border-radius: 6px;
}
.hint-dismiss:hover { background: var(--border-strong); color: var(--text); }

/* Offline outbox banner */
.outbox-banner {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: linear-gradient(135deg, var(--gold-light), var(--gold-dark));
  color: var(--on-gold);
  font-size: 0.85rem;
  font-weight: 700;
}
.outbox-banner button {
  background: rgba(0, 0, 0, 0.16);
  border: none;
  color: var(--on-gold);
  font-weight: 700;
  font-size: 0.78rem;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.outbox-banner button:active { background: rgba(0, 0, 0, 0.28); }

/* QR dialog */
.qr-card { text-align: center; padding: 26px 22px 22px; }
.qr-name { font-size: 1.15rem; font-weight: 800; }
.qr-id { margin-top: 0; margin-bottom: 14px; font-variant-numeric: tabular-nums; }
.qr-code-container {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}
.qr-code-container svg {
  width: 230px;
  height: 230px;
  background: #fff;
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

/* Ripple — a small authentic Material touch on tap feedback */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  transform: scale(0);
  animation: rippleAnim 0.55s ease-out;
  pointer-events: none;
}
button.btn .ripple, .chip.active .ripple { background: rgba(0, 0, 0, 0.16); }

/* Mobile: dialogs behave like an iOS action/bottom sheet — full width,
   flush to the bottom, rounded only on top. Desktop keeps the centered
   floating card (the default `dialog` rules above). */
@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
@media (max-width: 640px) {
  dialog {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    margin: 0;
    width: 100%;
    max-width: 100%;
    max-height: 88dvh;
    border-radius: 20px 20px 0 0;
    animation: sheetUp 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .dialog-shell { max-height: 88dvh; }
  .dialog-footer { padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom) + 6px); }
}
