:root {
    --bg-base: #f1f5f9;
    --panel-bg: rgba(255, 255, 255, 0.65); /* Elegant frost */
    --panel-border: rgba(255, 255, 255, 0.8); /* Crisp glass edge */
    --text-main: #0f172a; /* Slate 900 for high contrast */
    --text-dim: #475569; /* Slate 600 */
    --accent-blue-deep: #102764; /* Deep Ocean */
    --accent-blue: #025ec7; /* Vibrant Azure */
    --accent-blue-dim: rgba(2, 132, 199, 0.15); /* Soft active state */
    --accent-blue-deep-2: rgba(0, 22, 119, 0.807); /* Soft active state */
    --font-display: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

body {
    font-family: var(--font-body);
    background-color: var(--bg-base);
    color: var(--text-main);
    overflow: hidden;
}

#map {
    height: 100vh;
    width: 100vw;
    z-index: 1;
    background: #e2e8f0; 
}

/* Small Header */
.app-header {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 1000;
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 0.5px solid var(--panel-border);
    border-radius: 0px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
}

.logo {
    background: var(--accent-blue-deep);
    color: #fff;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 20px;
    padding: 10px 16px;
    border-radius: 0px;
    /* box-shadow: 0 4px 10px rgba(13, 40, 56, 0.3); */
    letter-spacing: 1px;
}

.header-titles h1 {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.1;
    letter-spacing: -0.5px;
    position: relative;
    padding-bottom: 8px;
    margin-bottom: 8px;
}

@keyframes h1-pulse-gloss {
    0% { background-position: -200% 0, 0 0; }
    100% { background-position: 300% 0, 0 0; }
}

.header-titles h1::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 3px;
    /* border-radius: 3px; */
    border-top: 2px solid rgba(255, 255, 255, 0.9);
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    /*box-shadow: inset 0 2px 4px rgba(255,255,255,0.4), 0 4px 6px rgba(0,0,0,0.1);*/
    backdrop-filter: blur(16px);
    background: 
        linear-gradient(90deg, transparent, rgba(255,255,255,1), transparent) no-repeat,
        rgba(2, 132, 199, 0.605);
    background-size: 60% 100%, 100% 100%;
    background-position: -200% 0, 0 0;
    animation: h1-pulse-gloss 5s infinite ease-in-out;
}

.header-titles p {
    font-family: var(--font-body);
    font-size: 12px;
    color: var(--accent-blue-deep);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Side Panel (Left Hover) */
.side-panel-container {
    position: absolute;
    top: 50%;
    left: 0;
    /* Hide mostly, peek 15px */
    transform: translateY(-50%) translateX(calc(-100% + 20px)); 
    width: 280px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.side-panel-container:hover,
.side-panel-container:focus-within,
.side-panel-container.pinned {
    transform: translateY(-50%) translateX(0); /* Show completely */
}

/* Near-transparent peeking bar */
.side-panel-container::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    width: 4px;
    height: 40px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    transition: opacity 0.3s;
    pointer-events: none;
}

.side-panel-container:hover::after,
.side-panel-container:focus-within::after,
.side-panel-container.pinned::after {
    opacity: 0;
}

/* Right Panel (Second Panel) */
.right-panel-container {
    position: absolute;
    top: 50%;
    right: 0;
    /* Completely hidden until triggered */
    transform: translateY(-50%) translateX(100%); 
    width: 280px;
    max-height: 69vh;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.right-panel-container.pinned {
    transform: translateY(-50%) translateX(0);
}

.right-panel {
    border-radius: 10px 0 0 10px !important;
    border-right: none !important;
    border-left: 1px solid var(--panel-border) !important;
    display: flex;
    flex-direction: column;
}

.right-panel-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    border-top: 1px solid rgba(0,0,0,0.05);
    padding-top: 12px;
}

.right-panel-content {
    overflow-y: auto;
    padding-right: 8px;
    margin-bottom: 0;
    flex: 1;
}

/* Custom scrollbar for right panel */
.right-panel-content::-webkit-scrollbar {
    width: 6px;
}
.right-panel-content::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.02);
}
.right-panel-content::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 4px;
    transition: background 0.3s ease;
}
.right-panel:hover .right-panel-content::-webkit-scrollbar-thumb {
    background: rgba(2, 132, 199, 0.4);
}
.right-panel-content::-webkit-scrollbar-thumb:hover {
    background: rgba(2, 132, 199, 0.7);
}

.side-panel {
    width: 100%;
    height: 100%;
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-left: none;
    border-radius: 0 0px 0px 0;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    padding: 12px 20px;
    pointer-events: auto;
    position: relative;
    overflow: hidden;
}

@keyframes side-panel-shimmer {
    0% { left: -150%; }
    20% { left: 150%; }
    100% { left: 150%; }
}

.side-panel::before {
    content: '';
    position: absolute;
    top: 0; left: -150%;
    width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.5), transparent);
    transform: skewX(-20deg);
    animation: side-panel-shimmer 6s infinite;
    pointer-events: none;
    z-index: 10;
}

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

.side-header h2 {
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 800;
    color: var(--accent-blue-deep);
    margin: 0;
    letter-spacing: 1.5px;
}

.pin-btn {
    width: 26px;
    height: 26px; /* Approx 80% of header height */
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: var(--text-dim);
    rotate: z 30deg;
    transition: all 0.2s ease;
}

.pin-btn:hover {
    background: white;
    color: var(--accent-blue);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.pin-btn.pinned-active {
    background: var(--accent-blue);
    color: white;
    rotate: z 0deg;
    border-color: var(--accent-blue);
}

.pin-btn.pinned-active svg {
    fill: white;
}

.side-layer-list {
    display: flex;
    flex-direction: column;
    gap: 6px; /* Reduced spacing */
    margin-bottom: 20px;
}

#layer-list {
    max-height: 33vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
}
#layer-list::-webkit-scrollbar {
    width: 6px;
}
#layer-list::-webkit-scrollbar-track {
    background: transparent;
}
#layer-list::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 4px;
    transition: background 0.3s ease;
}
#layer-list:hover::-webkit-scrollbar-thumb {
    background: rgba(2, 132, 199, 0.4);
}
#layer-list::-webkit-scrollbar-thumb:hover {
    background: rgba(2, 132, 199, 0.7);
}

/* Coordinate Tool Styling */
.coord-tool {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    width: 100%;
    border-top: 1px solid rgba(0,0,0,0.05);
    padding-top: 15px;
}

.coord-tool h3 {
    font-size: 12px;
    margin-bottom: 8px;
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.coord-inputs {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.coord-inputs input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 12px;
    outline: none;
}

.coord-tool button {
    width: 100%;
    padding: 8px;
    background: var(--accent-blue);
    color: white;
    border: none;
    /* border-radius: 6px; */
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.coord-tool button:hover {
    background: #63b3ed;
}

.loading-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--accent-blue);
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--accent-blue-dim);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Layer Control Item */
.layer-arc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: transparent;
    border: 1px solid var(--panel-border);
    padding: 10px 14px;
    border-radius: 4px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
}

.layer-arc-item:hover {
    border-color: #93c5fd;
    box-shadow: 0 8px 20px rgba(2, 132, 199, 0.1);
    transform: scale(1.02);
}

.layer-arc-item.active {
    background: var(--accent-blue-dim);
    border-color: #06486b;
}

.layer-info {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.layer-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.layer-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* A layer whose data could not be fetched: shown, but visibly inert, so a
   missing database table is obvious instead of silently absent. */
.layer-arc-item.failed {
    cursor: default;
    opacity: 0.65;
    border-style: dashed;
    border-color: #b45309;
}

.layer-arc-item.failed:hover {
    border-color: #b45309;
    box-shadow: none;
    transform: none;
}

.layer-color-failed {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    background: repeating-linear-gradient(45deg, #b45309, #b45309 2px, transparent 2px, transparent 4px);
}

.layer-load-error {
    margin-left: 22px;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #b45309;
}

.legend-more-btn {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #e2e8f0;
    color: var(--text-dim);
    font-size: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    border: 1px solid #cbd5e1;
    transition: all 0.2s;
}
.legend-more-btn:hover {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

.right-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-main);
    padding: 6px 4px;
    border-bottom: 1px solid rgba(0,0,0,0.04);
}
.right-legend-color {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.1);
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    width: 28px;
    height: 16px;
    background: #cbd5e1;
    border-radius: 20px;
    transition: all 0.3s;
    flex-shrink: 0;
}

.layer-arc-item.active .toggle-switch {
    background: var(--accent-blue);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.layer-arc-item.active .toggle-switch::after {
    transform: translateX(12px);
}

/* Tooltip Revamp */
.tooltip {
    position: absolute;
    z-index: 1100;
    pointer-events: auto;
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 12px 20px;
    width: max-content;
    max-width: 320px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    opacity: 0;
    transition: opacity 0.15s ease;
}

.tooltip.visible {
    opacity: 1;
}

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

.rhd-ref {
    font-family: var(--font-mono);
    background: #f1f5f9;
    color: var(--text-main);
    border: 1px solid #cbd5e1;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
}

.layer-badge {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    color: var(--accent-blue);
    font-weight: 600;
    letter-spacing: 0.5px;
}

#tooltip-name {
    font-family: var(--font-display);
    font-size: 17px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 12px;
    line-height: 1.3;
}

.tooltip-details {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid #f1f5f9;
    padding-top: 12px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 11px;
    gap: 16px;
}

.detail-key { color: var(--text-dim); text-transform: capitalize; }
.detail-val { color: var(--text-main); font-weight: 600; text-align: right; max-width: 200px; word-break: break-word; }

.see-more-btn {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    color: var(--accent-blue);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    margin-top: 8px;
    text-align: center;
    width: 100%;
    padding: 6px;
    /* border-radius: 6px; */
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.see-more-btn:hover {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

/* Leaflet UI Overrides */
.leaflet-control-zoom {
    border: none !important;
    background: var(--panel-bg) !important;
    backdrop-filter: blur(12px);
    border: 2px solid var(--panel-border) !important;
    border-radius: 6px !important;
    overflow: hidden;
    margin-right: 20px !important;
    margin-bottom: 20px !important;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05) !important;
}

.leaflet-control-zoom a {
    background-color: transparent !important;
    color: var(--text-main) !important;
    border-bottom: 1px solid #f1f5f9 !important;
}
.leaflet-control-zoom a:hover {
    background-color: #f8fafc !important;
}
.leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.8) !important;
    color: var(--text-dim) !important;
    backdrop-filter: blur(4px);
    border-top-right-radius: 8px;
}
.leaflet-control-attribution a { color: var(--accent-blue) !important; }

#target-btn {
    width: 34px;
    flex-shrink: 0;
    padding: 0;
    background: #f1f5f9;
    color: var(--text-dim);
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#target-btn:hover, #target-btn.active {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

.crosshair-cursor {
    cursor: crosshair !important;
}
