:root {
    --primary: #2563eb;
    --bg-dark: #0f172a;
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --text: #f8fafc;
    --text-muted: #94a3b8;
}

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

body {
    font-family: 'Assistant', 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

#app {
    display: grid;
    grid-template-areas: 
        "header header"
        "aside main";
    grid-template-columns: 350px 1fr;
    grid-template-rows: auto 1fr;
    height: 100vh;
    direction: rtl; /* Force RTL locally */
}

header {
    grid-area: header;
    padding: 1rem 2rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-bottom: 1px solid var(--glass-border);
    background: #0f172a;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    background: linear-gradient(135deg, #60a5fa 0%, #a855f7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

header p {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.header-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(37, 99, 235, 0.12);
    border: 1px solid rgba(37, 99, 235, 0.25);
    border-radius: 12px;
    padding: 0.5rem 1rem;
    min-width: 80px;
    text-align: center;
    flex-shrink: 0;
}

.header-stat-num {
    font-size: 1.4rem;
    font-weight: 700;
    color: #60a5fa;
    line-height: 1;
}

.header-stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

main {
    grid-area: main;
    position: relative;
    border-right: 1px solid var(--glass-border);
}

#map {
    height: 100%;
    width: 100%;
    z-index: 1;
}

aside {
    grid-area: aside;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    z-index: 1000;
    overflow-y: auto;
    overflow-x: hidden;
    background: #0f172a;
    min-height: 0; /* Crucial for scrolling in grid/flex */
    height: calc(100vh - 80px); /* Fallback to header height */
}

.glass-panel {
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.control-group h3, .info-panel h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--glass-bg);
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    transition: all 0.2s ease;
}

.layer-item:hover {
    background: rgba(255, 255, 255, 0.15);
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: white;
    margin-bottom: 0.75rem;
    font-family: inherit;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.route-list {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.route-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.route-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.route-item.active {
    background: rgba(37, 99, 235, 0.15);
    border-right: 3px solid var(--primary);
}

.route-item .route-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.route-item .route-color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-left: 0.75rem;
}

.info-panel {
    padding: 1.5rem;
    background: var(--glass-bg);
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    transition: box-shadow 0.3s ease;
    width: 100%;
    position: relative;
    overflow: hidden;
    max-height: 400px;
    overflow-y: auto;
}

.info-panel.animate-in {
    animation: slideInRtl 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideInRtl {
    from { opacity: 0; }
    to { opacity: 1; }
}

.info-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--glass-border);
}

.focus-btn {
    width: 100%;
    padding: 0.6rem;
    margin-top: -0.5rem;
    margin-bottom: 1.25rem;
    background: rgba(37, 99, 235, 0.1);
    border: 1px solid rgba(37, 99, 235, 0.3);
    border-radius: 8px;
    color: #60a5fa;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.focus-btn:hover {
    background: rgba(37, 99, 235, 0.2);
}

.focus-btn.active {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: #f87171;
}

.focus-btn.active:hover {
    background: rgba(239, 68, 68, 0.2);
}

.info-section {
    margin-bottom: 1.25rem;
}

.section-title {
    font-size: 0.75rem;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.trail-badge {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.header-text h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    margin-bottom: 2px;
}

.trail-id {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: 'Inter', sans-serif;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
}

.info-grid.secondary {
    grid-template-columns: 1fr;
}

.info-panel .placeholder {
    color: var(--text-muted);
    font-size: 0.95rem;
    text-align: center;
    margin-top: 3rem;
    line-height: 1.6;
}

.info-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: all 0.2s ease;
}

.info-card:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.info-card.critical {
    background: rgba(37, 99, 235, 0.05);
    border-color: rgba(37, 99, 235, 0.1);
}

.info-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 400;
}

.info-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
}

.info-value.mini {
    font-size: 0.75rem;
    font-family: 'Inter', sans-serif;
    word-break: break-all;
}

.color-val {
    display: flex;
    align-items: center;
    gap: 8px;
}

.color-val .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.stats-panel {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(37, 99, 235, 0.1);
    border-radius: 12px;
    border: 1px solid rgba(37, 99, 235, 0.2);
    width: 100%;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-item .value {
    font-weight: 600;
    color: #60a5fa;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    transition: opacity 0.5s ease;
}

.loader-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--glass-border);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Leaflet Overrides */
.leaflet-container {
    background: #0b1121 !important;
}

.leaflet-bar {
    border: none !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
}

.leaflet-bar a {
    background-color: #1e293b !important;
    color: white !important;
    border: 1px solid var(--glass-border) !important;
}

.leaflet-bar a:hover {
    background-color: #334155 !important;
}
