:root {
    --team-Pyrzany: #e6532c;
    --team-Krzysztofy: #2a72c9;
    --team-Elastyny: #2e9e5b;
    --ink: #24303a;
    --muted: #6b7a86;
    --bg: #f4f6f4;
    --card-bg: #ffffff;
    --border: #dde3e6;
    --radius: 10px;
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    overflow-x: hidden;
}

.app-header {
    padding: 18px 24px 8px;
}

.app-header h1 {
    margin: 0 0 4px;
    font-size: 1.5rem;
}

.subtitle {
    margin: 0;
    color: var(--muted);
    font-size: 0.92rem;
}

@media (max-width: 600px) {
    .app-header { padding: 14px 14px 6px; }
    .app-header h1 { font-size: 1.2rem; }
    .subtitle { font-size: 0.85rem; }
}

/* ---------- Tabela wyników / standings ---------- */

.standings {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 8px 24px 16px;
}

.standing-card {
    flex: 1 1 200px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    min-width: 180px;
}

.standing-name {
    font-weight: 700;
    padding-left: 12px;
    position: relative;
    font-size: 0.98rem;
}

.standing-name::before {
    content: "";
    position: absolute;
    left: 0;
    top: 3px;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    background: currentColor;
}

@media (max-width: 600px) {
    .standings {
        padding: 6px 10px 12px;
        gap: 8px;
        flex-wrap: nowrap;
    }
    .standing-card {
        flex: 1 1 0;
        min-width: 0;
        padding: 8px 6px;
    }
    .standing-name {
        font-size: 0.72rem;
        padding-left: 11px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .standing-name::before { width: 8px; height: 8px; top: 2px; }
    .standing-count { font-size: 1.05rem; margin: 1px 0 5px; }
    .standing-count .count-value { font-size: 1.05rem; }
}

.team-Pyrzany { color: var(--team-Pyrzany); }
.team-Krzysztofy { color: var(--team-Krzysztofy); }
.team-Elastyny { color: var(--team-Elastyny); }

.standing-count {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 2px 0 6px;
}

.standing-count .count-value { font-size: 1.3rem; }

.standing-bar {
    height: 7px;
    border-radius: 5px;
    background: #edf1f2;
    overflow: hidden;
}

.standing-bar-fill {
    height: 100%;
    width: 0%;
    border-radius: 5px;
    transition: width .25s ease;
}

.standing-card[data-team="Pyrzany"] .standing-bar-fill { background: var(--team-Pyrzany); }
.standing-card[data-team="Krzysztofy"] .standing-bar-fill { background: var(--team-Krzysztofy); }
.standing-card[data-team="Elastyny"] .standing-bar-fill { background: var(--team-Elastyny); }

/* ---------- Layout główny ---------- */

.app-main {
    display: grid;
    grid-template-columns: minmax(320px, 62%) minmax(280px, 38%);
    gap: 18px;
    padding: 0 24px 28px;
    align-items: start;
}

@media (max-width: 900px) {
    .app-main { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .app-main { padding: 0 10px 20px; gap: 12px; }
}

.map-panel, .table-panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    position: sticky;
    top: 12px;
}

.map-panel { position: static; }

.table-panel {
    position: sticky;
    top: 12px;
    max-height: calc(100vh - 24px);
    display: flex;
    flex-direction: column;
}

@media (max-width: 900px) {
    .table-panel { position: static; max-height: none; }
}

@media (max-width: 600px) {
    .map-panel, .table-panel { padding: 10px; border-radius: 8px; }
}

.map-hint {
    color: var(--muted);
    font-size: 0.82rem;
    margin: 10px 2px 0;
}

.map-hint-mobile {
    display: none;
    color: var(--muted);
    font-size: 0.8rem;
    margin: 6px 2px 0;
}

@media (pointer: coarse) {
    .map-hint-mobile { display: block; }
}

/* ---------- Mapa i znaczniki ---------- */

.map-wrap {
    position: relative;
    width: 100%;
    line-height: 0;
    border-radius: 6px;
    overflow: hidden;
    background: #ddd;
}

.map-image {
    width: 100%;
    height: auto;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
}

.peak-marker {
    position: absolute;
    transform: translate(-50%, -100%);
    display: flex;
    padding: 0;
    border: 1.5px solid rgba(20, 25, 30, 0.75);
    border-radius: 4px;
    cursor: pointer;
    background: rgba(255,255,255,0.55);
    box-shadow: 0 1px 3px rgba(0,0,0,0.35);
    touch-action: manipulation;
    -webkit-appearance: none;
    appearance: none;
}

/* Niewidoczna, powiększona strefa dotyku - żeby na telefonie łatwiej było
   trafić palcem w mały znacznik, bez powiększania go wizualnie. */
.peak-marker::before {
    content: "";
    position: absolute;
    inset: -9px;
}

.peak-marker::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -5px;
    transform: translateX(-50%);
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid rgba(20, 25, 30, 0.75);
}

.peak-marker:hover, .peak-marker:focus-visible {
    box-shadow: 0 0 0 2px #222, 0 1px 4px rgba(0,0,0,0.4);
    z-index: 5;
}

.marker-seg {
    width: 7px;
    height: 13px;
    display: block;
    background: #cfd6d9;
}

.marker-seg:first-child { border-top-left-radius: 2.5px; border-bottom-left-radius: 2.5px; }
.marker-seg:last-child { border-top-right-radius: 2.5px; border-bottom-right-radius: 2.5px; }

.marker-seg.is-done[data-team="Pyrzany"] { background: var(--team-Pyrzany); }
.marker-seg.is-done[data-team="Krzysztofy"] { background: var(--team-Krzysztofy); }
.marker-seg.is-done[data-team="Elastyny"] { background: var(--team-Elastyny); }

.peak-marker.all-done {
    border-color: #111;
}

/* ---------- Tabela wyników ---------- */

.table-toolbar { margin-bottom: 8px; }

#filterInput {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.92rem;
}

@media (pointer: coarse) {
    #filterInput { padding: 11px 10px; font-size: 1rem; }
}

.table-scroll {
    overflow: auto;
    flex: 1;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.87rem;
}

.results-table thead th {
    position: sticky;
    top: 0;
    background: var(--card-bg);
    text-align: left;
    padding: 6px 6px;
    border-bottom: 2px solid var(--border);
    z-index: 1;
}

.results-table th.col-team, .results-table td.col-team {
    text-align: center;
    width: 68px;
}

.results-table td.col-elev { text-align: right; color: var(--muted); }

@media (max-width: 600px) {
    .results-table { font-size: 0.82rem; }
    .results-table th.col-team, .results-table td.col-team { width: 54px; }
    .results-table thead th { padding: 8px 4px; }
    .peak-range { font-size: 0.74rem; }
}

.results-table tbody tr {
    border-bottom: 1px solid var(--border);
}

.results-table tbody tr.row-highlight {
    background: #fff7e0;
}

.peak-name { display: block; font-weight: 600; }
.peak-range { display: block; color: var(--muted); font-size: 0.78rem; }

.peak-info-trigger {
    display: block;
    width: 100%;
    background: none;
    border: none;
    margin: 0;
    padding: 0;
    font: inherit;
    text-align: left;
    color: inherit;
    cursor: pointer;
}

.cell-team {
    cursor: pointer;
    padding: 4px 2px;
    border-radius: 6px;
}

@media (pointer: coarse) {
    .cell-team { padding: 9px 2px; }
}

.cell-team:hover { background: #eef2f3; }

.cell-status {
    display: inline-block;
    min-width: 1.4em;
    color: var(--muted);
    font-size: 0.8rem;
}

.cell-team.is-done .cell-status {
    font-weight: 700;
    color: #fff;
    background: var(--muted);
    border-radius: 5px;
    padding: 1px 5px;
}

.cell-team.is-done[data-team="Pyrzany"] .cell-status { background: var(--team-Pyrzany); }
.cell-team.is-done[data-team="Krzysztofy"] .cell-status { background: var(--team-Krzysztofy); }
.cell-team.is-done[data-team="Elastyny"] .cell-status { background: var(--team-Elastyny); }

/* ---------- Modal / formatka ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(20, 25, 30, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 50;
}

.modal-backdrop.is-open { display: flex; }

.modal {
    background: #fff;
    border-radius: 12px;
    padding: 22px 22px 18px;
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}

@media (max-width: 480px) {
    .modal-backdrop { padding: 0; align-items: flex-end; }
    .modal {
        max-width: none;
        max-height: 92vh;
        border-radius: 14px 14px 0 0;
        padding: 18px 16px 16px;
    }
}

.modal-close {
    position: absolute;
    right: 12px;
    top: 10px;
    border: none;
    background: none;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
}

.modal h2 {
    margin: 0 0 2px;
    font-size: 1.15rem;
    padding-right: 24px;
}

.modal-subtitle {
    margin: 0 0 14px;
    color: var(--muted);
    font-size: 0.85rem;
}

.modal-peak-info .modal-subtitle { margin-bottom: 18px; }

.modal-info-body {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px 12px 12px;
}

.modal-info-item {
    margin: 10px 0 0;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--ink);
}

.modal-info-item:first-child { margin-top: 12px; }

.modal-info-item strong {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
    margin-bottom: 2px;
}

.modal-team-label {
    margin: 0 0 6px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.required-star {
    color: #c0392b;
}

.modal-team-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.team-tab {
    border: 1.5px solid var(--border);
    background: #fff;
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 0.82rem;
    cursor: pointer;
    font-weight: 600;
    color: var(--muted);
}

@media (pointer: coarse) {
    .team-tab { padding: 9px 14px; font-size: 0.86rem; }
}


.team-tab[data-team="Pyrzany"].is-active { background: var(--team-Pyrzany); border-color: var(--team-Pyrzany); color: #fff; }
.team-tab[data-team="Krzysztofy"].is-active { background: var(--team-Krzysztofy); border-color: var(--team-Krzysztofy); color: #fff; }
.team-tab[data-team="Elastyny"].is-active { background: var(--team-Elastyny); border-color: var(--team-Elastyny); color: #fff; }

.form-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
    font-size: 0.88rem;
    font-weight: 600;
}

.form-row input[type="date"],
.form-row textarea {
    font-family: inherit;
    font-size: 0.92rem;
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-weight: 400;
    resize: vertical;
    width: 100%;
}

.form-row-checkbox {
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.form-row-checkbox input { width: 17px; height: 17px; }

@media (pointer: coarse) {
    .form-row input[type="date"],
    .form-row textarea {
        padding: 10px 10px;
        font-size: 1rem; /* min. 16px zapobiega automatycznemu przybliżeniu strony w Safari */
    }
    .form-row-checkbox { padding: 4px 0; }
    .form-row-checkbox input { width: 22px; height: 22px; }
    .btn { padding: 11px 20px; font-size: 0.98rem; }
    .modal-close { font-size: 1.7rem; padding: 6px 10px; }
}

.form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 6px;
}

.form-status {
    font-size: 0.82rem;
    color: var(--muted);
    margin-right: auto;
}

.form-status.is-error { color: #c0392b; }
.form-status.is-ok { color: #1e8e3e; }
.form-status.is-required { color: #b9770e; font-weight: 600; }

.form-row input:disabled,
.form-row textarea:disabled {
    background: #f2f4f5;
    color: var(--muted);
    cursor: not-allowed;
}

.form-row-checkbox input:disabled { cursor: not-allowed; }

.btn {
    border: none;
    border-radius: 8px;
    padding: 8px 18px;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-primary {
    background: #24303a;
    color: #fff;
}

.btn-primary:hover { background: #182028; }

.btn-primary:disabled {
    background: #b7c0c7;
    cursor: not-allowed;
}
