/* CI2D3 Ice Island Explorer - Custom Styles */

/* Global Styles */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    overflow: hidden;
}

/* Navigation */
.navbar {
    z-index: 1000;
}

.brand-icon {
    font-size: 1.5rem;
    margin-right: 0.5rem;
}

/* Layout
   A flex column: fixed-height header on top, the map/sidebar row fills the
   rest. min-height:0 on the body is required so the row can actually shrink
   inside the flex container instead of overflowing. */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-body {
    flex: 1 1 auto;
    min-height: 0;
}

.container-fluid {
    padding: 0;
    margin-top: 0;
}

.row {
    margin: 0;
}

/* Page Header */
.app-header {
    flex: 0 0 auto;
    background: linear-gradient(180deg, #0b3d62 0%, #10527f 100%);
    border-bottom: 1px solid #082b45;
    padding: 0.7rem 1.25rem 0.6rem;
    text-align: center;
    color: #fff;
}

.app-title {
    font-size: 1.45rem;
    font-weight: 600;
    letter-spacing: 0.2px;
    margin: 0 0 0.2rem;
    color: #fff;
}

.app-subtitle {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.85);
    margin: 0;
    line-height: 1.3;
}

/* "Show me how" button in the header */
.btn-guide {
    margin-left: 0.5rem;
    padding: 0.15rem 0.7rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: #0b3d62;
    background: #ffd400;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}

.btn-guide:hover {
    background: #ffe14d;
    transform: translateY(-1px);
}

.btn-guide span {
    font-size: 0.65rem;
    vertical-align: middle;
}

/* Sidebar */
.sidebar {
    background-color: #f8f9fa;
    border-right: 1px solid #dee2e6;
    height: 100%; /* Fills the flex body below the header */
    overflow-y: auto;
    padding: 0;
    transition: margin-left 0.3s ease;
}

.sidebar.hidden {
    margin-left: -100%;
}

/* Panel Headers */
.panel-header {
    background-color: #e9ecef;
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h5,
.panel-header h6 {
    margin: 0;
}

.panel-content {
    padding: 1rem;
}

/* Map Container */
.map-container {
    position: relative;
    padding: 0;
    height: 100%; /* Fills the flex body below the header */
}

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

/* Leaflet Map Panes - Force correct layer ordering */
/* Basemap should be below WMS layer */
.custom-basemap-pane {
    z-index: 100 !important;
}

.custom-wms-pane {
    z-index: 900 !important;
}

/* Ensure default Leaflet panes don't override our custom panes */
.leaflet-basemappane {
    z-index: 100 !important;
}

.leaflet-wmspane {
    z-index: 900 !important;
}

/* Inspect Panel */
.inspect-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 350px;
    max-height: 80%;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    overflow: hidden;
    display: none;
}

.inspect-panel.active {
    display: block;
}

.inspect-panel .panel-content {
    max-height: 400px;
    overflow-y: auto;
}

.inspect-panel .panel-footer {
    padding: 1rem;
    border-top: 1px solid #dee2e6;
    background-color: #f8f9fa;
}

.btn-track-lineage {
    width: 100%;
    font-weight: 500;
}

.btn-track-lineage:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Lineage tracking active state */
.btn-track-lineage.active {
    background-color: #198754;
    border-color: #198754;
}

/* Lineage info display */
.lineage-info {
    padding: 0.5rem;
    margin-top: 0.5rem;
    background-color: #e7f3ff;
    border-radius: 4px;
    font-size: 0.85rem;
}

.lineage-info strong {
    color: #0d6efd;
}

/* Lineage layer markers */
.lineage-marker {
    background: transparent;
    border: none;
}

.lineage-number {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    color: white;
    font-weight: bold;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    border: 2px solid white;
}

.lineage-tooltip {
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
}

.lineage-tooltip::before {
    border-top-color: rgba(0, 0, 0, 0.8);
}

/* Lineage legend.
   Rendered as a Leaflet control reusing the shared .legend styles, so it only
   needs a max-width guard here (role labels are longer than the calving codes). */
.lineage-legend-box {
    max-width: 200px;
}

/* Feature Properties Display */
.feature-property {
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e9ecef;
}

.feature-property:last-child {
    border-bottom: none;
}

.property-label {
    font-weight: 600;
    color: #495057;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.property-value {
    color: #212529;
    font-size: 1rem;
    margin-top: 0.25rem;
}

/* Layer Control - label the basemap group.
   Leaflet renders base layers in .leaflet-control-layers-base, so a ::before
   heading there labels the group without touching Leaflet's DOM. */
.leaflet-control-layers-base::before {
    content: "Basemap";
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

/* Filter Form */
#filterForm .form-label {
    font-weight: 500;
    color: #495057;
}

.filter-hint {
    font-size: 0.78rem;
    color: #6c757d;
    margin-bottom: 0.6rem;
}

/* Compact the filter sidebar so the action buttons stay above the fold in a
   short viewport. */
.sidebar .panel-header {
    padding: 0.6rem 1rem;
}

.sidebar .panel-header h5 {
    font-size: 1.05rem;
}

.sidebar .panel-content {
    padding: 0.75rem 1rem;
}

#filterForm .mb-3 {
    margin-bottom: 0.6rem !important;
}

#filterForm .form-label {
    margin-bottom: 0.15rem;
}

#filterForm .form-text {
    font-size: 0.75rem;
    line-height: 1.25;
}

/* Match the small buttons, and reclaim enough vertical space that the
   action buttons stay visible without scrolling on a short viewport. */
#filterForm .form-select,
#filterForm .form-control {
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
    font-size: 0.875rem;
}

/* Applied filter list */
.active-filter-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    background-color: #e7f3ff;
    border: 1px solid #b6d8f7;
    border-radius: 4px;
    padding: 0.35rem 0.5rem;
    margin-bottom: 0.35rem;
    font-size: 0.85rem;
}

.active-filter-item code {
    color: #0a58ca;
    background: none;
    padding: 0;
}

.active-filters-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #495057;
    margin-bottom: 0.35rem;
}

#filterResults {
    padding: 1rem;
    background-color: #e7f3ff;
    border-radius: 4px;
    display: none;
}

#filterResults.active {
    display: block;
}

.result-count {
    font-weight: 600;
    color: #0d6efd;
}

/* Loading Indicator */
.loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2000;
    display: none;
}

.loading-indicator.active {
    display: block;
}

/* Leaflet Popup Customization */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
}

.leaflet-popup-content {
    margin: 1rem;
    font-size: 0.9rem;
}

/* Calving Location Legend Colors */
.calving-loc-cg {
    color: #90de4c;
}
.calving-loc-na {
    color: #40d77a;
}
.calving-loc-ng {
    color: #debd76;
}
.calving-loc-pg {
    color: #6154da;
}
.calving-loc-rg {
    color: #dc25e6;
}
.calving-loc-sg {
    color: #d51c3e;
}

/* Legend Box */
.legend {
    background: white;
    padding: 10px;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    line-height: 1.5;
}

.legend h6 {
    margin: 0 0 5px;
    font-size: 0.9rem;
}

.legend-item {
    margin: 3px 0;
    font-size: 0.85rem;
}

.legend-color {
    display: inline-block;
    width: 20px;
    height: 15px;
    margin-right: 5px;
    border: 1px solid #333;
}

/* Responsive Design */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        width: 100%;
        z-index: 999;
    }

    .map-container {
        width: 100%;
    }

    .inspect-panel {
        width: 90%;
        left: 5%;
    }
}

/* Scrollbar Styling */
.panel-content::-webkit-scrollbar {
    width: 8px;
}

.panel-content::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.panel-content::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.panel-content::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Buttons */
.btn-primary {
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.btn-primary:hover {
    background-color: #0b5ed7;
    border-color: #0a58ca;
}

.btn-secondary {
    background-color: #6c757d;
    border-color: #6c757d;
}

/* Close Button */
.btn-close {
    filter: brightness(0) invert(1);
}

.panel-header .btn-close {
    filter: none;
}

/* ==========================================================================
   Guided tour
   ========================================================================== */

.tour-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 25, 40, 0);
    z-index: 1800;
    display: none;
    transition: background 0.25s ease;
}

.tour-backdrop.show {
    display: block;
    pointer-events: none;      /* steps that act on the app stay clickable */
}

/* Only the narrative steps dim the page; the acting steps leave it visible. */
.tour-backdrop.dim {
    background: rgba(10, 25, 40, 0.55);
    pointer-events: auto;
}

.tour-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.98);
    width: min(560px, calc(100vw - 2rem));
    max-height: min(80vh, 640px);
    overflow-y: auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
    z-index: 1900;
    padding: 1.1rem 1.3rem 1rem;
    display: none;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease, top 0.25s ease,
                left 0.25s ease, width 0.25s ease;
}

.tour-modal.show {
    display: block;
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* Steps that change the map move out of the way, bottom-right. */
.tour-modal.tour-aside {
    top: auto;
    bottom: 1.25rem;
    left: auto;
    right: 1.25rem;
    transform: none;
    width: min(400px, calc(100vw - 2rem));
    max-height: 62vh;
}

.tour-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}

.tour-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #0b3d62;
    background: #e3f0fa;
    border-radius: 999px;
    padding: 0.15rem 0.6rem;
}

.tour-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #14202b;
    margin: 0 0 0.5rem;
}

.tour-body {
    font-size: 0.88rem;
    color: #40505d;
    line-height: 1.45;
}

.tour-body p {
    margin: 0 0 0.5rem;
}

.tour-body ul {
    margin: 0 0 0.5rem;
    padding-left: 1.15rem;
}

.tour-body li {
    margin-bottom: 0.15rem;
}

.tour-body code {
    background: #f1f4f7;
    color: #0a58ca;
    padding: 0.05rem 0.3rem;
    border-radius: 3px;
    font-size: 0.85em;
}

.tour-note {
    font-size: 0.8rem;
    color: #6c757d;
}

.tour-legend {
    list-style: none;
    padding-left: 0 !important;
}

.tour-legend li {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.tour-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.35);
    flex: 0 0 auto;
}

/* Live result line for a step */
.tour-status {
    display: none;
    font-size: 0.82rem;
    border-radius: 6px;
    padding: 0.45rem 0.6rem;
    margin-top: 0.2rem;
}

.tour-status.show {
    display: block;
}

.tour-status.running {
    background: #f1f4f7;
    color: #6c757d;
}

.tour-status.done {
    background: #e8f6ed;
    color: #14663a;
    border-left: 3px solid #198754;
}

.tour-status.error {
    background: #fdecea;
    color: #842029;
    border-left: 3px solid #dc3545;
}

.tour-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.9rem;
    padding-top: 0.7rem;
    border-top: 1px solid #eceff2;
}

.tour-dots {
    display: flex;
    gap: 5px;
}

.tour-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #d3dae1;
    transition: background 0.2s ease, transform 0.2s ease;
}

.tour-dot.active {
    background: #10527f;
    transform: scale(1.25);
}

.tour-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

/* Element the current step is talking about */
.tour-highlight {
    outline: 3px solid #ffd400;
    outline-offset: 2px;
    border-radius: 6px;
    animation: tour-pulse 1.6s ease-in-out infinite;
}

@keyframes tour-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 212, 0, 0.55); }
    50%      { box-shadow: 0 0 0 7px rgba(255, 212, 0, 0); }
}

@media (max-width: 768px) {
    .tour-modal.tour-aside {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: calc(100vw - 1.5rem);
        max-height: 50vh;
    }
}

/* ==========================================================================
   Visual polish
   ========================================================================== */

.sidebar {
    background-color: #f7f9fb;
}

.sidebar .panel-header {
    background: #eef2f6;
    border-bottom: 1px solid #dde4ea;
}

.sidebar .panel-header h5 {
    color: #14202b;
    font-weight: 600;
}

#filterForm .form-select,
#filterForm .form-control {
    border-radius: 6px;
    border-color: #cdd6de;
}

#filterForm .form-select:focus,
#filterForm .form-control:focus {
    border-color: #10527f;
    box-shadow: 0 0 0 0.18rem rgba(16, 82, 127, 0.15);
}

#filterForm .btn {
    border-radius: 6px;
    font-weight: 500;
}

.btn-primary {
    background-color: #10527f;
    border-color: #10527f;
}

.btn-primary:hover {
    background-color: #0b3d62;
    border-color: #0b3d62;
}

.btn-outline-primary {
    color: #10527f;
    border-color: #10527f;
}

.btn-outline-primary:hover {
    background-color: #10527f;
    border-color: #10527f;
}

.inspect-panel {
    border-radius: 10px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
    border: 1px solid #dde4ea;
}

.inspect-panel .panel-header {
    background: #eef2f6;
    border-bottom: 1px solid #dde4ea;
}

.legend {
    border-radius: 8px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    border: 1px solid #dde4ea;
}

.leaflet-control-layers {
    border-radius: 8px !important;
    border: 1px solid #dde4ea !important;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18) !important;
}
