/* Markellia - Portail des rapports TER
   Design aligné sur www.markellia.com
   Palette : Navy #0e1b5a, Dark Navy #020834, Crème #F5F0E8, Blanc */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body.loading, body.loading * {
    cursor: wait !important;
}

body {
    font-family: 'Avenir Next', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: #F5F0E8;
    color: #1a1a2e;
    line-height: 1.6;
}

/* ===== Page Login ===== */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0e1b5a 0%, #020834 100%);
}

.login-card {
    background: white;
    border-radius: 8px;
    padding: 3rem 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}

.login-logo {
    text-align: center;
    margin-bottom: 0.5rem;
}

.login-subtitle {
    text-align: center;
    color: #6B7280;
    font-size: 0.9rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-bottom: 2rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.4rem;
}

.form-group input {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border: 1px solid #D1D5DB;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: #0e1b5a;
    box-shadow: 0 0 0 3px rgba(14, 27, 90, 0.1);
}

.btn-primary {
    width: 100%;
    padding: 0.75rem;
    background: #0e1b5a;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 0.5rem;
}

.btn-primary:hover {
    background: #020834;
}

/* ===== Flash messages ===== */

.flash {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.flash-error {
    background: #FEF2F2;
    color: #991B1B;
    border: 1px solid #FECACA;
}

/* ===== Layout principal ===== */

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ===== Sidebar ===== */

.sidebar {
    width: 260px;
    background: white;
    border-right: 1px solid #E5E7EB;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.25s ease;
    overflow: hidden;
}

/* Toggle burger */
.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: #374151;
    margin: 0.75rem 1rem 0;
    transition: background 0.15s;
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: #F5F0E8;
}

.sidebar-logo {
    text-align: center;
    padding: 2rem 1.5rem 0.5rem;
}

.sidebar-subtitle {
    text-align: center;
    font-size: 0.75rem;
    color: #6B7280;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #E5E7EB;
}

.sidebar-nav {
    padding: 1rem;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 1rem;
    border-radius: 6px;
    color: #374151;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s;
}

.nav-item:hover {
    background: #F5F0E8;
}

.nav-item.active {
    background: #0e1b5a;
    color: white;
}
.nav-badge {
    background: #C2410C;
    color: white;
    font-size: 0.65em;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 8px;
    margin-left: auto;
}

/* Sous-menu (conversations) */
.nav-submenu {
    margin-left: 1.5rem;
    padding: 0.25rem 0.5rem 0.5rem;
    border-left: 2px solid #E5E7EB;
}

.nav-submenu .conv-new-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0.4rem 0.6rem;
    background: none;
    color: #0e1b5a;
    border: 1px dashed #D1D5DB;
    border-radius: 5px;
    font-size: 0.78rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    margin-bottom: 0.25rem;
}

.nav-submenu .conv-new-btn:hover {
    background: #F5F0E8;
    border-color: #0e1b5a;
}

.nav-submenu .conv-list {
    max-height: 200px;
    overflow-y: auto;
}

.sidebar.collapsed .nav-submenu {
    display: none;
}

.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid #E5E7EB;
}

.user-menu-wrapper {
    position: relative;
}

.user-menu-trigger {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #374151;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
}

.user-menu-trigger:hover {
    background: #F3F4F6;
}

.user-menu-chevron {
    margin-left: auto;
    transition: transform 0.2s;
}

.user-menu.open ~ .user-menu-trigger .user-menu-chevron,
.user-menu-wrapper:has(.user-menu.open) .user-menu-chevron {
    transform: rotate(180deg);
}

.user-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    padding: 4px;
    display: none;
    z-index: 50;
}

.user-menu.open {
    display: block;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.7rem;
    border-radius: 6px;
    font-size: 0.82rem;
    color: #374151;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s;
}

.user-menu-item:hover {
    background: #F3F4F6;
}

.user-menu-item.disabled {
    color: #9CA3AF;
    cursor: default;
    pointer-events: none;
}

/* ===== Sidebar collapsed ===== */

.sidebar.collapsed {
    width: 64px;
}

.sidebar-region {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #E5E7EB;
}

.sidebar-region label {
    display: block;
    font-size: 0.7rem;
    font-weight: 500;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.35rem;
}

.sidebar-region select {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid #D1D5DB;
    border-radius: 6px;
    font-size: 0.8rem;
    font-family: inherit;
    background: white;
    color: #1a1a2e;
    cursor: pointer;
    transition: border-color 0.2s;
}

.sidebar-region select:focus {
    outline: none;
    border-color: #0e1b5a;
    box-shadow: 0 0 0 3px rgba(14, 27, 90, 0.1);
}

.sidebar.collapsed .sidebar-region {
    display: none;
}

.sidebar.collapsed .sidebar-logo,
.sidebar.collapsed .sidebar-subtitle,
.sidebar.collapsed .nav-label {
    display: none;
}

.sidebar.collapsed .sidebar-toggle {
    margin: 0.75rem auto 0;
}

.sidebar.collapsed .sidebar-nav {
    padding: 0.5rem;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 0.7rem;
}

.sidebar.collapsed .sidebar-footer {
    padding: 0.5rem;
}

.sidebar.collapsed .user-menu-trigger {
    justify-content: center;
    padding: 0.5rem;
}

.sidebar.collapsed .user-menu-chevron {
    display: none;
}

.sidebar.collapsed .user-menu {
    left: calc(100% + 6px);
    bottom: 0;
    right: auto;
    min-width: 160px;
}

/* ===== Contenu principal ===== */

.main-content {
    flex: 1;
    padding: 2rem 3rem;
    overflow-y: auto;
}

.content-header {
    margin-bottom: 2rem;
}

.content-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    color: #0e1b5a;
    margin-bottom: 0.3rem;
}

.header-subtitle {
    color: #6B7280;
    font-size: 0.9rem;
}

/* ===== Region selector ===== */

.content-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.schema-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.schema-selector label {
    font-size: 0.85rem;
    font-weight: 500;
    color: #6B7280;
}

.schema-selector select {
    padding: 0.45rem 0.8rem;
    border: 1px solid #D1D5DB;
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: inherit;
    background: white;
    color: #1a1a2e;
    cursor: pointer;
    transition: border-color 0.2s;
}

.schema-selector select:focus {
    outline: none;
    border-color: #0e1b5a;
    box-shadow: 0 0 0 3px rgba(14, 27, 90, 0.1);
}

/* ===== État vide ===== */

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: #9CA3AF;
}

.empty-state p {
    margin-top: 1rem;
    font-size: 0.95rem;
}

/* ===== Sources page ===== */
.sources-container { max-width: 900px; }
.source-section { margin-bottom: 2rem; }
.source-section h2 {
    font-size: 1.1em;
    color: #1B1F3B;
    border-bottom: 2px solid #E5E0D5;
    padding-bottom: 0.4rem;
    margin-bottom: 1rem;
}
.source-card {
    background: white;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    padding: 1rem 1.2rem;
    margin-bottom: 0.8rem;
}
.source-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0.3rem;
}
.source-header h3 { margin: 0; font-size: 0.95em; color: #1B1F3B; }
.source-card > p { color: #6B7280; font-size: 0.88em; margin: 0 0 0.6rem; }
.source-badge {
    font-size: 0.7em;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.badge-gtfs { background: #DBEAFE; color: #1E40AF; }
.badge-rt { background: #D1FAE5; color: #065F46; }
.badge-ref { background: #F0EDE5; color: #78716C; }
.badge-ia { background: #EDE9FE; color: #6D28D9; }
.badge-conv { background: #FEF3C7; color: #92400E; }
.source-meta {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 2px 12px;
    font-size: 0.85em;
    margin: 0;
}
.source-meta dt { color: #6B7280; font-weight: 500; }
.source-meta dd { margin: 0; color: #1a1a2e; }
.source-meta a { color: #2563EB; text-decoration: none; }
.source-meta a:hover { text-decoration: underline; }

/* ===== Search bar ===== */
.report-search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #D1CCC0;
    border-radius: 8px;
    margin-bottom: 16px;
}
.report-search-bar input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 14px;
    background: transparent;
}

/* ===== Arborescence ===== */

.tree-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

details summary {
    cursor: pointer;
    list-style: none;
    user-select: none;
}

details summary::-webkit-details-marker {
    display: none;
}

details summary::before {
    content: '▶';
    display: inline-block;
    font-size: 0.65rem;
    margin-right: 0.5rem;
    transition: transform 0.15s;
    color: #9CA3AF;
}

details[open] > summary::before {
    transform: rotate(90deg);
}

/* Region */

.tree-region {
    background: white;
    border-radius: 8px;
    border: 1px solid #E5E7EB;
    overflow: hidden;
}

.tree-region-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    font-weight: 600;
    font-size: 1rem;
    color: #0e1b5a;
    background: white;
}

.tree-region-title:hover {
    background: #FAFAFA;
}

/* Année */

.tree-year {
    margin-left: 1.25rem;
    border-top: 1px solid #F3F4F6;
}

.tree-year-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: #374151;
}

.tree-year-title:hover {
    background: #FAFAFA;
}

/* Mois */

.tree-month {
    margin-left: 1.25rem;
    border-top: 1px solid #F3F4F6;
}

.tree-month-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    font-size: 0.88rem;
    color: #4B5563;
}

.tree-month-title:hover {
    background: #FAFAFA;
}

.file-count {
    margin-left: auto;
    font-size: 0.75rem;
    color: #9CA3AF;
    font-weight: 400;
}

/* Fichiers */

.file-list {
    list-style: none;
    margin-left: 1.5rem;
    padding-bottom: 0.5rem;
}

.file-item {
    border-top: 1px solid #F3F4F6;
}

.file-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1rem;
    text-decoration: none;
    color: #1a1a2e;
    transition: background 0.15s;
    border-radius: 4px;
}

.file-link:hover {
    background: #F5F0E8;
}

.file-name {
    font-size: 0.85rem;
    font-weight: 500;
}

.file-meta {
    margin-left: auto;
    font-size: 0.75rem;
    color: #9CA3AF;
    white-space: nowrap;
}

/* ===== Responsive ===== */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 100;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
        transform: translateX(-100%);
        transition: transform 0.25s ease, width 0.25s ease;
        width: 260px;
    }
    .sidebar.mobile-open {
        transform: translateX(0);
        width: 260px;
    }
    .sidebar.collapsed {
        width: 64px;
    }
    .sidebar.collapsed.mobile-open {
        transform: translateX(0);
        width: 260px;
    }
    /* Show labels even if sidebar was collapsed on desktop */
    .sidebar.mobile-open .nav-label,
    .sidebar.mobile-open .sidebar-logo,
    .sidebar.mobile-open .sidebar-subtitle,
    .sidebar.mobile-open .sidebar-region {
        display: block !important;
        opacity: 1 !important;
        width: auto !important;
        height: auto !important;
        overflow: visible !important;
    }
    .main-content {
        padding: 1.5rem;
        padding-top: 3.5rem;
    }
}

/* Floating burger for mobile (hidden on desktop, shown via media query above) */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 101;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    background: white;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    cursor: pointer;
    color: #374151;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* Override: show burger on mobile */
@media (max-width: 768px) {
    .mobile-toggle {
        display: flex;
    }
}

/* Overlay behind sidebar on mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}

/* ===== Print styles ===== */
@media print {
    .sidebar, .mobile-toggle, .sidebar-overlay,
    .pilotage-filters, .report-search-bar,
    .export-btn, .filter-row, .nav-submenu,
    .chat-input-area, .user-menu-wrapper { display: none !important; }
    .main-content { margin-left: 0 !important; padding: 0 !important; }
    .app-layout { display: block; }
    .kpi-card { break-inside: avoid; border: 1px solid #ccc !important; }
    .kpi-detail { display: block !important; }
    .chart-wrapper canvas { max-height: 200px; }
    .content-header h1 { font-size: 1.2em; }
    body { font-size: 11pt; }
    a { text-decoration: none; color: inherit; }
}
