/* ==========================================================================
   Traincker — design system centralisé
   Toute la palette et les rayons se pilotent depuis :root ci-dessous.
   ========================================================================== */

:root {
    /* --- Source de vérité : ce sont CES variables que l'accessibilité et
       le thème clair surchargent dynamiquement (voir traincker/theme.py,
       réutilisé tel quel côté FastAPI) --- */
    --tk-bg-1: #0a0d12;
    --tk-bg-2: #161b23;
    --tk-glass: rgba(255, 255, 255, 0.05);
    --tk-glass-border: rgba(255, 255, 255, 0.10);
    --tk-text: #e7ebf1;
    --tk-text-muted: #8a94a6;
    --tk-accent: #5b8def;
    --tk-positive: #34d1a0;
    --tk-danger: #ef5b5b;

    /* --- Design tokens génériques, alias des tk-* ci-dessus. Un seul
       endroit à modifier (les tk-* plus haut) pour piloter toute
       l'application, y compris quand l'accessibilité les surcharge. --- */
    --bg: var(--tk-bg-1);
    --bg-2: var(--tk-bg-2);
    --surface: var(--tk-glass);
    --surface-hover: rgba(255, 255, 255, 0.08);
    --border: var(--tk-glass-border);
    --text: var(--tk-text);
    --text-muted: var(--tk-text-muted);
    --accent: var(--tk-accent);
    --accent-soft: rgba(91, 141, 239, 0.14);
    --positive: var(--tk-positive);
    --danger: var(--tk-danger);
    --radius: 20px;
    --radius-sm: 12px;
    --radius-pill: 999px;
}

* { box-sizing: border-box; }

html, body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text);
    background: linear-gradient(160deg, var(--bg) 0%, var(--bg-2) 100%);
    min-height: 100vh;
}

/* Blobs flottants en fond, très discrets */
.tk-blob { position: fixed; border-radius: 50%; filter: blur(100px); opacity: 0.30; z-index: 0; pointer-events: none; mix-blend-mode: screen; }
.tk-blob-1 { width: 460px; height: 460px; background: #3b6fe0; top: -140px; left: -110px; animation: tk-float-1 22s ease-in-out infinite; }
.tk-blob-2 { width: 420px; height: 420px; background: #1fa679; bottom: -160px; right: -90px; animation: tk-float-2 26s ease-in-out infinite; }
@keyframes tk-float-1 { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(40px, 30px); } }
@keyframes tk-float-2 { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-30px, -40px); } }
@media (prefers-reduced-motion: reduce) { .tk-blob-1, .tk-blob-2 { animation: none; } }

h1, h2, h3 { font-weight: 700; letter-spacing: -0.02em; color: var(--text); margin: 0 0 0.6rem; }

.tk-page { position: relative; z-index: 1; max-width: 1180px; width: 100%; margin: 0 auto; padding: 0 2rem 3rem; text-align: center; }

.tk-logo-wrap { text-align: center; margin: 2.2rem 0 0.3rem; }
.tk-caption { text-align: center; color: var(--text-muted); margin: 0 0 1.6rem; font-size: 0.95rem; }

/* --- KPI chips (bandeau supérieur, même style que le dashboard) --- */
.chip-row, .tk-chip-row { display: flex; gap: 12px; margin: 0 auto 1.6rem; max-width: 760px; }
.chip, .tk-chip {
    flex: 1; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 0.8rem 1rem; text-align: center;
    transition: transform 0.2s ease, background 0.2s ease;
}
.chip:hover, .tk-chip:hover { transform: translateY(-1px); background: var(--surface-hover); }
.chip-label, .tk-chip-label {
    display: block; font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase;
    letter-spacing: 0.06em; margin-bottom: 4px; font-weight: 600;
}
.chip-value, .tk-chip-value { display: block; font-size: 1.3rem; font-weight: 700; color: var(--text); }

/* --- Navigation : pastilles centrées, discrètes et arrondies --- */
.nav {
    position: relative; z-index: 1; display: flex; justify-content: center; gap: 6px;
    margin: 0 auto 2rem; padding: 6px; max-width: fit-content;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-pill);
}
.nav-link {
    color: var(--text-muted); text-decoration: none; font-weight: 600; font-size: 0.9rem;
    padding: 0.55rem 1.15rem; border-radius: var(--radius-pill);
    transition: color 0.15s ease, background 0.15s ease;
    white-space: nowrap;
}
.nav-link:hover { color: var(--text); background: var(--surface-hover); }
.nav-link.active { color: var(--text); background: var(--accent-soft); }

.container { position: relative; z-index: 1; max-width: 760px; margin: 0 auto; text-align: left; animation: tk-fade-in 0.4s ease; }
@keyframes tk-fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* --- Cartes --- */
.card, .tk-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35); padding: 1.5rem 1.7rem; margin-bottom: 1.2rem;
}
.card-header, .tk-section-title { display: flex; align-items: center; gap: 8px; font-size: 1.1rem; font-weight: 700; margin: 0.1rem 0 0.7rem; color: var(--text); }
.card-title { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.card-description, .tk-hint { font-size: 0.88rem; color: var(--text-muted); margin: -0.3rem 0 1rem; line-height: 1.5; }

/* --- Champs --- */
.input, input[type="text"] {
    width: 100%; padding: 0.7rem 1rem; border-radius: var(--radius-sm);
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text); font-size: 0.95rem; font-family: inherit;
}
.input:focus, input[type="text"]:focus { outline: none; border-color: var(--accent); }
.input::placeholder, input[type="text"]::placeholder { color: var(--text-muted); }
label.tk-field-label { display: block; font-weight: 600; font-size: 0.9rem; margin: 0.9rem 0 0.4rem; color: var(--text); }

.select, select {
    width: 100%; padding: 0.65rem 1rem; border-radius: var(--radius-sm);
    background: var(--surface); border: 1px solid var(--border);
    color: var(--text); font-size: 0.95rem; font-family: inherit; margin-bottom: 0.4rem;
}
.select:focus, select:focus { outline: none; border-color: var(--accent); }

.tk-checkbox-row {
    display: flex; align-items: center; gap: 8px; font-size: 0.92rem; font-weight: 500;
    margin: 0.6rem 0; cursor: pointer; color: var(--text);
}
.tk-checkbox-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.htmx-indicator { display: none; color: var(--text-muted); font-size: 0.85rem; }
.htmx-request .htmx-indicator { display: inline; }

/* --- Boutons --- */
.btn, .tk-btn {
    border-radius: var(--radius-pill); border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font-weight: 600; font-size: 0.9rem;
    font-family: inherit; padding: 0.55rem 1.2rem; cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
    text-decoration: none; display: inline-block;
}
.btn:hover, .tk-btn:hover { background: var(--surface-hover); border-color: var(--accent); transform: translateY(-1px); }
.btn-primary, .tk-btn-primary { background: var(--accent); color: #ffffff; border: none; }
.btn-primary:hover, .tk-btn-primary:hover { opacity: 0.92; background: var(--accent); }
.btn-secondary, .tk-btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.tk-btn-compact { padding: 0.4rem 0.85rem; font-size: 0.85rem; }
.tk-btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 0.6rem; }

/* --- Suggestions de gares --- */
.liste-suggestions {
    list-style: none; padding: 4px 0; margin: -4px 0 12px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); overflow: hidden;
}
.liste-suggestions li button {
    width: 100%; text-align: left; padding: 0.55rem 0.9rem; font-weight: 500;
    background: transparent; color: var(--text); border: none; cursor: pointer; font-family: inherit; font-size: 0.95rem;
}
.liste-suggestions li button:hover { background: var(--accent-soft); color: var(--accent); }
.suggestion-vide, .empty-state, .tk-empty { padding: 0.55rem 0.2rem; color: var(--text-muted); }

/* --- Liste des favoris --- */
.tk-favori { padding: 0.9rem 0; }
.tk-favori + .tk-favori { border-top: 1px solid var(--border); }
.tk-favori-ligne { display: flex; align-items: flex-start; gap: 10px; }
.tk-favori-nom { font-weight: 600; color: var(--text); }
.tk-favori-trajet { color: var(--text-muted); font-size: 0.9rem; }
.tk-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-top: 7px; flex-shrink: 0; }
.tk-dot-ok { background: var(--positive); }
.tk-dot-alert { background: var(--danger); }
.tk-favori-actions { margin-left: auto; display: flex; gap: 6px; flex-shrink: 0; }
.tk-next-train { display: flex; align-items: baseline; gap: 10px; margin: 0.3rem 0 0.2rem; }
.tk-next-train-time { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.02em; }
.tk-next-train-countdown { font-size: 0.85rem; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 2px 10px; border-radius: var(--radius-pill); }
.tk-confirm-text { font-size: 0.9rem; color: var(--danger); font-weight: 600; margin: 0.5rem 0 0.3rem; }

.tk-selection { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.3rem; }
.tk-selection strong { color: var(--text); }

.tk-success { color: var(--positive); font-weight: 600; font-size: 0.9rem; margin-top: 0.6rem; }

/* --- Tableaux --- */
.table-departs, .tk-table {
    width: 100%; border-collapse: collapse; margin: 0.6rem 0 1rem; font-size: 0.9rem;
}
.table-departs th, .table-departs td, .tk-table th, .tk-table td {
    padding: 0.55rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border);
}
.tk-table th { color: var(--text-muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
.table-departs tr.perturbe { color: var(--danger); }

/* --- Alertes / bandeaux d'information (fond bleu sombre, comme "Aucune activité...") --- */
.alert, .empty-state-info {
    background: var(--accent-soft); border: 1px solid rgba(91, 141, 239, 0.3);
    border-radius: var(--radius-sm); padding: 0.85rem 1.1rem; color: var(--text); font-weight: 600; font-size: 0.92rem;
}
.alerte-perturbation {
    background: linear-gradient(90deg, rgba(239,91,91,0.18), rgba(239,91,91,0.06));
    border: 1px solid rgba(239,91,91,0.35); border-radius: var(--radius-sm); padding: 0.7rem 1rem; margin-bottom: 0.75rem; font-weight: 600;
}
.erreur {
    background: linear-gradient(90deg, rgba(239,91,91,0.18), rgba(239,91,91,0.06));
    border: 1px solid rgba(239,91,91,0.35); border-radius: var(--radius-sm); padding: 0.75rem 1rem; color: var(--danger); margin-top: 1rem;
}

.tk-insight {
    background: var(--accent-soft); border: 1px solid rgba(91, 141, 239, 0.25); border-radius: var(--radius-sm);
    padding: 0.8rem 1.1rem; margin-bottom: 1rem; font-size: 0.95rem; line-height: 1.6; color: var(--text);
}
.tk-legend { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.5rem; }

.tk-chart { width: 100%; height: auto; border-radius: var(--radius-sm); margin: 0.6rem 0 1.4rem; display: block; }

/* --- Footer global --- */
.tk-footer {
    display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 10px;
    text-align: center; color: var(--text-muted); font-size: 0.85rem; font-weight: 500;
    letter-spacing: 0.01em; margin-top: 3rem; padding: 1.5rem 0 1rem; border-top: 1px solid var(--border);
}
.tk-footer-sep { color: var(--border); }
.tk-footer-link { color: var(--text-muted); font-weight: 600; }

/* --- Page En savoir plus --- */
.tk-tech-text { line-height: 1.7; font-size: 0.95rem; color: var(--text); }
.tk-tech-text ul { padding-left: 1.2rem; margin: 0.4rem 0; }
.tk-tech-text code {
    background: rgba(52, 209, 160, 0.12); color: var(--positive); padding: 1px 6px; border-radius: 6px;
    font-family: 'Courier New', monospace; font-size: 0.85rem; font-weight: 700;
}
.tk-changelog-entry { padding: 0.6rem 0; }
.tk-changelog-entry + .tk-changelog-entry { border-top: 1px solid var(--border); }
.tk-changelog-titre { font-weight: 600; color: var(--text); }
.tk-changelog-desc { color: var(--text-muted); font-size: 0.88rem; margin-top: 2px; }

.tk-logs {
    background: rgba(0,0,0,0.35); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 0.8rem 1rem; font-family: 'Courier New', monospace; font-size: 0.78rem; line-height: 1.5;
    max-height: 320px; overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}

.badge {
    display: inline-block; padding: 2px 10px; border-radius: var(--radius-pill);
    font-size: 0.75rem; font-weight: 700; background: var(--accent-soft); color: var(--accent);
}

/* --- Responsive --- */
@media (max-width: 640px) {
    .tk-page { padding: 0 1rem 3rem; }
    .chip-row, .tk-chip-row { flex-direction: column; }
    .nav { max-width: 100%; overflow-x: auto; justify-content: flex-start; }
    .card, .tk-card { padding: 1.2rem 1.1rem; }
    .tk-favori-ligne { flex-wrap: wrap; }
    .tk-favori-actions { margin-left: 0; width: 100%; }
    .tk-favori-actions .tk-btn { flex: 1; }
    .config-actions { flex-direction: column; align-items: stretch; }
    .config-actions .tk-btn, .file-upload-form { width: 100%; }
    .file-upload-form { flex-direction: column; align-items: stretch; }
    .tk-btn-row { flex-direction: column; }
    .tk-btn-row .tk-btn { width: 100%; text-align: center; }
    .timeline-content { min-width: 0; }
    .timeline-titre, .timeline-desc { word-break: break-word; }
}

/* Les tableaux (stats) débordent facilement sur petit écran : on scroll
   horizontalement DANS le tableau plutôt que de laisser la page entière
   déborder. */
.tk-table-scroll { overflow-x: auto; margin: 0 0 0.4rem; -webkit-overflow-scrolling: touch; }
.tk-table-scroll .tk-table { min-width: 480px; margin: 0.6rem 0 0; }

/* --- Recherche instantanée : les suggestions prennent une vraie place
   dans la page (poussent le contenu suivant vers le bas) plutôt que de
   flotter par-dessus, pour ne jamais rien recouvrir. --- */
.search-wrap { position: relative; }
.search-spinner {
    position: absolute; top: 50%; right: 14px; transform: translateY(-50%);
    color: var(--accent); font-weight: 700; letter-spacing: 1px;
}
.suggestions-dropdown {
    margin-top: 6px;
}
.suggestions-dropdown .liste-suggestions {
    margin: 0; max-height: 260px; overflow-y: auto;
    animation: tk-fade-in 0.15s ease;
}

/* --- Historique des évolutions : timeline verticale (flexbox, robuste) --- */
.timeline { display: flex; flex-direction: column; }
.timeline-entry { display: flex; gap: 14px; }
.timeline-rail { display: flex; flex-direction: column; align-items: center; width: 12px; flex-shrink: 0; }
.timeline-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--accent); flex-shrink: 0; margin-top: 4px; box-shadow: 0 0 0 4px var(--accent-soft); }
.timeline-line { flex: 1; width: 2px; background: var(--border); margin-top: 4px; min-height: 24px; }
.timeline-content { flex: 1; padding-bottom: 1.4rem; }
.timeline-entry:last-child .timeline-content { padding-bottom: 0; }
.timeline-marker { margin-bottom: 3px; }
.timeline-titre { font-weight: 700; color: var(--text); font-size: 0.98rem; }
.timeline-desc { color: var(--text-muted); font-size: 0.88rem; margin-top: 2px; line-height: 1.5; }

/* --- Sauvegarde de configuration : vrais boutons --- */
.config-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 0.4rem; }
.tk-btn-lg { padding: 0.7rem 1.4rem; font-size: 0.92rem; display: inline-flex; align-items: center; gap: 8px; }
.file-upload-form { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.file-upload-form input[type="file"] {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.file-upload-btn { cursor: pointer; }
.tk-btn:disabled, .btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

/* --- Feedback instantané sur tous les boutons pendant une requête HTMX --- */
.tk-btn.htmx-request, .btn.htmx-request { opacity: 0.55; pointer-events: none; }
form.htmx-request .tk-btn[type="submit"], form.htmx-request .btn[type="submit"] { opacity: 0.55; pointer-events: none; }
