/* Pipeline Map specific styles */

.pipe-layout {
    display: flex;
    height: calc(100vh - 72px);
}

.pipe-map-panel {
    flex: 1;
    overflow: hidden;
    padding: 0;
    background: var(--bg-deep);
    position: relative;
    cursor: grab;
}
.pipe-map-panel.panning { cursor: grabbing; }

#pipeline-svg {
    width: 100%;
    height: 100%;
    min-height: 500px;
    touch-action: none;
}

/* Zoom controls overlay */
.zoom-controls {
    position: absolute;
    bottom: 12px;
    left: 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 10;
}

.zoom-controls button {
    width: 28px;
    height: 28px;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 0;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.zoom-controls button:hover {
    background: var(--bg-hover);
    color: var(--accent);
    border-color: var(--accent);
}

/* Resize handle between map and chart panel */
.resize-handle {
    width: 4px;
    background: var(--bg-surface);
    cursor: col-resize;
    flex-shrink: 0;
    transition: all var(--transition);
    position: relative;
}

.resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 28px;
    background: var(--border-bright);
    border-radius: 0;
    opacity: 0;
    transition: opacity var(--transition);
}

.resize-handle:hover::after,
.resize-handle.dragging::after {
    opacity: 1;
}

.resize-handle:hover, .resize-handle.dragging {
    background: var(--bg-hover);
}

/* Zone labels */
.zone-label {
    font-size: 10px;
    font-weight: 700;
    fill: var(--text-secondary);
    pointer-events: none;
}

/* Pipeline lines */
.pipe-line {
    stroke-width: 4;
    fill: none;
    stroke-linecap: round;
}

/* Segment nodes */
.seg-node {
    cursor: pointer;
    transition: all 0.1s;
}

.seg-node:hover .seg-circle {
    stroke: #fff;
    stroke-width: 2;
    filter: brightness(1.3);
}

.seg-node.selected .seg-circle {
    stroke: var(--accent);
    stroke-width: 3;
    filter: brightness(1.3);
}

.seg-circle {
    stroke: rgba(255,255,255,0.15);
    stroke-width: 1;
    transition: all 0.1s;
}

.seg-label {
    font-size: 9px;
    fill: rgba(255,255,255,0.5);
    pointer-events: none;
    text-anchor: middle;
    font-weight: 500;
}

.seg-flow-label {
    font-size: 8px;
    fill: var(--text-muted);
    pointer-events: none;
    text-anchor: middle;
}

/* Zone background regions */
.zone-bg {
    fill-opacity: 0.04;
    stroke-opacity: 0.1;
    stroke-width: 1;
    rx: 0;
    stroke-dasharray: 4 4;
}

/* Tooltip */
.map-tooltip {
    position: absolute;
    background: var(--bg-elevated);
    border: 1px solid var(--border-bright);
    border-radius: 0;
    padding: 8px 10px;
    font-size: 11px;
    color: var(--text-primary);
    pointer-events: none;
    z-index: 100;
    display: none;
    max-width: 240px;
}

.map-tooltip .tt-name {
    font-weight: 600;
    color: var(--accent);
    font-size: 11px;
}

.map-tooltip .tt-flow {
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.map-tooltip .tt-util {
    margin-top: 2px;
    color: var(--text-secondary);
    font-size: 10px;
}

/* Station picker popup */
.station-picker {
    position: absolute;
    background: var(--bg-elevated);
    border: 1px solid var(--border-bright);
    border-radius: 0;
    padding: 4px 0;
    z-index: 110;
    min-width: 220px;
    animation: picker-in 0.1s ease-out;
}

@keyframes picker-in {
    from { opacity: 0; transform: translateY(-2px); }
    to { opacity: 1; transform: translateY(0); }
}

.sp-title {
    padding: 4px 12px 8px;
    font-size: 9px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

.sp-option {
    padding: 6px 12px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    transition: background var(--transition);
    border-radius: 0;
    margin: 0 2px;
}

.sp-option:hover {
    background: var(--bg-hover);
}

.sp-name {
    color: var(--text-primary);
    font-size: 11px;
    font-weight: 500;
}

.sp-flow {
    font-size: 10px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

/* ── Mobile / iPhone Responsive ──────────────────────────── */

@media (max-width: 640px) {
    .pipe-layout {
        flex-direction: column;
        height: auto;
    }

    .pipe-map-panel {
        height: 40vh;
        min-height: 220px;
    }

    #pipeline-svg {
        min-height: 220px;
    }

    /* Hide resize handle on mobile — stacked layout */
    .resize-handle {
        display: none;
    }

    .chart-panel {
        width: 100%;
        min-width: unset;
        max-width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
        min-height: 300px;
    }

    .chart-container {
        min-height: 250px;
    }

    /* Bigger zoom controls for touch */
    .zoom-controls button {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    /* Tooltip - full width at bottom on mobile */
    .map-tooltip {
        max-width: 90vw;
    }

    /* Station picker */
    .station-picker {
        min-width: 200px;
        max-width: 90vw;
    }

    .sp-option {
        padding: 8px 12px;
        min-height: 40px;
    }
}

/* ── Admin Edit Mode ────────────────────────────────────────────────── */

/* Admin toggle button — sits below zoom controls */
#admin-toggle-btn {
    margin-top: 6px;
    width: auto;
    padding: 3px 8px;
    font-size: 9px;
    letter-spacing: 0.03em;
    white-space: nowrap;
    background: var(--bg-elevated);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 0;
    cursor: pointer;
    transition: all var(--transition);
}

#admin-toggle-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

#admin-toggle-btn.admin-on {
    background: rgba(255, 140, 0, 0.12);
    color: #ff8c00;
    border-color: #ff8c00;
}

/* Admin toolbar — bottom of map panel */
.admin-toolbar {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(17, 17, 17, 0.95);
    border: 1px solid #ff8c00;
    border-radius: 0;
    z-index: 20;
    animation: admin-slide-up 0.1s ease-out;
}

@keyframes admin-slide-up {
    from { opacity: 0; transform: translateX(-50%) translateY(4px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.admin-modes {
    display: flex;
    gap: 2px;
}

.admin-mode-btn {
    padding: 4px 10px;
    font-size: 10px;
    font-weight: 500;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 0;
    cursor: pointer;
    transition: all var(--transition);
}

.admin-mode-btn:hover {
    color: #ff8c00;
    border-color: #ff8c00;
}

.admin-mode-btn.active {
    background: rgba(255, 140, 0, 0.12);
    color: #ff8c00;
    border-color: #ff8c00;
}

.admin-divider {
    width: 1px;
    height: 20px;
    background: var(--border-bright);
    margin: 0 2px;
}

.admin-save-btn {
    padding: 4px 12px;
    font-size: 10px;
    font-weight: 600;
    background: rgba(0, 200, 83, 0.12);
    color: var(--green);
    border: 1px solid var(--green);
    border-radius: 0;
    cursor: pointer;
    transition: all var(--transition);
}

.admin-save-btn:hover {
    background: rgba(0, 200, 83, 0.2);
}

.admin-reset-btn {
    padding: 4px 8px;
    font-size: 10px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 0;
    cursor: pointer;
    transition: all var(--transition);
}

.admin-reset-btn:hover {
    color: var(--red);
    border-color: var(--red);
}

.admin-hint {
    font-size: 9px;
    color: var(--text-muted);
    font-style: italic;
    margin-left: 2px;
    white-space: nowrap;
}

/* Active edit mode indicator — orange border on map */
.admin-edit-active .pipe-map-panel {
    box-shadow: inset 0 0 0 2px rgba(255, 140, 0, 0.3);
}

/* Waypoint handles */
.admin-wp-handle {
    transition: opacity 0.1s;
}

.admin-wp-handle:hover {
    filter: brightness(1.4);
    stroke-width: 2.5;
}

/* Slide handles */
.admin-slide-handle {
    transition: stroke 0.1s, stroke-width 0.1s;
}

.admin-slide-handle:hover {
    stroke: rgba(96, 165, 250, 0.8);
    fill: rgba(96, 165, 250, 0.15);
}

/* Swap rings */
.admin-swap-ring {
    transition: stroke 0.1s, fill 0.1s;
}

.admin-swap-ring:hover {
    stroke: rgba(255, 200, 0, 0.7);
    fill: rgba(255, 200, 0, 0.08);
}

/* Add-line controls */
.admin-addline-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: 8px;
}

.admin-addline-controls select {
    background: #222;
    color: #eee;
    border: 1px solid #555;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 12px;
}

/* During edit mode, change cursor on segment nodes */
.admin-edit-active .seg-node {
    pointer-events: none;
}

/* But re-enable in waypoint mode (nodes aren't interactive there) */
.admin-edit-active .admin-overlay {
    pointer-events: auto;
}

/* ── Builder Sidebar ────────────────────────────────────────────────── */

.admin-segment-sidebar {
    position: absolute;
    top: 44px;
    left: 0;
    width: 220px;
    max-height: calc(100% - 44px);
    background: rgba(10, 10, 10, 0.95);
    border-right: 1px solid var(--border-bright, #333);
    display: flex;
    flex-direction: column;
    z-index: 10;
    font-family: 'Inter', sans-serif;
}

.sidebar-header {
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 600;
    color: #ff8c00;
    border-bottom: 1px solid #333;
}

.sidebar-filter {
    padding: 6px 10px;
    border-bottom: 1px solid #222;
}

.sidebar-filter select {
    width: 100%;
    padding: 4px 6px;
    background: #1a1a1a;
    color: #ccc;
    border: 1px solid #333;
    border-radius: 3px;
    font-size: 11px;
}

.sidebar-segments {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.sidebar-seg {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 11px;
    color: #ccc;
}

.sidebar-seg:hover {
    background: rgba(255, 140, 0, 0.12);
}

.sidebar-seg.seg-selected {
    background: rgba(255, 140, 0, 0.25);
    outline: 1px solid rgba(255, 140, 0, 0.6);
}

.seg-id-label {
    font-weight: 600;
    color: #fff;
    min-width: 30px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
}

.seg-name-label {
    color: #888;
    font-size: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-zone-header {
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: rgba(255,255,255,0.03);
    border-bottom: 1px solid #222;
    margin-top: 2px;
    position: sticky;
    top: 0;
    z-index: 1;
}

.sidebar-zone-group + .sidebar-zone-group {
    margin-top: 4px;
}
