/* ============ RESET & GLOBAL ============ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #60a5fa;
    --surface: #14141f;
    --surface-variant: #1a1a2e;
    --background: #0a0a0f;
    --on-surface: #eef2ff;
    --on-surface-variant: #8b9bb0;
    --border: #23232e;
    --error: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;

    --shadow-1: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 3px 6px rgba(0, 0, 0, 0.4), 0 3px 6px rgba(0, 0, 0, 0.5);
    --shadow-3: 0 10px 20px rgba(0, 0, 0, 0.5), 0 6px 6px rgba(0, 0, 0, 0.6);

    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --font-size-xs: 12px;
    --font-size-sm: 13px;
    --font-size-base: 14px;
    --font-size-lg: 16px;
    --font-size-xl: 18px;
    --font-size-2xl: 20px;
    --font-size-3xl: 24px;
}

html, body {
    width: 100%;
    height: 100%;
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    background: var(--background);
    color: var(--on-surface);
    overflow: hidden;
}

/* ============ APP LAYOUT ============ */
.app {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

/* ============ APP BAR ============ */
.app-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-1);
    position: relative;
    z-index: 100;
}

.app-bar-content {
    display: flex;
    align-items: center;
    padding: 0 var(--spacing-md);
    height: 64px;
    max-width: 100%;
}

.app-title {
    font-size: var(--font-size-2xl);
    font-weight: 500;
    margin-left: var(--spacing-md);
    color: var(--on-surface);
}

.app-bar-spacer {
    flex: 1;
}

/* ============ ICON BUTTON ============ */
.icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
}

.icon-button:hover {
    background: rgba(255, 255, 255, 0.08);
}

.icon-button .material-icons {
    font-size: 24px;
    color: var(--on-surface);
}

/* ============ MAIN CONTENT ============ */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ============ SIDEBAR TAGS ============ */
.sidebar-tags {
    width: 320px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    box-shadow: var(--shadow-1);
}

.sidebar-header {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border);
}

.current-folder-name {
    font-size: var(--font-size-lg);
    font-weight: 500;
    color: var(--on-surface);
    margin: 0;
}

.tags-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: var(--spacing-md);
    overflow-y: auto;
}

.tags-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    flex: 1;
}

.tag-item {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: var(--font-size-base);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tag-item > * {
    min-width: 0;
}

.tag-item:hover {
    background: var(--surface-variant);
    border-color: var(--primary-light);
}

.tag-item.dragging {
    opacity: 0.4;
    border-style: dashed;
}

.tag-item.drag-over {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.15);
    transform: scale(1.02);
    box-shadow: var(--shadow-2);
}

.tag-item.active {
    background: rgba(59, 130, 246, 0.2);
    color: var(--primary-light);
    border-color: var(--primary);
}

.tag-name {
    flex: 1 1 auto;
    overflow: hidden;
    white-space: nowrap;
    position: relative;
    min-width: 0;
}

.tag-count {
    flex-shrink: 0;
    white-space: nowrap;
}

.tag-name span {
    display: inline-block;
    transition: transform 0.3s ease;
    padding-right: 4px;
}

.tag-item:hover .tag-name span.scroll {
    animation: tagTextScroll 20s ease-in-out infinite;
}

@keyframes tagTextScroll {
    0%, 10% { transform: translateX(0); }
    40%, 70% { transform: translateX(calc(-100% + 60px)); }
    90%, 100% { transform: translateX(0); }
}

.tag-count {
    font-size: var(--font-size-xs);
    opacity: 0.7;
    font-weight: 500;
}

/* ============ ADD TAG SECTION ============ */
.add-tag-section {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.divider {
    height: 1px;
    background: var(--border);
    margin: var(--spacing-md) 0;
}

/* ============ MAP + PREVIEW CONTAINER ============ */
.map-preview-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    gap: 0;
}

.map-wrapper {
    flex: 1.5;
    position: relative;
    background: #111114;
}

#map {
    width: 100%;
    height: 100%;
}

.divider-vertical {
    width: 6px;
    background: var(--border);
    cursor: col-resize;
    transition: background 0.2s;
}

.divider-vertical:hover {
    background: var(--primary-light);
}

.preview-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--background);
    border-left: 1px solid var(--border);
}

.preview-header {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.preview-header h3 {
    font-size: var(--font-size-lg);
    font-weight: 500;
    color: var(--on-surface);
    margin: 0;
}

.preview-content {
    flex: 1;
    background: #0a0a0f;
    overflow: hidden;
    position: relative;
}

#panoViewerEl {
    width: 100%;
    height: 100%;
    touch-action: none;
}

.preview-content iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.preview-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #5a5a7a;
    text-align: center;
}

.preview-placeholder .material-icons {
    font-size: 48px;
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
}

.preview-placeholder p {
    font-size: var(--font-size-sm);
    margin: 0;
}

/* ============ DRAWER ============ */
.drawer-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
}

.drawer-overlay.active {
    display: block;
}

.drawer {
    position: fixed;
    left: -320px;
    top: 64px;
    width: 320px;
    height: calc(100% - 64px);
    background: var(--surface);
    box-shadow: var(--shadow-3);
    z-index: 10001;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.drawer.active {
    left: 0;
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border);
}

.drawer-header h2 {
    font-size: var(--font-size-xl);
    font-weight: 500;
    color: var(--on-surface);
    margin: 0;
    flex: 1;
}

.close-drawer {
    width: 36px;
    height: 36px;
}

.drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
}

.folder-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.folder-item {
    padding: var(--spacing-md);
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: var(--font-size-base);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.folder-item:hover {
    background: var(--surface-variant);
    border-color: var(--primary-light);
}

.folder-item.active {
    background: rgba(59, 130, 246, 0.2);
    color: var(--primary-light);
    border-color: var(--primary);
}

.folder-item .material-icons {
    font-size: 20px;
}

.folder-name {
    flex: 1;
}

/* ============ ADD FOLDER SECTION ============ */
.add-folder-section {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

/* ============ SETTINGS DRAWER ============ */
.settings-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
}

.settings-overlay.active {
    display: block;
}

.settings-drawer {
    position: fixed;
    right: -400px;
    top: 64px;
    width: 400px;
    height: calc(100% - 64px);
    background: var(--surface);
    box-shadow: var(--shadow-3);
    z-index: 10001;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.settings-drawer.active {
    right: 0;
}

/* ============ SETTINGS SECTION ============ */
.settings-section {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-lg);
    border-bottom: 1px solid var(--border);
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-section h4 {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--on-surface);
    margin: 0;
}

.setting-item {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.setting-item label {
    font-size: var(--font-size-sm);
    color: var(--on-surface-variant);
}

/* ============ PROGRESS BAR ============ */
.progress-container {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin: var(--spacing-sm) 0;
}

.progress-bar {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s;
}

.progress-text {
    font-size: var(--font-size-xs);
    color: var(--on-surface-variant);
    margin: 0;
}

/* ============ FORM ELEMENTS ============ */
.text-field {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.text-field:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.slider {
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    transition: all 0.2s;
}

.slider::-webkit-slider-thumb:hover {
    width: 20px;
    height: 20px;
    box-shadow: 0 0 0 8px rgba(31, 136, 229, 0.1);
}

.slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.slider::-moz-range-thumb:hover {
    width: 20px;
    height: 20px;
    box-shadow: 0 0 0 8px rgba(31, 136, 229, 0.1);
}

.coverage-color-select {
    width: 100%;
    padding: 6px 8px;
    background: #1a1a2e;
    border: 1px solid #2a2a3a;
    border-radius: 4px;
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    outline: none;
}
.coverage-color-select:hover {
    border-color: #1f88e5;
}
.coverage-color-select option {
    background: #1a1a2e;
    color: #fff;
}

/* ============ BUTTON ============ */
.button {
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-size-base);
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    width: 100%;
}

.button-primary {
    background: var(--primary);
    color: white;
}

.button-primary:hover {
    background: var(--primary-dark);
    box-shadow: var(--shadow-2);
}

.button-primary:active {
    background: var(--primary-dark);
}

.button-secondary {
    background: var(--surface-variant);
    color: var(--on-surface);
    border: 1px solid var(--border);
}

.button-secondary:hover {
    background: #2a2a3e;
}

.button-danger {
    background: var(--error);
    color: white;
}

.button-danger:hover {
    background: #B71C1C;
    box-shadow: var(--shadow-2);
}

.button .material-icons {
    font-size: 20px;
}

/* ============ CHECKBOX ============ */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
    font-size: var(--font-size-base);
    color: var(--on-surface);
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
    filter: brightness(1.2);
}

/* ============ TOAST ============ */
.toast {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%) translateY(120px);
    background: #1e1e2e;
    color: #eef2ff;
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    z-index: 99999;
    display: none;
    box-shadow: var(--shadow-2);
    border: 1px solid var(--border);
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.toast.show {
    display: block;
}

.toast.error {
    background: var(--error);
}

.toast.success {
    background: var(--success);
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(120px);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #0a0a0f;
}

::-webkit-scrollbar-thumb {
    background: #23232e;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #3b82f6;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
    .sidebar-tags {
        display: none;
    }

    .settings-drawer {
        width: 100%;
        right: -100%;
    }

    .drawer {
        width: 280px;
        left: -280px;
    }
}

/* ============ REVIEW POPUP (MapLibre) ============ */
.review-popup .maplibregl-popup-content {
    background: #1a1a2e;
    color: #eef2ff;
    border: 1px solid #f59e0b;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    padding: 14px 16px;
    font-size: 12px;
    min-width: 220px;
}

.review-popup .maplibregl-popup-tip {
    background: #1a1a2e;
    border-color: #f59e0b;
}

.review-popup .maplibregl-popup-close-button {
    color: #888;
    font-size: 18px;
    padding: 4px 8px;
    border: none;
    background: none;
    cursor: pointer;
}
.review-popup .maplibregl-popup-close-button:hover {
    color: #f59e0b;
}

/* Popup inner elements */
.popup-content { line-height: 1.6; }
.popup-header { font-size: 14px; margin-bottom: 4px; }
.popup-info { color: #888; font-size: 11px; margin-bottom: 8px; }
.popup-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.popup-tag {
    display: inline-block;
    color: white;
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.popup-delete {
    margin-top: 10px;
    width: 100%;
    padding: 6px;
    background: #f44336;
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    font-size: 11px;
    opacity: 0.8;
}
.popup-delete:hover { opacity: 1; }

/* Fix overflow select di popup */
.review-popup select {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Fix z-index popup */
.maplibregl-popup { z-index: 100 !important; }
.maplibregl-popup-content { z-index: 101 !important; }

/* ============ MARKER GLOW RING ANIMATION ============ */
.marker-glow-ring {
    animation: markerPulse 1.5s ease-in-out infinite;
    pointer-events: none;
}

@keyframes markerPulse {
    0%   { opacity: 0.15; }
    50%  { opacity: 0.4;  }
    100% { opacity: 0.15; }
}