/* ============================================================
   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(79, 172, 254, 0.12);
    border: 1px solid rgba(79, 172, 254, 0.3);
    color: #1a1a1a;
    padding: 5px 10px;
    border-radius: 20px;
    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,
.btn.active {
    background: rgba(79, 172, 254, 0.28);
    border-color: #4facfe;
    transform: translateY(-1px);
}

.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;
    cursor: grab;
    touch-action: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

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

.svg-wrapper {
    transform-origin: center center;
    transition: transform 0.1s ease-out;
    will-change: transform;
}

/* ============================================================
   Bottom Controls
   ============================================================ */
.bottom-controls {
    background: rgba(242, 243, 246, 0.97);
    backdrop-filter: blur(15px);
    padding: 8px;
    display: grid;
    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;
}

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

.control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    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);
}

.control-btn:hover {
    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(79, 172, 254, 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-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);
}

/* ============================================================
   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: 15px;
        background: none;
        border: none;
    }

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

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

    .bottom-controls {
        grid-template-columns: repeat(5, 1fr);
    }

    .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;
}

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;
}
