/* Sledování Podbaba — layout styles.
   Mobile first: the base rules target a phone, media queries add desktop.
   Locomotive livery colours come from the external laky*.css sheets; nothing
   here may override the .lakVozidla / .lakVozidlaMapa rules. */

@font-face {
    font-family: "JetBrains Mono";
    src: url("JetBrainsMono-Regular.ttf") format("truetype");
    font-weight: 400;
    font-display: swap;
}

:root {
    /* The livery palette assumes a light page. Pinning the scheme also stops
       mobile browsers from recolouring form controls in dark mode, which is
       what used to make button labels invisible on phones. */
    color-scheme: light;

    --bg: #fafbfc;
    --fg: #2b303a;
    --muted: #8b93a1;
    /* Hairlines rather than borders: the single biggest source of visual weight
       was every card, row and control carrying a solid grey outline. */
    --line: #ebedf1;
    --line-strong: #dcdfe6;
    --card: #ffffff;
    --accent: #2f6fdb;
    --accent-fg: #ffffff;
    --danger: #c0392b;
    --warn: #b07d1a;
    --ok: #3a9e6a;

    --header-h: 3.25rem;
    /* Comfortable touch target: iOS/Android guidance is ~44px. */
    --tap: 2.75rem;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
    /* 16px keeps iOS Safari from zooming in when a field gets focus. */
    font-size: 16px;
    line-height: 1.55;
    background: var(--bg);
    color: var(--fg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.centered { justify-content: center; align-items: center; padding: 1rem; }

main {
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem;
}

h1 { font-size: 1.25rem; font-weight: 600; margin: 0.25rem 0 0.75rem; }
h1 small { display: block; font-size: 0.85rem; font-weight: normal; color: var(--muted); }
h2 { font-size: 0.95rem; font-weight: 600; color: var(--muted); margin: 1.5rem 0 0.5rem; }

a { color: var(--accent); text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); }

/* --- header / hamburger -------------------------------------------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: var(--header-h);
    padding: 0.4rem 0.75rem;
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    background: var(--card);
    border-bottom: 1px solid var(--line);
}

.brand { font-weight: 600; text-decoration: none; color: var(--fg); white-space: nowrap; flex: 0 0 auto; }

.burger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: var(--tap);
    height: var(--tap);
    padding: 0.6rem;
    cursor: pointer;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
}
.burger span { display: block; height: 1.5px; background: var(--fg); border-radius: 2px; }

.menu { display: none; }
/* Checkbox hack: the menu opens without any JavaScript. */
.nav-toggle:checked ~ .topbar .menu { display: block; }

@media (max-width: 1023px) {
    .menu {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--card);
        border-bottom: 1px solid var(--line);
        box-shadow: 0 6px 20px rgba(20, 25, 40, 0.06);
        padding: 0.5rem 0.75rem 0.75rem;
    }
}

.nav { display: flex; flex-direction: column; }
.nav a {
    display: block;
    padding: 0.7rem 0.25rem;
    text-decoration: none;
    font-weight: 500;
    color: var(--fg);
    border-bottom: 1px solid var(--line);
}
.nav a:last-child { border-bottom: none; }

.userbox {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.6rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--line);
    font-size: 0.9rem;
}
.userbox .username { font-weight: 600; }

/* --- quick query --------------------------------------------------------- */

.quickquery {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.5rem 0.75rem 0;
}
.quickquery form { display: flex; align-items: center; gap: 0.4rem; }
.quickquery label { flex: 0 0 2.5rem; font-weight: 400; font-size: 0.8rem; color: var(--muted); }
.quickquery input { background-color: transparent; }
.quickquery button { font-size: 0.85rem; padding: 0.5rem 0.7rem; color: var(--muted); }
.quickquery button:hover { color: var(--accent); }
.quickquery input { flex: 1; min-width: 0; }
.quickquery button { flex: 0 0 auto; }

/* --- form controls ------------------------------------------------------- */

input[type="text"], input[type="password"], select, button {
    font: inherit;
    font-size: 1rem;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    /* Explicit colours: without them a phone in dark mode paints the label in
       its own light "ButtonText" colour on our white background. */
    color: var(--fg);
    background-color: var(--card);
    -webkit-appearance: none;
    appearance: none;
}

input[type="text"], input[type="password"], select {
    padding: 0.5rem 0.6rem;
    min-height: var(--tap);
    max-width: 100%;
}

select {
    /* appearance:none removes the native arrow; draw our own. */
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                      linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 2rem;
}

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap);
    max-width: 100%;
    padding: 0.5rem 0.9rem;
    cursor: pointer;
    font-weight: 500;
    /* Long Czech labels must wrap rather than push the page sideways on a
       320px screen; only the short row-action buttons stay on one line. */
    white-space: normal;
    text-align: center;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button:active { background-color: #f2f5fa; }
button.primary { background-color: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 500; }
button.primary:hover { color: var(--accent-fg); filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); color: var(--danger); }

input[type="checkbox"] { width: 1.5rem; height: 1.5rem; accent-color: var(--accent); flex: 0 0 auto; }

.inline-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.inline-form input[type="text"], .inline-form input[type="password"] { flex: 1 1 12rem; min-width: 0; }

/* Full-width stacked fields on a phone, one row from tablet up. */
.stacked-form { display: flex; flex-direction: column; gap: 0.5rem; }
.stacked-form input, .stacked-form select, .stacked-form button { width: 100%; }
@media (min-width: 768px) {
    .stacked-form { flex-direction: row; flex-wrap: wrap; align-items: center; }
    .stacked-form input { flex: 1 1 10rem; width: auto; min-width: 0; }
    .stacked-form select { flex: 0 1 14rem; width: auto; }
    .stacked-form button { width: auto; }
    .stacked-form label { flex: 0 0 auto; font-weight: 600; }
}

/* Checkbox sitting next to the livery badge it belongs to. The label makes the
   whole strip tappable, so the box itself need not be 44px. */
.checkline {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: var(--tap);
    cursor: pointer;
}

/* --- cards / status ------------------------------------------------------ */

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.9rem 1rem;
    margin-bottom: 1rem;
}
.card-head { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; justify-content: space-between; }
.card-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.login-card { width: 100%; max-width: 380px; }
.login-card label { display: block; margin-top: 0.75rem; font-weight: 500; color: var(--muted); font-size: 0.85rem; }
.login-card input { width: 100%; margin-top: 0.25rem; }
.login-card button { margin-top: 1rem; width: 100%; }

.statusline {
    display: grid;
    gap: 0.35rem;
    padding: 0.1rem 0.15rem 0.75rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--line);
    font-size: 0.8rem;
    color: var(--muted);
}
.statusline strong { font-weight: 500; color: var(--muted); }

.refresh-state { display: flex; align-items: center; gap: 0.4rem; color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.dot-ok { background: var(--ok); }
.dot-busy { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.dot-error { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }

.stat-list { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: 0.4rem; }

/* --- messages ------------------------------------------------------------ */

.flashes { list-style: none; padding: 0; margin: 0 0 0.75rem; }
.flash { padding: 0.55rem 0.8rem; border-radius: 8px; margin-bottom: 0.5rem; word-break: break-word; font-size: 0.9rem; }
.flash-info { background: #f0f5fd; color: #2d5aa8; }
.flash-error { background: #fdf0ef; color: var(--danger); }
.flash-warning { background: #fdf6e9; color: var(--warn); }

.notice { padding: 0.55rem 0.8rem; background: #fdf6e9; color: var(--warn); border-radius: 8px; font-size: 0.9rem; }
.hint { color: var(--muted); font-size: 0.85rem; }
.empty { color: var(--muted); text-align: center; padding: 1.25rem 0; }

/* --- tables -------------------------------------------------------------- */

/*
 * Deliberately dense. This list runs to a couple of hundred locomotives and is
 * read by scanning down it, so every row that fits on screen is worth more than
 * the breathing room around it -- v1 fitted far more in a screenful.
 *
 * The floor is the livery badge: .lakVozidla carries 4px/6px top and bottom
 * borders from the external sheets, which *are* the livery colours, so they
 * stay. That leaves the line box and the cell padding, which is where the
 * space below comes from.
 */
.locotable {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 0.875rem;
    line-height: 1.25;
}
.locotable th, .locotable td {
    padding: 0.15rem 0.6rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}
/* No fill, no uppercase shouting -- just a quiet label row. */
.locotable th {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: 0.02em;
}
.locotable tr:last-child td { border-bottom: none; }
.locotable tr.cold { color: var(--muted); }
.locotable tr.divider td { height: 8px; background: var(--bg); padding: 0; border-bottom: none; }
.locotable .center { text-align: center; }
.locotable .nowrap { white-space: nowrap; }

/*
 * The flex lives on an inner wrapper, never on the <td> itself. `display: flex`
 * on a table cell replaces `table-cell`, so the cell stops sharing the row's
 * height: it shrinks to its own content and draws its bottom border there,
 * leaving the number sitting high and the rule broken partway across the row.
 * On the management pages, where other cells hold buttons, that was a 44px step.
 */
.cell { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.loco-cell a { text-decoration: none; }

/* laky.css gives .lakVozidla a bottom margin so stacked badges do not touch.
   In a table each row holds exactly one, where that margin is just height --
   and this list is meant to be dense. Two classes, so it outranks the livery
   sheets whatever order they load in. The map keeps its margin: .lakVozidlaMapa
   stacks several labels at one station and measures them to do it. */
.locotable .lakVozidla { margin-bottom: 0; }

.row-actions form { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; margin: 0; }
.row-actions button { white-space: nowrap; }

/* Touch devices keep full-size targets; only a real pointer gets the compact
   36px buttons, so tablets are not treated like desktops. */
@media (hover: hover) and (pointer: fine) and (min-width: 1024px) {
    .row-actions button { font-size: 0.85rem; padding: 0.4rem 0.6rem; min-height: 2.25rem; }
    .row-actions select, .row-actions input { font-size: 0.85rem; min-height: 2.25rem; padding: 0.3rem 0.5rem; }
}

/* On a phone the action buttons get the full card width. */
@media (max-width: 767px) {
    .row-actions { padding-top: 0.5rem !important; margin-top: 0.3rem; border-top: 1px solid var(--line) !important; }
    .row-actions .cell { gap: 0.4rem; }
    .row-actions button { flex: 1 1 auto; }
    .row-actions form { flex: 1 1 100%; }
}

.tag {
    font-size: 0.65rem;
    padding: 0.1rem 0.35rem;
    background: #f2f4f7;
    border-radius: 4px;
    color: var(--muted);
    text-transform: uppercase;
    white-space: nowrap;
}
.tag-ok { color: var(--ok); background: #eef7f2; }
.tag-muted { opacity: 0.7; }

/*
 * Phone layout for the locomotive list: each row becomes a card. The header is
 * hidden and every cell prints its own label from data-label, so the markup
 * stays a single <table> shared with the desktop view and the live fragment.
 */
@media (max-width: 767px) {
    .locotable.responsive { border: none; background: none; }
    .locotable.responsive thead { display: none; }
    .locotable.responsive tbody, .locotable.responsive tr, .locotable.responsive td { display: block; }

    .locotable.responsive tbody tr {
        background: var(--card);
        border: 1px solid var(--line);
        border-radius: 10px;
        padding: 0.45rem 0.7rem;
        margin-bottom: 0.35rem;
    }
    .locotable.responsive tr.divider { display: none; }
    .locotable.responsive tbody tr.cold { opacity: 0.75; }

    /* Grid, not flex: minmax(0, 1fr) lets the value column shrink below its
       min-content width, so a long reservation list wraps instead of pushing
       the whole page into horizontal scroll. */
    .locotable.responsive td {
        border: none;
        padding: 0;
        display: grid;
        grid-template-columns: 4.5rem minmax(0, 1fr);
        gap: 0 0.5rem;
        align-items: baseline;
        overflow-wrap: anywhere;
    }
    .locotable.responsive td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 0.78rem;
    }
    /* The value wrapper is the second grid item; without it every inline
       element in the cell would become an item of its own and get stretched
       into a column. min-width:0 lets long content wrap. */
    .locotable.responsive td > .v { min-width: 0; }
    /* Cells that opt out of the label column span the full card width. */
    .locotable.responsive td.loco-cell,
    .locotable.responsive td.row-actions,
    .locotable.responsive td.empty { grid-template-columns: minmax(0, 1fr); }
    /* The locomotive number is the card heading, so it needs no label. Plain
       blocks: the inner .cell does the arranging, here as on the desktop. */
    .locotable.responsive td.loco-cell,
    .locotable.responsive td.row-actions { display: block; }
    .locotable.responsive td.loco-cell { padding-bottom: 0.2rem; }
    .locotable.responsive td.loco-cell::before { content: none; }
    .locotable.responsive td.row-actions::before { content: none; }
    /* Cells with nothing in them would print a lonely label. A placeholder
       dash counts as nothing here -- see _loco_table.html. */
    .locotable.responsive td:empty,
    .locotable.responsive td:has(> .v:empty),
    .locotable.responsive td:has(> .v.placeholder) { display: none; }
}

/* --- loco detail --------------------------------------------------------- */

.detail-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.5rem; }
.detail-head .number { font-size: 1.55rem; font-weight: 600; letter-spacing: -0.01em; }
.detail-note { color: var(--muted); }

/* Key/value grid: one column on a phone, two from tablet up. */
.factgrid { display: grid; grid-template-columns: 1fr; gap: 0.5rem 1rem; margin: 0; }
.factgrid > div {
    display: flex;
    gap: 0.5rem;
    align-items: baseline;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--line);
}
.factgrid > div:last-child { border-bottom: none; }
.factgrid dt { flex: 0 0 5.5rem; color: var(--muted); font-size: 0.8rem; }
.factgrid dd { margin: 0; min-width: 0; font-weight: 500; word-break: break-word; }
/* A value that needs the full width even in the two-column desktop grid. */
.factgrid > div.wide { grid-column: 1 / -1; }

/* A reservation is a small card: train number, function, route. */
.reservations { display: grid; gap: 0.5rem; }
.reservation {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.15rem 0.75rem;
    align-items: baseline;
    padding: 0.6rem 0.75rem;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
}
.reservation.current { box-shadow: inset 2px 0 0 var(--accent); }
.reservation .train { grid-row: span 2; font-size: 1.1rem; font-weight: 600; text-decoration: none; }
.reservation .route { word-break: break-word; }
.reservation .func { color: var(--muted); font-size: 0.82rem; }
.reservation .badge {
    grid-column: 1 / -1;
    justify-self: start;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent);
    font-weight: 700;
}

.detail-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.detail-actions form { flex: 1 1 12rem; }
.detail-actions button { width: 100%; }

/* --- raw ISOR output ----------------------------------------------------- */

.isor-output {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.6rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.isor-output pre {
    margin: 0;
    font-family: "JetBrains Mono", ui-monospace, "Courier New", monospace;
    font-size: 0.72rem;
    line-height: 1.35;
}
.isor-output table { border-collapse: collapse; }
.isor-output td, .isor-output th { padding: 0.15rem 0.4rem; }

/* Wide tables that cannot be restructured scroll inside their own box. */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.footer {
    text-align: center;
    color: var(--muted);
    font-size: 0.75rem;
    opacity: 0.7;
    padding: 1.5rem 0 calc(1.5rem + env(safe-area-inset-bottom));
}

/* --- full-bleed map page ------------------------------------------------- */

/* The map is full-bleed: it must escape the 1200px centred column every other
   page lives in, or it renders as a narrow strip on a wide screen.
   Height comes from the flex layout rather than `100dvh - header`, so it is
   exact whatever the header actually measures. */
body.map-page { height: 100dvh; overflow: hidden; }
body.map-page main {
    max-width: none;
    width: 100%;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
body.map-page #map { flex: 1; width: 100%; min-height: 0; }
body.map-page .footer { display: none; }
body.map-page .flashes { position: absolute; z-index: 600; margin: 0.5rem; }

/* Shown only when the Leaflet CDN could not be reached. */
.map-fallback { padding: 0.75rem; overflow-y: auto; }
.fallback-list { list-style: none; padding: 0; margin: 0.75rem 0 0; display: grid; gap: 0.4rem; }
.fallback-list li { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem 0.7rem; }

/* --- tablet / desktop ---------------------------------------------------- */

@media (min-width: 768px) {
    main { padding: 1rem; }
    h1 { font-size: 1.5rem; }
    h1 small { display: inline; margin-left: 0.5rem; }

    .quickquery { flex-direction: row; gap: 1.5rem; padding: 0.75rem 1rem 0; }
    .quickquery form { flex: 0 1 auto; }
    .quickquery label { flex: 0 0 auto; }
    .quickquery input { flex: 0 1 15rem; }

    .statusline { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.5rem 1.5rem; }
    .factgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .reservations { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
    .detail-actions form { flex: 0 0 auto; }
    .isor-output pre { font-size: 0.8rem; }
}

/* The header only switches from hamburger to a horizontal row once there is
   room for every nav item AND the user box; at 768px an admin's six links
   squeezed the brand onto two lines. */
@media (min-width: 1024px) {
    .burger { display: none; }
    .menu { display: flex !important; align-items: center; gap: 1.25rem; }
    .nav { flex-direction: row; gap: 1.25rem; }
    .nav a { padding: 0.25rem 0; border-bottom: none; }
    /* Separates navigation from the account controls -- on a phone the
       userbox's border-top does the same job in the stacked menu. */
    .userbox {
        margin: 0;
        border-top: none;
        padding: 0.15rem 0 0.15rem 1.25rem;
        border-left: 1px solid var(--line-strong);
    }
}

/* --- departure board ----------------------------------------------------- */

/* Times and delays read as one unit; the delay carries the colour so the board
   can be scanned without reading every number. */
.board .t { font-variant-numeric: tabular-nums; }
.board .train-no { font-weight: 600; text-decoration: none; font-variant-numeric: tabular-nums; }
.board td .v { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.35rem; }

.delay {
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    padding: 0.05rem 0.3rem;
    border-radius: 4px;
}
.delay-ontime { color: var(--ok); background: #eef7f2; }
.delay-slight { color: var(--warn); background: #fdf6e9; }
.delay-late { color: var(--danger); background: #fdf0ef; }
/* Diacritics survive better without the uppercase transform. */
.tag-unconfirmed { text-transform: none; letter-spacing: 0; }
