/* ═══════════════════════════════════════════════════════════════════════
   üstra Live – Design System
   Inspiration: Deutsche Bahn App × Apple Maps × üstra-Markenfarben
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── Custom Properties ──────────────────────────────────────────────── */

:root {
    /* üstra-Markenfarben */
    --uestra-rot:       #C8002D;
    --uestra-rot-dunkel: #9e0023;

    /* Hellmodus-Farben */
    --bg-primary:       #ffffff;
    --bg-secondary:     #f2f2f7;
    --bg-tertiary:      #e5e5ea;
    --bg-elevated:      #ffffff;
    --text-primary:     #000000;
    --text-secondary:   #6c6c70;
    --text-tertiary:    #aeaeb2;
    --separator:        #c6c6c8;
    --separator-light:  #e5e5ea;
    --accent:           var(--uestra-rot);
    --accent-text:      #ffffff;

    /* Skeleton */
    --skeleton-base:    #e0e0e0;
    --skeleton-shimmer: #f5f5f5;

    /* Status-Farben */
    --gruen:            #34c759;
    --orange:           #ff9500;
    --rot:              #ff3b30;

    /* Abstände */
    --safe-top:         env(safe-area-inset-top, 0px);
    --safe-bottom:      env(safe-area-inset-bottom, 0px);
    --safe-left:        env(safe-area-inset-left, 0px);
    --safe-right:       env(safe-area-inset-right, 0px);

    /* Header */
    --header-hoehe:     56px;
    --header-gesamt:    calc(var(--header-hoehe) + var(--safe-top));

    /* Radien */
    --radius-sm:        8px;
    --radius-md:        12px;
    --radius-lg:        16px;

    /* Übergänge */
    --transition:       150ms ease;
}

[data-theme="dark"] {
    --bg-primary:       #000000;
    --bg-secondary:     #1c1c1e;
    --bg-tertiary:      #2c2c2e;
    --bg-elevated:      #1c1c1e;
    --text-primary:     #ffffff;
    --text-secondary:   #98989d;
    --text-tertiary:    #636366;
    --separator:        #38383a;
    --separator-light:  #2c2c2e;
    --skeleton-base:    #2c2c2e;
    --skeleton-shimmer: #3a3a3c;
}

/* ─── Reset & Basis ───────────────────────────────────────────────────── */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue",
                 "Segoe UI", Arial, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none; /* Verhindert Browser-Pull-to-Refresh */
    min-height: 100dvh;
}

/* ─── App-Shell ────────────────────────────────────────────────────────── */

#app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100dvh;
    position: relative;
    background: var(--bg-secondary);
}

/* ─── Header ──────────────────────────────────────────────────────────── */

#header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--uestra-rot);
    padding-top: var(--safe-top);
    box-shadow: 0 1px 0 rgba(0,0,0,.15);
}

[data-theme="dark"] #header {
    background: var(--bg-secondary);
    box-shadow: 0 1px 0 var(--separator);
}

.header-inner {
    height: var(--header-hoehe);
    display: flex;
    align-items: center;
    padding: 0 8px 0 4px;
    gap: 4px;
}

#header-title {
    flex: 1;
    font-size: 17px;
    font-weight: 600;
    color: white;
    text-align: center;
    letter-spacing: -0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

[data-theme="dark"] #header-title {
    color: var(--text-primary);
}

.header-back {
    display: flex;
    align-items: center;
    gap: 2px;
    color: white;
    background: none;
    border: none;
    font-size: 17px;
    font-family: inherit;
    padding: 8px 8px 8px 4px;
    min-width: 44px;
    min-height: 44px;
    cursor: pointer;
    flex-shrink: 0;
}

[data-theme="dark"] .header-back {
    color: var(--accent);
}

.header-back svg {
    width: 12px;
    height: 20px;
    flex-shrink: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    min-width: 44px;
    justify-content: flex-end;
}

#theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    border-radius: 50%;
    transition: background var(--transition);
}

[data-theme="dark"] #theme-toggle {
    color: var(--text-secondary);
}

#theme-toggle:active {
    background: rgba(255,255,255,.2);
}

/* ─── Screens ──────────────────────────────────────────────────────────── */

.screen {
    display: none;
    padding-bottom: calc(16px + var(--safe-bottom));
    min-height: calc(100dvh - var(--header-gesamt));
}

.screen.active {
    display: block;
}

/* ─── Suchfeld ─────────────────────────────────────────────────────────── */

#search-bar {
    padding: 12px 16px 8px;
    background: var(--bg-secondary);
    position: sticky;
    top: var(--header-gesamt);
    z-index: 90;
}

.search-input-wrap {
    position: relative;
}

.search-input-wrap svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
}

#search-input {
    width: 100%;
    height: 36px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 10px;
    padding: 0 12px 0 34px;
    font-size: 16px; /* Verhindert iOS-Zoom */
    font-family: inherit;
    color: var(--text-primary);
    outline: none;
    transition: background var(--transition);
    -webkit-appearance: none;
    appearance: none;
}

#search-input::placeholder {
    color: var(--text-tertiary);
}

/* ─── Pull-to-Refresh ──────────────────────────────────────────────────── */

#ptr-indicator {
    display: flex;
    justify-content: center;
    padding: 8px;
    height: 0;
    overflow: hidden;
    transition: height var(--transition);
    opacity: 0;
}

#ptr-indicator.visible {
    height: 48px;
    opacity: 1;
}

.ptr-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--separator);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: drehen 0.7s linear infinite;
}

@keyframes drehen {
    to { transform: rotate(360deg); }
}

/* ─── Abschnittstitel ─────────────────────────────────────────────────── */

.section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 16px 16px 6px;
}

/* ─── Listen ──────────────────────────────────────────────────────────── */

.stop-list,
.departure-list,
.journey-list {
    list-style: none;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    margin: 0 12px 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

[data-theme="dark"] .stop-list,
[data-theme="dark"] .departure-list,
[data-theme="dark"] .journey-list {
    box-shadow: none;
}

/* ─── Haltestelleneintrag ─────────────────────────────────────────────── */

.list-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--separator-light);
    cursor: pointer;
    transition: background var(--transition);
    min-height: 64px;
    gap: 8px;
}

.list-item:last-child {
    border-bottom: none;
}

.list-item:active {
    background: var(--bg-secondary);
}

.stop-main {
    flex: 1;
    min-width: 0;
}

.stop-info {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
}

.stop-name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stop-distance {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
}

.stop-badges {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.mode-badge {
    font-size: 11px;
    font-weight: 500;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

.mode-badge.tram   { background: rgba(200,0,45,.12); color: var(--uestra-rot); }
.mode-badge.sbahn  { background: rgba(0,115,52,.12);  color: #007334; }
.mode-badge.bus    { background: rgba(99,99,102,.12); color: var(--text-secondary); }
.mode-badge.fern   { background: rgba(238,28,35,.12); color: #EE1C23; }

[data-theme="dark"] .mode-badge.tram  { background: rgba(200,0,45,.25); }
[data-theme="dark"] .mode-badge.sbahn { background: rgba(0,115,52,.25); }
[data-theme="dark"] .mode-badge.bus   { background: rgba(99,99,102,.25); }

/* Favoriten-Button */
.fav-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: color var(--transition), transform 120ms ease;
    flex-shrink: 0;
    border-radius: 50%;
}

.fav-btn:active {
    transform: scale(0.88);
}

.fav-btn.active {
    color: #ff9500;
}

/* ─── Abfahrtseintrag ─────────────────────────────────────────────────── */

.departure-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--separator-light);
    cursor: pointer;
    transition: background var(--transition);
    min-height: 68px;
    gap: 12px;
}

.departure-item:last-child {
    border-bottom: none;
}

.departure-item:active {
    background: var(--bg-secondary);
}

.dep-line-col {
    flex-shrink: 0;
    width: 52px;
    display: flex;
    justify-content: center;
}

.line-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 30px;
    padding: 0 6px;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.3px;
    white-space: nowrap;
}

.dep-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.dep-direction {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dep-platform {
    font-size: 12px;
    color: var(--text-secondary);
}

.dep-time-col {
    flex-shrink: 0;
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
}

.dep-time {
    font-size: 18px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.dep-time.on-time    { color: var(--gruen); }
.dep-time.slight-late{ color: var(--orange); }
.dep-time.late       { color: var(--rot); }

.dep-planned {
    font-size: 12px;
    color: var(--text-tertiary);
    text-decoration: line-through;
    font-variant-numeric: tabular-nums;
}

.dep-delay {
    font-size: 12px;
    font-weight: 600;
}

.dep-delay.slight-late { color: var(--orange); }
.dep-delay.late        { color: var(--rot); }

/* ─── Abfahrts-Header ─────────────────────────────────────────────────── */

.stop-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 8px;
    gap: 8px;
}

.stop-title-text {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.live-badge {
    background: var(--gruen);
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    letter-spacing: 0.3px;
    flex-shrink: 0;
}

/* ─── Fahrtverlauf ────────────────────────────────────────────────────── */

.journey-list {
    margin-top: 8px;
    padding: 8px 0;
}

.journey-stop {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    transition: background var(--transition);
    gap: 16px;
    min-height: 56px;
}

.journey-stop:active {
    background: var(--bg-secondary);
}

.journey-stop.passed .journey-stop-name,
.journey-stop.passed .journey-time {
    color: var(--text-tertiary);
}

.journey-line {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    width: 20px;
    flex-shrink: 0;
    align-self: stretch;
    justify-content: center;
}

/* Vertikale Linie */
.journey-line::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    background: var(--separator);
}

.journey-stop:first-child .journey-line::before {
    top: 50%;
}

.journey-stop:last-child .journey-line::before {
    bottom: 50%;
}

.journey-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--separator);
    border: 2px solid var(--bg-primary);
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.journey-stop.current .journey-dot {
    width: 14px;
    height: 14px;
    background: var(--accent);
    box-shadow: 0 0 0 3px rgba(200,0,45,.2);
}

.journey-stop.passed .journey-dot {
    background: var(--text-tertiary);
}

.journey-info {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.journey-stop-name {
    font-size: 15px;
    font-weight: 400;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.journey-stop.current .journey-stop-name {
    font-weight: 600;
    color: var(--accent);
}

.journey-time {
    font-size: 14px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.journey-fallback {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

/* ─── Skeleton ────────────────────────────────────────────────────────── */

@keyframes schimmer {
    0%   { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--skeleton-base) 25%,
        var(--skeleton-shimmer) 50%,
        var(--skeleton-base) 75%
    );
    background-size: 800px 100%;
    animation: schimmer 1.4s ease-in-out infinite;
    border-radius: 6px;
}

.skeleton-item { pointer-events: none; }

.sk-name   { height: 16px; width: 55%; margin-bottom: 6px; }
.sk-meta   { height: 13px; width: 30%; }
.sk-badges { display: flex; gap: 4px; margin-top: 4px; }
.sk-badge  { height: 18px; width: 52px; border-radius: 4px; }
.sk-badge-lg { height: 30px; width: 44px; border-radius: 6px; }
.sk-time   { height: 22px; width: 44px; }
.sk-stop-title { height: 28px; width: 60%; margin: 16px 16px 8px; border-radius: 8px; }

/* ─── Zustandsanzeigen ────────────────────────────────────────────────── */

.error-state,
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.5;
}

.error-icon {
    font-size: 32px;
    margin-bottom: 4px;
}

/* ─── Offline-Hinweis ─────────────────────────────────────────────────── */

#offline-notice {
    position: fixed;
    top: var(--header-gesamt);
    left: 0;
    right: 0;
    max-width: 480px;
    margin: 0 auto;
    background: #ff9500;
    color: white;
    text-align: center;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    z-index: 200;
}

/* ─── Install-Banner ──────────────────────────────────────────────────── */

#install-banner {
    position: fixed;
    bottom: var(--safe-bottom);
    left: 0;
    right: 0;
    max-width: 480px;
    margin: 0 auto;
    background: var(--bg-elevated);
    border-top: 1px solid var(--separator);
    padding: 16px;
    z-index: 150;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 -2px 16px rgba(0,0,0,.1);
}

#install-banner p {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.4;
}

#install-banner button {
    padding: 8px 14px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    min-height: 36px;
}

#install-btn {
    background: var(--accent);
    color: white;
}

#install-dismiss {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* ─── Externer Link ───────────────────────────────────────────────────── */

.ext-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 15px;
}

.ext-link:hover {
    text-decoration: underline;
}

/* ─── Scroll Sentinel ─────────────────────────────────────────────────── */

.scroll-sentinel {
    height: 1px;
    width: 100%;
}

/* ─── Fokus (Barrierefreiheit) ────────────────────────────────────────── */

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ─── Übergangsanimation zwischen Screens ─────────────────────────────── */

.screen {
    animation: einblenden 200ms ease both;
}

@keyframes einblenden {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── Responsiv ───────────────────────────────────────────────────────── */

@media (min-width: 480px) {
    #app {
        box-shadow: 0 0 40px rgba(0,0,0,.12);
    }
}

/* Landscape auf kleinen Geräten */
@media (max-height: 500px) and (orientation: landscape) {
    #header { position: relative; }
    .screen {
        min-height: auto;
    }
}
