/* Svijetla tema (zadana) */
:root {
    color-scheme: light;
    --bg: #f6f4ef;
    --surface: #ffffff;
    --text: #1f2328;
    --muted: #6b6f76;
    --border: #e2ded5;
    --stripe: #faf8f4;
    --hover: #eef3f8;
    --accent: #1d4f7a;   /* pozadine: zaglavlje tablice, aktivna stranica */
    --link: #1d4f7a;     /* tekst linkova */
}

/* Tamna tema: prema postavci sustava, osim ako je ručno odabrana svijetla */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #14171b;
        --surface: #1c2025;
        --text: #e4e6e9;
        --muted: #9aa1a9;
        --border: #30363d;
        --stripe: #20252b;
        --hover: #263240;
        --accent: #24527c;
        --link: #8cbcec;
    }
}

/* Tamna tema odabrana ručno (isti tokeni kao gore) */
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #14171b;
    --surface: #1c2025;
    --text: #e4e6e9;
    --muted: #9aa1a9;
    --border: #30363d;
    --stripe: #20252b;
    --hover: #263240;
    --accent: #24527c;
    --link: #8cbcec;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 24px 16px 48px;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

/* Gornja traka: odabir tablice + prekidač teme */
.topbar {
    max-width: 960px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.topbar form {
    margin: 0;
}

.theme-toggle {
    font: inherit;
    font-size: 13px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.theme-toggle:hover {
    background: var(--hover);
}

/* Odabir tablice */
form {
    max-width: 960px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

label {
    font-weight: 600;
}

select {
    font: inherit;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
}

/* Tablica */
table {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
    border: 1px solid var(--border);
}

.napomena {
    max-width: 960px;
    margin: 10px auto 0;
    color: var(--muted);
    font-size: 13px;
}

thead th {
    position: sticky;
    top: 0;
    background: var(--accent);
    color: #fff;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 10px 14px;
}

tbody td {
    padding: 8px 14px;
    border-top: 1px solid var(--border);
    vertical-align: top;
}

tbody tr:nth-child(even) {
    background: var(--stripe);
}

tbody tr:hover {
    background: var(--hover);
}

/* Redni broj */
th:first-child,
td:first-child {
    width: 1%;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

td:first-child {
    color: var(--muted);
}

/* Prezime */
td.prezime {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

/* Godine */
td:last-child {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Filteri (classes/Filters.php) */
form.filters {
    display: grid;
    /* Koliko god filtera: stupci min. 160px, sami prelaze u novi red */
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    align-items: end;
    gap: 12px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
}

.filter {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.filter {
    position: relative;
}

/* "×" unutar polja aktivnog filtera, lijevo od strelice */
.filter-clear {
    position: absolute;
    right: 30px;
    bottom: 1px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 36px;
    color: var(--muted);
    font-size: 20px;
    line-height: 1;
    text-decoration: none;
}

/* Tekstualni filter (npr. ime / prezime), izgleda kao ostala polja */
.filter-text {
    width: 100%;
    height: 40px;
    padding: 6px 30px 6px 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

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

.filter-text:focus {
    outline: none;
    border-color: var(--accent);
}

/* S Tom Selectom i u tekstualnom polju nema strelice, pa "×" ide skroz desno */
.filter:has(.filter-text) .filter-clear,
.filter:has(.ts-wrapper) .filter-clear {
    right: 1px;
}

.filter-clear:hover {
    color: var(--text);
}

.filter label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.filter select {
    width: 100%;
    border-radius: 0;
}

.filters-reset {
    grid-column: 1 / -1;
    justify-self: start;
    font-size: 13px;
    color: var(--link);
}

/* Tom Select: uskladi s ostatkom stranice */
.ts-wrapper .ts-control,
.ts-dropdown,
.ts-dropdown .dropdown-input {
    border-radius: 0;
    border-color: var(--border);
    font: inherit;
}

.ts-wrapper .ts-control,
.ts-wrapper.single.input-active .ts-control,
.ts-dropdown,
.ts-dropdown .dropdown-input,
.ts-control input,
.ts-dropdown .dropdown-input-wrap input {
    background: var(--surface);
    color: var(--text);
}

.ts-control input::placeholder {
    color: var(--muted);
}

.ts-wrapper.focus .ts-control {
    border-color: var(--accent);
    box-shadow: none;
}

.ts-dropdown .active {
    background: var(--hover);
    color: var(--text);
}

.ts-dropdown .selected {
    background: var(--accent);
    color: #fff;
}

/* Naslov skupine unutar tablice (npr. Zimske olimpijske igre) */
tbody tr.skupina td,
tbody tr.skupina:hover td {
    width: auto;
    text-align: left;
    background: var(--bg);
    color: var(--text);
    font-weight: 600;
    font-size: 13px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding-top: 14px;
}

/* Olimpijske igre: red igara + redovi "Sport: sportaši" ispod njega */
table.olimpijske-igre tbody tr:nth-child(even) {
    background: none;
}

/* Fiksna širina stupca "#", da se redovi sportova poravnaju s nazivom igara */
table.olimpijske-igre {
    --rb-sirina: 52px;
}

table.olimpijske-igre th:first-child,
table.olimpijske-igre tr.igra td:first-child {
    width: var(--rb-sirina);
    min-width: var(--rb-sirina);
}

table.olimpijske-igre tr.igra td {
    font-weight: 600;
    border-top: 2px solid var(--border);
}

table.olimpijske-igre tr.sport-red td {
    width: auto;
    text-align: left;
    color: var(--text);
    border-top: none;
    /* Uvlaka = širina stupca "#" + lijevi padding ćelije naziva */
    padding: 2px 14px 2px calc(var(--rb-sirina) + 14px);
    font-size: 14px;
    white-space: normal;
}

/* Naziv sporta lijevo, imena desno; dugi popis se lomi poravnat s imenima */
.sport-sadrzaj {
    display: flex;
    gap: 8px;
}

/* Zadnji sport ispod igara: malo zraka prije sljedećih igara */
table.olimpijske-igre tr.sport-red:has(+ tr:not(.sport-red)) td,
table.olimpijske-igre tr.sport-red:last-child td {
    padding-bottom: 10px;
}

/* Nositelji medalja: sportaš se proteže kroz više redova (rowspan) */
table.medalje tbody tr:nth-child(even),
table.medalje tbody tr:hover {
    background: none;
}

table.medalje tr.nastavak td {
    border-top: none;
    padding-top: 0;
}

/* U nastavnim redovima "Mjesto" je prva ćelija: poništi stil stupca "#" */
table.medalje td.mjesto {
    width: auto;
    text-align: left;
    color: var(--text);
    white-space: nowrap;
}

span.prezime {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.medalja::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 7px;
    border-radius: 50%;
    vertical-align: -1px;
    background: var(--medalja-boja);
}

.medalja-zlato  { --medalja-boja: #d4a72c; }
.medalja-srebro { --medalja-boja: #a7adb4; }
.medalja-bronca { --medalja-boja: #b0703c; }

.ekipna {
    margin-left: 4px;
    padding: 0 6px;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
}

.disciplina {
    margin-left: 4px;
    color: var(--muted);
    font-size: 13px;
}

/* Sportaš odabran u filteru */
mark {
    background: var(--hover);
    color: var(--text);
    font-weight: 600;
    padding: 0 3px;
    box-shadow: inset 0 -2px 0 var(--link);
}

.sport-naziv {
    flex: 0 0 140px;
    color: var(--muted);
    font-weight: 600;
}

/* "Nema rezultata" (td, da nadjača stil prvog stupca) */
tbody td.prazno {
    width: auto;
    text-align: center;
    color: var(--muted);
    padding: 24px 14px;
}

/* Paginacija (classes/Pagination.php) */
.pagination {
    max-width: 960px;
    margin: 12px auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
}

.pagination-info {
    color: var(--muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.pagination-pages {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.pagination-link {
    min-width: 34px;
    padding: 5px 9px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--link);
    text-align: center;
    text-decoration: none;
    font-variant-numeric: tabular-nums;
}

a.pagination-link:hover {
    background: var(--hover);
}

.pagination-link.is-current {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

.pagination-link.is-disabled {
    color: var(--border);
}

.pagination-gap {
    padding: 5px 4px;
    color: var(--muted);
}

/* Poništava stil glavnog forma za odabir tablice */
form.pagination-per-page {
    margin: 0;
    gap: 8px;
}

.pagination-per-page label {
    font-weight: 400;
    color: var(--muted);
    font-size: 13px;
}

.pagination-per-page select {
    border-radius: 0;
    padding: 4px 8px;
}

/* Mobitel: tablica se skrola vodoravno umjesto da se lomi */
@media (max-width: 640px) {
    body {
        font-size: 14px;
    }

    table {
        display: block;
        overflow-x: auto;
    }

    thead th,
    tbody td {
        padding: 7px 10px;
    }
}
