/* Posunovací tabule Čerčany – výchozí a končící vlaky na 24 h */
:root {
    --bg:       #0b1320;
    --panel:    #111b2e;
    --panel-2:  #17233b;
    --border:   #25334d;
    --ink:      #ffd24d;
    --ink-dim:  #c69a2a;
    --muted:    #8c7a3e;
    --white:    #f4f4f4;
    --red:      #ff4b4b;
    --green:    #44d07a;
    --blue:     #58b2ff;
    --orange:   #ffa94d;
    --row-alt:  #14203680;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Inter", "Segoe UI", "DejaVu Sans", system-ui, sans-serif;
    font-variant-numeric: tabular-nums;
    min-height: 100vh;
}

.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
    padding: 0.7rem 1.3rem;
    background: linear-gradient(180deg, #152238 0%, #0b1320 100%);
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 500;
}
.station { display: flex; align-items: baseline; gap: 0.8rem; flex-wrap: wrap; }
.station-label {
    color: var(--muted);
    font-size: 0.9rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}
.station-name {
    color: var(--white);
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 0.05em;
}
.station-sub {
    color: var(--muted);
    font-size: 0.9rem;
}
.mode-toggle {
    cursor: pointer;
    user-select: none;
    padding: 0.15rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    transition: background .15s;
}
.mode-toggle:hover { background: var(--panel-2); color: var(--ink); }
.btn-s121 {
    display: inline-block;
    margin-right: 0.8rem;
    padding: 0.25rem 0.7rem;
    background: var(--panel-2);
    color: var(--ink);
    border: 1px solid var(--border);
    border-radius: 4px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
}
.btn-s121:hover { background: var(--border); color: var(--white); }
.clock {
    text-align: center;
    color: var(--white);
    font-size: 2.6rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}
.updated {
    text-align: right;
    color: var(--muted);
    font-size: 0.9rem;
}
.status { font-size: 1.3rem; vertical-align: -2px; margin-left: 0.4rem; }
.status.ok  { color: var(--green); }
.status.err { color: var(--red); }

main {
    padding: 0.8rem 1rem 0.5rem;
}

table.trains {
    width: 100%;
    border-collapse: collapse;
    font-size: 1.2rem;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.trains thead th {
    text-align: left;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    padding: 0.55rem 0.7rem;
    border-bottom: 1px solid var(--border);
    background: #0e182a;
}
.trains tbody td {
    padding: 0.5rem 0.7rem;
    border-bottom: 1px dashed var(--border);
    vertical-align: middle;
}
.trains tbody tr:nth-child(even) td { background: var(--row-alt); }

/* Sloupce */
col.c-druh     { width: 7.5rem; }
col.c-vlak     { width: 5rem; }
col.c-cas      { width: 6rem; }
col.c-zpozdeni { width: 4rem; }
col.c-obeh     { width: 5rem; }
col.c-smer     { width: 18rem; }
col.c-kolej    { width: 3rem; }
col.c-razeni   { width: auto; }
col.c-nalezitosti { width: 22rem; }

/* Buňky */
.druh { white-space: nowrap; }
.event {
    display: inline-block;
    font-weight: 800;
    font-size: 0.9rem;
    padding: 0.1rem 0.45rem;
    border-radius: 5px;
    margin-right: 0.4rem;
    min-width: 4.5rem;
    text-align: center;
    letter-spacing: 0.04em;
}
.event.arrival   { background: var(--blue);   color: #002033; }
.event.departure { background: var(--orange); color: #331a00; }
.kind {
    display: inline-block;
    font-weight: 700;
    color: var(--white);
    background: #2a3a5a;
    padding: 0.05rem 0.45rem;
    border-radius: 4px;
    min-width: 2rem;
    text-align: center;
}

.vlak {
    font-weight: 700;
    color: var(--white);
    font-size: 1.3rem;
}

.cas .plan {
    color: var(--white);
    font-weight: 700;
    font-size: 1.35rem;
    line-height: 1.1;
}
.cas .real {
    color: var(--red);
    font-size: 1rem;
    line-height: 1.2;
}
.cas .day {
    color: var(--muted);
    font-size: 0.8rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.delay { text-align: right; font-weight: 700; }
.delay.on       { color: var(--green); }
.delay.early    { color: #ffe066; }
.delay.small    { color: var(--muted); }
.delay.late     { color: var(--red); }
.delay.very-late{ color: #fff; background: var(--red); border-radius: 4px; padding: 0.1rem 0.35rem; display: inline-block; }
.delay.na       { color: var(--muted); font-weight: 400; }
.delay.canceled { color: var(--red); }

.smer {
    font-weight: 600;
    font-size: 1.25rem;
    color: var(--ink);
}
tr.arrival   .smer > div:first-child,
tr.arrival   .smer .stop-name-sub,
tr.arrival   .smer .stop-name-sub .stop-time { color: var(--blue); }
tr.departure .smer > div:first-child,
tr.departure .smer .stop-name-sub,
tr.departure .smer .stop-name-sub .stop-time { color: var(--orange); }
.smer .stop-time {
    font-weight: 700;
    margin-left: 0.15rem;
}
.kolej {
    text-align: center;
    font-weight: 800;
    color: var(--white);
    font-size: 1.3rem;
}

.obeh { color: var(--ink-dim); font-weight: 600; font-size: 1rem; }
.razeni {
    color: var(--white);
    font-size: 1.15rem;
    font-weight: 600;
    line-height: 1.25;
}
.nalezitosti {
    color: var(--ink-dim);
    font-size: 0.95rem;
    line-height: 1.3;
}
tr.arrival   .nalezitosti { color: var(--blue); }
tr.departure .nalezitosti { color: var(--orange); }
.razeni:empty::before,
.nalezitosti:empty::before,
.obeh.placeholder:empty::before {
    content: "—";
    color: #3b4b6b;
}
.smer .stop-name-sub {
    display: block;
    font-size: 0.8rem;
    font-weight: 400;
    letter-spacing: 0.02em;
    margin-top: 0.1rem;
}
.zbroji {
    display: inline-block;
    color: var(--orange);
    font-weight: 700;
    border: 1px solid var(--orange);
    border-radius: 3px;
    padding: 0 0.3rem;
    margin: 0 0.1rem;
}
.crossday {
    display: inline-block;
    color: var(--blue);
    font-weight: 700;
    border: 1px solid var(--blue);
    border-radius: 3px;
    padding: 0 0.3rem;
    margin: 0 0.1rem;
    font-size: 0.85em;
}
.vozidlo-line {
    color: var(--white);
    font-weight: 600;
    font-size: 0.95rem;
    margin-top: 0.15rem;
    cursor: help;
    display: inline-block;
}
.vozidlo-click { cursor: pointer; }
.vozidlo-click:hover { color: #ffd166; }

/* Popup sestavy 121 */
.s121-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    display: none; align-items: center; justify-content: center;
    z-index: 9999;
}
.s121-overlay.visible { display: flex; }
.s121-modal {
    background: #1e2533; color: #fff;
    border: 1px solid #3a4a66; border-radius: 8px;
    padding: 1rem 1.25rem; min-width: 320px; max-width: 92vw; max-height: 88vh;
    overflow: auto; position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.s121-close {
    position: absolute; top: 0.35rem; right: 0.5rem;
    background: transparent; color: #fff; border: 0;
    font-size: 1.6rem; line-height: 1; cursor: pointer;
}
.s121-modal h3 { margin: 0 0 0.75rem 0; font-size: 1.05rem; }
.s121-head {
    display: flex; align-items: center; gap: 1rem;
    margin-bottom: 1rem; padding-bottom: 0.75rem;
    border-bottom: 1px solid #2a3446;
}
.s121-hero {
    max-height: 58px; max-width: 60vw;
    image-rendering: -webkit-optimize-contrast;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.5));
}
.s121-title { display: flex; flex-direction: column; gap: 0.15rem; }
.s121-voz { font-size: 1.3rem; font-weight: 700; }
.s121-vlak { color: #9fb3d9; font-size: 0.9rem; }
.s121-meta { color: #cfe0ff; margin: 0 0 0.5rem 0; font-size: 0.92rem; }
.s121-cil { font-size: 1.1rem; }
.s121-cil b { color: #ffd166; }
.s121-tbl thead .event { margin-right: 0; }
.s121-empty { color: #9fb3d9; font-style: italic; }

.s121-tbl { border-collapse: collapse; margin: 0 0 1rem 0; width: 100%; }
.s121-tbl thead th {
    background: #253049; color: #dfe8f9;
    padding: 0.35rem 0.5rem; text-align: left;
    border-bottom: 2px solid #3a4a66; font-weight: 600; font-size: 0.95rem;
}
.s121-tbl tbody th {
    color: #9fb3d9; font-weight: 500; text-align: left;
    padding: 0.3rem 0.5rem; width: 30%; white-space: nowrap;
    border-bottom: 1px solid #2a3446;
}
.s121-tbl tbody td {
    padding: 0.3rem 0.5rem; border-bottom: 1px solid #2a3446;
    font-size: 0.95rem; vertical-align: top;
}
@media (max-width: 600px) {
    .s121-head { flex-direction: column; text-align: center; gap: 0.5rem; }
    .s121-hero { max-height: 58px; max-width: 90%; }
    .s121-tbl tbody th { width: auto; }
}

.rada-img {
    height: 24px;
    vertical-align: middle;
    image-rendering: -webkit-optimize-contrast;
}
.razeni-main .rada-img { height: 24px; }
.vozidla-line { margin-top: 0.15rem; }
.razeni-units { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.15rem 0.35rem; }
.raz-unit { display: inline-flex; flex-direction: column; align-items: center; }
.raz-top { display: flex; align-items: flex-end; line-height: 1; }
.raz-top .rada-img { display: block; }
.raz-voz { margin-top: 0.15rem; font-size: 0.9em; text-align: center; color: #cfe0ff; white-space: nowrap; }
.raz-no-hv .raz-top img, .raz-no-hv .rada-img { filter: grayscale(1); opacity: 0.75; }
.raz-no-hv .raz-voz { color: #999; font-style: italic; }
.raz-sep { align-self: center; color: #9fb3d9; padding: 0 0.15rem; }
tr.train-row { cursor: default; }
tr.train-row.hover-match td { background: #1e2d4a !important; }
tr.train-row:hover td { background: #223354 !important; }

/* Oddělovač dne */
tr.day-sep td {
    background: #0e182a !important;
    color: var(--ink-dim);
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    padding: 0.35rem 0.7rem !important;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
}

/* Speciální stavy */
tr.row-canceled td {
    text-decoration: line-through;
    color: var(--red) !important;
}
tr.row-canceled .event { text-decoration: none; }

tr.empty td {
    text-align: center;
    color: var(--muted);
    padding: 2rem;
    font-style: italic;
}

.infotexts {
    padding: 0.5rem 1.3rem 1rem;
    color: var(--ink-dim);
    font-size: 0.95rem;
    min-height: 1rem;
}
.infotexts .it {
    padding: 0.3rem 0.6rem;
    border-left: 3px solid var(--ink-dim);
    margin-bottom: 0.3rem;
    background: var(--panel-2);
}

/* Kompaktnější zobrazení na menších monitorech */
@media (max-width: 1000px) {
    table.trains { font-size: 1rem; }
    col.c-razeni { width: auto; }
    col.c-smer   { width: 14rem; }
    col.c-nalezitosti { width: 14rem; }
    .vlak, .smer, .kolej { font-size: 1.1rem; }
    .cas .plan { font-size: 1.15rem; }
}

/* Soupravové vlaky – z oběhů, ne v Golemiu */
tr.train-row.soupravovy { background: #1b2a1b33; }
tr.train-row.soupravovy .druh .badge { background: #556b2f; color: #fff; }
tr.train-row.soupravovy td.cas .real, tr.train-row.soupravovy td.zpozdeni { opacity: 0.4; }

/* ===== Mobil: vlaky jako karty ===== */
@media (max-width: 700px) {
    /* Na dotykových/úzkých zařízeních neměníme pozadí při hoveru/kliku na řádku
       (na mobilu to generuje zbytečné vizuální „zdánlivé výběry"). */
    tr.train-row.hover-match td { background: inherit !important; }

    /* Vypni tap highlight a zvýraznění kartíček po stisku */
    tr.train-row, tr.train-row td, tr.train-row * {
        -webkit-tap-highlight-color: transparent;
    }
    tr.train-row:active, tr.train-row:focus,
    tr.train-row:active td, tr.train-row:focus td {
        background: var(--panel) !important;
    }

    .topbar {
        grid-template-columns: 1fr;
        text-align: center;
        gap: 0.4rem;
        padding: 0.5rem 0.8rem;
    }
    .topbar .station { justify-content: center; }
    .topbar .clock { font-size: 1.4rem; }
    .topbar .updated { justify-content: center; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
    .station-name { font-size: 1.5rem; }

    main { padding: 0.3rem; }

    table.trains { display: block; width: 100%; border-collapse: separate; }
    table.trains colgroup, table.trains thead { display: none; }
    table.trains tbody { display: block; }

    /* Oddělovač dne + prázdný řádek: zachovat blokově */
    tr.day-sep, tr.empty {
        display: block;
        padding: 0.4rem 0.6rem;
        margin: 0.6rem 0 0.3rem;
    }
    tr.day-sep td, tr.empty td { display: block; width: 100%; padding: 0; }

    /* Karta = 1 řádek tabulky */
    tr.train-row {
        display: grid;
        grid-template-columns: auto 1fr auto auto;
        grid-template-areas:
            "druh vlak cas  zpozdeni"
            "smer smer smer smer"
            "obeh obeh kolej kolej"
            "razeni razeni razeni razeni"
            "nalez nalez nalez nalez";
        gap: 0.25rem 0.5rem;
        padding: 0.6rem 0.7rem;
        margin-bottom: 0.5rem;
        background: var(--panel);
        border: 1px solid var(--border);
        border-radius: 8px;
    }
    tr.train-row + tr.train-row { margin-top: 0; }
    tr.train-row > td { display: block; padding: 0; border: 0; background: transparent; }

    tr.train-row td.druh     { grid-area: druh; }
    tr.train-row td.vlak     { grid-area: vlak; font-size: 1.2rem; font-weight: 700; align-self: center; }
    tr.train-row td.cas      { grid-area: cas;  text-align: right; }
    tr.train-row td.zpozdeni { grid-area: zpozdeni; align-self: center; text-align: right; min-width: 2.8rem; }
    tr.train-row td.smer     { grid-area: smer; border-top: 1px dashed var(--border); padding-top: 0.35rem; }
    tr.train-row td.obeh     { grid-area: obeh; }
    tr.train-row td.kolej    { grid-area: kolej; text-align: right; }
    tr.train-row td.razeni   { grid-area: razeni; }
    tr.train-row td.nalezitosti { grid-area: nalez; border-top: 1px dashed var(--border); padding-top: 0.3rem; }

    /* Popisky před hodnotami (kromě vlak/cas/druh/smer kde jsou samozřejmé) */
    tr.train-row td.obeh::before     { content: "Oběh: "; color: var(--muted); font-weight: 400; font-size: 0.85rem; }
    tr.train-row td.kolej::before    { content: "Kol. "; color: var(--muted); font-weight: 400; font-size: 0.85rem; }
    tr.train-row td.razeni::before   { content: "Řazení: "; color: var(--muted); font-weight: 400; font-size: 0.85rem; }

    /* Schovej buňky v kartách, pokud jsou prázdné (kromě koleje) */
    tr.train-row td.razeni:empty,
    tr.train-row td.nalezitosti:empty,
    tr.train-row td.obeh.placeholder:empty { display: none; }

    .cas .plan { font-size: 1.2rem; }
    .cas .day, .cas .real { font-size: 0.85rem; }
    .smer { font-size: 1.05rem; }
    .kolej { font-size: 1.2rem; display: inline; }

    .infotexts { padding: 0.4rem 0.6rem 0.8rem; font-size: 0.85rem; }
}

/* Velmi úzké displeje: zmenši kartu ještě o něco */
@media (max-width: 380px) {
    tr.train-row { padding: 0.5rem 0.5rem; font-size: 0.95rem; }
    tr.train-row td.vlak { font-size: 1.1rem; }
    .cas .plan { font-size: 1.1rem; }
}

/* ===== Vzkaz – žlutý pruh s hazard okraji nahoře a dole ===== */
.vzkaz-bar[hidden] { display: none !important; }
.vzkaz-bar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: 96px;
    display: grid;
    grid-template-rows: 6px 1fr 6px;
    background: #ffd100;
    color: #111;
    font-weight: 800;
    font-size: 2.8rem;
    letter-spacing: 0.02em;
    z-index: 400;
    box-shadow: 0 -4px 14px rgba(0,0,0,0.4);
}
.vzkaz-hazard {
    background: repeating-linear-gradient(135deg,
        #111 0 14px,
        #ffd100 14px 28px);
}
.vzkaz-hazard-r { background: repeating-linear-gradient(45deg,
        #111 0 14px,
        #ffd100 14px 28px); }
.vzkaz-text-wrap {
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: #ffd100;
}
.vzkaz-text {
    white-space: nowrap;
    padding: 0 1rem;
    text-align: center;
}
.vzkaz-text-wrap.scroll {
    justify-content: flex-start;
}
.vzkaz-text-wrap.scroll .vzkaz-text {
    display: inline-block;
    padding-left: 100%;
    animation: vzkaz-marquee linear infinite;
}
@keyframes vzkaz-marquee {
    0%   { transform: translateX(0); }
    100% { transform: translateX(-100%); }
}
/* Vyhraď místo pod tabulí, aby pruh nepřekryl poslední řádek */
body.has-vzkaz main { padding-bottom: 110px; }
body.has-vzkaz .infotexts { margin-bottom: 100px; }

@media (max-width: 700px) {
    .vzkaz-bar { height: 72px; font-size: 2rem; grid-template-rows: 4px 1fr 4px; }
    body.has-vzkaz main { padding-bottom: 84px; }
}

/* ===== Vzkaz – modal ===== */
.vzkaz-modal[hidden] { display: none !important; }
.vzkaz-modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 1rem;
}
.vzkaz-dialog {
    background: var(--panel);
    color: var(--white);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem 1.2rem;
    width: min(560px, 100%);
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.vzkaz-dialog h2 { margin: 0 0 0.7rem; color: var(--ink); font-size: 1.2rem; }
.vzkaz-dialog textarea {
    width: 100%;
    box-sizing: border-box;
    background: #0b1320;
    color: var(--white);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.7rem;
    font: inherit;
    font-size: 1rem;
    resize: vertical;
}
.vzkaz-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.9rem;
    align-items: center;
    flex-wrap: wrap;
}
.vzkaz-actions button {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #1e2a42;
    color: var(--white);
    cursor: pointer;
    font-weight: 600;
}
.vzkaz-actions .btn-ok  { background: #2b7bd4; border-color: #3e8ee2; }
.vzkaz-actions .btn-del { background: #a33; border-color: #c44; }
.vzkaz-actions button:hover { filter: brightness(1.15); }

/* Date picker na kliknutí na hodiny */
.clock { cursor: pointer; }
#datepick-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: none; align-items: center; justify-content: center; z-index: 10000;
}
#datepick-overlay.visible { display: flex; }
.datepick-modal {
  position: relative;
  background: #142038; color: #e6edf6;
  border: 1px solid #22324f; border-radius: 12px;
  padding: 24px 28px; min-width: 300px;
  box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
.datepick-modal h3 { margin: 0 0 14px; font-size: 18px; }
.datepick-modal input[type=date] {
  background: #0b1322; color: #e6edf6;
  border: 1px solid #2c3e61; border-radius: 6px;
  padding: 8px 10px; font-size: 15px; width: 100%;
  color-scheme: dark;
}
.datepick-actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; }
.datepick-actions button {
  padding: 8px 16px; border-radius: 6px; border: 1px solid #2c3e61;
  background: #1f3a63; color: #fff; cursor: pointer; font-size: 14px;
}
.datepick-actions .btn-ok { background: #2b7bd4; border-color: #3e8ee2; }
.datepick-actions button:hover { filter: brightness(1.15); }
.datepick-close {
  position: absolute; top: 6px; right: 10px;
  background: transparent; border: 0; color: #cfe0ff;
  font-size: 24px; cursor: pointer;
}
#altdate-banner {
  position: fixed; left: 0; right: 0; top: 0;
  background: #b87a1a; color: #fff; padding: 8px 16px;
  text-align: center; font-size: 15px;
  z-index: 600;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
#altdate-banner a { color: #fff; text-decoration: underline; }

.s121-actions { margin: 14px 0 6px; text-align: center; }
.s121-btn-obeh {
  display: inline-block; padding: 6px 14px;
  background: #2b7bd4; color: #fff !important;
  border: 1px solid #3e8ee2; border-radius: 6px;
  text-decoration: none; font-size: 14px; font-weight: 500;
}
.s121-btn-obeh:hover { background: #3689e0; filter: brightness(1.1); }

.obeh-table .strojvedouci { color: #cfe0ff; font-size: 13px; }
.obeh-table .hv { font-variant-numeric: tabular-nums; color: #cfe0ff; white-space: nowrap; }
