/* ============================================================================
   TODSS STYLE.CSS - VERSION 2.8 - 26-Jan-2026
   Wave animations: ONLY for crew duty > 10hrs (yellow) and > 12hrs (red)
   Loco alerts: Violet border only, NO pulsating wave
   Banking alerts: Orange pulsing border for trains needing banking loco
   Added: Train tooltip on hover, LFD mode UI optimization
   Fixed: Dynamic stock type filter, inspection status filter
   ============================================================================ */

/* Railway Train Visualization - Styles */

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

/* ============================================================================
   RBAC HEADER SECTION
   ============================================================================ */

.rbac-header-section {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
    padding: 0 16px;
}

.rbac-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(30, 41, 59, 0.6);
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.15);
}

.rbac-user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: white;
    text-transform: uppercase;
}

.rbac-user-details {
    display: flex;
    flex-direction: column;
}

.rbac-user-name {
    font-size: 12px;
    font-weight: 600;
    color: #e2e8f0;
    line-height: 1.2;
}

.rbac-user-role {
    font-size: 10px;
    color: #94a3b8;
    line-height: 1.2;
}

.rbac-nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(139, 92, 246, 0.15);
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 6px;
    color: #a78bfa;
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.rbac-nav-link:hover {
    background: rgba(139, 92, 246, 0.25);
    color: #c4b5fd;
}

.rbac-nav-link.admin-link {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.3);
    color: #60a5fa;
}

.rbac-nav-link.admin-link:hover {
    background: rgba(59, 130, 246, 0.25);
    color: #93c5fd;
}

.rbac-logout-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 6px;
    color: #f87171;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.rbac-logout-btn:hover {
    background: rgba(239, 68, 68, 0.25);
    color: #fca5a5;
}

/* ============================================================================
   TRAIN SEARCH BOX
   ============================================================================ */

.search-section {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}

.search-container {
    position: relative;
}

.search-input-wrapper {
    display: flex;
    align-items: center;
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.2s ease;
}

.search-input-wrapper:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.search-input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px 12px;
    color: #e2e8f0;
    font-size: 13px;
    outline: none;
}

.search-input::placeholder {
    color: #64748b;
}

.search-clear-btn {
    background: transparent;
    border: none;
    color: #64748b;
    padding: 10px 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: none;
}

.search-clear-btn:hover {
    color: #ef4444;
}

.search-clear-btn.visible {
    display: block;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: rgba(15, 23, 42, 0.98);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
    transition: all 0.15s ease;
}

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

.search-result-item:hover {
    background: rgba(59, 130, 246, 0.15);
}

.search-result-item.selected {
    background: rgba(59, 130, 246, 0.2);
}

.search-result-main {
    font-size: 13px;
    font-weight: 600;
    color: #e2e8f0;
    margin-bottom: 2px;
}

.search-result-sub {
    font-size: 11px;
    color: #94a3b8;
}

.search-result-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 9px;
    font-weight: 600;
    margin-left: 6px;
}

.search-result-badge.freight {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
}

.search-result-badge.coaching {
    background: rgba(236, 72, 153, 0.2);
    color: #f472b6;
}

.search-no-results {
    padding: 16px 12px;
    text-align: center;
    color: #64748b;
    font-size: 12px;
}

.search-active-filter {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    margin-top: 8px;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 6px;
}

.search-active-filter.visible {
    display: flex;
}

.search-active-filter-text {
    font-size: 12px;
    color: #60a5fa;
    font-weight: 500;
}

.search-active-filter-clear {
    background: transparent;
    border: none;
    color: #60a5fa;
    cursor: pointer;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.search-active-filter-clear:hover {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: #e2e8f0;
    min-height: 100vh;
    overflow-x: hidden;
}

.dashboard-container {
    display: grid;
    grid-template-columns: 340px 1fr;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
    transition: grid-template-columns 0.3s ease;
}

.dashboard-container.sidebar-collapsed {
    grid-template-columns: 0px 1fr;
}

/* Header */
.header {
    grid-column: 1 / -1;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1100;
    position: relative;
}

.logo-section { display: flex; align-items: center; gap: 16px; }

.logo-icon {
    width: 42px; height: 42px;
    background: linear-gradient(135deg, #0ea5e9, #22c55e);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; color: #0f172a; font-weight: bold;
}

.logo-text h1 {
    font-size: 18px; font-weight: 700;
    background: linear-gradient(135deg, #e2e8f0, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text span {
    font-size: 11px; color: #64748b;
    text-transform: uppercase; letter-spacing: 1.5px;
}

.header-stats { display: flex; gap: 20px; align-items: center; }

.stat-item {
    text-align: center; padding: 8px 16px;
    background: rgba(30, 41, 59, 0.5);
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.1);
    cursor: pointer; transition: all 0.2s;
}

.stat-item:hover { border-color: rgba(14, 165, 233, 0.5); }
.stat-item.alert { border-color: rgba(239, 68, 68, 0.5); background: rgba(239, 68, 68, 0.1); }
.stat-item.analytics-btn { 
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(14, 165, 233, 0.1));
    border-color: rgba(139, 92, 246, 0.3);
}
.stat-item.analytics-btn:hover { border-color: rgba(139, 92, 246, 0.5); }

.stat-item.reports-btn { 
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.2), rgba(14, 165, 233, 0.1));
    border-color: rgba(34, 197, 94, 0.3);
    cursor: pointer;
    color: inherit;
}
.stat-item.reports-btn:hover { border-color: rgba(34, 197, 94, 0.5); }
.stat-item.reports-btn .stat-value { color: #22c55e; }

.stat-value { font-size: 20px; font-weight: 700; color: #0ea5e9; }
.stat-value.alert-count { color: #ef4444; }
.stat-label { font-size: 10px; color: #64748b; text-transform: uppercase; letter-spacing: 1px; }

.header-time { text-align: right; }
.current-time { font-size: 24px; font-weight: 300; color: #e2e8f0; font-variant-numeric: tabular-nums; }
.current-date { font-size: 11px; color: #64748b; }

/* Sidebar */
.sidebar {
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(20px);
    border-right: 1px solid rgba(148, 163, 184, 0.1);
    padding: 16px;
    overflow-y: auto;
    max-height: calc(100vh - 70px);
    width: 340px;
    transition: transform 0.3s ease, opacity 0.3s ease, width 0.3s ease;
    position: relative;
    z-index: 100;
}

.sidebar.collapsed {
    transform: translateX(-100%);
    opacity: 0;
    width: 0;
    padding: 0;
    overflow: hidden;
}

/* Drawer Toggle Button */
.drawer-toggle {
    position: fixed;
    left: 340px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 500;
    width: 24px;
    height: 48px;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-left: none;
    border-radius: 0 8px 8px 0;
    color: #94a3b8;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
}

.drawer-toggle:hover {
    background: rgba(30, 41, 59, 0.95);
    color: #0ea5e9;
    width: 28px;
}

.drawer-toggle i {
    transition: transform 0.3s ease;
    font-size: 12px;
}

.drawer-toggle.collapsed {
    left: 0;
    border-left: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 0 8px 8px 0;
}

.drawer-toggle.collapsed i {
    transform: rotate(180deg);
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.3); border-radius: 3px; }

.sidebar-title {
    font-size: 12px; text-transform: uppercase;
    letter-spacing: 1.5px; color: #64748b;
    margin-bottom: 16px;
    display: flex; align-items: center; gap: 8px;
}

.sidebar-title i { color: #0ea5e9; }

/* Filter Section */
.filter-section { margin-bottom: 20px; }

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Section Cards */
.section-card {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: 12px; padding: 14px;
    margin-bottom: 10px; cursor: pointer;
    transition: all 0.2s;
}

.section-card:hover {
    background: rgba(30, 41, 59, 0.9);
    border-color: rgba(14, 165, 233, 0.3);
    transform: translateX(4px);
}

.section-card.active {
    background: rgba(14, 165, 233, 0.15);
    border-color: rgba(14, 165, 233, 0.5);
}

.section-header {
    display: flex; justify-content: space-between;
    align-items: center; margin-bottom: 12px;
}

.section-name { font-weight: 600; font-size: 14px; color: #e2e8f0; }

.section-total {
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    color: white; padding: 4px 10px;
    border-radius: 20px; font-size: 12px; font-weight: 700;
}

.section-lines { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.line-stat {
    text-align: center; padding: 8px;
    background: rgba(15, 23, 42, 0.5); border-radius: 8px;
}

.line-count { font-size: 18px; font-weight: 700; }
.line-count.up { color: #22c55e; }
.line-count.dn { color: #f97316; }
.line-count.third { color: #a78bfa; }

.line-label {
    font-size: 9px; color: #64748b;
    text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px;
}

/* Summary Box */
.summary-box {
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.15), rgba(34, 197, 94, 0.1));
    border: 1px solid rgba(14, 165, 233, 0.2);
    border-radius: 12px; padding: 16px; margin-bottom: 16px;
}

.summary-title {
    font-size: 10px; text-transform: uppercase;
    letter-spacing: 1px; color: #0ea5e9; margin-bottom: 12px;
}

.summary-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.summary-item { text-align: center; }
.summary-value { font-size: 24px; font-weight: 700; color: #e2e8f0; }
.summary-label { font-size: 10px; color: #94a3b8; }

/* Map */
.map-container { position: relative; height: calc(100vh - 70px); }
#map { width: 100%; height: 100%; background: #0f172a; }

/* Leaflet Customization */
.leaflet-popup-content-wrapper {
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.leaflet-popup-content { margin: 0; color: #e2e8f0; min-width: 380px; }
.leaflet-popup-tip { background: rgba(15, 23, 42, 0.98); }

/* Train Markers */
.train-marker-icon {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; color: white; cursor: pointer;
    transition: all 0.2s; position: relative;
}

.train-marker-icon::after {
    content: ''; position: absolute;
    width: 100%; height: 100%;
    border-radius: 50%; border: 2px solid currentColor;
    animation: pulse-ring 2s ease-out infinite; opacity: 0;
}

@keyframes pulse-ring {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(1.8); opacity: 0; }
}

.train-marker-icon:hover { transform: scale(1.15); }
.train-marker-icon.loaded { background: linear-gradient(135deg, #22c55e, #16a34a); }
.train-marker-icon.empty { background: linear-gradient(135deg, #f97316, #ea580c); }
.train-marker-icon.alert { 
    background: linear-gradient(135deg, #ef4444, #dc2626);
    animation: pulse-alert 1.5s infinite;
}

@keyframes pulse-alert {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
    50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}

/* Popup Styles */
.popup-header {
    padding: 16px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.15);
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.1), rgba(34, 197, 94, 0.05));
    border-radius: 14px 14px 0 0;
}

.popup-title { font-size: 16px; font-weight: 700; color: #e2e8f0; }
.popup-subtitle { font-size: 11px; color: #64748b; margin-top: 4px; }
.popup-badges { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

.popup-badge {
    font-size: 10px; padding: 3px 8px;
    border-radius: 4px; font-weight: 600;
}

.badge-up { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
.badge-dn { background: rgba(249, 115, 22, 0.2); color: #f97316; }
.badge-freight { background: rgba(14, 165, 233, 0.2); color: #0ea5e9; }
.badge-coaching { background: rgba(139, 92, 246, 0.2); color: #a78bfa; }
.badge-validated { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
.badge-pending { background: rgba(234, 179, 8, 0.2); color: #eab308; }
.badge-banking { 
    background: rgba(249, 115, 22, 0.3); 
    color: #fb923c; 
    border: 1px solid rgba(249, 115, 22, 0.5);
    animation: badgePulse 1.5s ease-in-out infinite;
}

@keyframes badgePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Banking alert section in popup */
.banking-alert-section {
    background: rgba(249, 115, 22, 0.1);
    border: 1px solid rgba(249, 115, 22, 0.3);
    border-radius: 8px;
    padding: 12px !important;
    margin: 12px 0;
}

.banking-alert-section .popup-section-title {
    color: #f97316;
}

/* Banking alert row in analytics table */
.banking-alert-row {
    background: rgba(249, 115, 22, 0.1);
}

.banking-alert-row:hover {
    background: rgba(249, 115, 22, 0.2);
}

.popup-body { padding: 16px; }
.popup-section { margin-bottom: 16px; }
.popup-section:last-child { margin-bottom: 0; }

.popup-section-title {
    font-size: 10px; text-transform: uppercase;
    letter-spacing: 1px; color: #64748b;
    margin-bottom: 10px;
    display: flex; align-items: center; gap: 6px;
}

.popup-section-title i { color: #0ea5e9; font-size: 12px; }
.popup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.popup-item { display: flex; flex-direction: column; gap: 2px; }
.popup-label { font-size: 9px; color: #64748b; text-transform: uppercase; }
.popup-value { font-size: 13px; color: #e2e8f0; font-weight: 500; }

.popup-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(148, 163, 184, 0.15);
    display: flex; gap: 8px;
}

.popup-btn {
    flex: 1; padding: 10px; border: none;
    border-radius: 8px; font-size: 12px;
    font-weight: 600; cursor: pointer; transition: all 0.2s;
}

.popup-btn-primary { background: linear-gradient(135deg, #0ea5e9, #0284c7); color: white; }
.popup-btn-secondary { background: rgba(148, 163, 184, 0.2); color: #e2e8f0; }
.popup-btn:hover { transform: translateY(-1px); }
/* Crew action chooser (Handover vs Detach) — active state */
.crew-action-btn { border: 1px solid transparent; }
.crew-action-btn.active {
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    color: #fff;
    border-color: rgba(56, 189, 248, 0.6);
    box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.3) inset;
}
#actionDetachBtn.active {
    background: linear-gradient(135deg, #f97316, #ea580c);
    border-color: rgba(249, 115, 22, 0.6);
    box-shadow: 0 0 0 1px rgba(249, 115, 22, 0.3) inset;
}

/* Modal */
.modal-backdrop {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; visibility: hidden; transition: all 0.3s;
}

.modal-backdrop.active { opacity: 1; visibility: visible; }

.modal-card {
    background: linear-gradient(145deg, rgba(15, 23, 42, 0.98), rgba(30, 41, 59, 0.98));
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 20px;
    width: 90%; max-width: 800px; max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5);
    transform: scale(0.9); transition: transform 0.3s;
}

.modal-backdrop.active .modal-card { transform: scale(1); }

.modal-header {
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.2), rgba(34, 197, 94, 0.1));
    padding: 24px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
    position: relative;
}

.modal-title { font-size: 22px; font-weight: 700; color: #e2e8f0; }
.modal-subtitle { font-size: 13px; color: #94a3b8; margin-top: 4px; }

.close-modal-btn {
    position: absolute; top: 16px; right: 16px;
    width: 36px; height: 36px;
    background: rgba(148, 163, 184, 0.1);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 10px; color: #94a3b8;
    font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}

.close-modal-btn:hover { background: rgba(239, 68, 68, 0.2); color: #ef4444; }

.modal-body {
    padding: 24px; overflow-y: auto;
    max-height: calc(90vh - 150px);
}

.modal-body::-webkit-scrollbar { width: 6px; }
.modal-body::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.3); border-radius: 3px; }

/* Forms */
.form-section {
    margin-bottom: 24px; padding-bottom: 24px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}

.form-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.form-title {
    font-size: 12px; text-transform: uppercase;
    letter-spacing: 1.5px; color: #64748b;
    margin-bottom: 16px;
    display: flex; align-items: center; gap: 8px;
}

.form-title i { color: #0ea5e9; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full-width { grid-column: 1 / -1; }

.form-label {
    font-size: 11px; color: #94a3b8;
    text-transform: uppercase; letter-spacing: 0.5px;
}

.form-input, .form-select {
    padding: 12px 14px;
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 8px; color: #e2e8f0;
    font-size: 14px; transition: all 0.2s;
}

.form-input:focus, .form-select:focus {
    outline: none; border-color: #0ea5e9;
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.form-select option { background: #1e293b; }

/* Operational filter toggle buttons */
.ops-filter-btn {
    display: flex; align-items: center; gap: 8px; width: 100%;
    padding: 7px 10px; border-radius: 6px; font-size: 11px; font-weight: 600;
    color: #94a3b8; background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(148, 163, 184, 0.12); cursor: pointer;
    transition: all 0.15s; font-family: inherit;
}
.ops-filter-btn:hover { background: rgba(30, 41, 59, 0.8); color: #e2e8f0; }
.ops-filter-btn.active { background: rgba(14, 165, 233, 0.15); border-color: #0ea5e9; color: #0ea5e9; }
.ops-count {
    margin-left: auto; font-size: 10px; font-weight: 700;
    background: rgba(148, 163, 184, 0.15); padding: 1px 7px; border-radius: 10px;
}
.ops-filter-btn.active .ops-count { background: rgba(14, 165, 233, 0.25); }

/* Loco Entry */
.loco-entry {
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(148, 163, 184, 0.15);
    border-radius: 12px; padding: 16px; margin-bottom: 12px;
}

.loco-header {
    display: flex; justify-content: space-between;
    align-items: center; margin-bottom: 12px;
}

.loco-position {
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    color: white; padding: 4px 12px;
    border-radius: 20px; font-size: 11px; font-weight: 600;
}

.distress-indicator { display: flex; align-items: center; gap: 8px; }

.distress-toggle {
    width: 44px; height: 24px;
    background: rgba(148, 163, 184, 0.3);
    border-radius: 12px; position: relative;
    cursor: pointer; transition: all 0.3s;
}

.distress-toggle.active { background: #ef4444; }

.distress-toggle::after {
    content: ''; position: absolute;
    width: 18px; height: 18px;
    background: white; border-radius: 50%;
    top: 3px; left: 3px; transition: all 0.3s;
}

.distress-toggle.active::after { left: 23px; }

.severity-select { display: flex; gap: 4px; }

.severity-btn {
    width: 28px; height: 28px; border: none;
    border-radius: 6px;
    background: rgba(148, 163, 184, 0.2);
    color: #94a3b8; font-size: 11px; font-weight: 600;
    cursor: pointer; transition: all 0.2s;
}

.severity-btn.active { background: #ef4444; color: white; }
.severity-btn:hover { background: rgba(239, 68, 68, 0.3); }

.submit-btn {
    width: 100%; padding: 14px;
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    border: none; border-radius: 10px;
    color: white; font-size: 14px; font-weight: 600;
    cursor: pointer; transition: all 0.2s; margin-top: 16px;
}

.submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(14, 165, 233, 0.4);
}

/* Decision Badges */
.decision-badge {
    padding: 4px 10px; border-radius: 6px;
    font-size: 10px; font-weight: 700; text-transform: uppercase;
}

.decision-good { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
.decision-caution { background: rgba(234, 179, 8, 0.2); color: #eab308; }
.decision-alert { background: rgba(239, 68, 68, 0.2); color: #ef4444; }

/* Crew Status */
.duty-hours { font-weight: 600; }
.duty-hours.warning { color: #eab308; }
.duty-hours.critical { color: #ef4444; }

/* Loading */
.loading { display: flex; align-items: center; justify-content: center; padding: 40px; }

.spinner {
    width: 40px; height: 40px;
    border: 3px solid rgba(14, 165, 233, 0.2);
    border-top-color: #0ea5e9;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Map Legend */
.map-legend {
    position: absolute;
    bottom: 24px;
    right: 24px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 12px;
    padding: 16px;
    z-index: 400;
    min-width: 160px;
}

.legend-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #64748b;
    margin-bottom: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 11px;
    color: #94a3b8;
}

.legend-marker {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid white;
}

/* New train type legend markers */
.legend-freight { 
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%); 
}
.legend-coaching { 
    background: linear-gradient(135deg, #ec4899 0%, #be185d 100%); 
}

/* Alert ring indicators in legend */
.legend-ring-yellow {
    box-shadow: 0 0 0 2px #facc15, 0 0 6px #facc15;
}
.legend-ring-red {
    box-shadow: 0 0 0 2px #ef4444, 0 0 6px #ef4444;
}
.legend-ring-violet {
    box-shadow: 0 0 0 2px #8b5cf6, 0 0 6px #8b5cf6;
}

/* Legacy legend markers */
.legend-loaded { background: #22c55e; }
.legend-empty { background: #f97316; }
.legend-alert { background: #ef4444; }
.legend-station { background: #64748b; width: 10px; height: 10px; }

.legend-line { width: 24px; height: 3px; border-radius: 2px; }
.legend-track1 { background: #22c55e; }
.legend-track2 { background: #f97316; }
.legend-track3 { background: #a78bfa; }
.legend-up-line { background: #22c55e; }
.legend-dn-line { background: #f97316; }

/* Legend section title */
.legend-section-title {
    font-size: 9px;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    margin-top: 8px;
    padding-bottom: 2px;
    border-bottom: 1px solid rgba(100, 116, 139, 0.2);
}

.legend-section-title:first-of-type {
    margin-top: 0;
}

/* Analytics Modal */
.analytics-modal { max-width: 1000px; }
.analytics-header { background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(14, 165, 233, 0.1)); }

.analytics-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
    padding-bottom: 12px;
    flex-wrap: wrap;
}

.analytics-tab {
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: rgba(30, 41, 59, 0.5);
    color: #94a3b8;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.analytics-tab:hover { background: rgba(30, 41, 59, 0.8); color: #e2e8f0; }
.analytics-tab.active { 
    background: rgba(14, 165, 233, 0.2); 
    border-color: rgba(14, 165, 233, 0.3); 
    color: #0ea5e9; 
}

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.analytics-card {
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
}

.analytics-card-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #64748b;
    margin-bottom: 8px;
}

.analytics-card-value {
    font-size: 28px;
    font-weight: 700;
    color: #e2e8f0;
}

.analytics-card-value.good { color: #22c55e; }
.analytics-card-value.warning { color: #eab308; }
.analytics-card-value.bad { color: #ef4444; }

.analytics-card-subtitle {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 4px;
}

.analytics-table-container {
    max-height: 300px;
    overflow-y: auto;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.1);
}

.analytics-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.analytics-table th {
    background: rgba(30, 41, 59, 0.8);
    color: #94a3b8;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 10px;
    position: sticky;
    top: 0;
}

.analytics-table td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
    color: #e2e8f0;
}

.analytics-table tr:hover td { background: rgba(14, 165, 233, 0.05); }

/* Gradient Tooltip Styles */
.gradient-tooltip {
    background: rgba(15, 23, 42, 0.95) !important;
    border: 1px solid rgba(148, 163, 184, 0.3) !important;
    border-radius: 8px !important;
    padding: 0 !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4) !important;
    z-index: 1000 !important;
}

.gradient-tooltip-content {
    padding: 10px 12px;
    min-width: 180px;
}

.gradient-tooltip .tooltip-title {
    font-weight: 600;
    font-size: 13px;
    color: #e2e8f0;
    margin-bottom: 6px;
}

.gradient-tooltip .tooltip-divider {
    height: 1px;
    background: rgba(148, 163, 184, 0.2);
    margin: 6px 0;
}

.gradient-tooltip .tooltip-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 4px 0;
    font-size: 11px;
}

.gradient-tooltip .tooltip-label {
    color: #94a3b8;
}

.gradient-tooltip .tooltip-value {
    color: #e2e8f0;
    font-weight: 500;
}

.gradient-tooltip .tooltip-info {
    color: #64748b;
    font-size: 11px;
    font-style: italic;
}

.leaflet-tooltip.gradient-tooltip {
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(148, 163, 184, 0.3);
    color: #e2e8f0;
    z-index: 1000 !important;
}
/* Ensure tooltip arrow colors match for all directions */
.leaflet-tooltip.gradient-tooltip.leaflet-tooltip-top::before {
    border-top-color: rgba(15, 23, 42, 0.95);
}
.leaflet-tooltip.gradient-tooltip.leaflet-tooltip-bottom::before {
    border-bottom-color: rgba(15, 23, 42, 0.95);
}
.leaflet-tooltip.gradient-tooltip.leaflet-tooltip-left::before {
    border-left-color: rgba(15, 23, 42, 0.95);
}
.leaflet-tooltip.gradient-tooltip.leaflet-tooltip-right::before {
    border-right-color: rgba(15, 23, 42, 0.95);
}

/* Override Leaflet's default tooltip pane z-index */
.leaflet-tooltip-pane {
    z-index: 700 !important;
}

.leaflet-tooltip.gradient-tooltip::before {
    border-top-color: rgba(15, 23, 42, 0.95);
}

/* Responsive */
@media (max-width: 768px) {
    .dashboard-container { grid-template-columns: 1fr; }
    .dashboard-container.sidebar-collapsed { grid-template-columns: 1fr; }
    .sidebar { 
        max-height: 300px; 
        width: 100%;
        position: relative;
    }
    .sidebar.collapsed {
        transform: translateY(-100%);
        max-height: 0;
    }
    .drawer-toggle {
        left: 50%;
        top: 70px;
        transform: translateX(-50%);
        width: 48px;
        height: 24px;
        border-radius: 0 0 8px 8px;
        border-top: none;
        border-left: 1px solid rgba(148, 163, 184, 0.2);
    }
    .drawer-toggle.collapsed {
        left: 50%;
        top: 70px;
    }
    .drawer-toggle i {
        transform: rotate(-90deg);
    }
    .drawer-toggle.collapsed i {
        transform: rotate(90deg);
    }
    .modal-card { width: 95%; max-width: none; }
    .form-grid { grid-template-columns: 1fr; }
}

/* ============================================================================
   TRAIN MARKER STYLES - Updated Color Scheme
   - Blue for Freight trains
   - Pink for Coaching trains  
   - Alert wave animations for duty hours and loco alerts
   ============================================================================ */

/* Train marker container */
.train-marker {
    background: transparent !important;
    border: none !important;
}

.train-marker-wrapper {
    position: relative;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Train marker icon with rotation support */
.train-marker-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: all 0.2s ease;
    transform-origin: center center;
    z-index: 10;
    position: relative;
}

/* The arrow icon inside */
.train-marker-icon i {
    font-size: 12px;
}

/* FREIGHT trains - Blue */
.train-marker-icon.freight {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    border: 2px solid #60a5fa;
}

/* COACHING trains - Pink */
.train-marker-icon.coaching {
    background: linear-gradient(135deg, #ec4899 0%, #be185d 100%);
    border: 2px solid #f472b6;
}

/* Loco Alert (BPC expired / Inspection due) - Violet border */
.train-marker-icon.loco-alert {
    border: 3px solid #a78bfa !important;
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Banking Alert (Banking loco required) - Orange border with glow */
.train-marker-icon.banking-alert {
    border: 3px solid #f97316 !important;
    box-shadow: 0 0 10px rgba(249, 115, 22, 0.7), 0 0 20px rgba(249, 115, 22, 0.4), 0 2px 8px rgba(0, 0, 0, 0.4);
    animation: bankingPulse 1.5s ease-in-out infinite;
}

@keyframes bankingPulse {
    0%, 100% {
        box-shadow: 0 0 10px rgba(249, 115, 22, 0.7), 0 0 20px rgba(249, 115, 22, 0.4), 0 2px 8px rgba(0, 0, 0, 0.4);
    }
    50% {
        box-shadow: 0 0 15px rgba(249, 115, 22, 0.9), 0 0 30px rgba(249, 115, 22, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4);
    }
}

/* Legacy classes for backward compatibility */
.train-marker-icon.loaded {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    border: 2px solid #4ade80;
}

.train-marker-icon.empty {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border: 2px solid #60a5fa;
}

.train-marker-icon.alert {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    border: 2px solid #f87171;
}

.train-marker-icon.banking {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    border: 2px solid #fb923c;
}

/* Hover effect */
.train-marker:hover .train-marker-icon {
    transform: scale(1.3);
    z-index: 1000 !important;
}

/* ============================================================================
   ALERT WAVE ANIMATIONS - Encircling wave blinks
   ============================================================================ */

/* Base alert wave ring */
.alert-wave-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 5;
}

/* Yellow wave - Crew duty > 10 hrs (warning) */
.alert-wave-ring.crew-warning-wave {
    animation: yellowWavePulse 2.5s ease-out infinite;
}

@keyframes yellowWavePulse {
    0% {
        width: 30px;
        height: 30px;
        border: 2px solid rgba(250, 204, 21, 0.8);
        box-shadow: 0 0 6px rgba(250, 204, 21, 0.5);
        opacity: 1;
    }
    50% {
        width: 42px;
        height: 42px;
        border: 2px solid rgba(250, 204, 21, 0.5);
        box-shadow: 0 0 8px rgba(250, 204, 21, 0.3);
        opacity: 0.6;
    }
    100% {
        width: 54px;
        height: 54px;
        border: 1px solid rgba(250, 204, 21, 0.2);
        box-shadow: 0 0 4px rgba(250, 204, 21, 0.1);
        opacity: 0;
    }
}

/* Red wave - Crew duty > 12 hrs (critical) */
.alert-wave-ring.crew-critical-wave {
    animation: redWavePulse 2s ease-out infinite;
}

@keyframes redWavePulse {
    0% {
        width: 30px;
        height: 30px;
        border: 2px solid rgba(239, 68, 68, 0.9);
        box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
        opacity: 1;
    }
    50% {
        width: 44px;
        height: 44px;
        border: 2px solid rgba(239, 68, 68, 0.6);
        box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
        opacity: 0.7;
    }
    100% {
        width: 58px;
        height: 58px;
        border: 1px solid rgba(239, 68, 68, 0.2);
        box-shadow: 0 0 5px rgba(239, 68, 68, 0.1);
        opacity: 0;
    }
}

/* Multiple wave rings for subtle layered effect */
.alert-wave-ring::before,
.alert-wave-ring::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    pointer-events: none;
}

/* Second wave ring (delayed) */
.crew-warning-wave::before {
    animation: yellowWavePulse 2.5s ease-out 0.8s infinite;
}

.crew-critical-wave::before {
    animation: redWavePulse 2s ease-out 0.65s infinite;
}

/* Third wave ring (more delayed) */
.crew-warning-wave::after {
    animation: yellowWavePulse 2.5s ease-out 1.6s infinite;
}

.crew-critical-wave::after {
    animation: redWavePulse 2s ease-out 1.3s infinite;
}






/* ============================================================================
   STATION LABELS - Permanent visible labels on dark map
   ============================================================================ */

.station-label {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: #e2e8f0 !important;
    font-size: 11px !important;
    font-weight: 500 !important;
    padding: 2px 6px !important;
    white-space: nowrap !important;
    text-shadow: 
        -1px -1px 0 #0f172a,
        1px -1px 0 #0f172a,
        -1px 1px 0 #0f172a,
        1px 1px 0 #0f172a,
        0 0 4px rgba(0, 0, 0, 0.8) !important;
}

.station-label::before {
    display: none !important;
}

.leaflet-tooltip.station-label {
    background: transparent;
    border: none;
    box-shadow: none;
}

/* Station popup on click */
.station-popup .leaflet-popup-content-wrapper {
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 8px;
    color: #e2e8f0;
}

.station-popup .leaflet-popup-content {
    margin: 10px 14px;
    font-size: 13px;
}

.station-popup .leaflet-popup-tip {
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(148, 163, 184, 0.3);
}

/* ============================================================================
   TRAIN TOOLTIP ON HOVER (v2.8)
   ============================================================================ */
.train-tooltip {
    background: rgba(15, 23, 42, 0.95) !important;
    border: 1px solid rgba(148, 163, 184, 0.4) !important;
    border-radius: 6px !important;
    padding: 6px 10px !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    color: #e2e8f0 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4) !important;
}

.train-tooltip::before {
    border-top-color: rgba(15, 23, 42, 0.95) !important;
}

/* ============================================================================
   LFD (LARGE FORMAT DISPLAY) MODE STYLES
   Optimized for 15ft x 4ft display with 16:9 aspect ratio
   ============================================================================ */
body.lfd-mode {
    /* Larger base font for readability from distance */
    font-size: 18px;
}

/* Critical: Change grid layout to single column for full-width map */
body.lfd-mode .dashboard-container {
    grid-template-columns: 1fr !important;
}

body.lfd-mode .header {
    /* Increase header height for better visibility */
    height: 80px;
    padding: 0 24px;
}

body.lfd-mode .logo-text h1 {
    font-size: 24px;
}

body.lfd-mode .logo-text span {
    font-size: 12px;
}

body.lfd-mode .stat-item .stat-value {
    font-size: 28px;
}

body.lfd-mode .stat-item .stat-label {
    font-size: 12px;
}

body.lfd-mode .header-time .current-time {
    font-size: 28px;
}

body.lfd-mode .header-time .current-date {
    font-size: 14px;
}

/* Hide sidebar completely in LFD mode */
body.lfd-mode .sidebar {
    display: none !important;
    width: 0 !important;
}

body.lfd-mode .drawer-toggle {
    display: none !important;
}

/* Full width map in LFD mode */
body.lfd-mode .map-container {
    width: 100% !important;
    height: calc(100vh - 80px) !important;
}

/* Train dots in LFD mode — simple circles on the polyline, no animations */
body.lfd-mode .train-dot-lfd {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

/* Hide any inherited marker styles in LFD */
body.lfd-mode .train-marker-icon,
body.lfd-mode .train-marker-wrapper,
body.lfd-mode .alert-wave-ring {
    display: none !important;
}

/* ── LFD Enroute Hotspot Overlay Panel ─────────────────────────────── */
#lfdHotspotPanel {
    display: none;
    position: fixed;
    top: 90px;
    left: 12px;
    width: 260px;
    background: #0f172a;
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 10px;
    padding: 14px;
    z-index: 1500;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    font-family: 'Segoe UI', system-ui, sans-serif;
}
body.lfd-mode #lfdHotspotPanel { display: block; }

.lfd-hotspot-title {
    font-size: 13px;
    font-weight: 700;
    color: #f1f5f9;
    margin-bottom: 2px;
}
.lfd-hotspot-title i { color: #f97316; margin-right: 6px; }

.lfd-hotspot-subtitle {
    font-size: 9px;
    color: #64748b;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
    padding-bottom: 8px;
}

.lfd-hotspot-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.06);
}
.lfd-hotspot-row:last-child { border-bottom: none; }

.lfd-hotspot-rank {
    font-size: 11px;
    font-weight: 700;
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.lfd-hotspot-pair {
    flex: 1;
    min-width: 0;
}

.lfd-hotspot-stations {
    font-size: 11px;
    font-weight: 600;
    color: #e2e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lfd-hotspot-bar {
    height: 3px;
    border-radius: 2px;
    margin-top: 3px;
    transition: width 0.5s ease;
}

.lfd-hotspot-count {
    font-size: 14px;
    font-weight: 800;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.lfd-hotspot-avg {
    font-size: 9px;
    color: #64748b;
    width: 40px;
    text-align: right;
    flex-shrink: 0;
}

.lfd-hotspot-empty {
    font-size: 11px;
    color: #475569;
    text-align: center;
    padding: 12px 0;
}

/* Station labels smaller in LFD to reduce clutter */
body.lfd-mode .station-label {
    font-size: 10px !important;
    font-weight: 500 !important;
    opacity: 0.7;
}

/* Map legend larger and repositioned */
body.lfd-mode .map-legend {
    font-size: 14px;
    padding: 16px;
    max-width: 220px;
    bottom: 30px;
    right: 20px;
}

body.lfd-mode .map-legend .legend-title {
    font-size: 16px;
    margin-bottom: 12px;
}

body.lfd-mode .map-legend .legend-item {
    margin: 8px 0;
}

/* LFD mode badge in header */
.lfd-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    color: white;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    margin-left: 12px;
    animation: lfd-pulse 2s ease-in-out infinite;
}

@keyframes lfd-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.lfd-badge i {
    font-size: 14px;
}

/* Make train popup content larger for LFD */
body.lfd-mode .leaflet-popup-content {
    font-size: 14px !important;
    min-width: 350px;
}

body.lfd-mode .popup-title {
    font-size: 20px !important;
}

body.lfd-mode .popup-subtitle {
    font-size: 14px !important;
}

body.lfd-mode .popup-section-title {
    font-size: 14px !important;
}

body.lfd-mode .popup-label {
    font-size: 12px !important;
}

body.lfd-mode .popup-value {
    font-size: 14px !important;
}

body.lfd-mode .popup-badge {
    font-size: 11px !important;
    padding: 4px 10px !important;
}

/* Train tooltip larger in LFD mode */
body.lfd-mode .train-tooltip {
    font-size: 16px !important;
    padding: 10px 14px !important;
}




/* ── Notification Drawer ──────────────────────────────────────────────── */
.notif-type-btn {
    font-size: 10px; font-weight: 600; padding: 4px 10px; border-radius: 20px;
    border: 1px solid rgba(148, 163, 184, 0.15); background: transparent;
    color: #64748b; cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.notif-type-btn:hover { color: #e2e8f0; border-color: rgba(148, 163, 184, 0.3); }
.notif-type-btn.active { background: rgba(14, 165, 233, 0.15); border-color: #0ea5e9; color: #0ea5e9; }

.notif-item {
    display: flex; gap: 10px; padding: 10px 8px; border-radius: 8px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.06); transition: background 0.1s;
}
.notif-item:hover { background: rgba(30, 41, 59, 0.5); }
.notif-icon {
    width: 32px; height: 32px; border-radius: 8px; display: flex;
    align-items: center; justify-content: center; flex-shrink: 0; font-size: 13px;
}
.notif-body { flex: 1; min-width: 0; }
.notif-title { font-size: 11px; font-weight: 700; color: #e2e8f0; margin-bottom: 2px; }
.notif-text { font-size: 10px; color: #94a3b8; line-height: 1.4; }
.notif-meta { display: flex; gap: 8px; align-items: center; margin-top: 4px; font-size: 9px; color: #475569; }
.notif-wa { color: #22c55e; }



/* ── Phase 2: duty-band legend filter ─────────────────────────────── */
.legend-count {
    color: #94a3b8;
    font-size: 10px;
    margin-left: 2px;
}
.legend-item[data-band] {
    border-radius: 6px;
    padding: 2px 4px;
    transition: background 0.15s;
}
.legend-item[data-band]:hover {
    background: rgba(148, 163, 184, 0.12);
}
.legend-item.legend-active {
    background: rgba(14, 165, 233, 0.22);
    box-shadow: inset 0 0 0 1px rgba(14, 165, 233, 0.5);
}

/* ── Phase 3: Map/Table view toggle ───────────────────────────────── */
.view-toggle {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 1000;
    display: flex;
    gap: 0;
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
}
.view-toggle-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.view-toggle-btn:hover { color: #e2e8f0; }
.view-toggle-btn.active {
    background: #0ea5e9;
    color: #fff;
}

/* ── Phase 3: Table view ───────────────────────────────────────────── */
.train-table-view {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    display: flex;
    flex-direction: column;
    z-index: 500;
}
.train-table-header {
    padding: 14px 18px 10px;
    font-size: 15px;
    font-weight: 700;
    color: #e2e8f0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
}
.train-table-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0 12px 12px;
}
.train-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.train-table thead th {
    position: sticky;
    top: 0;
    background: #166534;
    color: #fff;
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    font-size: 12px;
    z-index: 1;
}
.train-table tbody td {
    padding: 10px 12px;
    color: #cbd5e1;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}
.train-table tbody tr:hover {
    filter: brightness(1.15);
}

/* ============================================================================
   MOBILE RESPONSIVE RETROFIT (v2.5)
   Goal: let controllers update crew / charge / detach and other data entry
   comfortably from a phone. Targets the real pain points — the Leaflet train
   popup and the modal forms (crew, loco, alerts) — without changing desktop.

   Two breakpoints:
     <= 768px  tablet / large phone (landscape)
     <= 480px  phone (portrait) — tightest layout + full-screen modals
   These rules are appended last so they win the cascade over earlier widths.
   ============================================================================ */

@media (max-width: 768px) {

    /* ---- Train marker popup: stop forcing a 380px min width on small screens.
       Let it size to the viewport so nothing clips off-screen. ---- */
    .leaflet-popup-content { min-width: 0 !important; width: 78vw; max-width: 320px; }

    /* ---- Modals: near-full-screen, internally scrollable. ---- */
    .modal-card {
        width: 100%;
        max-width: none;
        max-height: 92vh;
        border-radius: 16px 16px 0 0;   /* bottom-sheet feel */
        margin: 0;
    }
    .modal-backdrop {
        align-items: flex-end;          /* dock the sheet to the bottom */
    }
    .modal-body { max-height: calc(92vh - 70px); overflow-y: auto; -webkit-overflow-scrolling: touch; }

    /* ---- Forms collapse to a single column everywhere. ---- */
    .form-grid { grid-template-columns: 1fr; gap: 12px; }

    /* ---- Touch targets: 44px min height for inputs, selects, buttons. ---- */
    .form-input, .form-select {
        min-height: 44px;
        font-size: 16px;               /* >=16px stops iOS auto-zoom on focus */
    }
    .submit-btn, .popup-btn, .crew-action-btn {
        min-height: 44px;
        font-size: 15px;
    }

    /* ---- Crew action toggle (Handover / Detach) stacks full-width. ---- */
    .crew-action-toggle { flex-direction: column; }
    .crew-action-toggle .crew-action-btn { min-width: 0 !important; width: 100%; }

    /* ---- Top bar: stop it forcing page-wide horizontal scroll. ----
       The header wraps into rows; the stat/action strip scrolls *inside*
       the viewport instead of widening the page (which was pushing the
       Modules menu and other items off-screen). ---- */
    .header {
        flex-wrap: wrap;
        gap: 10px;
        padding: 10px 14px;
        row-gap: 10px;
    }
    .header-stats {
        order: 3;
        width: 100%;
        gap: 10px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        padding-bottom: 4px;
        /* allow the Modules dropdown to escape the scroll strip */
        scroll-snap-type: x proximity;
    }
    .header-stats .stat-item {
        flex: 0 0 auto;            /* keep each card its natural width */
        padding: 6px 12px;
        scroll-snap-align: start;
    }
    .stat-value { font-size: 17px; }
    .logo-section { gap: 12px; }
    .logo-icon { width: 36px; height: 36px; font-size: 17px; }
    .logo-text h1 { font-size: 15px; }
    .logo-text span { font-size: 9px; letter-spacing: 1px; }
    .rbac-header-section { order: 2; margin-left: auto; }
    .header-time { order: 1; }

    /* Modules dropdown: escape the scrollable strip's clipping at all mobile
       widths by pinning to the viewport. Give it a real, bounded width so it
       renders as a readable panel (not a sliver squeezed against the edge).
       The inline min-width:220px is overridden below. ---- */
    #modulesMenu {
        position: fixed !important;
        top: auto !important;
        right: 12px !important;
        bottom: 12px !important;
        left: auto !important;
        width: min(280px, calc(100vw - 24px)) !important;
        min-width: 0 !important;
        margin-top: 0 !important;
        max-height: 65vh;
        overflow-y: auto;
        z-index: 3000 !important;
    }
    #modulesMenu a { padding: 13px 16px; font-size: 14px; }
}

@media (max-width: 480px) {

    /* ---- Phone portrait: take the whole screen for data-entry modals. ---- */
    .modal-card {
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    .modal-body { max-height: calc(100vh - 64px); padding: 16px; }
    .modal-header { padding: 14px 16px; }
    .modal-title { font-size: 16px; }

    /* Popup grows a little more relative to the (smaller) viewport. */
    .leaflet-popup-content { width: 84vw; max-width: 300px; }

    /* Form sections breathe less; labels and values stay legible. */
    .form-section { padding: 14px; margin-bottom: 14px; }
    .form-label { font-size: 12px; }

    /* Crew history rows: single column so nothing is cramped. */
    #crewHistoryList .form-grid { grid-template-columns: 1fr; }

    /* Close button easier to hit. */
    .close-modal-btn { width: 40px; height: 40px; }

    /* ---- Top bar at phone-portrait: hide the verbose date/time to save
       width; keep the COA freshness line which controllers rely on. ---- */
    .header-time .current-time { font-size: 18px; }
    .header-time .current-date { display: none; }
    .logo-text span { display: none; }   /* keep the name, drop the tagline */

    /* ---- Modules dropdown must NOT be clipped by the scrollable stat strip.
       Phone-portrait: full-width panel docked to the bottom of the screen.
       Explicitly override the 768px width rule for a self-consistent box. ---- */
    #modulesMenu {
        position: fixed !important;
        top: auto !important;
        right: 10px !important;
        left: 10px !important;
        bottom: 10px !important;
        width: auto !important;
        min-width: 0 !important;
        max-height: 60vh;
        overflow-y: auto;
    }
}
