/**
 * Satsight Map Tool - Main Styles
 * Version: 1.0.0
 */

:root {
    --bg-color: #FFFFFF;
    --panel-color: #F8F9FA;
    --border-color: #DADCE0;
    --text-primary: #202124;
    --text-secondary: #5F6368;
    --accent-primary: #1A73E8;
    --accent-hover: #1765CC;
    --accent-danger: #D93025;
    --accent-success: #1E8E3E;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --box-shadow: 0 1px 3px 0 rgba(60, 64, 67, .3), 0 2px 6px 2px rgba(60, 64, 67, .15);
    --box-shadow-light: 0 1px 2px 0 rgba(60, 64, 67, .1);
}

/* Main Container */
.satsight-container {
    width: 100%;
    height: 100vh;
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-family);
    display: flex;
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--box-shadow-light);
}

body.admin-bar .satsight-container {
    height: calc(100vh - 32px);
}

/* Main Content */
.satsight-main-content {
    flex-grow: 1;
    min-width: 0;
    /* CRITICAL: Allow flex shrinking, prevents map from pushing sidebar */
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
}

#satsight-map {
    flex-grow: 1;
    width: 100%;
}

/* Sidebar */
.satsight-sidebar {
    width: 360px;
    min-width: 360px;
    height: 100%;
    z-index: 20;
    background: var(--bg-color);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: margin-right .35s cubic-bezier(.4, 0, .2, 1);
    box-shadow: -2px 0 5px rgba(0, 0, 0, .05);
    flex-shrink: 0;
}

.satsight-container.sidebar-collapsed .satsight-sidebar {
    margin-right: -360px;
}

/* Sidebar Views */
.sidebar-view {
    display: none;
    flex-direction: column;
    flex-grow: 1;
    min-height: 0;
    /* Important for nested flex scrolling */
    overflow-y: auto;
    /* Allow scrolling if content exceeds */
}

.sidebar-view.active {
    display: flex;
}

.sidebar-header {
    padding: 12px 16px;
    font-size: 18px;
    font-weight: 500;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    position: relative;
}

.sidebar-header .header-title {
    flex-grow: 1;
}

.sidebar-header .back-button,
.sidebar-header .hide-sidebar-btn {
    background: 0 0;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 5px;
    line-height: 1;
    border-radius: 50%;
}

.sidebar-header .back-button:hover,
.sidebar-header .hide-sidebar-btn:hover {
    background-color: #f1f3f4;
}

.hide-sidebar-btn {
    margin-left: auto;
}

/* Show Sidebar Button */
.show-sidebar-btn {
    position: absolute;
    top: 15px;
    right: -50px;
    z-index: 15;
    background-color: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: var(--box-shadow);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: right .4s cubic-bezier(.4, 0, .2, 1);
}

.show-sidebar-btn:hover {
    background-color: #f1f3f4;
}

.satsight-container.sidebar-collapsed .show-sidebar-btn {
    right: 15px;
}

/* Timeline Bar */
.satsight-timeline-bar {
    background-color: var(--bg-color);
    padding: 8px;
    flex-shrink: 0;
    border-top: 1px solid var(--border-color);
    z-index: 10;
    display: flex;
    align-items: center;
    box-shadow: 0 -2px 5px rgba(0, 0, 0, .05);
}

#timeline-dates-container {
    overflow-x: auto;
    white-space: nowrap;
    flex-grow: 1;
    text-align: center;
}

.timeline-date-item {
    display: inline-block;
    padding: 6px 16px;
    margin: 0 4px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
}

.timeline-date-item.selected {
    background-color: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

/* Toast Messages */
.satsight-toast-container {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: fit-content;
    max-width: 80%;
    pointer-events: none;
}

.toast-message {
    padding: 12px 20px;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--box-shadow);
    display: flex;
    align-items: center;
    gap: 15px;
    opacity: 0;
    transform: translateY(-20px);
    transition: all .35s ease-in-out;
    pointer-events: all;
}

.toast-message.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-message.info {
    background-color: var(--accent-primary);
}

.toast-message.error {
    background-color: var(--accent-danger);
}

.toast-message.success {
    background-color: var(--accent-success);
}

.toast-close-btn {
    background: 0 0;
    border: none;
    color: #fff;
    opacity: .7;
    cursor: pointer;
    font-size: 20px;
    padding: 0;
    line-height: 1;
    margin-left: auto;
}

.toast-close-btn:hover {
    opacity: 1;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(32, 33, 36, .6);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-color);
    padding: 24px;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--box-shadow);
}

.modal-buttons {
    margin-top: 24px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-buttons button {
    padding: 8px 20px;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: pointer;
}

.modal-btn-primary {
    background: var(--accent-primary);
    color: #fff;
}

.modal-btn-secondary {
    border-color: var(--border-color);
    color: var(--text-primary);
}

/* Loading Indicator */
#loading-indicator {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, .7);
    z-index: 9998;
    display: none;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Left Toolbar */
.satsight-left-toolbar {
    position: absolute;
    top: 15px;
    left: 15px;
    z-index: 10;
    background: var(--bg-color);
    border-radius: 8px;
    box-shadow: var(--box-shadow);
    display: flex;
    flex-direction: column;
    padding: 5px;
}

.btn-toolbar-custom {
    color: var(--text-secondary);
    background-color: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all .2s ease;
    width: 40px;
    height: 40px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 2px;
}

.btn-toolbar-custom:hover {
    background-color: #f1f3f4;
    color: var(--text-primary);
}

.btn-toolbar-custom:disabled {
    color: #bdbdbd;
    cursor: not-allowed;
    background-color: transparent;
}

/* Search Box */
#satsight-search-box-container {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    width: 100%;
    max-width: 450px;
}

.search-group {
    display: flex;
    align-items: center;
    background: var(--bg-color);
    border-radius: 24px;
    box-shadow: var(--box-shadow);
}

#satsight-search-box {
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 12px 20px;
    outline: none;
    flex-grow: 1;
    font-size: 15px;
}

#satsight-search-button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0 16px;
    font-size: 16px;
}

/* Area Display */
#aoi-area-display {
    position: absolute;
    bottom: 65px;
    left: 15px;
    z-index: 10;
    background-color: rgba(0, 0, 0, .7);
    color: #fff;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 13px;
    display: none;
}

/* Sidebar Content */
.sidebar-content {
    padding: 16px;
    overflow-y: auto;
    flex-grow: 1;
}

/* Field Items */
.field-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

.field-item:hover {
    background-color: #f1f3f4;
}

.field-item.selected {
    background-color: #e8f0fe;
}

.field-item-icon {
    color: var(--text-secondary);
    margin-right: 16px;
    font-size: 16px;
}

.field-item-details {
    flex-grow: 1;
}

.field-item-name {
    font-weight: 500;
}

.field-item-info {
    font-size: 13px;
    color: var(--text-secondary);
}

.field-item-actions .delete-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.field-item-actions .delete-btn:hover {
    color: var(--accent-danger);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-footer button {
    width: 100%;
    padding: 10px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.sidebar-footer button:first-child {
    margin-top: 0;
}

#add-field-btn {
    background-color: var(--accent-primary);
    color: white;
    border: none;
}

#add-field-btn:hover {
    background-color: var(--accent-hover);
}

.sidebar-btn-secondary {
    background-color: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.sidebar-btn-secondary:hover {
    background-color: #f1f3f4;
}

/* Panel Control Groups */
.panel-control-group {
    margin-bottom: 16px;
}

.form-select,
.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

/* Sidebar Tabs */
.sidebar-main-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-tab-btn {
    background: none;
    border: none;
    padding: 10px 5px;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 3px solid transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 13px;
    flex-grow: 1;
}

.sidebar-tab-btn:hover {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

.sidebar-tab-btn.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

.sidebar-view-wrapper {
    display: none;
    flex-grow: 1;
    min-height: 0;
    /* Important for nested flex scrolling */
    flex-direction: column;
}

.sidebar-view-wrapper.active {
    display: flex;
}

/* Weather Controls */
#weather-tool-wrapper .panel-control-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
}

#weather-tool-wrapper .panel-control-group label:has(input:checked) {
    background-color: #e8f0fe;
}

/* Profile Header */
.satsight-sidebar .profile-header {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    background-color: #f7f7f7;
    flex-shrink: 0;
}

.profile-header .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--accent-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    font-size: 18px;
}

.profile-header .user-info {
    flex-grow: 1;
}

.profile-header .display-name {
    font-weight: 600;
    font-size: 15px;
}

.profile-header .action-links {
    font-size: 12px;
}

.profile-header .action-links a,
.profile-header .action-links button {
    text-decoration: none;
    color: var(--text-secondary);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-size: 12px;
}

.profile-header .action-links a:hover,
.profile-header .action-links button:hover {
    color: var(--accent-primary);
}

/* Deepness Model Styles */
.model-category {
    font-weight: bold;
    font-size: 16px;
    margin-top: 20px;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.model-category:first-child {
    margin-top: 0;
}

.model-item {
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 4px;
    margin-bottom: 5px;
    font-size: 14px;
}

.model-item:hover {
    background-color: #f1f3f4;
}

#model-details-view {
    color: var(--text-primary);
    display: none;
    padding: 25px;
    overflow-y: auto;
    height: 100%;
    background-color: var(--bg-color);
}

#model-details-view .model-details-container {
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
    align-items: flex-start;
    justify-content: center;
}

#model-details-view .details-content {
    flex: 1 1 500px;
    min-width: 300px;
}

#model-details-view .details-image-container {
    flex: 1 1 500px;
    text-align: center;
}

#model-details-view img {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--box-shadow-light);
    object-fit: contain;
}

#model-details-view h2 {
    font-size: 24px;
    margin-top: 0;
    margin-bottom: 15px;
    border-bottom: 2px solid var(--accent-primary);
    padding-bottom: 10px;
}

#model-details-view p {
    line-height: 1.6;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

#model-details-view .details-meta {
    background-color: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 15px;
    margin-top: 20px;
}

#model-details-view .details-meta span {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
}

#model-details-view .details-meta strong {
    color: var(--text-primary);
}

#login-prompt-btn {
    margin-top: 1rem;
    background-color: var(--accent-success);
    color: #fff;
    border: none;
}

/* ========================================
   LOADING INDICATORS & SKELETON LOADING
======================================== */

/* Button Loading State */
.btn-loading {
    pointer-events: none;
    opacity: 0.7;
    position: relative;
}

.btn-loading::after {
    content: '';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Skeleton Loading for Field List */
.skeleton-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

.skeleton-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
    margin-right: 16px;
}

.skeleton-text {
    flex-grow: 1;
}

.skeleton-line {
    height: 14px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 8px;
}

.skeleton-line:last-child {
    width: 60%;
    margin-bottom: 0;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Enhanced Loading Overlay */
#loading-indicator .loading-text {
    margin-top: 15px;
    font-size: 14px;
    color: var(--text-secondary);
}

/* ========================================
   MOBILE RESPONSIVE STYLES
======================================== */

/* Tablet and below */
@media (max-width: 1024px) {
    .satsight-sidebar {
        width: 320px;
    }

    .satsight-container.sidebar-collapsed .satsight-sidebar {
        margin-right: -320px;
    }
}

/* Mobile devices */
@media (max-width: 768px) {

    /* Full-width sidebar on mobile */
    .satsight-sidebar {
        position: absolute;
        top: 0;
        right: 0;
        width: 100%;
        height: 100%;
        z-index: 100;
        transform: translateX(100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .satsight-sidebar.mobile-open {
        transform: translateX(0);
    }

    .satsight-container:not(.sidebar-collapsed) .satsight-sidebar {
        transform: translateX(0);
    }

    .satsight-container.sidebar-collapsed .satsight-sidebar {
        margin-right: 0;
        transform: translateX(100%);
    }

    /* Touch-friendly toolbar buttons */
    .btn-toolbar-custom {
        width: 48px;
        height: 48px;
        font-size: 18px;
    }

    .satsight-left-toolbar {
        top: 10px;
        left: 10px;
    }

    /* Show sidebar button - more prominent on mobile */
    .show-sidebar-btn {
        width: 48px;
        height: 48px;
        font-size: 20px;
    }

    /* Timeline touch scrolling */
    .satsight-timeline-bar {
        padding: 10px;
    }

    #timeline-dates-container {
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
    }

    .timeline-date-item {
        scroll-snap-align: center;
        padding: 10px 18px;
        margin: 0 6px;
        font-size: 14px;
    }

    /* Search box adjustments */
    #satsight-search-box-container {
        max-width: 70%;
        left: 70px;
        transform: none;
    }

    #satsight-search-box {
        padding: 10px 15px;
        font-size: 14px;
    }

    /* Modal adjustments */
    .modal-content {
        width: 95%;
        max-width: none;
        margin: 20px;
    }

    /* Sidebar tabs - larger touch targets */
    .sidebar-tab-btn {
        padding: 12px 8px;
        font-size: 12px;
    }

    .sidebar-tab-btn i {
        font-size: 18px;
    }

    /* Field items - larger touch targets */
    .field-item {
        padding: 16px 12px;
    }

    .field-item-actions .delete-btn {
        padding: 10px;
        font-size: 18px;
    }

    /* Form controls */
    .form-select,
    .form-control {
        padding: 12px;
        font-size: 16px;
    }

    /* Sidebar footer buttons */
    .sidebar-footer button {
        padding: 14px;
        font-size: 16px;
    }

    /* Profile header */
    .profile-header {
        padding: 16px;
    }

    .profile-header .avatar {
        width: 48px;
        height: 48px;
        font-size: 20px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {

    /* Even larger touch targets */
    .btn-toolbar-custom {
        width: 52px;
        height: 52px;
    }

    .timeline-date-item {
        padding: 12px 20px;
    }

    #satsight-search-box-container {
        max-width: calc(100% - 80px);
    }

    /* Model details view */
    #model-details-view {
        padding: 15px;
    }

    #model-details-view h2 {
        font-size: 20px;
    }

    #model-details-view .model-details-container {
        flex-direction: column;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .satsight-container {
        height: 100vh;
    }

    .satsight-timeline-bar {
        padding: 5px 8px;
    }

    .timeline-date-item {
        padding: 6px 12px;
    }
}