/* ==================== */
/* CAD-Style UI - Base */
/* ==================== */

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

:root {
    --toolbar-height: 48px;
    --panel-bg: rgba(30, 40, 50, 0.94);
    --panel-border: rgba(255, 255, 255, 0.1);
    --accent: #007bff;
    --accent-hover: #0056b3;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.5);
    --success: #28a745;
    --warning: #ffc107;
    --danger: #dc3545;
    --panel-width: 320px;
    --panel-width-wide: 380px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1a2e;
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ==================== */
/* Toolbar */
/* ==================== */

.toolbar {
    height: var(--toolbar-height);
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 8px;
    z-index: 100;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.toolbar-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    min-width: 48px;
}

.toolbar-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.toolbar-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-icon {
    font-size: 18px;
    line-height: 1;
}

.btn-label {
    font-size: 10px;
    margin-top: 2px;
}

.mode-group {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.2);
    padding: 4px;
    border-radius: 8px;
}

.mode-group .toolbar-btn {
    padding: 4px 10px;
}

/* ==================== */
/* Canvas Area */
/* ==================== */

.canvas-area {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#canvas {
    width: 100%;
    height: 100%;
    display: block;
    background: #f8f9fa;
    touch-action: none;
}

.canvas-watermark {
    position: absolute;
    top: 16px;
    left: 16px;
    font-size: 14px;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.15);
    pointer-events: none;
    user-select: none;
    line-height: 1.4;
}

.watermark-preset {
    font-weight: 400;
    font-size: 12px;
}

.reset-view-btn {
    position: absolute;
    bottom: 16px;
    left: 16px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    z-index: 50;
}

.reset-view-btn:hover {
    background: rgba(50, 60, 70, 0.95);
    transform: scale(1.05);
}


.linkage-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(220, 53, 69, 0.95);
    backdrop-filter: blur(10px);
    padding: 16px 24px;
    border-radius: 12px;
    display: none;
    align-items: center;
    gap: 12px;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.linkage-error.visible {
    display: flex;
}

.linkage-error .error-icon {
    font-size: 24px;
}

.linkage-error .error-text {
    color: white;
    font-size: 14px;
    font-weight: 500;
}

/* ==================== */
/* Panel Overlay (Mobile) */
/* ==================== */

.panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.panel-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ==================== */
/* Overlay Panels */
/* ==================== */

/* Left panel (Display) - fixed position */
.overlay-panel.panel-left {
    position: fixed;
    top: var(--toolbar-height);
    bottom: 0;
    left: 0;
    width: var(--panel-width);
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--panel-border);
    z-index: 200;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
}

.overlay-panel.panel-left.open {
    transform: translateX(0);
}

/* Right panels container */
.panels-right {
    position: fixed;
    top: var(--toolbar-height);
    bottom: 0;
    right: 0;
    display: flex;
    flex-direction: row-reverse;
    z-index: 200;
    pointer-events: none;
}

/* Right panels */
.overlay-panel.panel-right {
    width: var(--panel-width);
    height: 100%;
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    border-left: 1px solid var(--panel-border);
    display: none;
    flex-direction: column;
    flex-shrink: 0;
    pointer-events: auto;
}

.overlay-panel.panel-right.open {
    display: flex;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--panel-border);
    flex-shrink: 0;
}

.panel-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.panel-close {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.panel-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
}

/* ==================== */
/* Collapsible Sections */
/* ==================== */

.collapsible-section {
    margin-bottom: 8px;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease;
}

.section-header:hover {
    background: rgba(255, 255, 255, 0.08);
}

.section-icon {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.section-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.section-content {
    padding: 12px;
    overflow: hidden;
    transition: max-height 0.25s ease;
}

.collapsible-section.collapsed .section-icon {
    transform: rotate(-90deg);
}

.collapsible-section.collapsed .section-content {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
}

/* ==================== */
/* Control Rows */
/* ==================== */

.control-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
    padding: 4px 0;
    flex-shrink: 0;
}

.control-row:last-child {
    margin-bottom: 0;
}

.control-row label {
    flex: 0 0 100%;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.control-row input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    cursor: pointer;
}

.control-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.control-row input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.control-row input[type="number"] {
    flex: 0 0 60px;
    width: 60px;
    height: 28px;
    padding: 4px 6px;
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-primary);
    font-size: 12px;
    text-align: right;
}

.control-row input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
}

.control-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--accent);
}

.checkbox-row {
    flex-wrap: nowrap;
    justify-content: space-between;
}

.checkbox-row label {
    flex: 1;
    margin-bottom: 0;
}

/* Color indicators - match canvas colors (each feature unique) */
.color-blue { border-left: 3px solid #3498db; padding-left: 8px; margin-left: -4px; }      /* x,a arm */
.color-purple { border-left: 3px solid #9b59b6; padding-left: 8px; margin-left: -4px; }    /* x,b arm */
.color-hotpink { border-left: 3px solid #ff69b4; padding-left: 8px; margin-left: -4px; }   /* angle a,b */
.color-green { border-left: 3px solid #27ae60; padding-left: 8px; margin-left: -4px; }     /* x,d arm */
.color-orange { border-left: 3px solid #e67e22; padding-left: 8px; margin-left: -4px; }    /* x,c arm */
.color-sienna { border-left: 3px solid #a0522d; padding-left: 8px; margin-left: -4px; }    /* angle c,d */
.color-magenta { border-left: 3px solid #ff00ff; padding-left: 8px; margin-left: -4px; }   /* closed offset */
.color-cyan { border-left: 3px solid #00bcd4; padding-left: 8px; margin-left: -4px; }      /* frame travel */
.color-teal { border-left: 3px solid #00aa88; padding-left: 8px; margin-left: -4px; }      /* c offset */
.color-coral { border-left: 3px solid #ff7f50; padding-left: 8px; margin-left: -4px; }     /* shock open */
.color-crimson { border-left: 3px solid #dc143c; padding-left: 8px; margin-left: -4px; }   /* shock travel */

/* ==================== */
/* Toggle Items (Display Panel) */
/* ==================== */

.toggle-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    transition: color 0.15s ease;
}

.toggle-item:hover {
    color: var(--text-primary);
}

.toggle-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

/* ==================== */
/* State Grid */
/* ==================== */

.state-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin: 12px 0;
    flex-shrink: 0;
}

.state-item {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.state-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.state-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.state-indicator {
    font-size: 9px;
    color: var(--warning);
    background: rgba(255, 193, 7, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
    display: none;
}

.state-indicator.visible {
    display: inline-block;
}

/* ==================== */
/* Shock State */
/* ==================== */

.shock-section {
    margin-bottom: 12px;
}

.shock-section:last-child {
    margin-bottom: 0;
}

.shock-section h5 {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.shock-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.shock-row span:first-child {
    color: var(--text-muted);
}

.shock-status-ok { color: var(--success) !important; }
.shock-status-warning { color: var(--warning) !important; }
.shock-status-error { color: var(--danger) !important; }

/* ==================== */
/* Analysis Panel */
/* ==================== */

.analysis-summary {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.analysis-stat {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 12px;
    text-align: center;
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 20px;
    font-weight: 600;
    color: var(--accent);
    margin-top: 4px;
    display: block;
}

.travel-table-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
}

.travel-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.travel-table thead {
    position: sticky;
    top: 0;
    background: rgba(30, 40, 50, 0.98);
}

.travel-table th {
    padding: 10px 16px;
    text-align: left;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 1px solid var(--panel-border);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.5px;
}

.travel-table td {
    padding: 8px 16px;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.travel-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* ==================== */
/* Presets Panel */
/* ==================== */

.preset-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.preset-controls select {
    flex: 1;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-primary);
    font-size: 13px;
}

.preset-actions {
    display: flex;
    gap: 8px;
}

.btn-primary,
.btn-secondary {
    flex: 1;
    height: 36px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    border: 1px solid var(--panel-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
}

/* ==================== */
/* Disabled State */
/* ==================== */

.control-row.disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* ==================== */
/* Mobile Layout */
/* ==================== */

@media (max-width: 767px) {
    :root {
        --toolbar-height: 48px;
        --panel-width: 100%;
    }

    .toolbar {
        padding: 0 4px;
        gap: 4px;
    }

    .btn-label {
        display: none;
    }

    .toolbar-btn {
        padding: 6px;
        min-width: 36px;
    }

    .mode-group {
        padding: 2px;
        gap: 2px;
    }

    .toolbar-center,
    .toolbar-right {
        gap: 2px;
    }

    /* Mobile: Right panels container becomes bottom sheet area */
    .panels-right {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        flex-direction: column;
        max-height: 70vh;
    }

    .overlay-panel.panel-right {
        width: 100%;
        max-height: 70vh;
        border-left: none;
        border-top: 1px solid var(--panel-border);
        border-radius: 16px 16px 0 0;
    }

    /* Left panel also slides from bottom on mobile */
    .overlay-panel.panel-left {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 70vh;
        border-right: none;
        border-top: 1px solid var(--panel-border);
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
    }

    .overlay-panel.panel-left.open {
        transform: translateY(0);
    }

    .panel-header {
        padding: 16px;
        position: relative;
    }

    .panel-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 2px;
    }

    .control-row input[type="range"]::-webkit-slider-thumb {
        width: 22px;
        height: 22px;
    }

    .control-row input[type="range"]::-moz-range-thumb {
        width: 22px;
        height: 22px;
    }
}


/* ==================== */
/* Scrollbar Styling */
/* ==================== */

.panel-content::-webkit-scrollbar,
.travel-table-container::-webkit-scrollbar {
    width: 6px;
}

.panel-content::-webkit-scrollbar-track,
.travel-table-container::-webkit-scrollbar-track {
    background: transparent;
}

.panel-content::-webkit-scrollbar-thumb,
.travel-table-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.panel-content::-webkit-scrollbar-thumb:hover,
.travel-table-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ==================== */
/* Tooltip (JS-based) */
/* ==================== */

.tooltip {
    cursor: help;
}

/* ==================== */
/* Animations */
/* ==================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
