/* ============================================================
   SVG Wiring Editor; UI Styles
   Layout, header, toolbar, panels, switches, controls
   Light mode is default; dark mode via body.dark-mode
   ============================================================ */

/* ============================================================
   Base
   ============================================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    height: 100vh;
    overflow: hidden;
    background-color: #f4f5f7;
    color: #1a1a1a;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* ============================================================
   TIFANY-style Header; light default, let TIFANY CSS lead
   ============================================================ */
.tifany-header {
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
}

.tifany-header .logo h1 a {
    color: #0066cc;
    text-decoration: none;
}

.tifany-header .logo h1 {
    color: #0066cc;
}

.tifany-header .logo-accent {
    color: #0099dd;
}

.tifany-header .tool-subtitle {
    display: block;
    font-size: 10px;
    color: rgba(0, 0, 0, 0.45);
    font-weight: 400;
    letter-spacing: 0.3px;
    margin-top: 1px;
    text-align: center;
}

.tifany-header .nav-link {
    color: rgba(0, 0, 0, 0.55);
    font-size: 13px;
    padding: 5px 10px;
    border-radius: 6px;
    text-decoration: none;
    transition: all 150ms ease;
}

.tifany-header .nav-link:hover {
    color: rgba(0, 0, 0, 0.9);
    background: rgba(0, 0, 0, 0.06);
}

.tifany-header .theme-toggle-btn {
    background: none;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: rgba(0, 0, 0, 0.55);
    font-size: 16px;
    transition: all 150ms ease;
    flex-shrink: 0;
}

.tifany-header .theme-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #1a1a1a;
}

/* ============================================================
   Toolbar Strips
   ============================================================ */
.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-end;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: -1px;
    justify-content: flex-end;
}

.custom-bar {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    background-color: rgba(242, 243, 246, 0.97);
    border-bottom: 1px solid rgba(0, 0, 0, 0.07);
    flex-shrink: 0;
}

/* ============================================================
   Accordion panels
   ============================================================ */
.custom-bar .accordion+.panel {
    display: none;
}

.custom-bar .accordion.active+.panel {
    display: flex;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.14);
    color: #1a1a1a;
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(5px);
    margin-right: 4px;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn:hover {
    background: rgba(0, 0, 0, 0.1);
    border-color: rgba(0, 0, 0, 0.25);
    transform: translateY(-1px);
}

.btn.active {
    background: rgba(79, 172, 254, 0.18);
    border-color: #4facfe;
    color: #0066cc;
}

.btn:disabled,
.btn.disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}

.btn.primary {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    border: none;
}

.slide-bar {
    background: rgba(235, 236, 240, 0.9) !important;
    color: #333;
    border: none;
    border-right: 1px solid rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    cursor: pointer;
    flex-shrink: 0;
}

.sidebar-nav-rail {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}


.sidebar-nav-rail a,
.sidebar-nav-rail a:hover {
    padding: 4px 6px;
    border-radius: 5px;
}

/* ============================================================
   Toggle Switch
   ============================================================ */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    background-color: rgba(0, 0, 0, 0.18);
    border-radius: 24px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    overflow: hidden;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.switch-slider {
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    top: 3px;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.switch.active {
    background-color: #4facfe;
}

.switch.active .switch-slider {
    transform: translateX(20px);
}

.switch-content {
    white-space: nowrap;
    color: rgba(0, 0, 0, 0.55);
    font-size: 11px;
    margin: 0 4px;
    display: flex;
    align-items: center;
    gap: 3px;
}

/* ============================================================
   Main Layout (sidebar + viewer)
   ============================================================ */
.main-layout {
    flex: 1;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    min-height: 0;
}

/* ============================================================
   SVG Viewer Area
   ============================================================ */
.svg-viewer {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: radial-gradient(circle at center, rgba(0, 0, 0, 0.03) 0%, transparent 70%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
}

.svg-container {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    /* Fix #2: clips content that moves outside bounds */
    cursor: grab;
    touch-action: none;
}

.svg-container:active {
    cursor: grabbing;
}

/* #svgWrapper receives CSS transforms only for 3D effects
   (rotation, pitch, yaw).  Zoom + pan are handled via SVG
   viewBox so content is always crisp at every zoom level.
   will-change is intentionally omitted — GPU compositing
   would rasterize the SVG and cause blurry zoom. */
.svg-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-origin: 50% 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* SVG fills wrapper; viewBox controls the logical coordinate space */
.svg-wrapper svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* ============================================================
   Bottom Controls
   ============================================================ */
.bottom-controls {
    background: rgba(242, 243, 246, 0.97);
    backdrop-filter: blur(15px);
    padding: 8px;
    display: flex;
    /* grid-template-columns: repeat(auto-fit, minmax(40px, 1fr)); */
    gap: 6px;
    border-top: 1px solid rgba(0, 0, 0, 0.07);
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    flex-shrink: 0;
    position: absolute;
    bottom: 5px;
    left: 25%;
    right: 25%;
    border-radius: 10px;
    overflow: auto;
}

.bottom-controls.expanded {
    display: none;
}

.control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 10px;
    color: rgba(0, 0, 0, 0.6);
}

.control-btn:hover,
.control-btn.active {
    background: rgba(79, 172, 254, 0.12);
    border-color: rgba(79, 172, 254, 0.4);
    color: #0066cc;
}

.control-btn:active {
    transform: scale(0.95);
    background: rgba(67, 162, 245, 0.22);
}

.control-btn .icon {
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-group {
    margin: 4px;
    background: rgba(0, 0, 0, 0.03);
    padding: 10px;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.07);
}

.control-group-flex {
    display: flex;
    flex-wrap: wrap;
    margin: 4px;
    background: rgba(0, 0, 0, 0.04);
    padding: 5px;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    align-items: center;
}

.control-group h3,
.custom-bar h3 {
    margin: 8px;
    color: #0066cc;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ============================================================
   Side Panel
   ============================================================ */
.side-panel {
    position: fixed;
    top: 0;
    right: -320px;
    width: 320px;
    height: 100vh;
    background: #ffffff;
    backdrop-filter: blur(20px);
    border-left: 1px solid rgba(0, 0, 0, 0.1);
    transition: right 0.3s ease;
    z-index: 2000;
    overflow-y: auto;
}

.side-panel.open {
    right: 0;
}

.side-panel-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.07);
    border: none;
    color: #1a1a1a;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.side-panel-close:hover {
    background: rgba(0, 0, 0, 0.13);
}

/* ============================================================
   Layers Panel (side panel tree)
   ============================================================ */
.layers-tree {
    font-size: 11px;
    font-family: 'Courier New', monospace;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 4px;
    margin: 2px 0;
    background: rgba(79, 172, 254, 0.06);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-left: 2px solid transparent;
}

.layer-item:hover {
    background: rgba(79, 172, 254, 0.14);
    border-left-color: #4facfe;
}

.layer-item.active {
    background: rgba(79, 172, 254, 0.2);
    border-left-color: #0099dd;
    color: #0066cc;
}

.layer-item-locked {
    border-left-color: rgba(251, 191, 36, 0.5);
    background: rgba(251, 191, 36, 0.05);
}

.layer-item-locked:hover {
    background: rgba(251, 191, 36, 0.1);
    border-left-color: #fbbf24;
}

.layer-item-locked .layer-name {
    color: rgba(255, 255, 255, 0.4);
    cursor: default;
    font-style: italic;
}

.layer-lock-btn {
    transition: color 0.15s;
}

.layer-lock-btn:hover {
    color: #fbbf24 !important;
}

body:not(.dark-mode) .layer-item-locked .layer-name {
    color: rgba(0, 0, 0, 0.35);
}

.layer-toggle {
    width: 18px;
    height: 18px;
    background: none;
    border: none;
    color: rgba(0, 0, 0, 0.5);
    cursor: pointer;
    font-size: 10px;
    padding: 0;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.layer-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 10px;
    cursor: text;
}

.layer-name-input {
    flex: 1;
    background: rgba(79, 172, 254, 0.12);
    border: 1px solid #4facfe;
    border-radius: 3px;
    color: inherit;
    font-size: 10px;
    font-family: inherit;
    padding: 1px 5px;
    min-width: 0;
    width: 100%;
    outline: none;
}

.layer-name-input:focus {
    background: rgba(79, 172, 254, 0.2);
    box-shadow: 0 0 0 2px rgba(79, 172, 254, 0.3);
}

/* ── Topology layer groups ──────────────────────────────── */
.layer-group {
    margin-bottom: 6px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.07);
}

.layer-group-header {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 7px;
    background: rgba(0, 0, 0, 0.04);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
    font-size: 11px;
    font-weight: 600;
}

.layer-group-header:hover {
    background: rgba(0, 0, 0, 0.08);
}

.layer-group-arrow {
    font-size: 9px;
    color: rgba(0, 0, 0, 0.4);
    width: 10px;
    flex-shrink: 0;
}

.layer-group-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.layer-group-count {
    font-size: 9px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    padding: 1px 5px;
    color: rgba(0, 0, 0, 0.5);
    font-weight: 500;
}

.layer-group-body {
    max-height: 600px;
    overflow: hidden;
    transition: max-height 0.25s ease;
}

.layer-group-body.collapsed {
    max-height: 0;
}

/* Topology item row */
.topo-item {
    padding: 4px 7px 4px 10px;
    gap: 6px;
}

.layer-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
    opacity: 0.85;
}

.layer-extra {
    font-size: 9px;
    color: rgba(0, 0, 0, 0.35);
    font-family: 'Courier New', monospace;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ============================================================
   Timeline Panel; thumbnail filmstrip, same style as bottom controls
   ============================================================ */
.timeline-panel {
    display: none;
    background: rgba(242, 243, 246, 0.97);
    backdrop-filter: blur(15px);
    border-top: 1px solid rgba(0, 0, 0, 0.07);
    padding: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    flex-shrink: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

.timeline-panel.open {
    display: flex;
}

.timeline-tracks {
    display: flex;
    gap: 6px;
    align-items: flex-start;
}

.timeline-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 4px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 10px;
    color: rgba(0, 0, 0, 0.6);
    min-width: 72px;
    flex-shrink: 0;
    position: relative;
}

.timeline-card:hover {
    background: rgba(79, 172, 254, 0.12);
    border-color: rgba(79, 172, 254, 0.4);
    color: #0066cc;
}

.timeline-card:active {
    transform: scale(0.95);
    background: rgba(79, 172, 254, 0.22);
}

.timeline-card.active {
    background: rgba(79, 172, 254, 0.14);
    border-color: #4facfe;
    color: #0066cc;
}

.timeline-card-preview {
    width: 60px;
    height: 42px;
    background: white;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.timeline-card-preview svg {
    width: 100%;
    height: 100%;
    display: block;
}

.timeline-card-name {
    font-size: 9px;
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    color: inherit;
}

.timeline-card-del {
    position: absolute;
    top: 2px;
    right: 3px;
    background: none;
    border: none;
    font-size: 9px;
    color: rgba(0, 0, 0, 0.25);
    cursor: pointer;
    line-height: 1;
    padding: 1px 2px;
    border-radius: 2px;
    display: none;
}

.timeline-card:hover .timeline-card-del {
    display: block;
}

.timeline-card-del:hover {
    color: #e53935;
    background: rgba(229, 57, 53, 0.08);
}

.timeline-add-card {
    border-style: dashed;
    color: rgba(0, 0, 0, 0.35);
}

.timeline-add-card:hover {
    border-style: solid;
}

/* ============================================================
   Sliders
   ============================================================ */
.slider-group {
    margin: 10px 0;
}

.slider-group label {
    display: block;
    font-size: 11px;
    margin-bottom: 5px;
    color: rgba(0, 0, 0, 0.6);
}

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

.slider::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #4facfe;
    cursor: pointer;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
}

.value-display {
    font-size: 10px;
    color: rgba(0, 0, 0, 0.42);
    margin-top: 3px;
}

/* ============================================================
   Toast
   ============================================================ */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.96);
    color: #1a1a1a;
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 12px;
    z-index: 3000;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.toast.show {
    opacity: 1;
}

.toast.success {
    border-color: rgba(76, 175, 80, 0.5);
}

.toast.error {
    border-color: rgba(244, 67, 54, 0.5);
}

/* ============================================================
   Loading Indicator
   ============================================================ */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 13px;
    color: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    gap: 10px;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(0, 0, 0, 0.12);
    border-radius: 50%;
    border-top-color: #4facfe;
    animation: spin 0.8s ease-in-out infinite;
}

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

/* ============================================================
   Touch Feedback Ripple
   ============================================================ */
.touch-feedback {
    position: absolute;
    width: 36px;
    height: 36px;
    background: rgba(79, 172, 254, 0.22);
    border-radius: 50%;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0);
    animation: touch-ripple 0.5s ease-out forwards;
}

@keyframes touch-ripple {
    to {
        transform: translate(-50%, -50%) scale(2.5);
        opacity: 0;
    }
}

/* ============================================================
   Mini Map
   ============================================================ */
.mini-map {
    position: absolute;
    bottom: 90px;
    left: 60px;
    width: 120px;
    height: 80px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 8px;
    overflow: hidden;
    z-index: 500;
    opacity: 0;
    transition: opacity 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.mini-map.visible {
    opacity: 1;
}

.mini-map svg {
    width: 100%;
    height: 100%;
}

.mini-map-viewport {
    position: absolute;
    border: 2px solid #4facfe;
    background: rgba(79, 172, 254, 0.15);
    pointer-events: none;
}

/* ============================================================
   3D Perspective Wrapper
   ============================================================ */
.svg-wrapper.perspective-3d {
    perspective: var(--perspective-distance, 1500px);
    transform-style: preserve-3d;
}

.svg-wrapper.perspective-3d #svgDisplay {
    transform-style: preserve-3d;
    transition: transform 0.1s ease-out;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
    .panel-content {
        display: none;
    }

    .btn {
        /* padding: 4px 6px; */
        font-size: 20px;
        background: none;
        border: none;
    }

    .side-panel {
        width: 50%;
        right: -100%;
    }

    .slide-bar {
        writing-mode: sideways-lr;
    }

    .bottom-controls {
        width: 72%;
        left: 15%;
    }

    .control-group-flex {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .header-left {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 5px;
        margin: 6px 0;
    }
}

/* ============================================================
   DARK MODE; body.dark-mode overrides
   ============================================================ */
body.dark-mode {
    background-color: #bfbfbf;
    color: white;
}

body.dark-mode .tifany-header {
    background: rgba(18, 18, 18, 0.97) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
    backdrop-filter: blur(10px);
}

body.dark-mode .tifany-header .logo h1 a,
body.dark-mode .tifany-header .logo h1 {
    color: #4facfe;
}

body.dark-mode .tifany-header .logo-accent {
    color: #00f2fe;
}

body.dark-mode .tifany-header .tool-subtitle {
    color: rgba(255, 255, 255, 0.45);
}

body.dark-mode .tifany-header .nav-link {
    color: rgba(255, 255, 255, 0.55) !important;
}

body.dark-mode .tifany-header .nav-link:hover {
    color: rgba(255, 255, 255, 0.9) !important;
    background: rgba(255, 255, 255, 0.07) !important;
}

body.dark-mode .tifany-header .theme-toggle-btn {
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    color: rgba(255, 255, 255, 0.6) !important;
}

body.dark-mode .tifany-header .theme-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    color: white !important;
}

body.dark-mode .custom-bar {
    background-color: rgb(40 40 40 / 97%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

body.dark-mode .btn {
    background: rgb(79 172 254 / 18%);
    border: 1px solid rgba(79, 172, 254, 0.3);
    color: white;
}

body.dark-mode .btn:hover,
body.dark-mode .btn.active {
    background: rgba(79, 172, 254, 0.35);
}

body.dark-mode .slide-bar {
    background: rgb(55 55 55 / 90%) !important;
    color: rgba(255, 255, 255, 0.8);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

body.dark-mode .switch {
    background-color: rgba(255, 255, 255, 0.2);
}

body.dark-mode .switch-content {
    color: rgba(255, 255, 255, 0.7);
}

body.dark-mode .svg-viewer {
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.04) 0%, transparent 70%);
}

body.dark-mode .bottom-controls {
    background: rgb(40 40 40 / 97%);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

body.dark-mode .control-btn {
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.7);
}

body.dark-mode .control-btn:hover {
    background: rgba(79, 172, 254, 0.15);
    border-color: rgba(79, 172, 254, 0.4);
    color: #4facfe;
}

body.dark-mode .control-btn:active {
    background: rgba(79, 172, 254, 0.25);
}

body.dark-mode .control-group {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

body.dark-mode .control-group-flex {
    background: rgb(0 0 0 / 15%);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

body.dark-mode .control-group h3,
body.dark-mode .custom-bar h3 {
    color: #4facfe;
}

body.dark-mode .side-panel {
    background: rgb(28 28 28);
    border-left: 1px solid rgba(255, 255, 255, 0.08);
}

body.dark-mode .side-panel-close {
    background: rgba(255, 255, 255, 0.08);
    color: white;
}

body.dark-mode .side-panel-close:hover {
    background: rgba(255, 255, 255, 0.15);
}

body.dark-mode .layer-toggle {
    color: rgba(255, 255, 255, 0.6);
}

body.dark-mode .layer-item.active {
    color: #00f2fe;
}

/* Dark mode — topology layer groups */
body.dark-mode .layer-group {
    border-color: rgba(255, 255, 255, 0.07);
}

body.dark-mode .layer-group-header {
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.85);
}

body.dark-mode .layer-group-header:hover {
    background: rgba(255, 255, 255, 0.08);
}

body.dark-mode .layer-group-arrow {
    color: rgba(255, 255, 255, 0.3);
}

body.dark-mode .layer-group-count {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.4);
}

body.dark-mode .topo-item {
    background: rgba(255, 255, 255, 0.03);
}

body.dark-mode .topo-item:hover {
    background: rgba(255, 255, 255, 0.07);
    border-left-color: rgba(255, 255, 255, 0.2);
}

body.dark-mode .topo-item.active {
    background: rgba(79, 172, 254, 0.15);
    border-left-color: #4facfe;
    color: #4facfe;
}

body.dark-mode .layer-extra {
    color: rgba(255, 255, 255, 0.25);
}

body.dark-mode .timeline-panel {
    background: rgb(40 40 40 / 97%);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

body.dark-mode .timeline-card {
    border-color: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.7);
}

body.dark-mode .timeline-card:hover {
    background: rgba(79, 172, 254, 0.15);
    border-color: rgba(79, 172, 254, 0.4);
    color: #4facfe;
}

body.dark-mode .timeline-card.active {
    background: rgba(79, 172, 254, 0.18);
    border-color: #4facfe;
    color: #4facfe;
}

body.dark-mode .timeline-card-preview {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.08);
}

body.dark-mode .timeline-card-del {
    color: rgba(255, 255, 255, 0.25);
}

body.dark-mode .slider-group label {
    color: rgba(255, 255, 255, 0.7);
}

body.dark-mode .slider {
    background: rgba(255, 255, 255, 0.15);
}

body.dark-mode .value-display {
    color: rgba(255, 255, 255, 0.45);
}

body.dark-mode .toast {
    background: rgba(10, 10, 10, 0.92);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: none;
}

body.dark-mode .loading {
    color: rgba(255, 255, 255, 0.7);
}

body.dark-mode .loading::after {
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: #4facfe;
}

body.dark-mode .mini-map {
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: none;
}

/* Sidebar nav dark override */
body.dark-mode .sidebar-nav-rail {
    background: rgb(28 28 28 / 98%) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.07) !important;
}

body.dark-mode .sidebar-nav-rail a,
body.dark-mode .sidebar-nav-rail button {
    color: rgba(255, 255, 255, 0.45) !important;
}

body.dark-mode .sidebar-nav-rail a:hover,
body.dark-mode .sidebar-nav-rail button:hover {
    background: rgba(79, 172, 254, 0.15) !important;
    color: #4facfe !important;
}

body.dark-mode .sidebar-nav-rail a.active {
    color: #4facfe !important;
    background: rgba(79, 172, 254, 0.2) !important;
}

/* ============================================================
   Modal; shared base
   ============================================================ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-backdrop.open {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    width: 100%;
    max-width: 340px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-title {
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    color: #1a1a1a;
}

/* ── Measure Modal ───────────────────────────────────────── */

.measure-tabs {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 8px;
    padding: 3px;
}

.measure-tab {
    flex: 1;
    padding: 5px 0;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    color: rgba(0, 0, 0, 0.5);
    transition: background 0.15s, color 0.15s;
}

.measure-tab.active {
    background: #fff;
    color: #0066cc;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.measure-unit-btns {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.measure-unit-btn {
    padding: 5px 14px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    background: transparent;
    font-size: 12px;
    cursor: pointer;
    color: #1a1a1a;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.measure-unit-btn.active {
    background: #0066cc;
    border-color: #0066cc;
    color: #fff;
}

.measure-scale-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.measure-scale-input {
    width: 64px;
    padding: 5px 8px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    font-size: 12px;
    text-align: center;
    background: transparent;
    color: #1a1a1a;
}

.measure-scale-sep {
    font-size: 11px;
    color: rgba(0, 0, 0, 0.45);
    white-space: nowrap;
}

.measure-scale-unit-label {
    font-size: 11px;
    font-weight: 600;
    color: #0066cc;
    min-width: 24px;
}

.measure-hint {
    font-size: 11px;
    color: rgba(0, 0, 0, 0.45);
    margin-top: 4px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding-top: 4px;
}

.btn-ghost {
    background: transparent;
    border: 1px solid rgba(0, 0, 0, 0.15);
    color: rgba(0, 0, 0, 0.6);
}

.btn-primary {
    background: #0066cc;
    border: 1px solid #0066cc;
    color: #fff;
}

.btn-primary:hover {
    background: #0055aa;
    border-color: #0055aa;
}

/* ── Dark mode; Modal ───────────────────────────────────── */

body.dark-mode .modal {
    background: #1e1e1e;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

body.dark-mode .modal-title {
    color: rgba(255, 255, 255, 0.9);
}

body.dark-mode .measure-tabs {
    background: rgba(255, 255, 255, 0.07);
}

body.dark-mode .measure-tab {
    color: rgba(255, 255, 255, 0.4);
}

body.dark-mode .measure-tab.active {
    background: rgba(255, 255, 255, 0.1);
    color: #4facfe;
    box-shadow: none;
}

body.dark-mode .measure-unit-btn {
    border-color: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.7);
}

body.dark-mode .measure-unit-btn.active {
    background: #4facfe;
    border-color: #4facfe;
    color: #000;
}

body.dark-mode .measure-scale-input {
    border-color: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.8);
    background: rgba(255, 255, 255, 0.05);
}

body.dark-mode .measure-scale-sep {
    color: rgba(255, 255, 255, 0.35);
}

body.dark-mode .measure-scale-unit-label {
    color: #4facfe;
}

body.dark-mode .measure-hint {
    color: rgba(255, 255, 255, 0.35);
}

body.dark-mode .btn-ghost {
    border-color: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.55);
}

body.dark-mode .btn-primary {
    background: #4facfe;
    border-color: #4facfe;
    color: #000;
}

body.dark-mode .btn-primary:hover {
    background: #3d9ef0;
    border-color: #3d9ef0;
}

/* ============================================================
   PHASE 1 — Side Panel Tabs
   ============================================================ */
.side-panel-tabs {
    display: flex;
    gap: 3px;
    padding: 0 8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.side-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 7px 4px;
    font-size: 11px;
    font-weight: 500;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    color: rgba(0, 0, 0, 0.45);
    transition: all 0.15s ease;
    white-space: nowrap;
}

.side-tab:hover {
    color: rgba(0, 0, 0, 0.75);
}

.side-tab.active {
    color: #0066cc;
    border-bottom-color: #4facfe;
}

body.dark-mode .side-panel-tabs {
    border-bottom-color: rgba(255, 255, 255, 0.07);
}

body.dark-mode .side-tab {
    color: rgba(255, 255, 255, 0.35);
}

body.dark-mode .side-tab:hover {
    color: rgba(255, 255, 255, 0.75);
}

body.dark-mode .side-tab.active {
    color: #4facfe;
    border-bottom-color: #4facfe;
}

/* ============================================================
   PHASE 1 — Property Panel
   ============================================================ */
.prop-panel {
    padding: 8px 10px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.prop-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #0066cc;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 0 4px;
}

body.dark-mode .prop-section-title {
    color: #4facfe;
}

.prop-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: rgba(0, 0, 0, 0.4);
    margin-top: 8px;
    margin-bottom: 2px;
}

body.dark-mode .prop-section-label {
    color: rgba(255, 255, 255, 0.35);
}

.prop-section {
    margin-top: 4px;
}

.prop-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.prop-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.prop-label {
    font-size: 10px;
    color: rgba(0, 0, 0, 0.55);
    display: flex;
    flex-direction: column;
    gap: 3px;
}

body.dark-mode .prop-label {
    color: rgba(255, 255, 255, 0.5);
}

.prop-input {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 5px;
    font-size: 11px;
    background: rgba(79, 172, 254, 0.07);
    color: inherit;
    outline: none;
    transition: border-color 0.15s;
}

.prop-input:focus {
    border-color: #4facfe;
}

body.dark-mode .prop-input {
    background: rgba(79, 172, 254, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
}

body.dark-mode .prop-input:focus {
    border-color: #4facfe;
}

.prop-slider {
    width: 100%;
    height: 4px;
    background: rgba(0, 0, 0, 0.12);
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.prop-slider::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #4facfe;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

body.dark-mode .prop-slider {
    background: rgba(255, 255, 255, 0.15);
}

.prop-pill {
    font-size: 10px;
    color: #4facfe;
    font-weight: 600;
    white-space: nowrap;
    min-width: 30px;
    text-align: right;
}

.prop-select {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 5px;
    font-size: 11px;
    background: rgba(79, 172, 254, 0.07);
    color: inherit;
    outline: none;
}

body.dark-mode .prop-select {
    background: rgba(79, 172, 254, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
}

.prop-color-wrap {
    display: flex;
    align-items: center;
    gap: 5px;
}

.prop-color {
    width: 28px;
    height: 22px;
    border: none;
    border-radius: 4px;
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
    background: none;
}

.prop-color-hex {
    font-size: 10px;
    color: rgba(0, 0, 0, 0.5);
    font-family: monospace;
}

body.dark-mode .prop-color-hex {
    color: rgba(255, 255, 255, 0.4);
}

.prop-textarea {
    width: 100%;
    padding: 5px 7px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 5px;
    font-size: 11px;
    background: rgba(79, 172, 254, 0.07);
    color: inherit;
    outline: none;
    resize: vertical;
    font-family: inherit;
}

body.dark-mode .prop-textarea {
    background: rgba(79, 172, 254, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
}

.prop-no-fill-btn {
    font-size: 10px;
    padding: 3px 10px;
    margin-top: 2px;
}

.prop-info-row {
    font-size: 10px;
    align-items: center;
}

.prop-value-tag {
    font-size: 10px;
    font-family: monospace;
    background: rgba(79, 172, 254, 0.12);
    border: 1px solid rgba(79, 172, 254, 0.25);
    border-radius: 4px;
    padding: 1px 6px;
    color: #4facfe;
}

/* Align button row */
.prop-align-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.prop-align-btn {
    padding: 5px 7px !important;
    font-size: 16px !important;
    min-width: 32px;
}


/* ============================================================
   PHASE 1 — New Canvas Modal
   ============================================================ */
/* (Re-uses existing .modal, .modal-backdrop, .modal-title,
   .modal-actions, .btn-primary, .btn-ghost styles — no additions needed) */

/* ============================================================
   BUG-FIX PASS — Visual corrections
   ============================================================ */

/* ── Fix #3: Canvas background — neutral checkerboard,
   no longer a solid blue-tinted surface ───────────────────── */
.svg-viewer {
    background: #dfe1e6;
    background-image:
        linear-gradient(45deg, rgba(0, 0, 0, 0.04) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(0, 0, 0, 0.04) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(0, 0, 0, 0.04) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(0, 0, 0, 0.04) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

body.dark-mode .svg-viewer {
    background: #1a1b22;
    background-image:
        linear-gradient(45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.025) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.025) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

/* ── Fix #3: Dark mode button neutrals ──────────────────────── */
body.dark-mode .btn {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.14);
    color: rgba(255, 255, 255, 0.85);
}

body.dark-mode .btn:hover {
    background: rgba(255, 255, 255, 0.13);
    border-color: rgba(255, 255, 255, 0.28);
}

body.dark-mode .btn.active {
    background: rgba(79, 172, 254, 0.22);
    border-color: #4facfe;
    color: #4facfe;
}

body.dark-mode .btn:disabled {
    opacity: 0.3;
}

/* ── Fix #3: Neutral snap guides (distinguish from selection) ── */
.snap-guide {
    stroke: #f0a500 !important;
    stroke-width: 0.75;
    stroke-dasharray: 4, 4;
    opacity: 0.55;
}

/* Figma-style alignment guides — solid, bounded, pink-red */
.snap-guide.snap-align {
    stroke: #ff6b9d !important;
    stroke-width: 1 !important;
    stroke-dasharray: none !important;
    opacity: 0.9 !important;
}

/* ── Fix #3: Grid lines — gray, not blue ─────────────────────── */
.grid-line-minor {
    stroke: rgba(128, 128, 128, 0.2);
    stroke-width: 0.5;
}

.grid-line-major {
    stroke: rgba(128, 128, 128, 0.4);
    stroke-width: 1;
}

/* Specifically override the grid pattern colors set by snapGrid.js */
#snap-grid-minor {
    stroke: rgba(128, 128, 128, 0.22) !important;
}

#snap-grid-major {
    stroke: rgba(128, 128, 128, 0.42) !important;
}

/* ── Fix #5: editToolbar — horizontal scroll, hidden scrollbar ── */
#editToolbar {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    padding-bottom: 2px;
}

#editToolbar::-webkit-scrollbar {
    display: none;
}

#editToolbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* ── Fix #4: Mode switcher — mobile responsive dropdown ─────── */
/* Desktop: show pills, hide select */
.mode-switcher-select {
    display: none;
}

/* Mobile (<= 640px): hide pills, show native select */
@media (max-width: 640px) {
    .mode-switcher {
        display: none !important;
    }

    .mode-switcher-select {
        display: block;
        padding: 4px 8px;
        font-size: 12px;
        border: 1px solid rgba(79, 172, 254, 0.35);
        border-radius: 8px;
        background: rgba(79, 172, 254, 0.1);
        color: inherit;
        cursor: pointer;
        flex-shrink: 0;
    }

    body.dark-mode .mode-switcher-select {
        background: rgba(79, 172, 254, 0.18);
        border-color: rgba(79, 172, 254, 0.5);
        color: #4facfe;
    }

    /* Secondary toolbar wraps on mobile */
    .custom-bar.header-right .header-right {
        flex-wrap: wrap;
        gap: 4px;
    }
}

/* ── Fix #2: Ensure svgWrapper never overflows or scrolls ──── */
.svg-viewer {
    overflow: hidden;
}

/* ── Draw tool active state — keep blue for new content ─────── */
.draw-tool-btn.active {
    background: rgba(79, 172, 254, 0.22) !important;
    border-color: #4facfe !important;
    color: #0066cc !important;
    box-shadow: 0 0 6px rgba(79, 172, 254, 0.25);
}

body.dark-mode .draw-tool-btn.active {
    color: #4facfe !important;
}

/* ============================================================
   TAFNE Pipeline Modal
   ============================================================ */

.tafne-pipeline-modal {
    max-width: 400px;
}

.tafne-steps {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tafne-step {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

body:not(.dark-mode) .tafne-step {
    border-bottom-color: rgba(0, 0, 0, 0.06);
}

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

.tafne-step-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 700;
    margin-top: 1px;
}

.tafne-step-icon.pending {
    color: rgba(255, 255, 255, 0.25);
}

.tafne-step-icon.done {
    color: #34d399;
}

.tafne-step-icon.error {
    color: #ef4444;
}

.tafne-step-icon.skipped {
    color: rgba(255, 255, 255, 0.2);
}

body:not(.dark-mode) .tafne-step-icon.pending {
    color: rgba(0, 0, 0, 0.2);
}

.tafne-step-icon.running {
    position: relative;
    color: transparent;
}

.tafne-step-icon.running::after {
    content: '';
    position: absolute;
    inset: 2px;
    border-radius: 50%;
    border: 2px solid rgba(79, 172, 254, 0.25);
    border-top-color: #4facfe;
    animation: tafne-spin 0.7s linear infinite;
}

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

.tafne-step-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.tafne-step-label {
    font-size: 12px;
    color: inherit;
    line-height: 1.4;
}

.tafne-step[data-state="pending"] .tafne-step-label {
    opacity: 0.4;
}

.tafne-step[data-state="done"] .tafne-step-label {
    color: #34d399;
}

.tafne-step[data-state="error"] .tafne-step-label {
    color: #ef4444;
}

.tafne-step-detail {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

body:not(.dark-mode) .tafne-step-detail {
    color: rgba(0, 0, 0, 0.4);
}

.tafne-pipeline-footer {
    font-size: 11px;
    padding: 6px 4px 0;
    min-height: 18px;
    font-style: italic;
}

.tafne-pipeline-footer.success {
    color: #34d399;
    font-style: normal;
    font-weight: 600;
}

.tafne-pipeline-footer.error {
    color: #ef4444;
    font-style: normal;
}

.tafne-pipeline-footer.info {
    color: rgba(255, 255, 255, 0.45);
}

/* ============================================================
   Back-Annotate Modal
   ============================================================ */

.ba-modal {
    max-width: 460px;
    width: 100%;
}

.ba-summary {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    margin: 0 0 12px;
    line-height: 1.5;
}

body:not(.dark-mode) .ba-summary {
    color: rgba(0, 0, 0, 0.45);
}

.ba-safe-ct {
    color: #34d399;
    font-weight: 600;
}

.ba-review-ct {
    color: #f59e0b;
    font-weight: 600;
}

.ba-section {
    margin-bottom: 10px;
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 6px;
    overflow: hidden;
}

body:not(.dark-mode) .ba-section {
    border-color: rgba(0, 0, 0, 0.09);
}

.ba-section-hdr {
    font-size: 11px;
    font-weight: 600;
    padding: 6px 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.ba-section-hdr.safe {
    background: rgba(52, 211, 153, 0.12);
    color: #34d399;
}

.ba-section-hdr.review {
    background: rgba(245, 158, 11, 0.10);
    color: #f59e0b;
}

.ba-rows {
    display: flex;
    flex-direction: column;
}

.ba-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 7px 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 12px;
    line-height: 1.4;
}

body:not(.dark-mode) .ba-row {
    border-top-color: rgba(0, 0, 0, 0.05);
}

.ba-row:first-child {
    border-top: none;
}

.ba-tag {
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.ba-tag.safe {
    background: rgba(52, 211, 153, 0.15);
    color: #34d399;
}

.ba-tag.added {
    background: rgba(79, 172, 254, 0.15);
    color: #4facfe;
}

.ba-tag.removed {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.ba-tag.conflict {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.ba-desc {
    display: flex;
    align-items: baseline;
    gap: 5px;
    flex-wrap: wrap;
    color: rgba(255, 255, 255, 0.8);
    min-width: 0;
}

body:not(.dark-mode) .ba-desc {
    color: rgba(0, 0, 0, 0.75);
}

.ba-desc strong {
    color: inherit;
    font-weight: 600;
}

.ba-from {
    color: rgba(255, 255, 255, 0.4);
    text-decoration: line-through;
    font-style: italic;
}

.ba-to {
    color: #34d399;
    font-weight: 600;
}

.ba-arrow {
    color: rgba(255, 255, 255, 0.25);
    font-size: 10px;
}

body:not(.dark-mode) .ba-from {
    color: rgba(0, 0, 0, 0.35);
}

body:not(.dark-mode) .ba-arrow {
    color: rgba(0, 0, 0, 0.2);
}

.ba-empty {
    padding: 8px 10px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.25);
    font-style: italic;
}

body:not(.dark-mode) .ba-empty {
    color: rgba(0, 0, 0, 0.3);
}

/* ============================================================
   Layer Panel — Scene Graph View (Structure + Analysis)
   ============================================================ */

/* ── View toggle (Structure / Analysis) ─────────────────── */
.layer-view-toggle {
    display: flex;
    gap: 2px;
    background: rgba(0, 0, 0, 0.49);
    border-radius: 6px;
    padding: 2px;
    margin-bottom: 6px;
}

.lvt-btn {
    flex: 1;
    background: none;
    border: none;
    border-radius: 4px;
    padding: 4px 6px;
    font-size: 10px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    transition: background 0.15s, color 0.15s;
}

.lvt-btn.active {
    background: rgba(79, 172, 254, 0.18);
    color: #4facfe;
}

body:not(.dark-mode) .lvt-btn {
    color: rgba(0, 0, 0, 0.45);
}

body:not(.dark-mode) .lvt-btn.active {
    background: #fff;
    color: #0066cc;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* ── Drag-to-reorder handle ──────────────────────────────── */
.layer-drag-handle {
    cursor: grab;
    color: rgba(255, 255, 255, 0.18);
    font-size: 11px;
    flex-shrink: 0;
    padding: 0 2px;
    user-select: none;
    line-height: 1;
}

.layer-drag-handle:active {
    cursor: grabbing;
}

.layer-item[draggable="true"]:active {
    opacity: 0.5;
}

body:not(.dark-mode) .layer-drag-handle {
    color: rgba(0, 0, 0, 0.2);
}

/* ── Drop indicator line between rows ───────────────────── */
.layer-drop-indicator {
    height: 2px;
    background: #4facfe;
    border-radius: 1px;
    margin: 1px 0;
    pointer-events: none;
}

/* ── Topology badge (inline in Structure view) ───────────── */
.layer-topo-badge {
    font-size: 8px;
    padding: 1px 5px;
    border-radius: 8px;
    flex-shrink: 0;
    font-weight: 600;
    letter-spacing: 0.3px;
    line-height: 1.6;
    white-space: nowrap;
}

.badge-wire {
    background: rgba(79, 172, 254, 0.15);
    color: #4facfe;
}

.badge-module {
    background: rgba(52, 211, 153, 0.15);
    color: #34d399;
}

.badge-connector,
.badge-pin {
    background: rgba(167, 139, 250, 0.15);
    color: #a78bfa;
}

.badge-component {
    background: rgba(148, 163, 184, 0.15);
    color: #94a3b8;
}

.badge-junction {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
}

/* ── Lint badges (Structure panel) ───────────────────────── */
.layer-lint-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    font-size: 9px;
    font-weight: 700;
    flex-shrink: 0;
    margin-left: 2px;
}
.lint-error {
    background: #ef4444;
    color: #fff;
}

/* ── Unconnected pin indicator (canvas) ───────────────────── */
.pin-unconnected {
    fill: #ef4444 !important;
    stroke: #ef4444 !important;
    opacity: 0.85;
}

/* ── Property panel: multi-select banner ─────────────────── */
.prop-multi-banner {
    background: rgba(79, 172, 254, 0.10);
    border: 1px solid rgba(79, 172, 254, 0.25);
    border-radius: 4px;
    padding: 5px 8px;
    font-size: 11px;
    color: #4facfe;
    margin-bottom: 8px;
    text-align: center;
}

/* ── Property panel: component spec card ─────────────────── */
.prop-spec-desc {
    font-size: 11px;
    color: #8899aa;
    margin: 4px 0 6px;
    line-height: 1.4;
}
.prop-spec-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    font-size: 11px;
    padding: 3px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    gap: 8px;
}
.prop-spec-row .prop-label {
    color: #667788;
    flex-shrink: 0;
}
.prop-spec-row .prop-value {
    color: #b0c4de;
    text-align: right;
}

/* ── Structure view children container ───────────────────── */
.layer-struct-children {
    /* shown/hidden via jQuery .toggle() */
}

/* ============================================================
   MEASURE TOOL — SVG Canvas Overlays
   ============================================================ */

/* Tape line (live) — dashed cyan */
.measure-tape {
    stroke: #4facfe;
    stroke-width: 1;
    stroke-dasharray: 5, 3;
    fill: none;
    vector-effect: non-scaling-stroke;
    opacity: 0.8;
}

/* Tape line (finalized) — solid, slightly brighter */
.measure-tape.measure-tape-final {
    stroke: #00e5ff;
    stroke-dasharray: none;
    opacity: 1;
}

/* Point A (green) and Point B (orange) dots */
.measure-point {
    fill: none;
    stroke-width: 1.5;
    vector-effect: non-scaling-stroke;
}

.measure-point-a {
    fill: rgba(52, 211, 153, 0.25);
    stroke: #34d399;
}

.measure-point-b {
    fill: rgba(251, 191, 36, 0.25);
    stroke: #fbbf24;
}

/* Angle arc from Point A */
.measure-angle-arc {
    stroke: #a78bfa;
    stroke-width: 1;
    fill: none;
    stroke-dasharray: 2, 2;
    opacity: 0.75;
    vector-effect: non-scaling-stroke;
}

/* Main distance label */
.measure-hud-dist {
    fill: #00e5ff;
    font-family: 'DM Mono', 'Courier New', monospace;
    font-weight: 600;
    paint-order: stroke fill;
    stroke: rgba(0, 0, 0, 0.6);
    stroke-width: 3;
    stroke-linejoin: round;
}

/* Angle classification label (e.g. "53.7° Obtuse") */
.measure-hud-angle {
    fill: #a78bfa;
    font-family: 'DM Mono', 'Courier New', monospace;
    font-weight: 500;
    paint-order: stroke fill;
    stroke: rgba(0, 0, 0, 0.55);
    stroke-width: 2.5;
    stroke-linejoin: round;
}

/* Δx / Δy component labels */
.measure-hud-delta {
    fill: rgba(79, 172, 254, 0.8);
    font-family: 'DM Mono', 'Courier New', monospace;
    paint-order: stroke fill;
    stroke: rgba(0, 0, 0, 0.5);
    stroke-width: 2;
    stroke-linejoin: round;
}

/* Wire callout background bubble */
.measure-callout-bg {
    fill: rgba(0, 10, 25, 0.78);
    stroke: #4facfe;
    stroke-width: 0.75;
}

/* #measureBtn active state */
#measureBtn.active {
    background: rgba(0, 229, 255, 0.15) !important;
    border-color: #00e5ff !important;
    color: #00e5ff !important;
    box-shadow: 0 0 8px rgba(0, 229, 255, 0.25);
}