/* EWU TurnierView Theme - übernimmt Farben aus der Mobile App
   (siehe src/ewu.trails.mobile.app/Resources/Styles/ThemeLight.xaml + ThemeDark.xaml) */

:root {
    /* Layout-Masse — Single Source of Truth fuer die Klebe-Offsets.
       .ewu-header / .ewu-zeitplan-day erzwingen diese Hoehen per min-height,
       damit sticky top: var(--ewu-header-h) garantiert passt. */
    --ewu-header-h: 51px;
    --ewu-day-h: 37px;
    --ewu-content-max: 1100px;
    /* Deckel fuer die Pruefungsnamen-Spalte im Zeitplan (ab 600px).
       Bewusst in px und nicht in ch: Zeile und Reitplatz-Leiste haben
       unterschiedliche Schriftgroessen, ch waere dort verschieden breit. */
    --ewu-zp-name: 340px;

    /* Brand */
    --ewu-primary: #AFCB37;
    --ewu-accent: #10893E;

    /* Neutrals / Surfaces */
    --ewu-background: #F3F4F6;
    --ewu-surface: #FFFFFF;
    --ewu-surface-variant: #F0F2F5;
    --ewu-outline: #D1D5DB;
    --ewu-outline-variant: #E0E3E8;

    /* Text/Icon */
    --ewu-on-background: #111827;
    --ewu-on-surface: #111827;
    --ewu-on-surface-variant: #4B5563;
    --ewu-on-primary: #0E1208;

    /* Container */
    --ewu-primary-container: #E8F3C2;
    --ewu-on-primary-container: #182106;

    /* Surface Container */
    --ewu-surface-container: #F7F9FB;
    --ewu-surface-container-low: #FAFBFC;

    /* Status */
    --ewu-error: #DC2626;
    --ewu-warning: #D97706;
    --ewu-success: #16A34A;
    --ewu-info: #2563EB;

    /* Pause-Zeilen im Zeitplan */
    --ewu-pause-bg: #E3EFE6;
    --ewu-on-pause: #14532D;
}

@media (prefers-color-scheme: dark) {
    :root {
        --ewu-primary: #AFCB37;
        --ewu-accent: #2DBE70;

        --ewu-background: #0F1115;
        --ewu-surface: #161A1E;
        --ewu-surface-variant: #1E2329;
        --ewu-outline: #2A3037;
        --ewu-outline-variant: #343A41;

        --ewu-on-background: #E5E7EB;
        --ewu-on-surface: #E5E7EB;
        --ewu-on-surface-variant: #A7B0BE;
        --ewu-on-primary: #0E1208;

        --ewu-primary-container: #2A340B;
        --ewu-on-primary-container: #DCEB9B;

        --ewu-surface-container: #1A1E22;
        --ewu-surface-container-low: #1C2024;

        --ewu-error: #F87171;
        --ewu-warning: #FBBF24;
        --ewu-success: #4ADE80;
        --ewu-info: #60A5FA;

        --ewu-pause-bg: #16301F;
        --ewu-on-pause: #A7E3BE;
    }
}

/* Reset / Base */
html, body {
    margin: 0;
    padding: 0;
    background-color: var(--ewu-background);
    color: var(--ewu-on-background);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--ewu-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
.ewu-header {
    background-color: var(--ewu-primary);
    color: var(--ewu-on-primary);
    padding: 0 20px;
    /* Feste Hoehe, damit --ewu-header-h verlaesslich stimmt: die Klebe-Offsets
       von Tages- und Reitplatz-Leiste rechnen damit. */
    min-height: var(--ewu-header-h);
    display: flex;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    position: sticky;
    top: 0;
    z-index: 100;
}
.ewu-header-title { font-size: 1.25rem; font-weight: 600; margin: 0; }
.ewu-header-sub { font-size: 0.875rem; opacity: 0.85; margin: 0; }

/* Breadcrumb */
.ewu-breadcrumb {
    background-color: var(--ewu-surface-variant);
    padding: 8px 20px;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--ewu-outline);
    display: flex;
    align-items: center;
    gap: 8px;
}
.ewu-breadcrumb a {
    color: var(--ewu-on-surface-variant);
}
.ewu-breadcrumb .sep {
    color: var(--ewu-on-surface-variant);
    opacity: 0.5;
}

/* Page wrapper */
.ewu-page {
    background-color: var(--ewu-background);
    /* dvh statt vh: sonst springt die Hoehe auf Mobilgeraeten beim Ein- und
       Ausblenden der Browserleiste. Header-Hoehe aus dem Token statt 56px. */
    min-height: calc(100dvh - var(--ewu-header-h));
    padding: 12px 16px;
    max-width: var(--ewu-content-max);
    margin-inline: auto;
}

/* Cards / surfaces */
.ewu-card {
    background-color: var(--ewu-surface);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    border: 1px solid var(--ewu-outline-variant);
}

.ewu-pruefung-header {
    background-color: var(--ewu-surface);
    padding: 12px 16px;
    border-bottom: 1px solid var(--ewu-outline-variant);
}
/* h1, damit FocusOnNavigate Selector="h1" nach jeder Navigation greift und die
   Ueberschriftenhierarchie nicht auf Ebene 2 beginnt. Optik unveraendert. */
.ewu-pruefung-header h1,
.ewu-pruefung-header h2 {
    color: var(--ewu-on-surface);
    margin: 0 0 4px 0;
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.25;
}
.ewu-pruefung-header .meta {
    color: var(--ewu-on-surface-variant);
    font-size: 0.875rem;
}

/* Action bar (Buttons unten) */
.ewu-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    background-color: var(--ewu-background);
    border-top: 1px solid var(--ewu-outline-variant);
    position: sticky;
    bottom: 0;
    /* Ohne definierte Stapelordnung koennen darueber scrollende Zeilen
       durch die Leiste schlagen. */
    z-index: 50;
}
.ewu-btn {
    background-color: var(--ewu-primary);
    color: var(--ewu-on-primary);
    border: none;
    border-radius: 6px;
    padding: 11px 10px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.95rem;
    /* Mobil: drei gleich breite Buttons in EINER Reihe. flex:1 mit
       min-width:110px erzwang bei drei Buttons einen Umbruch auf zwei Reihen
       und kostete 14% des Handy-Viewports. */
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: filter 0.15s ease;
}
/* Ab Tablet feste Breite statt Streckung — sonst wird "Zurueck" auf 1280px
   knapp 400px breit. */
@media (min-width: 600px) {
    .ewu-actions { padding: 12px 16px; }
    .ewu-btn {
        flex: 0 0 auto;
        min-width: 132px;
        padding: 10px 18px;
    }
    .ewu-actions > .ewu-btn:first-child { margin-right: auto; }
}
.ewu-btn:hover { filter: brightness(0.95); text-decoration: none; }
.ewu-btn[disabled], .ewu-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}
.ewu-btn.ewu-btn-secondary {
    background-color: var(--ewu-surface-variant);
    color: var(--ewu-on-surface);
    border: 1px solid var(--ewu-outline);
}

/* Zeitplan-Liste
   Klebe-Reihenfolge von oben: App-Header (100) > Tag (20) > Reitplatz (15).
   Der Tag klebt UNTER dem Header, nicht dahinter — sonst ist er nie sichtbar. */
.ewu-zeitplan-day {
    background-color: var(--ewu-primary-container);
    color: var(--ewu-on-primary-container);
    padding: 0 16px;
    min-height: var(--ewu-day-h);
    display: flex;
    align-items: center;
    font-weight: 700;
    font-size: 1rem;
    position: sticky;
    top: var(--ewu-header-h);
    z-index: 20;
}
.ewu-zeitplan-platz {
    background-color: var(--ewu-surface-variant);
    color: var(--ewu-on-surface-variant);
    padding: 6px 16px;
    font-weight: 600;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--ewu-outline-variant);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: calc(var(--ewu-header-h) + var(--ewu-day-h));
    z-index: 15;
}
.ewu-zeitplan-row {
    display: grid;
    /* Randspalten auf den tatsaechlichen Bedarf: "10:00" braucht 50px, nicht 80,
       die Nennungszahl 19px, nicht 50. Der Rest gehoert dem Pruefungsnamen. */
    grid-template-columns: 52px minmax(0, 1fr) 30px;
    gap: 6px;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--ewu-outline-variant);
    background-color: var(--ewu-surface);
    color: var(--ewu-on-surface);
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.1s ease;
}
.ewu-zeitplan-row:hover {
    background-color: var(--ewu-surface-container);
    text-decoration: none;
    color: var(--ewu-on-surface);
}
.ewu-zeitplan-row.is-pause {
    background-color: var(--ewu-pause-bg);
    color: var(--ewu-on-pause);
    cursor: default;
}

/* Ab Tablet: Namensspalte deckeln und die Restbreite in eine leere Schlussspalte
   geben — sonst steht die Nennungszahl auf breiten Schirmen ueber 900px vom
   Namen entfernt am rechten Rand. Die Reitplatz-Leiste bekommt dasselbe Raster,
   damit "# Nennungen" ueber seiner Zahl steht. */
@media (min-width: 600px) {
    .ewu-zeitplan-row,
    .ewu-zeitplan-platz {
        display: grid;
        grid-template-columns: 64px minmax(0, var(--ewu-zp-name)) 44px 1fr;
        gap: 8px;
        padding-inline: 16px;
    }
    .ewu-zeitplan-platz > :last-child {
        grid-column: 3;
        text-align: right;
        white-space: nowrap;
    }
}
.ewu-zeitplan-row .zeit { font-weight: 600; }
.ewu-zeitplan-row .nennungen {
    text-align: right;
    font-weight: 700;
    color: var(--ewu-on-surface-variant);
}
.ewu-badge-startliste {
    display: inline-block;
    background-color: var(--ewu-primary);
    color: var(--ewu-on-primary);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 8px;
    vertical-align: middle;
}

/* Tabellen (Startliste / Ergebnisse) */
.ewu-table {
    width: 100%;
    border-collapse: collapse;
    background-color: var(--ewu-surface);
    color: var(--ewu-on-surface);
}
.ewu-table th, .ewu-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--ewu-outline-variant);
    font-size: 0.875rem;
    text-align: left;
    vertical-align: top;
}
.ewu-table th {
    background-color: var(--ewu-surface-variant);
    color: var(--ewu-on-surface-variant);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.ewu-table tr:hover td { background-color: var(--ewu-surface-container); }
.ewu-table .num { text-align: center; width: 50px; }
.ewu-table .reiter { font-weight: 600; }
.ewu-table .pferd { color: var(--ewu-on-surface-variant); font-size: 0.8rem; }
.ewu-table .score { font-weight: 700; text-align: right; white-space: nowrap; }
.ewu-table .strike { text-decoration: line-through; opacity: 0.6; }

/* Scoresheet
   Der Wrapper ist ein eigener, hoehenbegrenzter Scrollbereich. Vorher stand hier
   nur overflow-x: auto — das erzwingt per Spezifikation overflow-y: auto, machte
   den Wrapper zum Bezugsrahmen fuer sticky und liess ihn zugleich unbegrenzt
   wachsen. Der Tabellenkopf konnte deshalb nie kleben. Mit fester Maximalhoehe
   greifen beide Achsen: Kopf oben, Starter-Spalte links. */
.ewu-scoresheet-wrap {
    overflow: auto;
    max-height: max(240px, calc(100dvh - var(--ewu-header-h) - 12rem));
    overscroll-behavior: contain;
    background-color: var(--ewu-surface);
}
.ewu-scoresheet {
    /* separate statt collapse: klebende Zellen verlieren bei collapse in
       mehreren Browsern ihre Rahmen. Die Rahmen werden darum einzeln gesetzt. */
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    font-size: 0.8rem;
}
.ewu-scoresheet th, .ewu-scoresheet td {
    border-right: 1px solid var(--ewu-outline-variant);
    padding: 4px 6px;
    text-align: center;
    background-color: var(--ewu-surface);
    color: var(--ewu-on-surface);
    min-width: 60px;
}
.ewu-scoresheet th:first-child, .ewu-scoresheet td:first-child {
    border-left: 1px solid var(--ewu-outline-variant);
}
.ewu-scoresheet thead th {
    border-top: 1px solid var(--ewu-outline-variant);
    border-bottom: 1px solid var(--ewu-outline-variant);
}
/* dickere Trennlinie zwischen Startern */
.ewu-scoresheet tbody tr + tr td {
    border-top: 3px solid var(--ewu-outline);
}
.ewu-scoresheet tbody tr:last-child td {
    border-bottom: 1px solid var(--ewu-outline-variant);
}
.ewu-scoresheet th {
    background-color: var(--ewu-surface-variant);
    color: var(--ewu-on-surface-variant);
    font-weight: 700;
    position: sticky;
    top: 0;
    z-index: 3;
}
/* Starter-Spalte bleibt beim Scrollen nach rechts stehen — sonst sieht man
   Scores ohne zu wissen, zu wem sie gehoeren. */
.ewu-scoresheet th.starter-info,
.ewu-scoresheet td.starter-info {
    position: sticky;
    left: 0;
    text-align: left;
    min-width: 130px;
    box-shadow: 1px 0 0 var(--ewu-outline), 6px 0 8px -6px rgba(0, 0, 0, 0.28);
}
.ewu-scoresheet td.starter-info { z-index: 2; }
/* Kopfzelle liegt in beiden Achsen vorn */
.ewu-scoresheet th.starter-info { z-index: 4; }
.ewu-scoresheet td.starter-info .startnr { font-weight: 700; font-size: 0.95rem; }
.ewu-scoresheet td.starter-info .reiter { color: var(--ewu-on-surface-variant); font-size: 0.75rem; }
.ewu-scoresheet td.starter-info .pferd { color: var(--ewu-on-surface-variant); font-size: 0.7rem; }

/* Scoresheet-Zelle mit Penalty (oben) + Score (unten), getrennt durch Linie */
.ewu-scoresheet td.manoever-cell {
    padding: 0;
    vertical-align: stretch;
}
.ewu-scoresheet .penalty-part {
    color: var(--ewu-error);
    font-weight: 700;
    font-size: 0.75rem;
    padding: 3px 4px 2px 4px;
    border-bottom: 1px solid var(--ewu-outline-variant);
    text-align: center;
    min-height: 1.1em;
}
/* leere Penalty-Zeile soll trotzdem Trennlinie zeigen */
.ewu-scoresheet .penalty-part:empty::before {
    content: "\00a0";
}
.ewu-scoresheet .score-part {
    font-weight: 700;
    font-size: 1.05rem;
    padding: 4px 4px;
    text-align: center;
    color: var(--ewu-on-surface);
}
.ewu-scoresheet .score-part.special {
    color: var(--ewu-on-surface);
}
/* Legacy-Klassen für einfache Fallbacks */
.ewu-scoresheet td.score-cell { font-weight: 700; font-size: 1.05rem; }
.ewu-scoresheet td.penalty-cell {
    color: var(--ewu-error);
    font-weight: 700;
    font-size: 0.75rem;
}
.ewu-scoresheet td.total {
    background-color: var(--ewu-primary-container);
    color: var(--ewu-on-primary-container);
    font-weight: 700;
}
.ewu-scoresheet td.penalty-total {
    color: var(--ewu-error);
    font-weight: 700;
}

/* Empty state */
.ewu-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--ewu-on-surface-variant);
}
.ewu-empty h1,
.ewu-empty h2 { color: var(--ewu-on-surface); margin: 0 0 8px 0; font-size: 1.5rem; }

/* Startseite: Formular mit sichtbarem Label (F10) */
.ewu-form {
    max-width: 360px;
    margin: 24px auto 0;
    display: grid;
    gap: 8px;
    text-align: left;
}
.ewu-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--ewu-on-surface-variant);
}
.ewu-form-error {
    margin: 0;
    font-size: 0.875rem;
    color: var(--ewu-error);
}
.ewu-hint {
    font-size: 0.875rem;
    color: var(--ewu-on-surface-variant);
    margin-top: 16px;
}
.ewu-hint-muted {
    color: var(--ewu-on-surface-variant);
    font-size: 0.875rem;
    opacity: 0.85;
    margin-top: 4px;
}

/* Loading */
.ewu-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    color: var(--ewu-on-surface-variant);
    gap: 8px;
}

/* Polling indicator */
.ewu-poll {
    font-size: 0.75rem;
    color: var(--ewu-on-surface-variant);
    margin-left: auto;
    opacity: 0.7;
}
