/**
 * vcs-mapping.css
 * Styles for the VCS Mapping plugin.
 *
 * Key concerns:
 *  1. Leaflet requires a non-zero height on the container (set inline via PHP).
 *  2. z-index: 0 on the container prevents the Leaflet pane from stacking above
 *     the WP admin bar (#wpadminbar), which has z-index: 99999.
 *  3. Leaflet Routing Machine renders a panel inside the map; ensure it doesn't
 *     overflow outside the container in narrow layouts.
 */

/* ── Map container ──────────────────────────────────────────────────────────── */
.vcs-map-container {
    position: relative;
    z-index: 0;        /* Leaflet internal panes use z-index 1-700, stay in here */
    overflow: hidden;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Ensure the Leaflet map fills the container */
.vcs-map-container .leaflet-container {
    width: 100%;
    height: 100%;
    border-radius: 8px;
}

/* ── Error state ────────────────────────────────────────────────────────────── */
.vcs-map-error {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 20px;
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-radius: 4px;
    color: #dc2626;
    font-size: 14px;
}

.vcs-map-error .dashicons {
    flex-shrink: 0;
    font-size: 20px;
    width: 20px;
    height: 20px;
}

/* ── Loading state (set by JS before geocoding completes) ───────────────────── */
.vcs-map-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 4px;
    color: #0284c7;
    font-size: 14px;
    min-height: 200px;
}

/* ── Editor placeholder ─────────────────────────────────────────────────────── */
.vcs-map-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    background: #f0f0f0;
    border: 2px dashed #c3c4c7;
    border-radius: 4px;
    color: #646970;
    font-size: 14px;
    text-align: center;
    padding: 16px;
}

/* ── Directions control button (Leaflet custom control) ─────────────────────── */
.vcs-dir-ctrl-wrap {
    border: none !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
    border-radius: 6px !important;
    overflow: hidden;
    background: #fff !important;
}

.vcs-dir-ctrl-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 40px !important;
    height: 40px;
    background: #fff;
    color: #1a73e8;
    cursor: pointer;
    text-decoration: none !important;
    line-height: 1 !important;
    font-size: 18px;
    font-weight: 600;
    transition: all 0.2s ease;
    border: none !important;
}

.vcs-dir-ctrl-btn:hover,
.vcs-dir-ctrl-btn:focus {
    background: #f0f4ff;
    color: #1557b0;
    outline: 2px solid #1a73e8;
    outline-offset: -2px;
}

/* ── Directions panel (Google Maps-style overlay inside the map) ─────────────── */
.vcs-dir-panel {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 320px;
    max-width: 90%;
    background: #fff;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 0 1px rgba(0, 0, 0, 0.1);
    transform: translateX(-105%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    border-radius: 0;
}

.vcs-dir-panel.is-open {
    transform: translateX(0);
    pointer-events: all;
}

/* ── Backdrop overlay (blocks map interaction when panel is open) ─────────────── */
.vcs-dir-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    z-index: 999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.vcs-dir-overlay.is-open {
    pointer-events: auto;
}

/* ── Panel head ──────────────────────────────────────────────────────────────── */
.vcs-dir-panel-head {
    flex-shrink: 0;
    padding: 16px 14px 12px;
    background: linear-gradient(135deg, #1a73e8 0%, #185abc 100%);
    position: relative;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.vcs-dir-close {
    position: absolute;
    top: 12px;
    right: -18px;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: none;
    color: #202124;
    font-size: 24px;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    z-index: 1200;
    transition: all 0.2s ease;
}

.vcs-dir-close:hover {
    background: #f8f9fa;
    color: #0f172a;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transform: scale(1.08);
}

.vcs-dir-close:focus {
    outline: 2px solid #1a73e8;
    outline-offset: 2px;
}

.vcs-dir-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 6px;
    padding: 11px 12px;
    margin-bottom: 8px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.03);
    transition: all 0.2s ease;
}

.vcs-dir-dot {
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.vcs-dir-dot--from {
    background: #1a73e8;
    box-shadow: 0 1px 3px rgba(26, 115, 232, 0.4), 0 0 0 2px rgba(26, 115, 232, 0.15);
}

.vcs-dir-dot--to {
    background: #ea4335;
    box-shadow: 0 1px 3px rgba(234, 67, 53, 0.4), 0 0 0 2px rgba(234, 67, 53, 0.15);
}

.vcs-dir-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 14px;
    padding: 4px 0;
    background: transparent;
    min-width: 0;
    color: #202124;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    transition: color 0.2s ease;
}

.vcs-dir-input::placeholder {
    color: #9aa0a6;
}

.vcs-dir-input:focus {
    color: #0f172a;
}

/* Swap row: dashed connector + swap button */
.vcs-dir-swap-row {
    display: flex;
    align-items: center;
    height: 20px;
    padding: 0 8px;
    margin-bottom: 4px;
}

.vcs-dir-connector {
    flex: 1;
    height: 100%;
    border-left: 2px dashed rgba(255, 255, 255, 0.4);
    margin-left: 11px;
}

.vcs-dir-swap {
    background: rgba(255, 255, 255, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: #fff;
    cursor: pointer;
    border-radius: 6px;
    font-size: 16px;
    line-height: 1;
    padding: 4px 8px;
    flex-shrink: 0;
    transition: all 0.2s ease;
    font-weight: 500;
}

.vcs-dir-swap:hover {
    background: rgba(255, 255, 255, 0.4);
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.05);
}

.vcs-dir-swap:focus {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 2px;
}

.vcs-dir-go {
    width: 100%;
    margin-top: 10px;
    padding: 11px 14px;
    background: linear-gradient(135deg, #1a73e8 0%, #185abc 100%);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(26, 115, 232, 0.25);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.vcs-dir-go:hover {
    background: linear-gradient(135deg, #1557b0 0%, #0f4a8b 100%);
    box-shadow: 0 4px 10px rgba(26, 115, 232, 0.35);
    transform: translateY(-1px);
}

.vcs-dir-go:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(26, 115, 232, 0.25);
}

.vcs-dir-go:focus {
    outline: 2px solid #1a73e8;
    outline-offset: 2px;
}

.vcs-dir-go:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.vcs-dir-locate {
    width: 100%;
    margin-top: 8px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: 1.5px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    letter-spacing: 0.2px;
}

.vcs-dir-locate:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.6);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.vcs-dir-locate:active {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(0);
}

.vcs-dir-locate:focus {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 2px;
}

.vcs-dir-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.95);
    min-height: 18px;
    margin-top: 8px;
    padding: 0 2px;
    line-height: 1.4;
    font-weight: 500;
}

.vcs-dir-status.is-error {
    color: #ffeb3b;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* ── Panel body (summary + step list) ────────────────────────────────────────── */
.vcs-dir-panel-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
}

/* Custom scrollbar styling for webkit browsers */
.vcs-dir-panel-body::-webkit-scrollbar {
    width: 6px;
}

.vcs-dir-panel-body::-webkit-scrollbar-track {
    background: transparent;
}

.vcs-dir-panel-body::-webkit-scrollbar-thumb {
    background: #d0d7de;
    border-radius: 3px;
}

.vcs-dir-panel-body::-webkit-scrollbar-thumb:hover {
    background: #adb5bd;
}

.vcs-dir-summary {
    display: none;
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 700;
    color: #1a73e8;
    border-bottom: 1px solid #e8eaed;
    background: #f8f9fa;
    letter-spacing: 0.3px;
}

.vcs-dir-steps {
    list-style: none;
    margin: 0;
    padding: 0;
    background: #fff;
}

.vcs-dir-step {
    display: grid;
    grid-template-columns: 26px 1fr auto;
    align-items: start;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid #f0f1f3;
    font-size: 13px;
    transition: background-color 0.15s ease;
}

.vcs-dir-step:hover {
    background-color: #f8f9fa;
}

.vcs-dir-step:last-child {
    border-bottom: none;
}

.vcs-dir-step-icon {
    font-size: 16px;
    text-align: center;
    color: #5f6368;
    padding-top: 0;
    flex-shrink: 0;
    font-weight: 600;
}

.vcs-dir-step-text {
    color: #202124;
    line-height: 1.45;
    word-break: break-word;
    font-weight: 500;
}

.vcs-dir-step-dist {
    color: #80868b;
    font-size: 12px;
    white-space: nowrap;
    padding-top: 1px;
    flex-shrink: 0;
    font-weight: 500;
}

/* ── Leaflet Routing Machine ─────────────────────────────────────────────────── */

/* Container for the directions panel that LRM adds inside the map */
.vcs-map-container .leaflet-routing-container {
    max-width: 280px;
    max-height: 60%;
    overflow-y: auto;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 0 1px rgba(0, 0, 0, 0.1);
    font-size: 12px;
    z-index: 400;
}

/* Prevent the LRM input panel from overflowing on mobile */
@media (max-width: 480px) {
    .vcs-map-container .leaflet-routing-container {
        max-width: 200px;
    }
}

/* ── Attribution / focus ring ────────────────────────────────────────────────── */
.vcs-map-container .leaflet-container:focus {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

/* Ensure links in attribution bar are readable */
.vcs-map-container .leaflet-control-attribution a {
    color: #2563eb;
}

/* ── Map Type Switcher ────────────────────────────────────────────────────────── */
.vcs-map-type-switcher {
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    padding: 0;
    z-index: 800;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.vcs-map-type-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: transparent;
    border: none;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    color: #202124;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    border-bottom: 1px solid #e8eaed;
    padding: 0;
}

.vcs-map-type-btn:last-child {
    border-bottom: none;
}

.vcs-map-type-btn:hover {
    background: #f0f0f0;
    color: #1a73e8;
}

.vcs-map-type-btn.is-active {
    background: #e8f0fe;
    color: #1a73e8;
}

.vcs-map-type-btn svg {
    width: 20px;
    height: 20px;
    display: block;
}

/* ── Settings-page live preview map ─────────────────────────────────────────── */
#vcs-mapping-preview-map {
    width: 100%;
    height: 300px;
    border: 1px solid #d0d7de;
    border-radius: 8px;
    margin-top: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
