/**
 * Qorvia MapKit Playground Styles
 * Dark theme matching the landing page design
 */

:root {
    --pg-primary: #2563eb;
    --pg-primary-dark: #1d4ed8;
    --pg-dark: #0f172a;
    --pg-dark-lighter: #1e293b;
    --pg-gray: #64748b;
    --pg-success: #16a34a;
    --pg-danger: #dc2626;
    --pg-border: rgba(255, 255, 255, 0.1);
    --pg-text: #fff;
    --pg-text-muted: rgba(255, 255, 255, 0.7);
    --pg-text-dim: rgba(255, 255, 255, 0.5);
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--pg-dark);
    color: var(--pg-text);
    overflow: hidden;
}

/* ============ HEADER ============ */
.playground-header {
    height: 56px;
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--pg-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

.playground-header .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--pg-text);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1rem;
}

.playground-header .logo img {
    height: 28px;
}

.playground-header .back-link {
    color: var(--pg-text-muted);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.playground-header .back-link:hover {
    color: var(--pg-text);
}

/* ============ MAIN LAYOUT ============ */
.playground-main {
    display: flex;
    height: calc(100vh - 56px);
    margin-top: 56px;
}

/* ============ MAP CONTAINER ============ */
.map-container {
    flex: 1;
    position: relative;
    min-height: 400px; /* Fallback minimum height */
}

#map {
    width: 100%;
    height: 100%;
    min-height: 400px; /* Fallback minimum height */
    /* DEBUG: border: 3px solid red; */
}

/* ============ SIDEBAR ============ */
.sidebar {
    width: 320px;
    background: var(--pg-dark-lighter);
    border-left: 1px solid var(--pg-border);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid var(--pg-border);
}

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

.sidebar-section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--pg-gray);
    margin-bottom: 12px;
    font-weight: 600;
}

/* ============ SEARCH ============ */
.search-wrapper {
    position: relative;
}

.search-input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    background: var(--pg-dark);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: var(--pg-text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.search-input::placeholder {
    color: var(--pg-gray);
}

.search-input:focus {
    border-color: var(--pg-primary);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--pg-gray);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--pg-dark);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    margin-top: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    display: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.search-results.show {
    display: block;
}

.search-result-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.85rem;
    transition: background 0.15s;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* ============ TILE SELECTOR ============ */
.tile-select {
    width: 100%;
    padding: 10px 12px;
    background: var(--pg-dark);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: var(--pg-text);
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
}

.tile-select:hover {
    border-color: rgba(255, 255, 255, 0.3);
}

.tile-select option {
    background: var(--pg-dark);
    color: var(--pg-text);
}

/* ============ COLOR PICKERS ============ */
.color-picker-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.color-picker-row:last-child {
    margin-bottom: 0;
}

.color-picker-label {
    font-size: 0.85rem;
    color: var(--pg-text-muted);
}

.color-picker-input {
    width: 40px;
    height: 32px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    background: transparent;
}

.color-picker-input::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.color-picker-input::-webkit-color-swatch {
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* ============ MARKERS LIST ============ */
.markers-list {
    max-height: 200px;
    overflow-y: auto;
}

.marker-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: var(--pg-dark);
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s;
}

.marker-item:hover {
    background: rgba(37, 99, 235, 0.1);
}

.marker-item:last-child {
    margin-bottom: 0;
}

.marker-item-icon {
    width: 24px;
    height: 24px;
    background: var(--pg-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    flex-shrink: 0;
    font-weight: 600;
}

.marker-item-address {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--pg-text-muted);
}

.marker-item-delete {
    background: none;
    border: none;
    color: var(--pg-gray);
    cursor: pointer;
    padding: 4px;
    font-size: 1rem;
    transition: color 0.2s;
    border-radius: 4px;
}

.marker-item-delete:hover {
    color: var(--pg-danger);
    background: rgba(220, 38, 38, 0.1);
}

.empty-state {
    text-align: center;
    padding: 20px;
    color: var(--pg-gray);
    font-size: 0.85rem;
}

/* ============ ROUTE SECTION ============ */
.route-waypoints {
    max-height: 150px;
    overflow-y: auto;
}

.waypoint-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: var(--pg-dark);
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 0.85rem;
    cursor: move;
    transition: background 0.15s;
}

.waypoint-item:hover {
    background: rgba(22, 163, 74, 0.1);
}

.waypoint-number {
    width: 20px;
    height: 20px;
    background: var(--pg-success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    flex-shrink: 0;
}

.waypoint-address {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--pg-text-muted);
}

.route-info {
    display: flex;
    gap: 16px;
    margin-top: 12px;
    padding: 12px;
    background: var(--pg-dark);
    border-radius: 8px;
}

.route-info-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.route-info-label {
    font-size: 0.7rem;
    color: var(--pg-gray);
    text-transform: uppercase;
}

.route-info-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--pg-text);
}

/* ============ ROUTE MODE SELECTOR ============ */
.route-mode-selector {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    background: var(--pg-dark);
    padding: 4px;
    border-radius: 8px;
}

.route-mode-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 4px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--pg-gray);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.75rem;
}

.route-mode-btn i {
    font-size: 1.1rem;
}

.route-mode-btn span {
    font-weight: 500;
}

.route-mode-btn:hover {
    color: var(--pg-text-muted);
    background: rgba(255, 255, 255, 0.05);
}

.route-mode-btn.active {
    color: var(--pg-text);
    background: var(--pg-success);
}

.route-mode-btn.active:hover {
    background: #15803d;
}

/* Route info mode icon */
.route-info-mode {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-right: 12px;
    border-right: 1px solid var(--pg-border);
    margin-right: 4px;
}

.route-info-mode i {
    font-size: 1.4rem;
    color: var(--pg-success);
}

/* ============ BUTTONS ============ */
.btn-playground {
    width: 100%;
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s;
    margin-top: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-playground:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-playground-primary {
    background: var(--pg-primary);
    border: none;
    color: var(--pg-text);
}

.btn-playground-primary:hover:not(:disabled) {
    background: var(--pg-primary-dark);
}

.btn-playground-outline {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--pg-text-muted);
}

.btn-playground-outline:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.3);
    color: var(--pg-text);
}

.btn-playground-danger {
    background: transparent;
    border: 1px solid rgba(220, 38, 38, 0.5);
    color: var(--pg-danger);
}

.btn-playground-danger:hover:not(:disabled) {
    background: rgba(220, 38, 38, 0.1);
}

/* ============ LEAFLET POPUP STYLES ============ */
.leaflet-popup-content-wrapper {
    background: var(--pg-dark-lighter);
    color: var(--pg-text);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.leaflet-popup-tip {
    background: var(--pg-dark-lighter);
}

.leaflet-popup-content {
    margin: 12px 16px;
    font-size: 0.9rem;
}

.popup-address {
    font-weight: 500;
    margin-bottom: 8px;
    line-height: 1.4;
}

.popup-coords {
    font-size: 0.8rem;
    color: var(--pg-gray);
    margin-bottom: 10px;
    font-family: monospace;
}

.popup-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.popup-btn {
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.popup-btn-route {
    background: var(--pg-success);
    color: var(--pg-text);
}

.popup-btn-route:hover {
    background: #15803d;
}

.popup-btn-delete {
    background: rgba(220, 38, 38, 0.2);
    color: var(--pg-danger);
}

.popup-btn-delete:hover {
    background: rgba(220, 38, 38, 0.3);
}

/* ============ CUSTOM MARKERS ============ */
.custom-div-icon {
    background: transparent;
    border: none;
}

.custom-marker {
    width: 32px;
    height: 32px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s;
}

.custom-marker:hover {
    transform: rotate(-45deg) scale(1.1);
}

.custom-marker-inner {
    width: 12px;
    height: 12px;
    background: #fff;
    border-radius: 50%;
    transform: rotate(45deg);
}

/* ============ MODE INDICATOR ============ */
.mode-indicator {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: var(--pg-dark-lighter);
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    display: none;
    z-index: 500;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--pg-border);
}

.mode-indicator.show {
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideIn 0.2s ease-out;
}

.mode-indicator i {
    color: var(--pg-success);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============ LOADING STATE ============ */
.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--pg-text);
    animation: spin 1s linear infinite;
}

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

/* ============ SCROLLBAR ============ */
.sidebar::-webkit-scrollbar,
.markers-list::-webkit-scrollbar,
.route-waypoints::-webkit-scrollbar,
.search-results::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track,
.markers-list::-webkit-scrollbar-track,
.route-waypoints::-webkit-scrollbar-track,
.search-results::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb,
.markers-list::-webkit-scrollbar-thumb,
.route-waypoints::-webkit-scrollbar-thumb,
.search-results::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.markers-list::-webkit-scrollbar-thumb:hover,
.route-waypoints::-webkit-scrollbar-thumb:hover,
.search-results::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
    .playground-main {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: 40vh;
        border-left: none;
        border-top: 1px solid var(--pg-border);
    }

    .map-container {
        height: 60vh;
    }

    .playground-header {
        padding: 0 12px;
    }

    .playground-header .back-link span {
        display: none;
    }

    .sidebar-section {
        padding: 12px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        height: 45vh;
    }

    .map-container {
        height: 55vh;
    }

    .route-info {
        flex-direction: column;
        gap: 8px;
    }
}

/* ============ LEAFLET OVERRIDES ============ */
.leaflet-control-zoom {
    border: none !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}

.leaflet-control-zoom a {
    background: var(--pg-dark-lighter) !important;
    color: var(--pg-text) !important;
    border: none !important;
    width: 32px !important;
    height: 32px !important;
    line-height: 32px !important;
}

.leaflet-control-zoom a:hover {
    background: var(--pg-dark) !important;
}

.leaflet-control-attribution {
    background: rgba(15, 23, 42, 0.8) !important;
    color: var(--pg-gray) !important;
    font-size: 10px !important;
}

.leaflet-control-attribution a {
    color: var(--pg-primary) !important;
}

/* ============ GEOLOCATION BUTTON ============ */
.geolocation-btn {
    position: absolute;
    top: 80px;
    right: 10px;
    z-index: 1000;
    width: 36px;
    height: 36px;
    background: var(--pg-dark-lighter);
    border: none;
    border-radius: 6px;
    color: var(--pg-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
}

.geolocation-btn:hover {
    background: var(--pg-dark);
    color: var(--pg-primary);
}

.geolocation-btn:active {
    transform: scale(0.95);
}

.geolocation-btn.loading {
    pointer-events: none;
}

.geolocation-btn.loading i {
    animation: spin 1s linear infinite;
}

.geolocation-btn.success {
    color: var(--pg-success);
}

.geolocation-btn.error {
    color: var(--pg-danger);
}

/* User location marker */
.user-location-marker {
    width: 20px;
    height: 20px;
    background: var(--pg-primary);
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3), 0 2px 8px rgba(0, 0, 0, 0.3);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3), 0 2px 8px rgba(0, 0, 0, 0.3);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(37, 99, 235, 0.15), 0 2px 8px rgba(0, 0, 0, 0.3);
    }
}
