:root {
    /* Colors */
    --bg-dark: #050505;
    --bg-panel: rgba(30, 30, 30, 0.6);
    --bg-card: rgba(40, 40, 40, 0.4);
    --bg-hover: rgba(255, 255, 255, 0.1);

    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --primary-glow: rgba(168, 85, 247, 0.4);

    --text-main: #ffffff;
    --text-muted: #94a3b8;

    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.2);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    --header-height: 60px;
    --sidebar-width: 320px;
    --maps-sidebar-width: 420px;

    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --glass-border: 1px solid rgba(255, 255, 255, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    outline: none;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    background-image:
        radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(168, 85, 247, 0.08) 0%, transparent 25%);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    backdrop-filter: blur(100px);
    /* Extreme blur for background noise reduction if any */
}

/* Header */
.app-header {
    height: var(--header-height);
    background: rgba(10, 10, 10, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 24px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 10px var(--primary-glow));
}

.logo h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #fff, #ccc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-controls {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-main);
    border-color: var(--border);
    transform: translateY(-1px);
}

/* Main Content */
.app-main {
    flex: 1;
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr var(--maps-sidebar-width);
    overflow: hidden;
}

/* Sidebars Common */
.sidebar-left,
.sidebar-right {
    background: rgba(15, 15, 15, 0.6);
    backdrop-filter: blur(20px);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    border-right: var(--glass-border);
}

.sidebar-right {
    border-right: none;
    border-left: var(--glass-border);
}

/* Panels */
.panel {
    background: var(--bg-panel);
    border: var(--glass-border);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.panel:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--border-hover);
}

.panel-header {
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-header h3 {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    padding: 30px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    min-height: 180px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    opacity: 0.7;
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: #6366f1;
    background: rgba(99, 102, 241, 0.05);
    transform: scale(1.02);
    opacity: 1;
}

.upload-area:hover .upload-placeholder .icon {
    transform: scale(1.1);
    opacity: 1;
}

.upload-placeholder .icon {
    font-size: 40px;
    margin-bottom: 12px;
    opacity: 0.7;
    transition: transform 0.3s ease;
}

.upload-placeholder p {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

.source-preview {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    border-radius: var(--radius-md);
    z-index: 10;
}

.source-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.btn-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-close:hover {
    background: rgba(239, 68, 68, 0.8);
    transform: rotate(90deg);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    border: none;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.btn-block {
    width: 100%;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
    transform: translateY(-1px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-group {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.btn-group .btn {
    flex: 1;
}

/* Stats */
.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-muted);
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.stat-row:last-child {
    border-bottom: none;
}

.mono {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    color: var(--text-main);
    font-weight: 500;
}

/* Center Viewport */
.viewport-center {
    background: #000;
    position: relative;
    display: flex;
    flex-direction: column;
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.5);
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.viewport-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    height: 100%;
    width: 100%;
}

#previewCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.viewport-controls-overlay {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 15, 15, 0.8);
    backdrop-filter: blur(16px);
    padding: 10px 24px;
    border-radius: 100px;
    display: flex;
    gap: 24px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.viewport-controls-overlay:hover {
    background: rgba(20, 20, 20, 0.9);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateX(-50%) translateY(-2px);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.control-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
}

.control-group select {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.control-group select:hover {
    background: rgba(255, 255, 255, 0.1);
}

.control-group select option {
    background: #1a1a1a;
    color: white;
}

/* Maps Grid */
.maps-grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.map-card {
    background: var(--bg-card);
    border: var(--glass-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 200px;
    position: relative;
    transition: all 0.3s ease;
}

.map-card:hover {
    border-color: rgba(168, 85, 247, 0.3);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
}

.map-header {
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 2;
}

.map-header h4 {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.map-tools {
    display: flex;
    gap: 6px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.map-card:hover .map-tools {
    opacity: 1;
}

.btn-tiny {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    color: var(--text-muted);
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-tiny:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

.map-body {
    flex: 1;
    position: relative;
    background: #111;
    overflow: hidden;
}

.map-canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.5s ease;
}

.map-card:hover .map-canvas {
    transform: scale(1.05);
}

.map-actions-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(3px);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    opacity: 0;
    transition: all 0.3s ease;
}

.map-card:hover .map-actions-overlay {
    opacity: 1;
}

.map-actions-overlay .btn-icon {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    color: white;
    width: 40px;
    height: 40px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.map-actions-overlay .btn-icon:hover {
    background: var(--primary-gradient);
    border-color: transparent;
    transform: scale(1.1);
}

/* Loading & Toast */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 5, 5, 0.9);
    backdrop-filter: blur(10px);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #6366f1;
    border-right-color: #a855f7;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.viewport-controls-overlay:hover {
    background: rgba(20, 20, 20, 0.9);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateX(-50%) translateY(-2px);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.control-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
}

.control-group select {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.control-group select:hover {
    background: rgba(255, 255, 255, 0.1);
}

.control-group select option {
    background: #1a1a1a;
    color: white;
}

/* Maps Grid */
.maps-grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.map-card {
    background: var(--bg-card);
    border: var(--glass-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 200px;
    position: relative;
    transition: all 0.3s ease;
}

.map-card:hover {
    border-color: rgba(168, 85, 247, 0.3);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
}

.map-header {
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 2;
}

.map-header h4 {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.map-tools {
    display: flex;
    gap: 6px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.map-card:hover .map-tools {
    opacity: 1;
}

.btn-tiny {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    color: var(--text-muted);
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-tiny:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

.map-body {
    flex: 1;
    position: relative;
    background: #111;
    overflow: hidden;
}

.map-canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.5s ease;
}

.map-card:hover .map-canvas {
    transform: scale(1.05);
}

.map-actions-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(3px);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    opacity: 0;
    transition: all 0.3s ease;
}

.map-card:hover .map-actions-overlay {
    opacity: 1;
}

.map-actions-overlay .btn-icon {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    color: white;
    width: 40px;
    height: 40px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.map-actions-overlay .btn-icon:hover {
    background: var(--primary-gradient);
    border-color: transparent;
    transform: scale(1.1);
}

/* Loading & Toast */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 5, 5, 0.9);
    backdrop-filter: blur(10px);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #6366f1;
    border-right-color: #a855f7;
    border-radius: 50%;
    animation: spin 0.8s cubic-bezier(0.6, 0.2, 0.4, 0.8) infinite;
    margin-bottom: 20px;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.2);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.toast {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(20, 20, 20, 0.9);
    backdrop-filter: blur(12px);
    color: var(--text-main);
    padding: 12px 24px;
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    z-index: 2001;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Image Preview Modal */
.image-preview-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.image-preview-modal.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: #1a1a1a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.image-preview-modal.show .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 16px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
}

.btn-close-modal {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-close-modal:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.modal-body {
    padding: 20px;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    background: repeating-conic-gradient(#1a1a1a 0% 25%, #222 0% 50%) 50% / 20px 20px;
}

.modal-body img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}

/* Responsive */
@media (max-width: 1400px) {
    .app-main {
        grid-template-columns: 280px 1fr 360px;
    }
}

@media (max-width: 1024px) {
    .app-main {
        grid-template-columns: 1fr;
        grid-template-rows: auto 500px auto;
        overflow-y: auto;
    }

    .sidebar-left,
    .sidebar-right {
        border: none;
        padding: 16px;
        height: auto;
        overflow: visible;
    }

    .viewport-center {
        min-height: 500px;
    }

    body {}

    body {
        overflow: auto;
    }
}

/* Header Dropdown */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-btn {
    color: white;
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.dropdown-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background-color: #1a1a1a;
    min-width: 200px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    z-index: 1000;
    margin-top: 5px;
    overflow: hidden;
}

.dropdown:hover .dropdown-content {
    display: block;
}

.dropdown-content a {
    color: var(--text-secondary);
    padding: 10px 16px;
    text-decoration: none;
    display: block;
    font-size: 0.9em;
    transition: all 0.2s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.dropdown-content a:last-child {
    border-bottom: none;
}

.dropdown-content a:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    padding-left: 20px;
}