:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1c2733;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0e7c66;
  --primary-dark: #0a5f4e;
  --primary-soft: #e6f4f1;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --success: #1e8e5a;
  --success-soft: #e8f7ef;
  --warning: #b9770e;
  --warning-soft: #fdf3e0;
  --accent: #14539a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --sidebar-w: 240px;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #10261f;
  color: #d7e5df;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  padding: 1.25rem 1.25rem 1rem;
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand small { display: block; font-weight: 400; color: #9db8ae; font-size: .8rem; }
.sidebar .brand-logo { display: block; width: 100%; max-width: 180px; height: auto; max-height: 100px; margin: 0 auto .75rem; border-radius: 6px; background: rgba(255,255,255,.12); padding: 6px; object-fit: contain; }
.sidebar nav { padding: .75rem .5rem; flex: 1; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem .85rem;
  border-radius: 8px;
  color: #cfe0d9;
  font-size: .95rem;
}
.sidebar nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar .userbox {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: .85rem;
  color: #9db8ae;
}
.sidebar .userbox strong { color: #fff; display: block; }

.content { flex: 1; padding: 1.75rem 2rem 3rem; max-width: 1400px; }
/* Seite mit der grossen Mitglieder-Tabelle nutzt die volle Fensterbreite (dynamisch) */
.content:has(#mitgliederTable) { max-width: none; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.page-header h1 { margin: 0; font-size: 1.5rem; }
.page-header .subtitle { color: var(--muted); font-size: .9rem; margin-top: .15rem; }

/* ---------- Komponenten ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
}
.stat .label { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: .2rem; }
.stat .hint { font-size: .82rem; color: var(--muted); margin-top: .15rem; }
.stat.primary .value { color: var(--primary); }
.stat.success .value { color: var(--success); }
.stat.danger .value { color: var(--danger); }

.table-wrap { overflow-x: auto; }
table.data {
  /* Tabelle passt sich dynamisch dem Inhalt an (so breit wie nötig, mind. volle Breite);
     bei Ueberbreite scrollt .table-wrap horizontal statt abzuschneiden */
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: .92rem;
}
table.data th, table.data td {
  padding: .6rem .75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td:last-child { white-space: normal; }
table.data td .btn-row { justify-content: flex-end; }
table.data thead th {
  background: #f8fafc;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  position: sticky;
  top: 0;
}
table.data tbody tr:hover { background: #f1f5f9; }
table.data th a { color: inherit; }
table.data th a:hover { color: var(--primary); text-decoration: none; }
.sort-ind { font-size: .75em; margin-left: .25rem; }

.badge {
  display: inline-block;
  padding: .15rem .6rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
}
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.neutral { background: #eef2f7; color: var(--muted); }
.badge.primary { background: var(--primary-soft); color: var(--primary-dark); }

.btn {
  display: inline-block;
  padding: .5rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: #f1f5f9; }
.btn.danger { background: var(--danger); }
.btn.sm { padding: .3rem .65rem; font-size: .82rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }

.filterbar {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 1rem;
}
.filterbar .field { display: flex; flex-direction: column; gap: .25rem; }
.filterbar label { font-size: .78rem; color: var(--muted); font-weight: 600; }

input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="date"], select, textarea {
  padding: .5rem .7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .92rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  min-width: 160px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}

.flash {
  padding: .7rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: .92rem;
}
.flash.success { background: var(--success-soft); color: var(--success); }
.flash.danger { background: var(--danger-soft); color: var(--danger); }
.flash.info { background: var(--primary-soft); color: var(--primary-dark); }
.flash.warning { background: var(--warning-soft); color: var(--warning); }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: .4rem 2rem;
}
.detail-grid dt { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.detail-grid dd { margin: 0 0 .5rem; font-weight: 500; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #10261f 0%, #0e7c66 100%);
  padding: 1rem;
}
.login-card {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
  padding: 2.25rem;
  width: 100%;
  max-width: 400px;
}
.login-card h1 { margin: 0 0 .25rem; font-size: 1.4rem; }
.login-card p.sub { color: var(--muted); margin: 0 0 1.5rem; font-size: .9rem; }
.login-card .field { margin-bottom: 1rem; display: flex; flex-direction: column; gap: .3rem; }
.login-card label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.login-card input { width: 100%; }
.login-card .btn { width: 100%; padding: .65rem; }

.muted { color: var(--muted); }
.text-right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.money-positive { color: var(--success); font-weight: 600; }
.money-negative { color: var(--danger); font-weight: 600; }

.bar-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.bar-row .bar-label { width: 90px; font-size: .85rem; color: var(--muted); }
.bar-track { flex: 1; background: #eef2f7; border-radius: 6px; height: 14px; overflow: hidden; display: flex; }
.bar-ein { background: var(--success); height: 100%; }
.bar-aus { background: var(--danger); height: 100%; }
.bar-row .bar-val { width: 90px; text-align: right; font-size: .8rem; color: var(--muted); }

/* ---------- Bulk-Action-Bar ---------- */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: var(--radius);
  padding: .6rem 1rem;
  margin-bottom: 1rem;
}
.bulk-bar .bulk-info { font-size: .9rem; white-space: nowrap; }
.bulk-bar .bulk-info strong { color: var(--warning); }
.bulk-bar .bulk-actions { display: flex; align-items: flex-end; gap: .75rem; flex-wrap: wrap; flex: 1; }
.bulk-bar .bulk-actions form { display: flex; align-items: flex-end; gap: .5rem; flex-wrap: wrap; }
.bulk-bar .field { display: flex; flex-direction: column; gap: .15rem; }
.bulk-bar .field label { font-size: .72rem; color: var(--muted); font-weight: 600; }

table.data input[type="checkbox"] { cursor: pointer; width: 16px; height: 16px; accent-color: var(--primary); }
.member-row:hover { background: #f1f5f9; }

/* ---------- Mobil (Handy-Browser): alles dynamisch umbrechend ---------- */
@media (max-width: 860px) {
  .layout { flex-direction: column; }
  /* Sidebar wird zur kompakten Top-Bar */
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
  }
  .sidebar .brand {
    border-bottom: none;
    padding: .55rem .9rem;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: .5rem;
  }
  .sidebar .brand small { display: inline; font-size: .72rem; }
  .sidebar .brand-logo { width: auto; max-width: 44px; max-height: 32px; margin: 0; padding: 2px; }
  .sidebar nav { display: flex; flex-wrap: nowrap; overflow-x: auto; padding: .4rem .5rem; flex: 1 1 100%; }
  .sidebar nav a { white-space: nowrap; padding: .45rem .7rem; font-size: .88rem; }
  .sidebar .userbox { border-top: none; padding: .5rem .9rem; font-size: .78rem; }

  .content { padding: .9rem .75rem 2.5rem; }
  .page-header { flex-direction: column; align-items: flex-start; gap: .6rem; margin-bottom: .9rem; }
  .page-header h1 { font-size: 1.25rem; }

  .card { padding: .85rem .9rem; margin-bottom: .9rem; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .6rem; margin-bottom: .9rem; }
  .stat { padding: .7rem .9rem; }
  .stat .value { font-size: 1.25rem; }

  /* Formulare: Felder nehmen die volle Breite */
  .filterbar { flex-direction: column; align-items: stretch; gap: .6rem; }
  .filterbar .field { width: 100%; }
  .card form .field input, .card form .field select, .card form .field textarea { width: 100%; min-width: 0; }
  input[type="text"], input[type="password"], input[type="email"],
  input[type="number"], input[type="date"], select, textarea { min-width: 0; }
  .btn-row { gap: .4rem; }
  .btn { padding: .45rem .8rem; }

  .bulk-bar { flex-direction: column; align-items: stretch; }
  .bulk-bar .bulk-actions { flex-direction: column; align-items: stretch; }
  .bulk-bar .bulk-actions form { flex-direction: column; align-items: stretch; }

  /* Tabellen: kompakt, Text bricht um, alles sichtbar */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.data { width: 100%; min-width: 0; font-size: .82rem; }
  table.data th, table.data td { padding: .35rem .4rem; white-space: normal; overflow-wrap: anywhere; }
  table.data thead th { position: static; }

  /* Grosse Mitglieder-Tabelle (12 Spalten): bleibt breit und scrollt horizontal statt abzuschneiden */
  #mitgliederTable { width: max-content; min-width: 100%; }
  #mitgliederTable th, #mitgliederTable td { white-space: nowrap; overflow-wrap: normal; padding: .3rem .35rem; font-size: .78rem; }
  #mitgliederTable .col-filter-input { font-size: .68rem; padding: .12rem .18rem; }

  .bar-row .bar-label, .bar-row .bar-val { width: 58px; font-size: .75rem; }
}

@media (max-width: 480px) {
  .content { padding: .7rem .5rem 2rem; }
  .card { padding: .7rem .6rem; }
  .stats { grid-template-columns: 1fr 1fr; }
  .page-header h1 { font-size: 1.15rem; }
}

/* ---------- Mitgliederliste: Header + Filter-Zeile ---------- */
.header-row th {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: .5rem .6rem;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  vertical-align: middle;
  text-transform: none;
  letter-spacing: 0;
}

.filter-row th {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  padding: .25rem .3rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.sort-link {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}
.sort-link:hover { color: var(--primary); text-decoration: none; }

.sort-ind {
  font-size: .7rem;
  color: var(--primary);
  min-width: .8rem;
}

/* Filter-Eingabefelder in der Tabellen-Header-Zeile */
.col-filter-input {
  width: 100%;
  min-width: 0;
  padding: .2rem .3rem;
  font-size: .75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}
.col-filter-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}
.col-filter-input::placeholder { color: #94a3b8; font-size: .72rem; }
select.col-filter-input { padding: .18rem .2rem; }

/* Gestapelte Filterfelder in einer Header-Zelle (z. B. Name + EM, Kontakt + Handy + Fitarco) */
.col-stack { display: flex; flex-direction: column; gap: 2px; }
.filter-row .col-stack .col-filter-input { padding: .14rem .22rem; font-size: .7rem; }
.filter-row .col-stack select.col-filter-input { padding: .12rem .18rem; }

/* Tabelle kompakter */
#mitgliederTable th,
#mitgliederTable td {
  padding: .4rem .5rem;
  font-size: .85rem;
}
#mitgliederTable td.num {
  text-align: right;
  white-space: nowrap;
}
