/* Interactive complex map */
.cmap {
    position: relative;
    overflow: hidden;
    max-width: 100%;
}

.cmap::before,
.cmap::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
}

.cmap::before {
    width: 420px;
    height: 420px;
    background: radial-gradient(circle, rgba(139, 92, 246, 0.16), transparent 68%);
    top: -80px;
    left: -120px;
}

.cmap::after {
    width: 320px;
    height: 320px;
    background: radial-gradient(circle, rgba(34, 197, 94, 0.08), transparent 70%);
    bottom: -50px;
    right: -70px;
}

.cmap .container {
    position: relative;
    z-index: 1;
}

.cmap-board {
    background:
        radial-gradient(ellipse at 18% 0%, rgba(139, 92, 246, 0.1), transparent 48%),
        linear-gradient(180deg, #16161f 0%, #12121a 100%);
    border: 1px solid rgba(139, 92, 246, 0.22);
    border-radius: 1.6rem;
    padding: 1.25rem;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.04);
    width: 100%;
    min-width: 0;
    overflow: hidden;
}

.cmap-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.1rem;
}

.cmap-stats {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.cmap-chip {
    background: rgba(139, 92, 246, 0.1);
    border: 1px solid rgba(139, 92, 246, 0.25);
    color: #e4e4e7;
    border-radius: 999px;
    padding: 0.35rem 0.85rem;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.cmap-chip strong {
    color: var(--primary-light);
}

.cmap-tools {
    display: flex;
    flex: 1 1 260px;
    justify-content: flex-end;
    min-width: 0;
}

.cmap-picker {
    position: relative;
    display: block;
    width: 100%;
    max-width: 420px;
    margin-inline-start: auto;
}

.cmap-picker__icon {
    position: absolute;
    top: 50%;
    right: 14px;
    z-index: 2;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: rgba(139, 92, 246, 0.18);
    color: #c4b5fd;
    font-size: 0.82rem;
    pointer-events: none;
}

.cmap-picker > .cmap-select:not(.select2-hidden-accessible) {
    width: 100%;
    height: 48px;
    padding: 0 50px 0 16px;
    background:
        linear-gradient(180deg, rgba(139, 92, 246, 0.12), rgba(15, 15, 19, 0.92)),
        #0f0f13;
    border: 1px solid rgba(139, 92, 246, 0.38);
    border-radius: 1rem;
    color: #f4f4f5;
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    appearance: none;
}

.cmap-picker > .cmap-select:not(.select2-hidden-accessible):focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.18);
}

.cmap-tools .select2-container {
    width: 100% !important;
    font-family: inherit;
}

.cmap-tools .select2-container--default .select2-selection--single {
    height: 48px;
    background:
        linear-gradient(180deg, rgba(139, 92, 246, 0.12), rgba(15, 15, 19, 0.92)),
        #0f0f13;
    border: 1px solid rgba(139, 92, 246, 0.38);
    border-radius: 1rem;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.cmap-tools .select2-container--default.select2-container--open .select2-selection--single,
.cmap-tools .select2-container--default.select2-container--focus .select2-selection--single {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.18);
}

.cmap-tools .select2-container--default .select2-selection--single .select2-selection__rendered {
    color: #f4f4f5;
    line-height: 46px;
    padding-right: 50px;
    padding-left: 44px;
}

.cmap-tools .select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #a1a1aa;
}

.cmap-tools .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 46px;
    left: 10px;
    right: auto;
    width: 28px;
}

.cmap-tools .select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: #c4b5fd transparent transparent transparent;
    margin-top: -1px;
}

.cmap-tools .select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    border-color: transparent transparent #c4b5fd transparent;
}

.cmap-tools .select2-container--default .select2-selection__clear {
    color: #a1a1aa;
    font-size: 1.15rem;
    margin-left: 6px;
    margin-right: 0;
    float: left;
}

.cmap-sel {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    max-width: 100%;
}

.cmap-sel__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cmap-sel__units {
    flex-shrink: 0;
    font-size: 0.72rem;
    color: #c4b5fd;
    background: rgba(139, 92, 246, 0.16);
    border: 1px solid rgba(139, 92, 246, 0.28);
    border-radius: 999px;
    padding: 0.08rem 0.5rem;
    line-height: 1.5;
}

.select2-container {
    z-index: 1080;
}

.select2-dropdown.cmap-select2-drop {
    background: #16161f;
    border: 1px solid rgba(139, 92, 246, 0.4);
    border-radius: 1.1rem;
    overflow: hidden;
    box-shadow: 0 24px 50px rgba(0, 0, 0, 0.45);
    z-index: 1081;
    font-family: 'Vazirmatn', 'Vazir', sans-serif;
}

.select2-dropdown.cmap-select2-drop .select2-search--dropdown {
    padding: 0.7rem 0.7rem 0.35rem;
}

.select2-dropdown.cmap-select2-drop .select2-search--dropdown .select2-search__field {
    width: 100%;
    min-height: 44px;
    background: #0f0f13;
    border: 1px solid rgba(139, 92, 246, 0.35);
    border-radius: 0.8rem;
    color: #f4f4f5;
    font-family: inherit;
    font-size: 16px;
    padding: 0.55rem 0.9rem;
    outline: none;
}

.select2-dropdown.cmap-select2-drop .select2-search--dropdown .select2-search__field:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.16);
}

.select2-dropdown.cmap-select2-drop .select2-results > .select2-results__options {
    max-height: min(52vh, 360px);
    padding: 0.35rem 0.45rem 0.55rem;
}

.select2-dropdown.cmap-select2-drop .select2-results__group {
    color: #c4b5fd;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 0.65rem 0.7rem 0.3rem;
    background: transparent;
}

.select2-dropdown.cmap-select2-drop .select2-results__option--group {
    padding: 0;
    margin: 0;
}

.select2-dropdown.cmap-select2-drop .select2-results__option--selectable {
    color: #e4e4e7;
    border-radius: 0.8rem;
    padding: 0;
    margin: 0.12rem 0;
    cursor: pointer;
}

.select2-dropdown.cmap-select2-drop .cmap-opt {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.65rem 0.75rem;
    min-height: 48px;
}

.select2-dropdown.cmap-select2-drop .cmap-opt__icon {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    border-radius: 0.7rem;
    background: rgba(139, 92, 246, 0.16);
    color: #c4b5fd;
    font-size: 0.78rem;
}

.select2-dropdown.cmap-select2-drop .cmap-opt__body {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.select2-dropdown.cmap-select2-drop .cmap-opt__name {
    font-size: 0.92rem;
    font-weight: 600;
}

.select2-dropdown.cmap-select2-drop .cmap-opt__row {
    font-size: 0.72rem;
    color: #a1a1aa;
}

.select2-dropdown.cmap-select2-drop .cmap-opt__units {
    flex-shrink: 0;
    font-size: 0.72rem;
    color: #c4b5fd;
    background: rgba(139, 92, 246, 0.14);
    border-radius: 999px;
    padding: 0.18rem 0.55rem;
}

.select2-container--default .cmap-select2-drop .select2-results__option--selected .cmap-opt,
.select2-dropdown.cmap-select2-drop .select2-results__option--selected .cmap-opt {
    background: rgba(139, 92, 246, 0.18);
}

.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable .cmap-opt {
    background: linear-gradient(135deg, #7c3aed, #8b5cf6);
    color: #fff;
}

.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable .cmap-opt__icon {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable .cmap-opt__row,
.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable .cmap-opt__units {
    color: #fff;
    background: rgba(255, 255, 255, 0.16);
}

.select2-dropdown.cmap-select2-drop .select2-results__option--disabled {
    color: #a1a1aa;
}

.cmap-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem;
    margin-bottom: 1rem;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.cmap-legend span {
    display: inline-flex;
    align-items: flex-end;
    gap: 0.4rem;
}

.cmap-legend__img {
    height: 28px;
    width: auto;
    display: block;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
}

.cmap-layout {
    display: grid;
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
    gap: 1.1rem;
    align-items: stretch;
    width: 100%;
    min-width: 0;
}

.cmap-main {
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

.cmap-panel {
    background: rgba(26, 26, 36, 0.85);
    border: 1px solid rgba(139, 92, 246, 0.18);
    border-radius: 1.2rem;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.cmap-panel__idle,
.cmap-panel__live {
    display: none;
}

.cmap-panel.is-idle .cmap-panel__idle,
.cmap-panel.is-live .cmap-panel__live {
    display: block;
}

.cmap-panel__badge {
    width: 58px;
    height: 58px;
    border-radius: 1rem;
    display: grid;
    place-items: center;
    font-size: 1.4rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.28), rgba(139, 92, 246, 0.08));
    color: var(--primary-light);
}

.cmap-panel.is-live .cmap-panel__badge {
    background: linear-gradient(135deg, #a78bfa, #7c3aed);
    color: #fff;
    box-shadow: 0 10px 24px rgba(139, 92, 246, 0.4);
}

.cmap-panel h3 {
    font-size: 1.35rem;
    font-weight: 800;
    margin-bottom: 0.35rem;
}

.cmap-panel p {
    color: var(--text-muted);
    margin-bottom: 0;
}

.cmap-meta {
    margin-top: 1.1rem;
    display: grid;
    gap: 0.55rem;
}

.cmap-meta div {
    background: rgba(139, 92, 246, 0.08);
    border-radius: 0.8rem;
    padding: 0.7rem 0.85rem;
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.cmap-meta span {
    color: var(--text-muted);
}

.cmap-meta strong {
    color: #fff;
}

.cmap-hint {
    margin-top: auto;
    padding-top: 1.2rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.cmap-viewport {
    position: relative;
    width: 100%;
    min-width: 0;
}

.cmap-swipe {
    display: none;
    margin: 0 0 0.6rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: center;
}

.cmap-compass {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(15, 15, 19, 0.82);
    display: grid;
    place-items: center;
    z-index: 6;
    font-size: 0.62rem;
    color: var(--primary-light);
    pointer-events: none;
}

.cmap-compass i {
    color: #ef4444;
    font-size: 0.85rem;
}

.cmap-site {
    position: relative;
    border-radius: 1.15rem;
    overflow: hidden;
    background: #2f2f36;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
    width: 100%;
    min-width: 0;
}

.cmap-belt {
    position: relative;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #f4f4f5;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
    z-index: 2;
}

.cmap-belt--n,
.cmap-belt--s {
    height: clamp(22px, 3.2vw, 36px);
    background-image: var(--road-h);
    background-size: auto 100%;
    background-repeat: repeat-x;
    background-position: center;
}

.cmap-belt--w,
.cmap-belt--e {
    width: clamp(22px, 3.4vw, 36px);
    writing-mode: vertical-rl;
    background-image: var(--road-v);
    background-size: 100% auto;
    background-repeat: repeat-y;
    background-position: center;
    gap: 0.8rem;
}

.cmap-belt--w span,
.cmap-belt--e span {
    transform: rotate(180deg);
}

.cmap-gate {
    font-size: 0.62rem;
    font-weight: 800;
    color: #fef3c7;
    background: rgba(15, 15, 19, 0.55);
    border: 1px solid rgba(253, 224, 71, 0.45);
    border-radius: 6px;
    padding: 0.35rem 0.28rem;
}

.cmap-inner {
    display: grid;
    grid-template-columns: clamp(22px, 3.4vw, 36px) minmax(0, 1fr) clamp(22px, 3.4vw, 36px);
    width: 100%;
    min-width: 0;
}

.cmap-yard {
    position: relative;
    z-index: 3;
    background:
        radial-gradient(circle at 18% 20%, rgba(190, 242, 100, 0.12), transparent 42%),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.03) 0 8px, transparent 8px 36px),
        linear-gradient(180deg, #3d6b4a, #2d5438);
    padding: 0.45rem 0.35rem 0.3rem;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
}

.cmap-row {
    display: grid;
    gap: 4px 6px;
    align-items: end;
    justify-items: stretch;
    padding: 0.15rem 0.1rem 0;
    position: relative;
    z-index: 3;
    width: 100%;
    min-width: 0;
}

.cmap-row--6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.cmap-row--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cmap-row--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.cmap-road {
    position: relative;
    z-index: 1;
    height: clamp(14px, 2.2vw, 24px);
    background-image: var(--road-h);
    background-size: auto 100%;
    background-repeat: repeat-x;
    background-position: center;
}

.cmap-tree {
    position: absolute;
    bottom: 35%;
    width: clamp(18px, 3.6vw, 32px);
    height: auto;
    pointer-events: none;
    z-index: 4;
    filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.28));
}

.cmap-tree--b {
    width: clamp(16px, 3.1vw, 26px);
}

.bldg {
    appearance: none;
    border: 0;
    background: transparent;
    padding: 8px 2px 0;
    margin: 0;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    cursor: pointer;
    position: relative;
    z-index: 3;
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    animation: cmapRise 0.45s ease both;
    animation-delay: calc(var(--i, 0) * 12ms);
}

.bldg img {
    display: block;
    width: 100%;
    max-width: 100%;
    height: var(--img-h);
    object-fit: contain;
    object-position: bottom center;
    filter: drop-shadow(0 5px 4px rgba(0, 0, 0, 0.32));
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), filter 0.28s;
    pointer-events: none;
    user-select: none;
}

.bldg--s { --img-h: clamp(40px, 8.5vw, 62px); }
.bldg--m { --img-h: clamp(46px, 9.5vw, 70px); }
.bldg--l { --img-h: clamp(56px, 11.5vw, 86px); }
.bldg--xl { --img-h: clamp(62px, 12.5vw, 96px); }
.bldg--xxl { --img-h: clamp(72px, 14.5vw, 114px); }

.bldg-tag {
    margin-top: 2px;
    font-weight: 800;
    font-size: clamp(0.52rem, 1.3vw, 0.78rem);
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
    line-height: 1;
    background: rgba(15, 15, 19, 0.45);
    border-radius: 999px;
    padding: 0.12rem 0.35rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bldg.is-dim {
    opacity: 0.28;
    filter: grayscale(0.45);
}

.bldg:hover,
.bldg.is-on {
    z-index: 8;
}

.bldg:hover img,
.bldg.is-on img {
    transform: translateY(-8px) scale(1.08);
    filter:
        drop-shadow(0 0 10px rgba(167, 139, 250, 0.9))
        drop-shadow(0 12px 10px rgba(0, 0, 0, 0.35))
        brightness(1.12);
}

.bldg.is-on .bldg-tag {
    background: var(--primary);
    color: #fff;
}

.bldg.is-on::after {
    content: attr(data-name);
    position: absolute;
    bottom: calc(100% - 4px);
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    color: #111;
    font-size: 0.72rem;
    font-weight: 800;
    padding: 0.28rem 0.55rem;
    border-radius: 999px;
    white-space: nowrap;
    z-index: 9;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
    pointer-events: none;
}

.cmap-row .bldg:first-child.is-on::after {
    left: 0;
    transform: none;
}

.cmap-row .bldg:last-child.is-on::after {
    left: auto;
    right: 0;
    transform: none;
}

@keyframes cmapRise {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@media (max-width: 991px) {
    .cmap-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .cmap-panel {
        order: 2;
        min-height: auto;
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .cmap-panel__badge {
        margin: 0 auto 0.6rem;
        flex-shrink: 0;
    }

    .cmap-panel__idle,
    .cmap-panel__live {
        flex: 1;
    }

    .cmap-meta {
        grid-template-columns: 1fr 1fr;
        margin-top: 0.7rem;
    }

    .cmap-hint {
        display: none;
    }

    .cmap-swipe {
        display: block;
    }

    .cmap-viewport {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        padding-bottom: 0.4rem;
        max-width: 100%;
    }

    .cmap-site {
        width: 100%;
        min-width: 0;
    }

    .cmap-belt--w,
    .cmap-belt--e {
        width: 22px;
        font-size: 0.58rem;
        letter-spacing: 0;
    }

    .cmap-inner {
        grid-template-columns: 22px minmax(0, 1fr) 22px;
    }

    .cmap-tree {
        display: none;
    }

    .bldg:hover img,
    .bldg.is-on img {
        transform: translateY(-4px) scale(1.04);
    }
}

@media (max-width: 576px) {
    .cmap-board {
        padding: 0.7rem;
        border-radius: 1.15rem;
    }

    .cmap-tools,
    .cmap-picker {
        width: 100%;
        max-width: none;
        flex-basis: 100%;
    }

    .cmap-tools .select2-container--default .select2-selection--single {
        height: 50px;
        border-radius: 1.05rem;
    }

    .cmap-tools .select2-container--default .select2-selection--single .select2-selection__rendered {
        line-height: 48px;
    }

    .select2-dropdown.cmap-select2-drop .select2-results > .select2-results__options {
        max-height: 48vh;
    }

    .cmap-legend {
        gap: 0.45rem;
        justify-content: center;
    }

    .cmap-legend__img {
        height: 20px;
    }

    .cmap-gate {
        display: none;
    }

    .cmap-compass {
        width: 32px;
        height: 32px;
        top: 6px;
        left: 6px;
        font-size: 0.52rem;
    }

    .bldg {
        padding-top: 4px;
    }

    .bldg--s { --img-h: 42px; }
    .bldg--m { --img-h: 46px; }
    .bldg--l { --img-h: 54px; }
    .bldg--xl { --img-h: 58px; }
    .bldg--xxl { --img-h: 66px; }

    .bldg-tag {
        font-size: 0.5rem;
        padding: 0.08rem 0.22rem;
    }

    .bldg.is-on::after {
        font-size: 0.62rem;
        padding: 0.18rem 0.38rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .bldg,
    .bldg img {
        animation: none;
        transition: none;
    }
}
