/* ============================================================
   GSOP – Design-System
   Dunkel, kontrastreich, mobile first (iPhone 390 px).
   ============================================================ */

:root {
    --bg-base:      #0E1013;
    --bg-surface:   #171A1F;
    --bg-elevated:  #21262E;
    --border:       #2C333D;
    --text-primary: #F2F4F7;
    --text-muted:   #98A2B3;
    --accent-red:   #D6203A;
    --accent-red-dk:#A3162B;
    --felt-green:   #1B5E45;
    --gold:         #E8B931;
    --silver:       #C0C6CE;
    --bronze:       #B06B3A;

    --radius: 10px;
    --radius-sm: 8px;
    --shadow: 0 4px 16px rgba(0, 0, 0, .35);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
            "Helvetica Neue", Arial, sans-serif;
    --tabbar-h: 58px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 .8em; }
a  { color: var(--text-primary); }

::selection { background: var(--accent-red-dk); }

/* ------------------------------------------------------------
   App-Layout: mobil Tab-Bar unten, ab 900 px Sidebar links
   ------------------------------------------------------------ */
.app { min-height: 100dvh; }

.view {
    padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 20px);
    max-width: 1100px;
    margin: 0 auto;
}

.sidenav { display: none; }

.tabbar {
    position: fixed;
    inset: auto 0 0 0;
    display: flex;
    background: rgba(23, 26, 31, .96);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding-bottom: var(--safe-bottom);
    z-index: 50;
}

.tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--tabbar-h);
    text-decoration: none;
    color: var(--text-muted);
    font-size: .68rem;
    font-weight: 500;
}

.tabbar a .icon { font-size: 1.35rem; line-height: 1; }
.tabbar a.active { color: var(--text-primary); }
.tabbar a.active .icon { color: var(--accent-red); }

.tabbar a.tab-primary .icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin-top: -18px;
    border-radius: 50%;
    background: linear-gradient(160deg, var(--accent-red), var(--accent-red-dk));
    color: #fff;
    box-shadow: 0 4px 12px rgba(214, 32, 58, .45);
    font-size: 1.5rem;
}

@media (min-width: 900px) {
    .tabbar { display: none; }

    .app {
        display: grid;
        grid-template-columns: 230px 1fr;
    }

    .sidenav {
        display: flex;
        flex-direction: column;
        position: sticky;
        top: 0;
        height: 100dvh;
        background: var(--bg-surface);
        border-right: 1px solid var(--border);
        padding: 20px 12px;
    }

    .sidenav-brand {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 4px 10px 18px;
        font-size: 1.25rem;
        font-weight: 700;
        letter-spacing: .04em;
    }

    .brand-mark {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 34px;
        height: 34px;
        border-radius: 8px;
        background: linear-gradient(160deg, var(--accent-red), var(--accent-red-dk));
        color: #fff;
        font-size: 1.2rem;
    }

    .sidenav-links { display: flex; flex-direction: column; gap: 2px; flex: 1; }

    .sidenav-links a {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 11px 12px;
        border-radius: var(--radius-sm);
        color: var(--text-muted);
        text-decoration: none;
        font-weight: 500;
    }

    .sidenav-links a:hover { background: var(--bg-elevated); color: var(--text-primary); }
    .sidenav-links a.active { background: var(--bg-elevated); color: var(--text-primary); }
    .sidenav-links a.active .icon { color: var(--accent-red); }

    .sidenav-footer {
        border-top: 1px solid var(--border);
        padding-top: 12px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
    }

    .sidenav-user { font-size: .85rem; display: flex; flex-direction: column; }
    .sidenav-user small { color: var(--text-muted); }

    .view { padding: 28px 32px 40px; }
}

/* ------------------------------------------------------------
   Karten & Panels
   ------------------------------------------------------------ */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.card-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}
.card-title h2 { margin: 0; }

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.page-head h1 { margin: 0; }
.page-sub { color: var(--text-muted); font-size: .9rem; margin: 2px 0 0; }

.progress-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: .85rem;
    font-weight: 600;
    white-space: nowrap;
}
.progress-pill .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--felt-green);
    box-shadow: 0 0 6px var(--felt-green);
}

/* ------------------------------------------------------------
   Tabellen
   ------------------------------------------------------------ */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    font-size: .92rem;
    white-space: nowrap;
}

th, td {
    text-align: left;
    padding: 10px 10px;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-muted);
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 600;
    user-select: none;
}

th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text-primary); }
th .sort-arrow { font-size: .7rem; }

td.num, th.num { text-align: right; }

tbody tr:hover { background: var(--bg-elevated); }
tbody tr:last-child td { border-bottom: none; }

.table-sticky th:first-child,
.table-sticky td:first-child {
    position: sticky;
    left: 0;
    background: var(--bg-surface);
    z-index: 1;
}
.table-sticky tbody tr:hover td:first-child { background: var(--bg-elevated); }

tr.rank-1 td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
tr.rank-2 td:first-child { box-shadow: inset 3px 0 0 var(--silver); }
tr.rank-3 td:first-child { box-shadow: inset 3px 0 0 var(--bronze); }

.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 26px;
    border-radius: 50%;
    font-weight: 700;
    font-size: .8rem;
    background: var(--bg-elevated);
    color: var(--text-muted);
}
.rank-badge.gold   { background: var(--gold);   color: #201a03; }
.rank-badge.silver { background: var(--silver); color: #14171c; }
.rank-badge.bronze { background: var(--bronze); color: #1d0f04; }

/* ------------------------------------------------------------
   Spieler-Avatare (Initialen-Kreise)
   ------------------------------------------------------------ */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: .72rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    text-transform: uppercase;
}

.player-cell {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}
.player-cell .p-name { font-weight: 600; }
.player-cell small { color: var(--text-muted); display: block; font-size: .74rem; }
.player-inactive { opacity: .45; }

/* ------------------------------------------------------------
   Buttons
   ------------------------------------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 18px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: filter .12s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
    background: linear-gradient(160deg, var(--accent-red), var(--accent-red-dk));
    border-color: var(--accent-red-dk);
    color: #fff;
}
.btn-green {
    background: linear-gradient(160deg, #237a58, var(--felt-green));
    border-color: var(--felt-green);
    color: #fff;
}
.btn-ghost { background: transparent; }
.btn-danger { color: #ff8a97; border-color: #5c2730; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-icon { min-width: 44px; padding: 0; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ------------------------------------------------------------
   Formulare (Schrift >= 16px gegen iOS-Auto-Zoom)
   ------------------------------------------------------------ */
.field { display: block; margin-bottom: 14px; }
.field > span {
    display: block;
    font-size: .8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 600;
}

input[type="text"], input[type="password"], input[type="number"],
input[type="date"], select, textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    font: inherit;
    font-size: 16px;
    color: var(--text-primary);
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent-red);
    box-shadow: 0 0 0 3px rgba(214, 32, 58, .18);
}
input[type="date"] { color-scheme: dark; }
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2398A2B3' stroke-width='2' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 34px;
}

.form-error {
    color: #ff8a97;
    background: rgba(214, 32, 58, .12);
    border: 1px solid rgba(214, 32, 58, .4);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: .88rem;
}

.form-warning {
    color: var(--gold);
    background: rgba(232, 185, 49, .1);
    border: 1px solid rgba(232, 185, 49, .35);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: .88rem;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0 14px;
}
@media (min-width: 640px) {
    .form-grid { grid-template-columns: 1fr 1fr; }
}

/* ------------------------------------------------------------
   Chips (Teilnehmerauswahl)
   ------------------------------------------------------------ */
.chip-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.chip {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 52px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-base);
    cursor: pointer;
    font: inherit;
    color: var(--text-primary);
    text-align: left;
}
.chip .p-name { font-weight: 600; font-size: .9rem; }
.chip.selected {
    border-color: var(--felt-green);
    background: rgba(27, 94, 69, .22);
    box-shadow: inset 0 0 0 1px var(--felt-green);
}
.chip:disabled { opacity: .4; cursor: not-allowed; }

/* ------------------------------------------------------------
   Runden-Erfassung (Wizard)
   ------------------------------------------------------------ */
.wizard-steps {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
}
.wizard-steps .step {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-elevated);
}
.wizard-steps .step.done { background: var(--felt-green); }
.wizard-steps .step.current { background: var(--accent-red); }

.elim-list { display: flex; flex-direction: column; gap: 8px; }

.elim-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.elim-item .place-tag {
    min-width: 34px;
    text-align: center;
    font-weight: 700;
    color: var(--text-muted);
}
.elim-item.winner {
    border-color: var(--gold);
    background: rgba(232, 185, 49, .08);
}
.elim-item.winner .place-tag { color: var(--gold); }
.elim-item .ko-info { margin-left: auto; font-size: .8rem; color: var(--text-muted); text-align: right; }

.killer-picker {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-top: 10px;
}
.killer-picker h3 { margin-bottom: 10px; }

.points-preview td { padding: 8px 10px; }
.pts-pos  { color: var(--silver); }
.pts-ko   { color: var(--gold); }
.pts-total { font-weight: 700; }

/* ------------------------------------------------------------
   Statistiken
   ------------------------------------------------------------ */
.chart-box {
    position: relative;
    width: 100%;
    height: 300px;
}
@media (min-width: 900px) { .chart-box { height: 340px; } }

.heatmap-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.heatmap { border-collapse: collapse; font-size: .82rem; }
.heatmap th, .heatmap td {
    border: 1px solid var(--border);
    padding: 6px 8px;
    text-align: center;
    min-width: 42px;
}
.heatmap th.row-head {
    text-align: left;
    position: sticky;
    left: 0;
    background: var(--bg-surface);
    z-index: 1;
}
.heatmap td.self { background: repeating-linear-gradient(45deg, var(--bg-base), var(--bg-base) 4px, var(--bg-surface) 4px, var(--bg-surface) 8px); color: var(--text-muted); }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}
.stat-tile {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
}
.stat-tile .label { font-size: .74rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-tile .value { font-size: 1.3rem; font-weight: 700; margin-top: 2px; }

/* ------------------------------------------------------------
   Badges & Kleinkram
   ------------------------------------------------------------ */
.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .03em;
}
.badge-draft { background: rgba(232, 185, 49, .16); color: var(--gold); }
.badge-final { background: rgba(27, 94, 69, .3); color: #6fcfae; }
.badge-admin { background: rgba(214, 32, 58, .18); color: #ff8a97; }
.badge-readonly { background: var(--bg-elevated); color: var(--text-muted); }
.badge-inactive { background: var(--bg-elevated); color: var(--text-muted); }

.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.mt { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 16px;
}
.empty-state .icon { font-size: 2.2rem; display: block; margin-bottom: 8px; }

.list-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 4px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; min-width: 140px; }
.list-row .actions { display: flex; gap: 8px; margin-left: auto; }

/* ------------------------------------------------------------
   Toasts & Modals
   ------------------------------------------------------------ */
.toast-root {
    position: fixed;
    left: 50%;
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(92vw, 420px);
}
@media (min-width: 900px) { .toast-root { bottom: 24px; } }

.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    box-shadow: var(--shadow);
    font-size: .9rem;
    animation: toast-in .18s ease;
}
.toast.ok    { border-color: var(--felt-green); }
.toast.error { border-color: var(--accent-red); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(6, 8, 10, .7);
    backdrop-filter: blur(2px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    width: min(94vw, 440px);
    max-height: 86dvh;
    overflow-y: auto;
}
.modal h2 { margin-bottom: 10px; }
.modal .btn-row { margin-top: 18px; justify-content: flex-end; }

/* ------------------------------------------------------------
   Login
   ------------------------------------------------------------ */
.login-page { background: radial-gradient(1000px 600px at 50% -10%, #1a2b23 0%, var(--bg-base) 55%); }

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

.login-card {
    width: min(94vw, 380px);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 32px 26px;
    text-align: center;
}

.login-logo {
    width: 64px;
    height: 64px;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    font-size: 2rem;
    color: #fff;
    background: linear-gradient(160deg, var(--accent-red), var(--accent-red-dk));
    box-shadow: 0 6px 18px rgba(214, 32, 58, .4);
}

.login-title { letter-spacing: .06em; margin-bottom: 2px; }
.login-subtitle { color: var(--text-muted); font-size: .88rem; margin-bottom: 22px; }
.login-card form { text-align: left; }
.login-card .btn-block { margin-top: 6px; }
.login-card .form-error { margin-bottom: 12px; }

/* ------------------------------------------------------------
   Mobile Tabellen-Verdichtung
   ------------------------------------------------------------ */
@media (max-width: 640px) {
    .hide-mobile { display: none; }
    th, td { padding: 9px 7px; }
}
