:root {
  color-scheme: dark;
  --bg: #141218;
  --surface: #1e1a26;
  --surface-2: #2a2436;
  --primary: #d0bcff;
  --primary-2: #a78bfa;
  --text: #efeaf7;
  --text-2: #b7aec4;
  --border: #352d47;
  --danger: #ff6b81;
  --warning: #ffb86b;
  --ok: #7ee2a8;
  --radius: 14px;
  --m3-primary-container: #4f378b;
  --m3-on-primary-container: #eaddff;
  --m3-secondary-container: #4a4458;
  --m3-on-secondary-container: #e8def8;
  --m3-tertiary: #efb8c8;
  --m3-tertiary-container: #633b48;
  --m3-on-tertiary-container: #ffd8e4;
  --m3-surface-variant: #49454f;
  --m3-on-surface-variant: #cac4d0;
  --m3-outline-variant: #49454f;
  --m3-on-surface: #e6e0e9;
  --m3-error: #f2b8b5;
  --m3-error-container: #93000a;
  --m3-on-error-container: #ffdad6;
  --m3-surface-container-highest: #36343b;
}

* { box-sizing: border-box; }

:root {
  --app-max: 560px;
  --main-pad-x: 12px;
  --main-pad-bottom: 104px;
}

html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
button, [role="button"] { touch-action: manipulation; }
button { -webkit-tap-highlight-color: transparent; }
.train-card, .station-chip, .nav-item, .icon-btn, .btn, .chip {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#app { width: 100%; max-width: var(--app-max); margin: 0 auto; min-height: 100dvh; background: var(--bg); display: flex; flex-direction: column; }

/* Dokument (html/body) jest jedynym kontenerem przewijania.
   #main NIE może mieć `overflow-y: auto` ani `overscroll-behavior`,
   bo od Chromium 144 `overscroll-behavior` jest respektowany także na
   kontenerach bez przepełnienia. Taki kontener „połykał” gest przewijania
   zaczęty na kafelku (pociąg/wiadomość) i strona w ogóle się nie przewijała
   (szczególnie w zainstalowanej PWA). */
#main {
  flex: 1;
  padding: 12px max(var(--main-pad-x), env(safe-area-inset-right)) var(--main-pad-bottom) max(var(--main-pad-x), env(safe-area-inset-left));
}
/* Na czacie dolna belka pisania jest przyklejona nad nawigacją –
   rezerwujemy miejsce, żeby ostatniej wiadomości nie zasłaniały paski. */
#main.chat-tab { padding-bottom: calc(var(--bottomnav-height, 60px) + var(--chat-input-height, 72px) + 12px); }
@media (min-width: 561px) { #app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); } }

#app-sticky-top { position: sticky; top: 0; z-index: 30; background: var(--bg); }
#topbar { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) max(var(--main-pad-x), env(safe-area-inset-right)) 10px max(var(--main-pad-x), env(safe-area-inset-left)); background: rgba(20, 18, 24, 0.92); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
#topbar-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
#topbar-main { color: var(--text); font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#topbar-sub { color: var(--text-2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#topbar-actions { display: flex; gap: 6px; }

.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: none; background: transparent; color: var(--m3-on-surface-variant); font-size: 16px; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; cursor: pointer; transition: background-color 0.15s ease, color 0.15s ease; }
.icon-btn .icon { width: 22px; height: 22px; }
.icon-btn:hover { background: rgba(230, 224, 233, 0.08); color: var(--text); }
.icon-btn:active { background: rgba(230, 224, 233, 0.14); transform: scale(0.96); }
.icon-btn.muted { color: var(--danger); background: rgba(255, 107, 129, 0.14); }

/* Dyskretna zachęta do instalacji PWA - widoczna tylko w karcie przeglądarki,
   w trybie standalone app.js w ogóle jej nie renderuje. */
.install-hint { display: flex; align-items: center; gap: 4px; padding: 0 6px 0 12px; background: rgba(208, 188, 255, 0.07); border-bottom: 1px solid var(--border); }
.install-hint-action { flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px; background: none; border: none; color: var(--text-2); font-family: inherit; font-size: 12px; line-height: 1.25; text-align: left; padding: 8px 0; cursor: pointer; }
.install-hint-action .icon { color: var(--primary); flex: 0 0 auto; }
.install-hint-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.install-hint-cta { flex: 0 0 auto; color: var(--primary); font-weight: 700; padding-left: 8px; }
.install-hint-close { flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; background: none; border: none; color: var(--text-2); padding: 7px; border-radius: 8px; cursor: pointer; }
.install-hint-close:hover, .install-hint-close:active { color: var(--text); background: rgba(230, 224, 233, 0.08); }
.install-hint.installed .install-hint-action .icon { color: var(--ok); }
.install-hint.installed .install-hint-cta { color: var(--text-2); }

#bottomnav { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: min(100%, var(--app-max)); display: flex; background: rgba(30, 26, 38, 0.96); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); z-index: 30; }
.nav-item { flex: 1; background: none; border: none; color: var(--m3-on-surface-variant); padding: 10px 0 9px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; cursor: pointer; }
.nav-item.active { color: var(--primary); }
.nav-icon { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; }
.nav-icon .icon { width: 24px; height: 24px; }

/* Karty */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.card.alert { border-color: rgba(255, 107, 129, 0.6); background: rgba(255, 107, 129, 0.08); }

.section-title { font-size: 15px; font-weight: 700; margin: 14px 0 8px; color: var(--text); }
.muted { color: var(--text-2); }

/* ============================= Rozkład ============================= */

.icon { vertical-align: middle; flex-shrink: 0; }

/* Górna belka rozkładu – nie przewija się razem z listą pociągów.
   Mieści się w #app-sticky-top razem z topbarem, więc nie trzeba mierzyć
   wysokości nagłówka aplikacji w JS (także przy powiększeniu/obrocie). */
#timetable-header-root { display: none; background: var(--bg); padding: 6px max(var(--main-pad-x), env(safe-area-inset-right)) 4px max(var(--main-pad-x), env(safe-area-inset-left)); }
#timetable-header-root.active { display: block; }
#timetable-header-root .station-row { padding: 0; }
#timetable-header-root .summary-header { margin: 6px calc(-1 * var(--main-pad-x)) 0; }

/* Pasek wyboru stacji */
.station-row { display: flex; align-items: center; gap: 6px; padding: 6px 0; }
.station-chips { flex: 1; min-width: 0; display: flex; gap: 6px; align-items: center; }
.station-chip { flex: 1 1 0; min-width: 0; display: inline-flex; align-items: center; justify-content: center; gap: 4px; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 999px; padding: 8px 10px; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; overflow: hidden; }
.station-chip span { overflow: hidden; text-overflow: ellipsis; }
.station-chip.active { background: var(--m3-secondary-container); border-color: transparent; color: var(--m3-on-secondary-container); }
.chip-search { flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--m3-surface-container-highest); color: var(--primary); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.chip { flex: 0 0 auto; background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 999px; padding: 8px 14px; font-size: 13px; cursor: pointer; }
.chip.active { background: var(--primary); color: #241a33; border-color: var(--primary); font-weight: 700; }

/* Pasek podsumowania */
.summary-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: rgba(73, 69, 79, 0.5); margin: 0 calc(-1 * var(--main-pad-x)) 8px; padding: 8px calc(var(--main-pad-x) + 4px); }
.summary-left { min-width: 0; }
.summary-count { font-size: 12px; color: var(--m3-on-surface-variant); }
.summary-count.error { color: var(--m3-error); font-weight: 700; }
.summary-date { font-size: 11px; font-weight: 600; color: var(--primary); margin-top: 1px; }
.summary-stale { color: var(--text-2); font-weight: 500; }
.summary-right { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.summary-action { display: inline-flex; align-items: center; gap: 4px; background: none; border: none; color: var(--primary); font-size: 12px; font-weight: 700; cursor: pointer; padding: 0; }
.summary-spinner { width: 16px; height: 16px; border: 2px solid rgba(208, 188, 255, 0.25); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
.summary-spinner.small { width: 18px; height: 18px; }

/* Nagłówek daty */
.date-header { display: flex; align-items: center; gap: 8px; background: var(--m3-primary-container); color: var(--m3-on-primary-container); border-radius: 8px; padding: 8px 14px; margin: 4px 0; font-size: 14px; font-weight: 700; }

/* Karta pociągu */
.train-card { background: rgba(73, 69, 79, 0.25); border: 1px solid rgba(73, 69, 79, 0.5); border-radius: 12px; padding: 10px; margin-bottom: 8px; cursor: pointer; outline: none; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform 0.06s ease, background 0.15s ease; }
.train-card:active { transform: scale(0.995); }
.train-card.home { background: rgba(79, 55, 139, 0.25); border-color: rgba(208, 188, 255, 0.35); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35); }
.train-card.work { background: rgba(99, 59, 72, 0.25); border-color: rgba(239, 184, 200, 0.35); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35); }
.train-card.cancelled { background: rgba(147, 0, 10, 0.2); border-color: rgba(242, 184, 181, 0.4); }
.train-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.train-left { display: flex; align-items: flex-start; gap: 10px; flex: 1; min-width: 0; }
.train-badges { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; flex: 0 0 auto; }
.train-badge { display: inline-flex; align-items: center; gap: 3px; border-radius: 6px; padding: 2px 6px; font-size: 10px; font-weight: 800; line-height: 1.35; white-space: nowrap; color: #ffffff; }
.train-badge.carrier { font-weight: 700; font-size: 11px; padding: 4px 8px; }
.train-badge.bus { background: #D32F2F; }
.train-badge.gps { background: #2E7D32; }
.train-badge.stuck { background: #D32F2F; }
.train-badge.home { background: rgba(79, 55, 139, 0.8); color: #EADDFF; }
.train-badge.work { background: rgba(99, 59, 72, 0.8); color: #FFD8E4; }
.train-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.train-number { font-size: 16px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.train-relation { font-size: 13px; font-weight: 600; color: var(--primary); line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.delay-badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 12px; padding: 6px 10px; font-size: 11px; font-weight: 700; white-space: nowrap; flex: 0 0 auto; }
.route-delay-badge { padding: 4px 8px; }
.train-divider { height: 1px; background: rgba(73, 69, 79, 0.5); margin: 7px 0 5px; }
.train-time-cols { display: flex; align-items: center; gap: 24px; }
.time-col { width: 120px; max-width: 50%; }
.time-col.hidden { visibility: hidden; }
.time-label { font-size: 11px; color: var(--m3-on-surface-variant); }
.time-row { display: flex; align-items: center; gap: 4px; margin-top: 1px; }
.time-value { font-size: 16px; font-weight: 600; color: var(--text); }
.planned-strike { font-size: 13px; color: var(--m3-on-surface-variant); text-decoration: line-through; }
.actual-time { font-size: 16px; font-weight: 700; }
.train-status-line { display: flex; align-items: center; gap: 4px; margin-top: 4px; font-size: 11px; color: var(--m3-on-surface-variant); min-width: 0; }
.train-status-line span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.train-status-line.confirmed { color: #2E7D32; }
.train-status-line .icon { color: #2E7D32; }

/* Doładowanie listy */
.load-more-btn { width: 90%; margin: 4px auto; display: flex; align-items: center; justify-content: center; gap: 8px; background: none; border: 1px solid var(--border); color: var(--primary); border-radius: 20px; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer; }
.load-more-btn:disabled { opacity: 0.6; }
.load-more-btn .icon { color: var(--primary); }

/* Puste stany */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 40px 20px; }
.empty-icon { color: var(--m3-error); margin-bottom: 12px; }
.empty-title { font-size: 16px; font-weight: 700; color: var(--text); }
.empty-desc { margin-top: 4px; font-size: 14px; color: var(--m3-on-surface-variant); line-height: 1.4; }
.empty-retry { display: inline-flex; align-items: center; gap: 8px; margin-top: 16px; }
.plk-footer { text-align: center; font-size: 9px; color: rgba(202, 196, 208, 0.65); padding: 4px 0 8px; line-height: 1.4; }

/* ============================= Dialog trasy pociągu ============================= */

.route-overlay { z-index: 55; }
.route-modal { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; width: 95%; height: 88vh; max-height: 88dvh; display: flex; flex-direction: column; padding: 16px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5); }
.route-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.route-head-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.route-icon { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 8px; background: var(--m3-primary-container); color: var(--m3-on-primary-container); display: flex; align-items: center; justify-content: center; }
.route-icon.bus { background: #D32F2F; color: #ffffff; }
.route-head-text { min-width: 0; }
.route-number { font-size: 16px; font-weight: 700; }
.route-relation { font-size: 12px; color: var(--primary); font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.route-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 10px; font-size: 11px; color: var(--m3-on-surface-variant); }
.route-meta span:last-child { font-weight: 600; color: var(--primary); }
.route-status { margin-top: 4px; font-size: 12px; font-weight: 500; color: var(--m3-on-surface-variant); }
.route-vehicle { margin-top: 2px; font-size: 12px; font-weight: 600; color: var(--primary); }
.route-stuck { display: inline-flex; align-items: center; gap: 4px; margin-top: 4px; background: #D32F2F; color: #ffffff; border-radius: 6px; padding: 4px 8px; font-size: 12px; font-weight: 700; }
.route-disruptions { margin-top: 8px; background: rgba(147, 0, 10, 0.4); border-radius: 8px; padding: 10px; }
.route-disruptions-title { display: flex; align-items: center; gap: 6px; color: #FFDAD6; font-size: 12px; font-weight: 700; }
.route-disruption { margin-top: 4px; font-size: 12px; color: #FFDAD6; }
.route-divider { height: 1px; background: rgba(73, 69, 79, 0.5); margin: 8px 0; }
.route-body { flex: 1; overflow-y: auto; min-height: 0; }
.route-loading { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--m3-on-surface-variant); font-size: 13px; text-align: center; padding: 16px; }
.route-timeline { display: flex; flex-direction: column; }
.timeline-item { display: flex; align-items: center; padding: 6px 8px; border-radius: 6px; }
.timeline-item.current { background: rgba(79, 55, 139, 0.25); }
.timeline-indicator { display: flex; flex-direction: column; align-items: center; width: 28px; flex: 0 0 28px; }
.timeline-line { width: 2px; height: 8px; }
.timeline-dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 12px; }
.timeline-dot.current { width: 16px; height: 16px; flex-basis: 16px; }
.timeline-station { flex: 1.4; min-width: 0; margin-left: 8px; }
.timeline-name-row { display: flex; align-items: center; gap: 4px; min-width: 0; }
.timeline-station-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline-item.current .timeline-station-name { font-weight: 700; }
.timeline-station.current .timeline-station-name { color: var(--primary); }
.timeline-station.cancelled .timeline-station-name { color: var(--m3-error); }
.timeline-warn { display: inline-flex; align-items: center; background: none; border: none; padding: 0 2px; font-size: 12px; cursor: pointer; }
.timeline-check { display: inline-flex; color: #2E7D32; }
.timeline-sub { font-size: 10px; }
.timeline-sub.confirmed { color: #2E7D32; font-weight: 500; }
.timeline-sub.cancelled { color: var(--m3-error); font-weight: 700; }
.timeline-times { flex: 1; text-align: right; display: flex; flex-direction: column; align-items: flex-end; }
.timeline-planned { font-size: 12px; color: var(--m3-on-surface); }
.timeline-planned.strike { text-decoration: line-through; color: var(--m3-on-surface-variant); }
.timeline-actual { font-size: 12px; font-weight: 700; }
.timeline-delay { font-size: 10px; font-weight: 700; }
.route-explanation { margin-top: 12px; margin-bottom: 8px; background: rgba(73, 69, 79, 0.5); border-radius: 8px; padding: 10px; }
.route-explanation summary { list-style: none; display: flex; align-items: center; gap: 6px; color: var(--primary); font-size: 12px; font-weight: 700; cursor: pointer; }
.route-explanation summary::-webkit-details-marker { display: none; }
.route-explanation-toggle { margin-left: auto; font-size: 11px; }
.route-explanation:not([open]) .route-explanation-toggle { font-size: 0; }
.route-explanation:not([open]) .route-explanation-toggle::after { content: "▼ pokaż"; font-size: 11px; }
.route-explanation-body p { margin: 6px 0 0; font-size: 12px; color: var(--m3-on-surface-variant); line-height: 1.4; }
.route-explanation-body p.italic { font-size: 11px; font-style: italic; opacity: 0.85; }
.route-footer { display: flex; align-items: center; gap: 8px; padding-top: 8px; flex-wrap: wrap; }
.route-footer-spacer { flex: 1; }
.gps-btn { background: #2E7D32; color: #ffffff; display: inline-flex; align-items: center; gap: 4px; padding: 8px 10px; }
.route-footer .btn { padding: 8px 12px; font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }

/* Komunikaty o utrudnieniach na stacji */
.station-alerts-overlay { z-index: 60; }
.station-alerts-modal { max-width: 460px; }
.station-alerts-title { display: flex; align-items: center; gap: 8px; }
.station-alerts-title .icon { color: #D32F2F; }
.station-alert-reason { color: #D32F2F; font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.station-alert-info { color: #0076C8; font-weight: 700; font-size: 14px; margin: 8px 0 6px; }
.station-alert-reason .icon, .station-alert-info .icon { vertical-align: -3px; margin-right: 4px; }
.station-alert-item { font-size: 13px; color: var(--text); margin-bottom: 4px; }
.station-alerts-modal .alert-ok { background: #0076C8; color: #ffffff; }

/* ============================= Wyszukiwarka stacji / pociągu ============================= */

.search-modal { max-width: 460px; }
.search-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.search-tab { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); border-radius: 999px; padding: 8px 10px; font-size: 13px; font-weight: 600; cursor: pointer; }
.search-tab.active { background: var(--m3-secondary-container); color: var(--m3-on-secondary-container); border-color: transparent; }
.search-input-wrap { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 0 10px; }
.search-input-wrap .icon { color: var(--text-2); }
.search-input-wrap input { flex: 1; min-width: 0; background: none; border: none; outline: none; color: var(--text); padding: 10px 0; font-size: 14px; font-family: inherit; }
.search-input-wrap input[type="date"] { color-scheme: dark; }
.search-clear { background: none; border: none; color: var(--text-2); cursor: pointer; display: inline-flex; padding: 2px; }
.station-suggestions { margin-top: 4px; display: flex; flex-direction: column; max-height: 180px; overflow-y: auto; }
.station-suggestion { display: flex; align-items: center; gap: 8px; background: none; border: none; border-bottom: 1px solid rgba(53, 45, 71, 0.6); color: var(--text); padding: 9px 4px; font-size: 13px; text-align: left; cursor: pointer; }
.station-suggestion:last-child { border-bottom: none; }
.station-suggestion .icon { color: var(--text-2); }

/* Autouzupełnianie stacji w ustawieniach (jak w aplikacji Kotlin) */
.station-autocomplete { position: relative; }
.station-autocomplete .search-input-wrap:focus-within { border-color: var(--primary); }
.station-autocomplete .search-input-wrap input { flex: 1; min-width: 0; background: none; border: none; border-radius: 0; padding: 10px 0; font-size: 14px; font-family: inherit; }
.station-autocomplete-suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 70;
  margin-top: 0;
  max-height: 200px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  overscroll-behavior: contain;
}
.station-autocomplete-suggestions[hidden] { display: none; }
.station-autocomplete-suggestions .station-suggestion { width: 100%; padding: 9px 8px; border-bottom: none; border-radius: 8px; }
.station-autocomplete-suggestions .station-suggestion:hover,
.station-autocomplete-suggestions .station-suggestion:focus-visible { background: var(--surface); }

/* Komentarze */
.comments-meta { color: var(--text-2); font-size: 12px; margin-bottom: 10px; }
.comment { display: flex; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; margin-bottom: 8px; }
.comment.alert { border-color: rgba(255, 107, 129, 0.6); background: rgba(255, 107, 129, 0.08); }
.comment.alert .comment-avatar { background: rgba(255, 107, 129, 0.16); color: var(--danger); }
.comment.info { border-color: rgba(79, 195, 247, 0.5); background: rgba(79, 195, 247, 0.10); }
.comment.info .comment-nick, .comment.info .comment-avatar { color: #4FC3F7; }
.comment.info .comment-avatar { background: rgba(79, 195, 247, 0.16); }
.comment.disruption { border-color: rgba(255, 152, 0, 0.55); background: rgba(255, 152, 0, 0.09); }
.comment.disruption .comment-nick, .comment.disruption .comment-avatar { color: var(--warning); }
.comment.disruption .comment-avatar { background: rgba(255, 152, 0, 0.16); }
.comment.system { background: rgba(73, 69, 79, 0.35); }
.comment.system .comment-avatar { color: var(--m3-on-surface-variant); }
.comment-avatar { width: 38px; height: 38px; flex: 0 0 38px; border-radius: 50%; background: var(--surface-2); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 800; }
.comment-body { flex: 1; min-width: 0; }
.comment.mine { border-color: rgba(208, 188, 255, 0.45); background: rgba(208, 188, 255, 0.06); }
.comment-meta { display: flex; justify-content: space-between; gap: 8px; }
.comment-meta-right { display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.comment-own-actions { display: inline-flex; align-items: center; gap: 2px; }
.comment-action-btn { display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: 6px; background: none; color: var(--text-2); padding: 2px; cursor: pointer; }
.comment-action-btn:hover, .comment-action-btn:focus-visible { color: var(--primary); background: rgba(208, 188, 255, 0.14); }
.comment-action-btn.danger:hover, .comment-action-btn.danger:focus-visible { color: var(--danger); background: rgba(255, 107, 129, 0.14); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.comment-nick { font-weight: 700; font-size: 13px; color: var(--primary); }
.comment-time { color: var(--text-2); font-size: 11px; }
.comment-msg { margin-top: 4px; font-size: 14px; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.comment-img { margin-top: 6px; max-width: 100%; border-radius: 10px; border: 1px solid var(--border); }
.comment-route-btn { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; padding: 6px 10px; border-radius: 8px; border: 1px solid rgba(208, 188, 255, 0.5); background: rgba(208, 188, 255, 0.14); color: var(--primary); font-family: inherit; font-size: 12px; font-weight: 700; line-height: 1.25; text-align: left; cursor: pointer; }
.comment-route-btn:hover { background: rgba(208, 188, 255, 0.22); }
.comment-route-btn.detour { border-color: rgba(255, 152, 0, 0.5); background: rgba(255, 152, 0, 0.14); color: var(--warning); }
.comment-route-btn.detour:hover { background: rgba(255, 152, 0, 0.22); }
.comment-route-btn.alert { border-color: rgba(255, 107, 129, 0.5); background: rgba(255, 107, 129, 0.14); color: var(--danger); }
.comment-route-btn.alert:hover { background: rgba(255, 107, 129, 0.22); }
.comment-route-btn .icon { flex: 0 0 auto; }
.comment-reactions { position: relative; margin-top: 6px; display: flex; align-items: center; justify-content: flex-end; gap: 4px; flex-wrap: wrap; }
.mute-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: rgba(255, 107, 129, 0.12); border: 1px solid rgba(255, 107, 129, 0.45); border-radius: 12px; padding: 8px 10px; margin-bottom: 10px; }
.mute-banner-text { display: flex; align-items: center; gap: 6px; color: var(--danger); font-size: 12px; font-weight: 600; }
.mute-banner .btn { padding: 6px 10px; font-size: 12px; }
.time-filtered-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: rgba(208, 188, 255, 0.1); border: 1px solid rgba(208, 188, 255, 0.35); border-radius: 12px; padding: 8px 10px; margin-bottom: 10px; }
.time-filtered-banner-text { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 12px; font-weight: 600; }
.time-filtered-banner-text .icon { flex: 0 0 auto; color: var(--primary); }
.time-filtered-banner .btn { padding: 6px 10px; font-size: 12px; }
/* Reakcje – jak w wersji Android: tylko użyte emotikony + menu „Dodaj reakcję”. */
.reaction-btn { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 2px 8px; font-size: 12px; color: var(--text); line-height: 1.4; }
button.reaction-btn { cursor: pointer; }
.reaction-btn.mine { border-color: var(--primary); background: rgba(208, 188, 255, 0.14); }
.reaction-emoji { font-size: 12px; line-height: 1; }
.reaction-count { font-size: 11px; font-weight: 700; }
.reaction-add-wrap { display: inline-flex; }
.reaction-add-btn { display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: 10px; background: rgba(73, 69, 79, 0.6); color: var(--text-2); padding: 4px 8px; cursor: pointer; }
.reaction-add-btn:hover, .reaction-add-btn:active { color: var(--primary); }
.reaction-menu { position: absolute; right: 0; bottom: calc(100% + 6px); left: auto; z-index: 12; display: flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 4px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45); }
.reaction-menu[hidden] { display: none; }
.reaction-menu-btn { background: none; border: none; border-radius: 8px; padding: 5px 6px; font-size: 18px; line-height: 1; cursor: pointer; }
.reaction-menu-btn:hover, .reaction-menu-btn:active { background: rgba(208, 188, 255, 0.16); }

/* Input komentarza – nieruchomy nad dolną nawigacją, zawsze widoczny. */
.comment-input-bar { position: fixed; left: 50%; bottom: var(--bottomnav-height, 60px); transform: translateX(-50%); width: min(100%, var(--app-max)); z-index: 29; background: rgba(30, 26, 38, 0.97); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border-top: 1px solid var(--border); padding: 10px 12px; display: flex; gap: 8px; align-items: flex-end; }
.comment-input-bar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }

/* iOS: klawiatura nie zmniejsza layout viewportu. Chowamy dolną nawigację
   i przypinamy pasek pisania do visual viewportu (zmienne ustawia app.js). */
.keyboard-open #bottomnav { display: none; }
.keyboard-open .comment-input-bar {
  bottom: auto;
  top: calc(var(--vv-top, 0px) + var(--vv-height, 100dvh) - var(--chat-input-height, 72px));
}
.keyboard-open #main.chat-tab { padding-bottom: calc(var(--chat-input-height, 72px) + 12px); }
.comment-input-bar textarea { flex: 1; resize: none; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; color: var(--text); padding: 10px; font-size: 14px; min-height: 44px; max-height: 120px; font-family: inherit; }

/* Pływający przycisk „nowe wiadomości” – wisi nad belką pisania, gdy
   użytkownik czyta starsze wpisy i nie chcemy przesuwać mu widoku. */
.new-comments-btn { position: fixed; left: 50%; bottom: calc(var(--bottomnav-height, 60px) + var(--chat-input-height, 72px) + 14px); transform: translateX(-50%); z-index: 31; display: inline-flex; align-items: center; gap: 6px; border: none; border-radius: 999px; padding: 9px 16px; background: var(--primary); color: #241a33; font-family: inherit; font-size: 13px; font-weight: 700; line-height: 1; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45); cursor: pointer; animation: new-comments-in 0.18s ease-out; }
.new-comments-btn[hidden] { display: none; }
.new-comments-btn .icon { width: 18px; height: 18px; }
.new-comments-btn:active { transform: translateX(-50%) scale(0.97); }
/* Podczas pisania (klawiatura) przycisk nie jest potrzebny. */
.keyboard-open .new-comments-btn { display: none; }
@keyframes new-comments-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.btn { background: var(--primary); color: #241a33; border: none; border-radius: 12px; padding: 10px 14px; font-weight: 700; font-size: 14px; cursor: pointer; }
.btn:disabled { opacity: 0.5; }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 10px; font-size: 14px; cursor: pointer; }
.send-btn { width: 44px; height: 44px; min-width: 44px; flex: 0 0 44px; padding: 0; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }

/* Przyciski */
.btn-block { width: 100%; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 16px; width: 100%; max-width: 480px; max-height: 85dvh; overflow-y: auto; }
/* Telefony / PWA: klawiatura ekranowa zasłaniała modal z polem nicku.
   Overlay przypinamy do visual viewportu (--vv-height / --vv-top ustawia app.js),
   a modal ograniczamy do jego wysokości, żeby pole i przyciski były widoczne. */
@media (max-width: 900px) {
  .modal-overlay {
    top: var(--vv-top, 0px);
    right: 0;
    bottom: auto;
    left: 0;
    height: var(--vv-height, 100dvh);
    padding-top: calc(12px + env(safe-area-inset-top));
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .modal,
  .route-modal { max-height: 100%; }
}

.modal-title { font-size: 17px; font-weight: 800; margin-bottom: 10px; }
.modal-title .icon { vertical-align: -4px; margin-right: 4px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; justify-content: flex-end; }

/* ============================= Ustawienia: szersze okno + wskaźnik przewijania =============================
   Modal ustawień ma stały nagłówek przewijanej treści i stopkę z akcjami, a po prawej
   zawsze widoczny cienki pasek, gdy treść nie mieści się w widoku (także na iOS). */
.modal.settings-modal {
  max-width: 640px;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
@media (max-width: 900px) {
  /* O 4 px szersze okno z każdej strony niż pozostałe modale na telefonie. */
  .modal-overlay.settings-overlay {
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }
}
.settings-scroll-wrap { position: relative; display: flex; flex: 1 1 auto; min-height: 0; }
.settings-scroll {
  flex: 1 1 auto;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 26px 12px 16px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.settings-scroll::-webkit-scrollbar { width: 0; height: 0; }
.settings-scroll-track {
  position: absolute;
  top: 6px;
  bottom: 6px;
  right: 6px;
  width: 4px;
  border-radius: 999px;
  background: rgba(208, 188, 255, 0.16);
  display: none;
  pointer-events: none;
}
.settings-scroll-track.visible { display: block; }
.settings-scroll-thumb {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 24px;
  border-radius: 999px;
  background: var(--primary);
  opacity: 0.75;
  will-change: transform, height;
}
.settings-footer {
  flex: 0 0 auto;
  padding: 8px 16px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  border-radius: 0 0 18px 18px;
}
.settings-footer .modal-actions { margin-top: 6px; }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; color: var(--text); padding: 9px 10px; font-size: 14px; font-family: inherit; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; }
.switch { position: relative; width: 46px; height: 28px; flex: 0 0 46px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; transition: 0.2s; }
.slider::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: var(--text-2); border-radius: 50%; transition: 0.2s; }
.switch input:checked + .slider { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); background: #241a33; }
.mute-active-box { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: rgba(255, 107, 129, 0.14); border: 1px solid rgba(255, 107, 129, 0.5); border-radius: 12px; padding: 10px; margin-top: 4px; }
.mute-active-box .btn { padding: 8px 12px; font-size: 13px; }
.mute-duration-list { display: flex; flex-direction: column; gap: 8px; }

/* Stan / komunikaty */
.state-box { text-align: center; color: var(--text-2); padding: 40px 20px; font-size: 14px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; margin: 0 auto 10px; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-text { color: var(--danger); }
.ok-text { color: var(--ok); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); background: var(--surface-2); border: 1px solid var(--border); color: var(--text); padding: 10px 16px; border-radius: 12px; font-size: 13px; z-index: 60; max-width: 90%; text-align: center; }

/* ============================= Duże ekrany / tablety / desktop ============================= */

@media (min-width: 700px) {
  :root { --app-max: 640px; --main-pad-x: 18px; --main-pad-bottom: 104px; }
  .toast { max-width: min(90%, 420px); }
  .route-modal { max-width: 720px; }
}

@media (min-width: 1000px) {
  :root { --app-max: 720px; --main-pad-x: 24px; }

  /* Komentarze – czytelna szerokość kolumny */
  #view-comments { max-width: 720px; margin: 0 auto; }

  .route-modal { width: 90%; max-width: 720px; height: 82vh; }
  .modal { max-width: 560px; }
  .search-modal,
  .station-alerts-modal { max-width: 520px; }
}

@media (min-width: 1440px) {
  :root { --app-max: 800px; }
}

/* Telefony / składane w pionie – wykorzystaj całą dostępną szerokość ekranu */
@media (max-width: 900px) {
  :root { --app-max: 100%; --main-pad-x: 8px; }
  #app { max-width: 100%; }
  #bottomnav { width: 100%; max-width: 100%; }
  .comment-input-bar { width: 100%; max-width: 100%; }
}

/* ============================= Skalowanie UI na dużych ekranach =============================
   Powiększamy całą aplikację (tekst, przyciski, karty, modale) tak jak zoom przeglądarki.
   Wysokości oparte o vh/dvh dzielimy przez zoom, żeby aplikacja i modale nadal mieściły się
   w oknie. Starsze przeglądarki bez obsługi `zoom` zachowują układ bez powiększenia. */

@supports (zoom: 1) {
  /* Skalowanie całej aplikacji tylko na dużych ekranach.
     Na telefonach CSS zoom zwężał layout względem ekranu (czarne pasy po bokach),
     dlatego tam zwiększamy rozmiary bezpośrednio w regułach poniżej. */
  @media (min-width: 1000px) {
    body { zoom: 1.28; }
    #app { min-height: calc(100dvh / 1.28); }
    .modal { max-height: calc(85dvh / 1.28); }
    .route-modal { height: calc(82vh / 1.28); max-height: calc(88dvh / 1.28); }
  }

  @media (min-width: 1440px) {
    body { zoom: 1.38; }
    #app { min-height: calc(100dvh / 1.38); }
    .modal { max-height: calc(85dvh / 1.38); }
    .route-modal { height: calc(82vh / 1.38); max-height: calc(88dvh / 1.38); }
  }
}

/* ============================= Czytelniejszy interfejs na telefonach =============================
   Bez CSS zoom (który zwężał layout), więc zwiększamy bezpośrednio typografię i kontrolki. */
@media (max-width: 900px) {
  #topbar-main { font-size: 20px; }
  #topbar-sub { font-size: 13px; }
  .icon-btn { width: 42px; height: 42px; }
  .icon-btn .icon { width: 24px; height: 24px; }
  .nav-item { font-size: 13px; padding: 11px 0 10px; }
  .nav-icon, .nav-icon .icon { width: 26px; height: 26px; }

  .section-title { font-size: 16px; }
  .station-chip { font-size: 13px; padding: 9px 10px; }
  .chip-search { flex-basis: 42px; width: 42px; height: 42px; }
  .chip { font-size: 14px; }
  .summary-count { font-size: 13px; }
  .summary-date { font-size: 12px; }
  .summary-action { font-size: 13px; }
  .date-header { font-size: 15px; padding: 9px 14px; }

  .train-number { font-size: 18px; }
  .train-relation { font-size: 14px; }
  .train-badge { font-size: 11px; }
  .train-badge.carrier { font-size: 12px; }
  .delay-badge { font-size: 12px; }
  .time-label { font-size: 12px; }
  .time-value, .actual-time { font-size: 18px; }
  .planned-strike { font-size: 14px; }
  .train-status-line { font-size: 12px; }
  .load-more-btn { font-size: 14px; }
  .empty-title { font-size: 17px; }
  .empty-desc { font-size: 15px; }
  .plk-footer { font-size: 10px; }

  .comments-meta { font-size: 13px; }
  .comment-nick { font-size: 14px; }
  .comment-time { font-size: 12px; }
  .comment-msg { font-size: 15px; }
  .comment-route-btn { font-size: 13px; }
  .reaction-btn { font-size: 13px; }
  .mute-banner-text { font-size: 13px; }
  .time-filtered-banner-text { font-size: 13px; }
  .comment-input-bar textarea { font-size: 16px; }
  .btn { font-size: 15px; }
  .modal-title { font-size: 18px; }
  .field label { font-size: 13px; }
  /* 16px zapobiega automatycznemu zoomowi Safari przy focusie na iOS. */
  .field input, .field select, .field textarea { font-size: 16px; }
  .switch-row { padding: 10px 0; }
  .toast { font-size: 14px; }

  .route-number { font-size: 17px; }
  .route-relation { font-size: 13px; }
  .route-meta { font-size: 12px; }
  .route-status, .route-vehicle { font-size: 13px; }
  .route-disruption, .route-disruptions-title { font-size: 13px; }
  .route-loading { font-size: 14px; }
  .timeline-station-name, .timeline-planned, .timeline-actual { font-size: 13px; }
  .timeline-sub, .timeline-delay { font-size: 11px; }
  .route-footer .btn { font-size: 14px; }
  .search-tab, .station-suggestion { font-size: 14px; }
  .search-input-wrap input { font-size: 16px; }
}

