:root {
  --color-primary: #c8791e;
  --color-primary-dark: #a8631a;
  --color-bg: #f7f4ef;
  --color-card: #ffffff;
  --color-text: #2b2620;
  --color-text-muted: #6b6459;
  --color-border: #e4ddd0;
  --color-success: #2e7d32;
  --color-success-bg: #e8f5e9;
  --color-error: #c62828;
  --color-error-bg: #fdecea;
  --color-danger: #c62828;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

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

h1 { font-size: 1.5rem; margin: 0.2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }

a { color: var(--color-primary-dark); }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
}

/* --- Top bar / nav --- */

.topbar {
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--color-text);
  white-space: nowrap;
}

.nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1.2rem;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  justify-content: flex-end;
}

.nav-links a {
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: 0.92rem;
  padding: 0.3rem 0;
}

.nav-links a:hover { color: var(--color-primary-dark); }

@media (max-width: 700px) {
  .nav-toggle { display: inline-block; }
  .nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--color-border);
    margin-top: 0.5rem;
  }
  .nav-links.nav-open { display: flex; }
  .topbar-inner { flex-wrap: wrap; }
}

/* --- Flash messages --- */

.flash-list { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }

.flash {
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  font-size: 0.92rem;
}

.flash-success { background: var(--color-success-bg); color: var(--color-success); }
.flash-error { background: var(--color-error-bg); color: var(--color-error); }

/* --- Cards / forms --- */

.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.form-card { max-width: 420px; }

.form-card label,
.login-card label {
  display: block;
  margin-bottom: 0.9rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.form-card input[type="text"],
.form-card input[type="password"],
.login-card input {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: #fff;
  color: var(--color-text);
}

fieldset { border: 1px solid var(--color-border); border-radius: var(--radius); margin-bottom: 1rem; }

.radio-option { display: block; margin: 0.4rem 0; font-size: 0.95rem; }

.form-actions { display: flex; gap: 0.6rem; margin-top: 0.5rem; }

.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.form-inline input,
.form-inline select {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.92rem;
}

/* --- Buttons --- */

.btn {
  display: inline-block;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-outline { background: #fff; border-color: var(--color-border); color: var(--color-text); }
.btn-outline:hover { border-color: var(--color-primary); color: var(--color-primary-dark); }

.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

.btn-block { width: 100%; }

.btn-small { padding: 0.35rem 0.65rem; font-size: 0.82rem; }

.btn-beer:disabled { opacity: 0.45; cursor: not-allowed; }

.protected-hint {
  color: var(--color-text-muted);
  font-size: 0.82rem;
  font-style: italic;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Login --- */

.login-wrap {
  display: flex;
  justify-content: center;
  padding-top: 3rem;
}

.login-card { width: 100%; max-width: 340px; }

/* --- Dashboard table --- */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-bar { margin-bottom: 1rem; }

.search-bar input {
  width: 100%;
  max-width: 320px;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: #fff;
  color: var(--color-text);
}

.table-wrap { overflow-x: auto; background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow); }

.spieler-table { width: 100%; border-collapse: collapse; min-width: 560px; }

.spieler-table th,
.spieler-table td {
  padding: 0.7rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.92rem;
  vertical-align: middle;
}

.spieler-table thead th {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.spieler-table tbody tr:last-child td { border-bottom: none; }

.cell-name a { color: var(--color-text); text-decoration: none; font-weight: 600; }
.cell-name a:hover { color: var(--color-primary-dark); }

.cell-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.saldo-badge {
  display: inline-block;
  min-width: 2rem;
  text-align: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--color-success-bg);
  color: var(--color-success);
  font-weight: 700;
}

.saldo-badge.saldo-zero { background: var(--color-error-bg); color: var(--color-error); }

.qr-thumb { width: 40px; height: 40px; display: block; border-radius: 4px; border: 1px solid var(--color-border); }

/* Unter 700px: Tabelle als Karten-Liste, alle Aktionen ohne horizontales Scrollen sichtbar */
@media (max-width: 700px) {
  .table-wrap {
    overflow-x: visible;
    background: transparent;
    border: none;
    box-shadow: none;
  }

  .spieler-table { min-width: 0; }

  .spieler-table thead { display: none; }

  .spieler-table, .spieler-table tbody, .spieler-table tr, .spieler-table td {
    display: block;
    width: 100%;
  }

  .spieler-table tr {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.85rem 1rem;
    margin-bottom: 0.75rem;
  }

  .spieler-table tr:last-child { margin-bottom: 0; }

  .spieler-table td {
    padding: 0.4rem 0;
    border-bottom: none;
  }

  .spieler-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.2rem;
  }

  .spieler-table td.cell-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
  }
  .cell-actions .btn { width: 100%; }
}

.empty-state { color: var(--color-text-muted); padding: 1rem 0; }

.back-link { margin-bottom: 0.25rem; }
.back-link a { text-decoration: none; font-size: 0.9rem; }

/* --- Timeline / Verlauf --- */

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

.timeline-item {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}

.timeline-icon { font-size: 1.2rem; }

.timeline-meta { color: var(--color-text-muted); font-size: 0.82rem; margin-top: 0.15rem; }

/* --- Public player page --- */

.public-page { max-width: 480px; margin: 0 auto; }

.saldo-display {
  text-align: center;
  background: var(--color-success-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1rem 0;
}

.saldo-display.saldo-zero { background: var(--color-error-bg); }

.saldo-number { display: block; font-size: 3rem; font-weight: 800; color: var(--color-success); line-height: 1; }
.saldo-display.saldo-zero .saldo-number { color: var(--color-error); }

.saldo-label { display: block; color: var(--color-text-muted); font-size: 0.85rem; margin-top: 0.3rem; }

.qr-box { text-align: center; margin: 1.5rem 0; }
.qr-box img { width: 160px; height: 160px; border: 1px solid var(--color-border); border-radius: var(--radius); background: #fff; padding: 0.5rem; }
.qr-hint { color: var(--color-text-muted); font-size: 0.82rem; margin-top: 0.5rem; }

/* --- Popup --- */

.popup-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.popup-overlay.show { display: flex; }

.popup-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.popup-box h3 { margin-top: 0; }
.popup-box .btn { margin-top: 0.75rem; }
