/* =========================================================
   Faustball-App — Styles
   Minimaler, mobile-freundlicher MVP-Look.
   ========================================================= */

:root {
    --bg:           #f4f5f7;
    --surface:      #ffffff;
    --surface-2:    #f9fafb;
    --border:       #e5e7eb;
    --border-2:     #d1d5db;
    --text:         #111827;
    --text-muted:   #6b7280;
    --primary:      #2563eb;
    --primary-dk:   #1d4ed8;
    --primary-bg:   #dbeafe;
    --good:         #16a34a;
    --good-bg:      #dcfce7;
    --bad:          #dc2626;
    --bad-bg:       #fee2e2;
    --warn:         #d97706;
    --warn-bg:      #fef3c7;
    --serve-bad-bg: #f3f4f6;
    --serve-bad-fg: #6b7280;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
    --shadow:    0 2px 8px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
}

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

h1, h2, h3 { line-height: 1.2; margin: 1em 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; margin-top: 1.5em; }

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

/* ---------- Layout ---------- */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: .75rem 1rem;
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap;
    gap: .5rem;
    box-shadow: var(--shadow-sm);
}
.brand {
    color: var(--text);
    font-weight: 700;
    display: flex; align-items: center; gap: .5rem;
}
.brand .logo {
    display: inline-grid; place-items: center;
    width: 1.75rem; height: 1.75rem; border-radius: .375rem;
    background: var(--primary); color: #fff; font-weight: 800;
}
.topnav { display: flex; gap: .5rem 1rem; align-items: center; flex-wrap: wrap; }
.topnav a { color: var(--text); padding: .375rem .5rem; border-radius: .375rem; }
.topnav a:hover { background: var(--surface-2); text-decoration: none; }
.user-pill {
    background: var(--primary-bg); color: var(--primary-dk);
    padding: .25rem .625rem; border-radius: 999px; font-size: .85rem;
}
.inline { display: inline; }
.link-btn {
    background: none; border: none; padding: .375rem .5rem;
    color: var(--text); cursor: pointer; border-radius: .375rem;
    font: inherit;
}
.link-btn:hover { background: var(--surface-2); }

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

.bottombar {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
}

/* ---------- Cards & Lists ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: .625rem;
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
}
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}
.card.action {
    display: block;
    color: var(--text);
    transition: transform .08s ease, box-shadow .12s ease;
}
.card.action:hover {
    text-decoration: none;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: var(--border-2);
}
.card.action h2 { margin-top: 0; }

.card.resume {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    background: var(--primary-bg);
    border-color: #bfdbfe;
}

.table-list {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: .625rem;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.table-list th,
.table-list td {
    padding: .625rem .875rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.table-list th { background: var(--surface-2); font-weight: 600; color: var(--text-muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.table-list tr:last-child td { border-bottom: none; }
.table-list tr:hover { background: var(--surface-2); }

.badge {
    display: inline-block;
    padding: .125rem .5rem;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: .8rem;
}
.badge.done { background: var(--good-bg); border-color: #bbf7d0; color: var(--good); }
.badge.status-completed   { background: var(--good-bg);  color: var(--good);  border-color: #bbf7d0; }
.badge.status-in_progress { background: var(--primary-bg); color: var(--primary-dk); border-color: #bfdbfe; }
.badge.status-abandoned   { background: var(--warn-bg);  color: var(--warn);  border-color: #fde68a; }

/* ---------- Forms ---------- */
.alert {
    padding: .75rem 1rem;
    border-radius: .375rem;
    margin: .75rem 0;
    border: 1px solid var(--border);
    background: var(--surface);
}
.alert-error { background: var(--bad-bg);   border-color: #fecaca; color: var(--bad); }
.alert-info  { background: var(--primary-bg); border-color: #bfdbfe; color: var(--primary-dk); }

.form-stack { display: flex; flex-direction: column; gap: 1rem; max-width: 720px; }
.form-stack fieldset {
    border: 1px solid var(--border);
    border-radius: .625rem;
    padding: 1rem 1.25rem;
    background: var(--surface);
}
.form-stack legend { padding: 0 .5rem; font-weight: 600; }
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .75rem 1rem;
}
.grid-2 label { display: flex; flex-direction: column; gap: .25rem; }
@media (max-width: 540px) { .grid-2 { grid-template-columns: 1fr; } }

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="time"], input[type="number"],
select, textarea {
    padding: .5rem .625rem;
    border: 1px solid var(--border-2);
    border-radius: .375rem;
    font: inherit;
    background: #fff;
    color: var(--text);
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
    border-color: var(--primary);
}

button, .btn-primary, .btn-secondary, .btn-ghost, .btn-danger {
    padding: .5rem 1rem;
    border-radius: .375rem;
    border: 1px solid var(--border-2);
    background: #fff;
    color: var(--text);
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}
.btn-primary  { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dk); border-color: var(--primary-dk); text-decoration: none; }
.btn-secondary { background: var(--surface-2); }
.btn-ghost    { background: transparent; border-color: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--surface-2); text-decoration: none; }
.btn-danger   { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }

.form-actions {
    display: flex; justify-content: flex-end; gap: .5rem;
}

/* Auth Pages */
.auth-page main.container { max-width: 460px; }
.auth-card { background: var(--surface); padding: 1.5rem; border-radius: .625rem; box-shadow: var(--shadow); border: 1px solid var(--border); }
.auth-card form { display: flex; flex-direction: column; gap: .75rem; margin-top: 1rem; }
.auth-card label { display: flex; flex-direction: column; gap: .25rem; }
.auth-card .btn-primary { margin-top: .25rem; }

/* Players-Liste in new_game.php */
#players-list { display: flex; flex-direction: column; gap: .375rem; margin-bottom: .5rem; }
.player-row { display: flex; gap: .375rem; align-items: center; }
.player-row input { flex: 1; }
.remove-player {
    width: 2rem; height: 2rem;
    line-height: 1;
    display: grid; place-items: center;
    color: var(--bad);
    font-weight: 700;
    padding: 0;
    border-radius: .375rem;
}
.remove-player:hover { background: var(--bad-bg); }

/* ---------- Game Header ---------- */
.game-header {
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}
.game-header h1 { margin: 0; font-size: 1.5rem; }
.game-meta { text-align: right; }
.timer {
    font-variant-numeric: tabular-nums;
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--primary-dk);
    line-height: 1;
}

/* ---------- Set tabs ---------- */
.set-tabs {
    display: flex; gap: .25rem; flex-wrap: wrap;
    margin: 1rem 0;
}
.set-tab {
    padding: .5rem 1rem;
    border-radius: .375rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    display: inline-flex; align-items: center; gap: .375rem;
}
.set-tab:hover { background: var(--surface-2); text-decoration: none; }
.set-tab.is-current { background: var(--primary); color: #fff; border-color: var(--primary); }
.set-tab.is-current:hover { background: var(--primary-dk); }

/* ---------- Stat-Tabelle ---------- */
.stat-wrapper { overflow-x: auto; border-radius: .625rem; border: 1px solid var(--border); background: var(--surface); }
.table-scroll { overflow-x: auto; border-radius: .625rem; border: 1px solid var(--border); background: var(--surface); margin-bottom: 1rem; }

.stat-table {
    width: 100%;
    min-width: 880px;
    border-collapse: collapse;
    font-size: .92rem;
}
.stat-table th, .stat-table td {
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    text-align: center;
    padding: 0;
    height: 56px;
    background: var(--surface);
    transition: background .1s ease;
}
.stat-table th:last-child, .stat-table td:last-child { border-right: none; }
.stat-table thead th {
    background: var(--surface-2);
    font-weight: 600;
    font-size: .8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: .5rem .375rem;
    height: auto;
    border-bottom: 2px solid var(--border-2);
    position: sticky; top: 0;
    z-index: 1;
}
.stat-table .col-set {
    width: 36px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
}
.stat-table thead .col-set { background: var(--primary-dk); }
.stat-table .col-name {
    text-align: left;
    padding: 0 .75rem;
    width: 12ch;
    font-weight: 600;
    background: var(--surface-2);
}
.stat-table .col-position { width: 6rem; }
.stat-table .position-select {
    width: 100%; height: 100%; min-height: 56px;
    border: none; background: transparent;
    text-align: center; text-align-last: center;
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
}
.stat-table .position-select:focus { outline: 2px solid var(--primary); }

.counter-cell {
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}
.counter-cell .count {
    display: grid; place-items: center;
    width: 100%; height: 100%; min-height: 56px;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
}
.stat-wrapper.is-editable .counter-cell:hover { background: var(--primary-bg); }
.stat-wrapper.is-editable .counter-cell:active { background: var(--primary); color: #fff; }
.stat-wrapper.is-editable .counter-cell:active .count { color: #fff; }
.stat-wrapper.is-editable .counter-cell:focus { outline: 2px solid var(--primary); outline-offset: -2px; }

.counter-cell.readonly { cursor: default; }

/* Kategorie-Färbungen (subtil, lehnt sich an PDF an) */
.cat-play       { /* default white */ }
.cat-serve-good { background: #f0fdf4; }
.cat-fault      { background: #fffbeb; }
.cat-serve-bad  { background: var(--serve-bad-bg); color: var(--serve-bad-fg); }
.stat-table thead th.cat-serve-good { background: #dcfce7; color: #166534; }
.stat-table thead th.cat-fault      { background: #fef3c7; color: #92400e; }
.stat-table thead th.cat-serve-bad  { background: #e5e7eb; color: #374151; }

/* "Pulse" Animation für gerade aktualisierte Zelle */
.counter-cell.just-updated { animation: pulse .35s ease; }
@keyframes pulse {
    0%   { background-color: var(--primary); }
    50%  { background-color: var(--primary-bg); }
    100% { background-color: transparent; }
}
.cat-serve-good.just-updated { animation: pulse-good .35s ease; }
@keyframes pulse-good {
    0%   { background-color: var(--good); }
    50%  { background-color: #bbf7d0; }
    100% { background-color: #f0fdf4; }
}
.cat-fault.just-updated { animation: pulse-fault .35s ease; }
@keyframes pulse-fault {
    0%   { background-color: var(--warn); }
    50%  { background-color: #fde68a; }
    100% { background-color: #fffbeb; }
}

/* ---------- Action bar ---------- */
.action-bar {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin-top: 1rem;
    padding: .75rem;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: .625rem;
    box-shadow: 0 -2px 12px rgba(0,0,0,.06);
    display: flex; gap: .5rem; align-items: center;
}
.action-bar .spacer { flex: 1; }

.totals-row td { background: var(--primary-bg) !important; }

.legend {
    margin-top: 1rem;
    color: var(--text-muted);
    font-size: .85rem;
    line-height: 1.6;
}

/* Kleine Tweaks für die Read-Only-Kopie der stat-table */
.stat-table.is-readonly .counter-cell { cursor: default; }
.stat-table.is-readonly .position-select { pointer-events: none; }

/* Responsive */
@media (max-width: 700px) {
    .game-header { flex-direction: column; align-items: flex-start; }
    .game-meta { text-align: left; }
    .timer { font-size: 1.5rem; }
    h1 { font-size: 1.4rem; }
    .stat-table .col-name { padding: 0 .5rem; width: 10ch; }
    .counter-cell .count { font-size: 1.1rem; }
}

/* Visually-hidden focusing helper */
.toast {
    position: fixed; left: 50%; bottom: 5rem; transform: translateX(-50%);
    background: var(--text); color: #fff;
    padding: .5rem .875rem; border-radius: .375rem;
    font-size: .9rem; opacity: 0; pointer-events: none;
    transition: opacity .2s, transform .2s;
    z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.error { background: var(--bad); }

/* ---------- Team-Switcher in Topbar ---------- */
.team-switcher select {
    padding: .375rem .5rem;
    border-radius: .375rem;
    border: 1px solid var(--border);
    background: var(--surface);
    font-weight: 600;
    cursor: pointer;
    max-width: 240px;
}

/* ---------- Live-Indicator (game.php) ---------- */
.live-indicator {
    color: var(--good);
    font-weight: 700;
    font-size: .75rem;
    margin-left: .375rem;
    animation: pulse-live 2s ease-in-out infinite;
}
@keyframes pulse-live {
    0%, 100% { opacity: 1;   }
    50%      { opacity: .35; }
}

/* ---------- Edit-Modus auf game_view.php ---------- */
.edit-table.is-editing .editable-cell {
    cursor: default;
    padding: 0;
    position: relative;
}
.edit-table.is-editing .editable-cell .count {
    min-height: 40px;
    padding: 0;
}
.editable-cell .edit-inc,
.editable-cell .edit-dec {
    display: none;
    width: 26px; height: 26px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--border-2);
    background: var(--surface);
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    margin: 0 .125rem;
    vertical-align: middle;
}
.edit-table.is-editing .editable-cell .edit-inc,
.edit-table.is-editing .editable-cell .edit-dec {
    display: inline-grid;
    place-items: center;
}
.editable-cell .edit-inc { color: var(--good);   border-color: #bbf7d0; }
.editable-cell .edit-dec { color: var(--bad);    border-color: #fecaca; }
.editable-cell .edit-inc:hover { background: var(--good-bg); }
.editable-cell .edit-dec:hover { background: var(--bad-bg); }

.edit-position-select {
    width: 100%;
    height: 100%;
    border: 1px dashed var(--primary);
    background: var(--primary-bg);
    text-align: center;
    text-align-last: center;
    border-radius: .25rem;
    padding: .25rem;
}

#edit-meta-details summary { cursor: pointer; padding: .5rem; }

/* Form innerhalb von team.php */
.inline-form {
    display: flex;
    gap: .5rem;
    align-items: center;
    flex-wrap: wrap;
}
.inline-form input[type="text"] { flex: 1; min-width: 200px; }

/* topbar layout fuer mehr items */
@media (max-width: 700px) {
    .team-switcher select { max-width: 160px; }
    .topnav { font-size: .9rem; }
}

/* ---------- Fix: Edit-Mode Cell-Layout (-/count/+ inline, ohne TD zu zerstoeren) ---------- */
/* WICHTIG: kein display:flex auf das <td>! Das wuerde die Tabelle zerlegen. */
.edit-table.is-editing .editable-cell {
    padding: 0 .25rem;
    text-align: center;
    white-space: nowrap;
}
.edit-table.is-editing .editable-cell .count {
    display: inline-block;
    width: auto;
    height: auto;
    min-height: 0;
    min-width: 1.5em;
    padding: 0 .375rem;
    vertical-align: middle;
}
.edit-table.is-editing .editable-cell .edit-inc,
.edit-table.is-editing .editable-cell .edit-dec {
    display: inline-grid;
    place-items: center;
    vertical-align: middle;
    margin: 0 .125rem;
}
