/* ============================================
   UCM Editor - Main Stylesheet (Light Theme / Transit Style)
   ============================================ */

/* ============================================
   Base Edge Styles - CRITICAL: fill: none prevents SVG paths from being filled
   Stroke/width set as defaults, inline styles from edge properties can override
   ============================================ */
.ucm-edge {
    fill: none !important;
    /* Default stroke - can be overridden by inline styles from edge.properties */
    stroke: #000000;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: stroke 0.15s ease, stroke-width 0.15s ease, opacity 0.15s ease;
}

/* Edge hit area for easier selection - transparent but clickable stroke */
.edge-hit-area,
.hit-area {
    fill: none !important;
    stroke: transparent !important;
    stroke-width: 20px !important;
    pointer-events: stroke !important;
    cursor: pointer;
}

/* CSS Variables - B&W / Transit-Map Style */
/* Transit Map Mode Styles */
.transit-mode #canvas {
    background-color: #ffffff;
}

.transit-mode .ucm-edge {
    fill: none !important;
    stroke-width: 6px !important;
    stroke-linecap: round;
    stroke: #000000;
}

/* Hide midpoint arrows in Transit mode */
.transit-mode .mid-arrow {
    display: none;
}

/* Responsibility Nodes: X in Classic, Station in Transit */
.node-responsibility .transit-station {
    display: none;
}

.transit-mode .node-responsibility .transit-station {
    display: block;
}

.transit-mode .node-responsibility .classic-x {
    display: none;
}

.transit-mode .node-start circle:not(.hit-area) {
    r: 12;
    fill: #000000;
}

.transit-mode .node-end rect {
    width: 6px;
    height: 24px;
    x: -3px;
    y: -12px;
    fill: #000000;
}

/* Hide Grid */
#canvas-container.hide-grid {
    background-image: none;
}

/* Hide Labels */
.hide-labels .node-label,
.hide-labels .component-label {
    display: none;
}

:root {
    /* Backgrounds */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-hover: #e9ecef;

    /* Borders and Lines */
    --border-color: #000000;
    --border-light: #dee2e6;

    /* Text */
    --text-primary: #000000;
    --text-secondary: #495057;
    --text-muted: #6c757d;

    /* Accents (Grayscale) */
    --accent-primary: #000000;
    --accent-secondary: #343a40;
    --accent-hover: #212529;

    /* Status Colors (Grayscale) */
    --status-success: #000000;
    --status-error: #555555;
    --status-warning: #888888;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

:root {
    --node-fork: #000000;
    --node-join: #000000;

    /* Edges */
    --edge-color: #000000;
    --edge-hover: #495057;

    /* Selection - Draw.io style Blue */
    --selection-color: #29b6f6;
    --selection-glow: rgba(41, 182, 246, 0.2);

    /* Dimensions */
    --panel-width: 260px;
    --toolbar-height: 48px;

    --transition-fast: 0.15s ease;

    /* Shadows - softer for light mode */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.05);
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* App Container */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    /* Prevent default touch actions to help with custom drag */
    touch-action: none;
}

/* ============================================
   Toolbar
   ============================================ */
#toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    height: var(--toolbar-height);
    padding: 0 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    overflow: hidden;
    flex-shrink: 0;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.toolbar-title {
    margin-left: auto;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.file-selector {
    display: flex;
    align-items: center;
}

.file-selector select {
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    min-width: 180px;
}

.file-selector select:hover {
    border-color: var(--text-secondary);
}

.file-selector select:focus {
    outline: none;
    border-color: var(--accent-color, #0066cc);
}

.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.tool-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--border-color);
}

.tool-btn.active {
    background: var(--bg-active);
    color: var(--text-primary);
    border-color: var(--border-color);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

.tool-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#zoom-level {
    min-width: 50px;
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
}

/* Observability Links */
.toolbar-observability {
    margin-left: 8px;
    padding-left: 8px;
    border-left: 1px solid var(--border-color);
}

.tool-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    text-decoration: none;
    transition: background var(--transition-fast);
}

.tool-link:hover {
    background: var(--bg-hover);
}

.tool-link svg {
    opacity: 0.7;
    transition: opacity var(--transition-fast);
}

.tool-link:hover svg {
    opacity: 1;
}

/* Dropdown Menu */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 160px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    z-index: 1000;
    margin-top: 4px;
}

.dropdown:hover .dropdown-menu {
    display: block;
}

.menu-item {
    display: block;
    width: 100%;
    padding: 8px 12px;
    text-align: left;
    border: none;
    background: transparent;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.menu-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.menu-item+.menu-item {
    border-top: 1px solid var(--border-light);
}

/* ============================================
   Main Content Layout
   ============================================ */
#main-content {
    display: flex;
    flex: 1;
    min-height: 0;
    /* Critical flexbox fix */
    overflow: hidden;
}

/* ============================================
   Left Panel
   ============================================ */
#left-panel {
    display: flex;
    flex-direction: column;
    width: var(--panel-width);
    background: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    overflow: hidden;
}

/* ============================================
   Sidebar Tabs
   ============================================ */
.sidebar-tabs {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
}

.tab-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.tab-btn.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent-primary);
    background: var(--bg-primary);
}

.panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.tab-content {
    display: none;
    flex: 1;
    flex-direction: column;
    min-height: 0;
}

.tab-content.active {
    display: flex;
}

/* DSL Editor */
.dsl-editor-container {
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 12px;
}

#dsl-editor {
    flex: 1;
    width: 100%;
    min-height: 300px;
    padding: 12px;
    font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    resize: none;
    outline: none;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

#dsl-editor:focus {
    border-color: var(--accent-primary);
    background: var(--bg-primary);
}

.dsl-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

#editor-status {
    font-size: 11px;
    color: var(--text-muted);
}

.mini-btn {
    padding: 4px 12px;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
}

.primary-btn {
    padding: 8px 16px;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 4px;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.primary-btn:hover {
    opacity: 0.8;
}

/* DSL Error List */
.dsl-error-list {
    display: none;
    max-height: 120px;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-top: 8px;
}

.dsl-error-item {
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    transition: background var(--transition-fast);
}

.dsl-error-item:last-child {
    border-bottom: none;
}

.dsl-error-item:hover {
    background: var(--bg-hover);
}

.dsl-error-item.error {
    color: #c0392b;
}

.dsl-error-item.warning {
    color: #d68910;
}

.error-line {
    font-weight: 600;
    margin-right: 6px;
}

#dsl-editor.has-errors {
    border-color: #c0392b;
}

/* DSL Status Colors */
.status-synced {
    color: var(--text-muted);
}

.status-success {
    color: #27ae60;
}

.status-error {
    color: #c0392b;
}

.status-pending {
    color: #d68910;
}

/* Drag & Drop */
#tab-editor.drag-over {
    background: rgba(0, 0, 0, 0.05);
}

#tab-editor.drag-over .dsl-editor-container {
    border: 2px dashed var(--accent-primary);
    border-radius: 8px;
}

/* AI Chat */
.ai-chat-container {
    padding: 8px 12px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-secondary);
}

.ai-chat-input-wrap {
    display: flex;
    gap: 6px;
}

#ai-prompt {
    flex: 1;
    padding: 6px 10px;
    font-size: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
}

#ai-prompt:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.ai-response {
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-secondary);
    max-height: 60px;
    overflow-y: auto;
}

.ai-response.success {
    color: #27ae60;
}

.ai-response.error {
    color: #c0392b;
}

/* Hierarchy pinned indicator */
.node-pinned {
    font-size: 10px;
    margin-left: 4px;
    opacity: 0.7;
}

/* Settings Panel */
.settings-container {
    padding: 16px;
}

.settings-group {
    margin-bottom: 24px;
}

.settings-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
}

.setting-label {
    font-size: 13px;
    color: var(--text-primary);
}

/* Settings Select Dropdown */
.setting-select {
    padding: 4px 8px;
    font-size: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    min-width: 100px;
}

.setting-select:hover {
    border-color: var(--primary-color, #2196F3);
}

.setting-select:focus {
    outline: none;
    border-color: var(--primary-color, #2196F3);
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.2);
}

/* Switches (Toggles) */
.switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 20px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-hover);
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--accent-primary);
}

input:checked+.slider:before {
    transform: translateX(14px);
}

.placeholder-text {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    font-style: italic;
}

/* ============================================
   Hierarchy Tree
   ============================================ */
/* Hierarchy Tree */
.tree-node {
    user-select: none;
}

.tree-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.tree-item:hover {
    background: var(--bg-hover);
}

.tree-item.selected {
    background: var(--selection-color);
    color: white !important;
    font-weight: 600;
}

.tree-item.selected .tree-icon,
.tree-item.selected .tree-label {
    color: white !important;
}

.tree-toggle {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 10px;
    transition: transform var(--transition-fast);
}

.tree-toggle.expanded {
    transform: rotate(90deg);
}

.tree-icon {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.tree-label {
    flex: 1;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

/* Standard Indentation */
.tree-children {
    margin-left: 20px;
    /* Standard indented tree */
    border-left: 1px solid var(--border-light);
    /* Thin guide line, optional */
    padding-left: 4px;
}

.tree-children.collapsed {
    display: none;
}

/* Special case: No indent for "continuation" siblings (responsibilities) */
/* This will be handled by structure in JS, but ensure clean style here */
.tree-children.continuation {
    margin-left: 0;
    border-left: none;
    padding-left: 0;
}

/* Branch Indentation */
.branch-node {
    margin-left: 20px;
    /* Indent the entire branch block (label + children) */
}



.tree-item.selected .metro-node-marker::after {
    background: var(--text-primary);
}

/* ============================================
   Properties Panel
   ============================================ */
.property-group {
    margin-bottom: 16px;
}

.property-group-header {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.property-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.property-label {
    flex: 0 0 70px;
    font-size: 12px;
    color: var(--text-secondary);
}

.property-value {
    flex: 1;
}

.property-input {
    width: 100%;
    padding: 6px 8px;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    outline: none;
    transition: border-color var(--transition-fast);
}

.property-input:focus {
    border-color: var(--accent-secondary);
}

.property-input:disabled {
    background: var(--bg-secondary);
    color: var(--text-muted);
}

.property-textarea {
    min-height: 60px;
    resize: vertical;
}

.type-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

/* ============================================
   Canvas
   ============================================ */
#canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-height: 0;
    /* Critical flexbox fix - allows shrinking */
    height: 100%;
    /* Explicit height for SVG sizing */
    background: var(--bg-tertiary);
    /* Subtle dot grid - Strict B&W */
    background-image:
        radial-gradient(circle, #ddd 1px, transparent 1px);
    background-size: 20px 20px;
    /* Subtle inner border */
    border-left: 1px solid var(--border-light);
}

#canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: default;
}

#canvas.tool-path {
    cursor: crosshair;
}

/* Canvas Nodes */
.ucm-node {
    cursor: pointer;
    transition: opacity var(--transition-fast);
}

.ucm-node:hover {
    opacity: 0.7;
}

/* Functional, B&W Node Styles */
.node-start circle:not(.hit-area) {
    fill: var(--node-start);
    stroke: #000;
    stroke-width: 2;
}

.node-end rect {
    fill: var(--node-end);
    stroke: none;
}

.node-responsibility line {
    stroke: var(--node-responsibility);
    stroke-width: 3;
}

.node-empty circle:not(.hit-area) {
    fill: var(--node-empty);
    opacity: 0.5;
}

.node-fork polygon,
.node-join polygon {
    fill: none;
    stroke: var(--node-fork);
    stroke-width: 2;
}

/* Selection Box (New Bounding Box Highlight) */
.selection-box {
    display: none;
    fill: rgba(41, 182, 246, 0.15);
    /* Slightly darker tint */
    stroke: var(--selection-color);
    stroke-width: 2.5;
    /* Sharper border */
    stroke-dasharray: none;
    /* Solid line for clear border */
    filter: drop-shadow(0 0 4px var(--selection-glow));
    pointer-events: none;
}

.ucm-node.selected .selection-box {
    display: block;
}

/* Updated Selection Highlight - Reduce direct shape styling in favor of box, but keep some for visibility */
.ucm-node.selected circle:not(.hit-area),
.ucm-node.selected rect:not(.selection-box),
.ucm-node.selected polygon {
    stroke: var(--selection-color) !important;
    stroke-width: 2 !important;
    /* Reduced glowing effect on the shape itself since we have the box */
    filter: drop-shadow(0 0 2px var(--selection-glow)) !important;
}

/* Fork/Join AND-bar selection */
.ucm-node.selected .ucm-and-bar {
    stroke: var(--selection-color) !important;
    stroke-width: 2 !important;
}

/* Fork/Join OR-point selection */
.ucm-node.selected .ucm-or-point {
    stroke: var(--selection-color) !important;
    stroke-width: 2 !important;
}

/* Responsibility X-mark selection */
.ucm-node.selected.node-responsibility line.classic-x {
    stroke: var(--selection-color) !important;
    stroke-width: 4 !important;
}

/* Edge Selection Enhanced - MUST be visually distinct */
.ucm-edge-group.selected .ucm-edge {
    stroke: var(--selection-color) !important;
    stroke-width: 4 !important;
    filter: drop-shadow(0 0 8px var(--selection-color)) drop-shadow(0 0 4px var(--selection-color)) !important;
}

/* Selected edge arrow should also be highlighted */
.ucm-edge-group.selected .mid-arrow {
    fill: var(--selection-color) !important;
    filter: drop-shadow(0 0 4px var(--selection-color)) !important;
}

.transit-mode .ucm-edge-group.selected .ucm-edge {
    stroke: var(--selection-color) !important;
    stroke-width: 10px !important;
    filter: drop-shadow(0 0 12px var(--selection-color)) drop-shadow(0 0 6px var(--selection-color)) !important;
}

/* Hover state for edges - subtle preview */
.ucm-edge-group:hover:not(.selected) .ucm-edge {
    stroke: #666 !important;
    stroke-width: 2.5 !important;
}

.transit-mode .ucm-edge-group:hover:not(.selected) .ucm-edge {
    stroke: #444 !important;
    stroke-width: 8px !important;
}

/* Waypoint Markers - Always visible with clear states */
.waypoint-marker {
    fill: #888888;
    stroke: white;
    stroke-width: 2;
    cursor: move;
    opacity: 0.6;
    transition: opacity var(--transition-fast), fill var(--transition-fast), r var(--transition-fast);
    filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.6));
}

/* Show waypoints more prominently on hover */
.ucm-edge-group:hover .waypoint-marker {
    opacity: 1 !important;
    fill: #555555;
}

/* Selected edge waypoints - bright blue, larger, glowing */
.ucm-edge-group.selected .waypoint-marker {
    opacity: 1 !important;
    fill: var(--selection-color) !important;
    stroke: white !important;
    stroke-width: 3 !important;
    r: 8 !important;
    filter: drop-shadow(0 0 6px var(--selection-color)) drop-shadow(0 0 3px white) !important;
}

/* Individual waypoint hover - even larger */
.waypoint-marker:hover {
    r: 10 !important;
    fill: var(--selection-color) !important;
    stroke: white !important;
    stroke-width: 3 !important;
    filter: drop-shadow(0 0 8px var(--selection-color)) !important;
}

/* Dragging state */
.waypoint-marker.dragging {
    r: 10 !important;
    opacity: 1 !important;
    fill: #1976D2 !important;
    stroke: white !important;
    stroke-width: 3 !important;
}

/* Auto-generated waypoints (hidden by default) */
.auto-waypoint-marker {
    fill: #cccccc;
    stroke: #999999;
    stroke-width: 1.5;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
}

/* Show auto waypoints when setting is enabled */
body.show-auto-waypoints .auto-waypoint-marker {
    opacity: 0.5;
}

body.show-auto-waypoints .ucm-edge-group:hover .auto-waypoint-marker {
    opacity: 0.7;
}

body.show-auto-waypoints .ucm-edge-group.selected .auto-waypoint-marker {
    opacity: 0.8;
    fill: #aaddff;
    stroke: #66aacc;
}

/* Labels */
.node-label {
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 500;
    fill: var(--text-primary);
    text-anchor: middle;
    pointer-events: none;
    user-select: none;
    text-shadow: 0 0 2px white;
}

/* Hide labels when setting is off */
body.hide-labels .node-label,
body.hide-labels .component-label {
    display: none;
}

/* ============================================
   Scenario Path Highlighting
   ============================================ */

/* Scenario highlight group container */
.scenario-highlight-group {
    pointer-events: none;
}

/* Scenario edge highlight - colored path overlay */
.scenario-edge-highlight {
    pointer-events: none;
    animation: scenarioFadeIn 0.3s ease-out;
}

/* Scenario node highlight - colored ring around nodes */
.scenario-node-highlight {
    pointer-events: none;
    animation: scenarioFadeIn 0.3s ease-out;
}

/* Pulsing animation for start/end nodes in scenario */
.scenario-pulse {
    animation: scenarioPulse 1.5s ease-in-out infinite;
}

/* Scenario end marker (checkmark) */
.scenario-end-marker {
    pointer-events: none;
    animation: scenarioCheckIn 0.4s ease-out;
}

@keyframes scenarioFadeIn {
    from {
        opacity: 0;
        stroke-width: 0;
    }
    to {
        opacity: 0.6;
    }
}

@keyframes scenarioPulse {
    0%, 100% {
        opacity: 0.6;
        transform: scale(1);
    }
    50% {
        opacity: 0.9;
        transform: scale(1.05);
    }
}

@keyframes scenarioCheckIn {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Transit mode scenario highlighting - thicker paths */
.transit-mode .scenario-edge-highlight {
    stroke-width: 8 !important;
}

/* Ghost Elements */
.ghost-path {
    stroke: var(--text-muted);
    stroke-width: 2;
    stroke-dasharray: 6 3;
}

.ghost-node {
    fill: var(--text-muted);
    opacity: 0.5;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================
   Context Menu
   ============================================ */
.context-menu {
    position: fixed;
    z-index: 1000;
    min-width: 160px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: var(--shadow-md);
    padding: 4px 0;
    font-size: 13px;
}

.menu-item {
    padding: 8px 16px;
    cursor: pointer;
    color: var(--text-primary);
    transition: background var(--transition-fast);
}

.menu-item:hover {
    background: var(--bg-hover);
}

.menu-separator {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

/* Resize handles */
.resize-handle {
    cursor: pointer;
}

/* Component styles */
.ucm-component {
    cursor: pointer;
}

.ucm-component:hover rect:first-child {
    stroke-width: 2;
}

.ucm-component .component-header {
    cursor: move;
}

.ucm-component .component-header:hover {
    fill: rgba(0, 0, 0, 0.1);
}

.ucm-component.selected rect:first-child {
    stroke: var(--selection-color);
    stroke-width: 3;
    fill: rgba(41, 182, 246, 0.1);
    /* Background tint for selected component */
    /* Solid line for selection */
    stroke-dasharray: none;
    filter: drop-shadow(0 0 8px var(--selection-glow));
}

/* ============================================
   Custom Tooltips
   ============================================ */
.custom-tooltip {
    position: fixed;
    z-index: 10000;
    padding: 6px 10px;
    background: rgba(15, 15, 15, 0.95);
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.1);
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
    /* Very small tooltip style */
    padding: 4px 8px;
    font-size: 11px;
}

.custom-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.custom-tooltip .shortcut {
    margin-left: 8px;
    padding: 1px 4px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    font-size: 10px;
    font-family: 'JetBrains Mono', monospace;
    color: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ============================================
   Actions Panel
   ============================================ */
#actions-panel {
    border-top: 1px solid var(--border-light);
    max-height: 280px;
    overflow-y: auto;
}

#actions-content {
    padding: 8px;
}

.action-group {
    margin-bottom: 12px;
}

.action-group:last-child {
    margin-bottom: 0;
}

.action-group-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 4px 8px;
    letter-spacing: 0.5px;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 8px;
    border: none;
    background: transparent;
    font-size: 12px;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 4px;
    transition: background var(--transition-fast);
    text-align: left;
}

.action-btn:hover {
    background: var(--bg-hover);
}

.action-btn:active {
    background: var(--bg-secondary);
}

.action-icon {
    width: 16px;
    text-align: center;
    font-size: 14px;
}

.action-label {
    flex: 1;
}

/* ============================================
   Compact Properties Panel
   ============================================ */
.panel-compact {
    max-height: 200px;
    overflow-y: auto;
}

.panel-compact .panel-content {
    padding: 8px;
}

.panel-compact .property-row {
    margin-bottom: 4px;
}

.panel-compact .property-label {
    flex: 0 0 50px;
    font-size: 10px;
}

.panel-compact .property-input {
    padding: 4px 6px;
    font-size: 11px;
}

.panel-compact .property-group-header {
    font-size: 9px;
    margin-bottom: 4px;
    padding-bottom: 2px;
}

/* Fork/Join selection highlight - comprehensive coverage */
.ucm-node.selected.node-fork circle,
.ucm-node.selected.node-join circle,
.ucm-node.selected.node-fork .ucm-or-point,
.ucm-node.selected.node-join .ucm-or-point {
    stroke: var(--selection-color) !important;
    stroke-width: 3 !important;
    stroke-dasharray: none !important;
    filter: drop-shadow(0 0 6px var(--selection-color)) !important;
}

/* Fork/Join AND-bar selection */
.ucm-node.selected.node-fork .ucm-and-bar,
.ucm-node.selected.node-join .ucm-and-bar,
.ucm-node.selected.node-fork rect,
.ucm-node.selected.node-join rect {
    stroke: var(--selection-color) !important;
    stroke-width: 3 !important;
    stroke-dasharray: none !important;
    filter: drop-shadow(0 0 6px var(--selection-color)) !important;
}

/* ============================================
   Scenario Panel
   ============================================ */

.scenario-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 12px;
}

.scenario-panel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

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

.scenario-panel .panel-actions {
    display: flex;
    gap: 4px;
}

.scenario-panel .btn-icon {
    width: 24px;
    height: 24px;
    border: none;
    background: var(--bg-secondary);
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.scenario-panel .btn-icon:hover {
    background: var(--accent-primary);
    color: white;
}

.scenario-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.scenario-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.scenario-item:hover {
    border-color: var(--accent-primary);
}

.scenario-item.active {
    border-color: var(--accent-primary);
    background: rgba(41, 182, 246, 0.1);
}

.scenario-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.scenario-status {
    font-size: 12px;
}

.scenario-status.success {
    color: #27ae60;
}

.scenario-status.warning {
    color: #f39c12;
}

.scenario-name {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.scenario-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.1);
}

.scenario-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

.scenario-actions .btn-small {
    padding: 4px 8px;
    font-size: 11px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: var(--bg-primary);
    color: var(--text-secondary);
}

.scenario-actions .btn-small:hover {
    background: var(--accent-primary);
    color: white;
}

.scenario-actions .btn-run {
    background: #27ae60;
    color: white;
}

.scenario-actions .btn-run:hover {
    background: #229954;
}

.scenario-actions .btn-delete:hover {
    background: #e74c3c;
    color: white;
}

.traversal-info {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-light);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.traversal-info .success {
    color: #27ae60;
}

.traversal-errors {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.traversal-errors .error {
    color: #e74c3c;
    font-size: 10px;
}

.scenario-panel .empty-state {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
}

.scenario-panel .empty-state p {
    margin: 4px 0;
}

.scenario-panel .hint {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
}

.scenario-info {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

/* ============================================
   Notification System
   ============================================ */
.notification-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 400px;
    pointer-events: none;
}

.notification {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 2px 4px rgba(0, 0, 0, 0.1);
    font-size: 13px;
    line-height: 1.4;
    color: var(--text-primary);
    pointer-events: auto;
    cursor: pointer;
    opacity: 0;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.notification-show {
    opacity: 1;
    transform: translateX(0);
}

.notification-hide {
    opacity: 0;
    transform: translateX(100%);
}

.notification-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.notification-icon svg {
    width: 16px;
    height: 16px;
}

.notification-message {
    flex: 1;
    word-break: break-word;
}

.notification-close {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s ease, color 0.15s ease;
}

.notification-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Notification Types - Color Variations */
.notification-info {
    border-left: 4px solid #2196F3;
}

.notification-info .notification-icon {
    color: #2196F3;
}

.notification-success {
    border-left: 4px solid #4CAF50;
}

.notification-success .notification-icon {
    color: #4CAF50;
}

.notification-warning {
    border-left: 4px solid #FF9800;
}

.notification-warning .notification-icon {
    color: #FF9800;
}

.notification-error {
    border-left: 4px solid #f44336;
}

.notification-error .notification-icon {
    color: #f44336;
}

/* ============================================
   Mobile Responsive Design
   iOS Chrome, Safari, Android Chrome compatible
   ============================================ */

/* Mobile Bottom Navigation Bar (hidden on desktop) */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-light);
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.mobile-nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 56px;
    padding: 0 8px;
}

.mobile-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 8px 16px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 10px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-btn svg {
    width: 24px;
    height: 24px;
}

.mobile-nav-btn.active {
    color: var(--selection-color);
}

.mobile-nav-btn:active {
    background: var(--bg-hover);
    transform: scale(0.95);
}

/* Mobile Panel (slides up from bottom) */
.mobile-panel {
    display: none;
    position: fixed;
    bottom: 56px;
    left: 0;
    right: 0;
    max-height: 50vh;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-light);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    z-index: 999;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

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

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

.mobile-panel-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.mobile-panel-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
}

.mobile-panel-content {
    padding: 16px;
    overflow-y: auto;
    max-height: calc(50vh - 60px);
    -webkit-overflow-scrolling: touch;
}

/* Mobile backdrop overlay */
.mobile-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 56px;
    background: rgba(0,0,0,0.3);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-backdrop.visible {
    opacity: 1;
}

/* ============================================
   Tablet Breakpoint (768px - 1024px)
   ============================================ */
@media screen and (max-width: 1024px) {
    #sidebar {
        width: 280px;
    }
    
    .panel-header {
        padding: 8px 12px;
    }
    
    .panel-content {
        padding: 8px;
    }
}

/* ============================================
   Mobile Breakpoint (max-width: 768px)
   ============================================ */
@media screen and (max-width: 768px) {
    /* Hide desktop sidebar on mobile */
    #sidebar {
        display: none;
    }
    
    /* Show mobile navigation */
    .mobile-nav {
        display: block;
    }
    
    .mobile-panel {
        display: block;
    }
    
    .mobile-backdrop {
        display: block;
        pointer-events: none;
    }
    
    .mobile-backdrop.visible {
        pointer-events: auto;
    }
    
    /* Full-width canvas */
    #canvas-container {
        width: 100vw;
        height: calc(100vh - 48px - 56px); /* toolbar + bottom nav */
        margin-bottom: 56px;
    }
    
    /* Compact toolbar for mobile */
    #toolbar {
        padding: 4px 8px;
        height: 48px;
        gap: 4px;
    }
    
    .toolbar-group {
        gap: 2px;
    }
    
    .tool-btn {
        width: 36px;
        height: 36px;
        padding: 6px;
    }
    
    .tool-btn svg {
        width: 18px;
        height: 18px;
    }
    
    /* Hide title and some buttons on mobile */
    .toolbar-title span {
        display: none;
    }
    
    .file-selector select {
        max-width: 120px;
        font-size: 12px;
    }
    
    /* Hide export dropdown on mobile */
    .dropdown {
        display: none;
    }
    
    /* Larger touch targets */
    .ucm-node .hit-area {
        r: 32 !important;
    }
    
    .edge-hit-area {
        stroke-width: 30px !important;
    }
    
    /* Larger waypoint markers for touch */
    .waypoint-marker {
        r: 10 !important;
    }
    
    /* Disable hover effects on touch devices */
    @media (hover: none) {
        .tool-btn:hover {
            background: transparent;
        }
        
        .ucm-edge-group:hover .ucm-edge {
            stroke-width: inherit;
        }
    }
}

/* ============================================
   Small Mobile (max-width: 480px)
   ============================================ */
@media screen and (max-width: 480px) {
    #toolbar {
        padding: 2px 4px;
        height: 44px;
    }
    
    .tool-btn {
        width: 32px;
        height: 32px;
        padding: 4px;
    }
    
    .file-selector select {
        max-width: 100px;
        font-size: 11px;
        padding: 4px;
    }
    
    /* Hide undo/redo on very small screens */
    #btn-undo, #btn-redo {
        display: none;
    }
    
    #canvas-container {
        height: calc(100vh - 44px - 56px);
    }
    
    .mobile-nav-btn {
        padding: 6px 12px;
        font-size: 9px;
    }
    
    .mobile-nav-btn svg {
        width: 20px;
        height: 20px;
    }
}

/* ============================================
   Touch Device Optimizations
   ============================================ */
@media (pointer: coarse) {
    /* Larger tap targets */
    .tool-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    .switch {
        transform: scale(1.1);
    }
    
    .setting-select {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
    
    input[type="text"],
    input[type="number"],
    textarea {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
    
    /* Larger node selection area */
    .ucm-node .hit-area {
        r: 36 !important;
    }
}

/* ============================================
   Landscape Mobile
   ============================================ */
@media screen and (max-width: 768px) and (orientation: landscape) {
    #toolbar {
        height: 40px;
    }
    
    .mobile-nav {
        height: 48px;
    }
    
    .mobile-nav-items {
        height: 48px;
    }
    
    #canvas-container {
        height: calc(100vh - 40px - 48px);
        margin-bottom: 48px;
    }
    
    .mobile-panel {
        max-height: 40vh;
        bottom: 48px;
    }
}

/* ============================================
   iOS Safari Specific Fixes
   ============================================ */
@supports (-webkit-touch-callout: none) {
    /* iOS-specific padding for notch/home indicator */
    .mobile-nav {
        padding-bottom: max(env(safe-area-inset-bottom), 8px);
    }
    
    #canvas-container {
        /* Account for iOS bottom safe area */
        margin-bottom: calc(56px + env(safe-area-inset-bottom, 0));
    }
    
    /* Prevent elastic scrolling on canvas */
    #canvas {
        touch-action: none;
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ============================================
   Print / Export Styles
   ============================================ */
@media print {
    #sidebar,
    #toolbar,
    .mobile-nav,
    .mobile-panel,
    .mobile-backdrop {
        display: none !important;
    }
    
    #canvas-container {
        width: 100%;
        height: 100%;
        margin: 0;
    }
    
    .ucm-component rect {
        fill: white !important;
    }
}