:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #e3e7ef;
  --text: #141a26;
  --muted: #6b7486;
  --primary: #141a26;
  --accent: #2f5bea;
  --green: #2e8b46;
  --green-bg: #e8f6ec;
  --red: #c9372c;
  --red-bg: #fdecea;
  --yellow: #8a6a00;
  --yellow-bg: #fff6d6;
  --blue-bg: #e9efff;
  --orange: #d9822b;
  --reload-bg: #fff8e6;
  --reload-border: #f3d98f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 26, 38, .05), 0 2px 8px rgba(20, 26, 38, .04);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.7rem; margin: 0; }
h2 { font-size: 1.2rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }

/* --- Layout ------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1.25rem;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: .45rem; font-weight: 800; font-size: 1.1rem; color: var(--text); white-space: nowrap; }
.brand img { height: 30px; max-width: 120px; object-fit: contain; border-radius: 6px; }
.login-card h1.brand { font-size: 1.7rem; }
.login-card h1.brand img { height: 40px; }
.brand .wordmark span { color: var(--accent); }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; gap: .25rem; flex: 1; justify-content: center; overflow-x: auto; scrollbar-width: none; }
.mainnav::-webkit-scrollbar { display: none; }
.mainnav a {
  padding: .45rem .8rem; border-radius: 999px; color: var(--muted);
  font-weight: 600; white-space: nowrap;
}
.mainnav a:hover { text-decoration: none; color: var(--text); }
.mainnav a.active { background: var(--surface-2); color: var(--text); }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.topbar-actions form { margin: 0; }
.bell { position: relative; font-size: 1.15rem; padding: .25rem; color: var(--muted); }
.bell:hover { text-decoration: none; }
.bell-count {
  position: absolute; top: -4px; right: -6px;
  background: var(--red); color: #fff; font-size: .7rem; font-weight: 700;
  border-radius: 999px; padding: 0 .35rem; line-height: 1.3;
}

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.25rem;
}
.page-head .actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: flex-end; }
.page-head .sub { color: var(--muted); font-size: .85rem; margin-top: .3rem; }
.section-title { text-align: center; margin: 2rem 0 1rem; }
.stack-v > * + * { margin-top: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.spacer { flex: 1; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem;
}
.card + .card { margin-top: 1rem; }
.cards-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.cards-2 > .card + .card, .stats > .card + .card { margin-top: 0; }

/* --- Stat tiles ------------------------------------------------------------ */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.stat { padding: .9rem 1.1rem; }
.stat-label { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.stat-value { font-size: 1.45rem; font-weight: 800; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.stats-inline { display: flex; flex-wrap: wrap; gap: 1.5rem; }

/* --- Buttons, pills, badges ------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: .5rem .9rem; border-radius: 9px; font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap; line-height: 1.2;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-warn { background: var(--yellow-bg); border-color: #f1df9a; color: var(--yellow); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; border-radius: 7px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.linkbtn.danger { color: var(--red); }
form.inline { display: inline; margin: 0; }

.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .2rem; scrollbar-width: none; margin-bottom: 1rem; flex-wrap: wrap; }
.chip {
  padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: .85rem; white-space: nowrap;
}
.chip:hover { text-decoration: none; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.badge {
  display: inline-block; padding: .12rem .5rem; border-radius: 999px; font-size: .75rem;
  font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap;
  border: 1px solid transparent;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-blue { background: var(--blue-bg); color: var(--accent); }
.badge-dark { background: var(--primary); color: #fff; }
.badges { display: flex; flex-wrap: wrap; gap: .25rem; }

.pos { color: var(--green); }
.neg { color: var(--red); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Bookmaker logo -------------------------------------------------------- */
.logo { display: inline-flex; align-items: center; height: 28px; max-width: 96px; }
.logo img { max-height: 28px; max-width: 96px; object-fit: contain; border-radius: 4px; }
.logo-text {
  display: inline-block; max-width: 110px; padding: .2rem .45rem; border-radius: 6px;
  background: var(--primary); color: #fff; font-weight: 800; font-size: .78rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.logo-plain { color: var(--muted); font-weight: 600; font-size: .85rem; max-width: 140px; }

/* --- Tables (cards on mobile) ---------------------------------------------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; padding: .75rem .8rem; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data th a { color: inherit; }
table.data td { padding: .7rem .8rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.row-link { cursor: pointer; }
table.data tr.row-link:hover td { background: #fafbfd; }
table.data tr.highlight td { background: #f6fbf7; }
table.data th.num, table.data td.num { text-align: right; }
.sub-rows td { background: #fafbfd; font-size: .9rem; }
.account-lines { display: flex; flex-direction: column; gap: .15rem; }

@media (max-width: 760px) {
  table.data.responsive thead { display: none; }
  table.data.responsive, table.data.responsive tbody, table.data.responsive tr, table.data.responsive td { display: block; width: 100%; }
  table.data.responsive tr { padding: .6rem .9rem; border-bottom: 1px solid var(--border); }
  table.data.responsive tr:last-child { border-bottom: 0; }
  table.data.responsive td {
    border: 0; padding: .2rem 0; display: flex; justify-content: space-between; gap: 1rem; text-align: right;
  }
  table.data.responsive td::before {
    content: attr(data-label); color: var(--muted); font-size: .78rem; font-weight: 600; text-align: left;
  }
  table.data.responsive td[data-label=""]::before, table.data.responsive td:not([data-label])::before { content: none; }
  table.data.responsive td.cell-main { display: block; text-align: left; font-size: 1rem; }
  table.data.responsive td.num { justify-content: space-between; }
}

/* --- Forms ----------------------------------------------------------------- */
.form label { display: block; font-weight: 600; font-size: .88rem; color: #3b4456; margin-bottom: .85rem; }
.form label.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text); width: 100%; margin-top: .3rem;
  padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2);
}
input[type=checkbox], input[type=radio] { width: auto; margin: 0; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d4fb; border-color: var(--accent); background: #fff; }
textarea { min-height: 90px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .5rem; flex-wrap: wrap; }
.hint { font-size: .8rem; color: var(--muted); font-weight: 400; margin-top: .25rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; }
.inline-form input, .inline-form select { margin-top: 0; width: auto; flex: 1 1 140px; }
.checklist { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 9px; padding: .4rem .7rem; background: var(--surface); }
.checklist label { display: flex; gap: .5rem; align-items: center; font-weight: 500; margin: .3rem 0; }
.cat-picker { display: flex; flex-wrap: wrap; gap: .4rem; }
.cat-picker label { margin: 0; }
.cat-picker input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.cat-picker input:focus-visible + span { outline: 2px solid var(--accent); }
.cat-picker span {
  display: inline-block; padding: .3rem .7rem; border-radius: 999px; border: 1px solid #cfe6d6;
  background: #f4faf6; color: #6c8a74; font-weight: 600; font-size: .82rem; cursor: pointer;
}
.cat-picker input:checked + span { background: var(--green); border-color: var(--green); color: #fff; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: .3rem .6rem; font: inherit; font-size: .82rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--green-bg); color: var(--green); }

.login-wrap { display: flex; justify-content: center; padding-top: 10vh; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { margin-bottom: 1rem; }

.flash { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-weight: 600; }
.flash-ok { background: var(--green-bg); color: var(--green); }
.flash-error { background: var(--red-bg); color: var(--red); }
.flash-info { background: var(--blue-bg); color: var(--accent); }

/* --- Inbox ----------------------------------------------------------------- */
.searchbar { display: flex; gap: .5rem; margin-bottom: .9rem; }
.searchbar input { margin: 0; }
/* Einfache Listenzeile (Hinweise, leere Zustände) */
.mail-row { display: grid; grid-template-columns: 1fr auto; gap: .75rem; align-items: center; padding: .65rem .9rem; border-bottom: 1px solid var(--border); }
.mail-row:last-child { border-bottom: 0; }
.mail-row .date { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.icon-btn { background: none; border: 0; cursor: pointer; font-size: 1.05rem; padding: .25rem .35rem; border-radius: 6px; color: var(--muted); line-height: 1; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

/* --- Mail-Kacheln (E-Mail-Ansicht und Mitspieler-Datensatz) ------------------ */
.mail-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.mail-list > .mail-tile, .mail-list > details { border-bottom: 1px solid var(--border); }
.mail-list > :last-child { border-bottom: 0; }
.mail-list a, .mail-list a:hover { color: inherit; }
.mail-empty { padding: .9rem; }
.mail-tile {
  display: grid; align-items: center; gap: .75rem; padding: .6rem .9rem;
  grid-template-columns: 22px 110px 170px minmax(0, 1fr) auto auto auto;
  grid-template-areas: "sel sender who subject note date foot";
}
.mail-tile > .sel { grid-area: sel; }
.mail-tile > .sender { grid-area: sender; min-width: 0; }
.mail-tile > .who { grid-area: who; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-tile > .who a { font-weight: 600; }
.mail-tile > .subject { grid-area: subject; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-tile > .subject a { font-weight: 600; }
.mail-tile > .date { grid-area: date; color: var(--muted); font-size: .85rem; white-space: nowrap; }
.mail-tile > .foot { grid-area: foot; display: flex; align-items: center; justify-content: flex-end; gap: .6rem; }
.mail-tile.sub { grid-template-columns: 22px 170px minmax(0, 1fr) auto auto auto; grid-template-areas: "sel who subject note date foot"; padding-left: 2.2rem; font-size: .9rem; }
.mail-tile > .note { grid-area: note; }
.mail-tile.sub > .subject a { font-weight: 400; }
.mail-tile.reload-full, .mail-tile.reload-partial { background: var(--reload-bg); }
.partial-note { color: var(--orange); font-weight: 700; font-size: .82rem; white-space: nowrap; }

details.stack > summary { list-style: none; cursor: pointer; }
details.stack > summary::-webkit-details-marker { display: none; }
details.stack > .stack-body { border-top: 1px dashed var(--border); }
details.stack > .stack-body > .mail-tile + .mail-tile { border-top: 1px solid var(--border); }
.stack-count {
  display: inline-block; padding: .15rem .65rem; border-radius: 999px; white-space: nowrap;
  background: var(--blue-bg); color: var(--accent); border: 1px solid #cfdafb; font-weight: 700; font-size: .82rem;
}
details.stack > summary .stack-count::after { content: " ▸"; }
details.stack[open] > summary .stack-count::after { content: " ▾"; }

.mail-actions { display: flex; gap: .4rem; }
.act-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .25rem;
  width: 36px; height: 36px; padding: 0; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--muted); cursor: pointer; font: inherit;
}
.act-btn:hover { color: var(--text); border-color: #cbd2df; }
.act-btn svg { width: 18px; height: 18px; }
.act-btn.star-partial, .act-btn.star-full { color: var(--orange); border-color: #f2c88f; background: #fff0db; }
.act-btn.stack-btn { width: auto; padding: 0 .55rem; font-weight: 700; font-size: .8rem; }

@media (max-width: 760px) {
  .mail-list { background: none; border: 0; box-shadow: none; overflow: visible; display: flex; flex-direction: column; gap: .75rem; }
  .mail-list > .mail-tile, .mail-list > details, .mail-list > .mail-empty {
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden;
  }
  .mail-list > .reload-full, .mail-list > .reload-partial { background: var(--reload-bg); border-color: var(--reload-border); }
  .mail-tile, .mail-tile.sub {
    grid-template-columns: auto minmax(0, 1fr) auto; gap: .5rem .6rem; padding: .9rem 1rem;
    grid-template-areas: "who who date" "sender sender sender" "subject subject subject" "note foot foot";
  }
  .mail-tile.sub { grid-template-areas: "who who date" "subject subject subject" "note foot foot"; }
  .mail-tile > .sel { display: none; }  /* Mehrfachauswahl nur am Desktop */
  .mail-tile > .who { font-size: 1.05rem; }
  .mail-tile > .who a { font-weight: 700; }
  .mail-tile > .subject { white-space: normal; font-size: 1rem; }
  .mail-tile > .date { justify-self: end; }
  .mail-tile > .foot { justify-content: flex-end; }
  .act-btn { width: 46px; height: 46px; border-radius: 12px; }
  .act-btn svg { width: 22px; height: 22px; }
  .act-btn.stack-btn { width: auto; padding: 0 .7rem; }
}

/* --- Accounts -------------------------------------------------------------- */
.account-card .balance { font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.account-card .meta { font-size: .85rem; color: var(--muted); margin: .2rem 0 .8rem; }
.account-card .meta a, .account-card .meta button { font-size: .85rem; }
.tx-list { list-style: none; margin: .75rem 0 0; padding: 0; }
.tx-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: .75rem; align-items: center; padding: .5rem 0; border-top: 1px solid var(--border); font-size: .92rem; }
.tx-list .tx-date { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.tx-list .tx-amount { font-weight: 700; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx-desc .badges { margin-top: .15rem; }
details.fold > summary { cursor: pointer; font-weight: 600; color: var(--accent); margin: .5rem 0; }
.pager { display: flex; justify-content: center; gap: .75rem; align-items: center; margin-top: .75rem; color: var(--muted); }

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: .5rem .9rem; gap: .4rem; }
  .mainnav { order: 3; flex: 0 0 100%; justify-content: flex-start; }
  .topbar-actions { margin-left: auto; }
  .container { padding: 1rem .9rem 3rem; }
  h1 { font-size: 1.4rem; }
  .stat-value { font-size: 1.2rem; }
  .page-head .actions { justify-content: flex-start; }
  .cards-2 { grid-template-columns: 1fr; }
  .chips { flex-wrap: nowrap; }
}

/* --- Dialoge --------------------------------------------------------------- */
dialog.dialog {
  border: 0; border-radius: 14px; padding: 1.4rem; width: min(460px, calc(100vw - 1.5rem));
  box-shadow: 0 20px 60px rgba(20, 26, 38, .25); color: var(--text);
}
dialog.dialog::backdrop { background: rgba(20, 26, 38, .38); }
dialog.dialog h3 { font-size: 1.1rem; margin-bottom: .15rem; }

/* --- Konto-Logos --------------------------------------------------------- */
.acc-label { display: inline-flex; align-items: center; gap: .4rem; }
.acc-logo { height: 20px; max-width: 80px; object-fit: contain; border-radius: 4px; }
h1 .acc-logo { height: 28px; }

/* --- Mitspieler-Kacheln (nur mobil) ---------------------------------------- */
.mobile-only { display: none; }
.player-card { display: block; color: inherit; padding: 1rem; border-radius: 16px; }
.player-card:hover { text-decoration: none; }
.pc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; padding-bottom: .8rem; margin-bottom: .8rem; border-bottom: 1px solid var(--border); }
.pc-who { min-width: 0; }
.pc-name { font-weight: 800; font-size: 1.15rem; }
.pc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.pc-tile { border: 1px solid var(--border); border-radius: 12px; padding: .6rem .65rem; background: #fafbfd; min-width: 0; }
.pc-tile .stat-label { margin-bottom: .35rem; overflow-wrap: anywhere; }
.pc-tile.pc-alert { border-color: var(--red); box-shadow: 0 0 0 1px var(--red) inset; }
.pc-line { display: flex; flex-wrap: wrap; column-gap: .4rem; font-size: .88rem; font-variant-numeric: tabular-nums; }
.pc-line span { color: var(--muted); }
.pc-line b { white-space: nowrap; margin-left: auto; }
.pc-big { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
@media (max-width: 760px) {
  .desktop-only { display: none; }
  .mobile-only { display: block; }
  .player-cards { display: flex; flex-direction: column; gap: .9rem; }
  .player-cards > .card + .card { margin-top: 0; }
}

/* --- Mail-Inhalt als Text -------------------------------------------------- */
.mail-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; font-size: .98rem; }
.mail-body a, .mail-body a:hover { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.mail-body .url { color: var(--muted); font-size: .88em; }
.rl-remove { border-top: 1px solid var(--border); padding-top: .6rem; margin-top: .6rem; }
.rl-remove p { margin: 0 0 .4rem; }

/* --- Akkordeon (z. B. Postfächer) ------------------------------------------ */
details.accordion > summary { display: flex; align-items: center; gap: .6rem; cursor: pointer; list-style: none; }
details.accordion > summary::-webkit-details-marker { display: none; }
details.accordion > summary h2 { margin: 0; }
details.accordion > summary::after { content: "▸"; margin-left: auto; color: var(--muted); }
details.accordion[open] > summary::after { content: "▾"; }
details.accordion[open] > summary { margin-bottom: .75rem; }
details.accordion > summary .small { white-space: nowrap; }
