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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f9fafb;
    height: 100vh;
    overflow: hidden;
}

/* NEW: Mobile overlay style */
#mobile-overlay {
    display: none; /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #f9fafb;
    color: #111827;
    font-size: 18px;
    font-weight: 500;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
    z-index: 2000;
}

/* Main Container */
.main-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* NEW: Media query to show overlay and hide app on small screens */
@media (max-width: 768px) {
    #mobile-overlay {
        display: flex;
    }
    .main-container {
        display: none;
    }
}

/* Toolbar */
.toolbar {
    background: white;
    border-bottom: 1px solid #e5e7eb;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.toolbar-content {
    display: flex;
    align-items: center;
    gap: 16px;
}

.ml-auto {
    margin-left: auto;
}

.app-title {
    margin-left: 24px;
    font-size: 18px;
    font-weight: 600;
    color: #111827;
    white-space: nowrap;
}

@media (max-width: 640px) {
    .app-title {
        display: none;
    }
}

#modelTitleInput {
    font-size: 18px;
    font-weight: 600;
    color: #374151;
    font-family: inherit;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    /* margin-left: 20px; */ /* REMOVED - Handled by wrapper */
    flex-shrink: 1; /* Allow shrinking */
    min-width: 150px; /* Don't get too small */
    background: transparent;
}

#modelTitleInput:hover {
    background: #f9fafb;
}

#modelTitleInput:focus {
    outline: none;
    background: #f9fafb;
    box-shadow: 0 0 0 2px #3b82f6;
}


/* Content Area */
.content-area {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    position: relative;
    transition: all 0.3s ease;
}

.canvas-container.panel-open {
    margin-right: 33.333%;
}

#canvas {
    width: 100%;
    height: 100%;
    cursor: default;
    /* --- THIS IS THE FIX --- */
    /* Prevents browser text selection from interfering with app selection */
    user-select: none;
    -webkit-user-select: none; /* For Safari */
    -moz-user-select: none; /* For Firefox */
    -ms-user-select: none; /* For IE */
}

#marquee {
    pointer-events: none;
}
#marquee rect {
    fill: rgba(59, 130, 246, 0.1);
    stroke: #3b82f6;
    stroke-width: 1;
    stroke-dasharray: 4 2;
}

/* Right Panel */
.right-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 33.333%;
    background: white;
    border-left: 1px solid #e5e7eb;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    transform: translateX(0);
    transition: transform 0.3s ease;
    z-index: 90;
    display: flex;
    flex-direction: column;
}

.right-panel.hidden {
    transform: translateX(100%);
}

.panel-handle {
    display: none;
    position: absolute;
    left: -35px;
    top: 50%;
    transform: translateY(-50%);
    width: 35px;
    height: 80px;
    background: white;
    border: 1px solid #e5e7eb;
    border-right: none;
    border-radius: 12px 0 0 12px;
    cursor: grab;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
}

.panel-handle:active {
    cursor: grabbing;
    background: #f3f4f6;
}

.panel-handle svg {
    pointer-events: none;
}

@keyframes pulse {
    0% {
        box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    }
    50% {
        box-shadow: -2px 0 12px rgba(59, 130, 246, 0.3);
    }
    100% {
        box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    }
}

.right-panel.hidden .panel-handle {
    animation: pulse 2s infinite;
}

/* Panel Tab Styles */
.panel-tabs {
    display: flex;
    background: white;
    border-bottom: 1px solid #e5e7eb;
    margin-top: 80px; /* Clear main toolbar */
    flex-shrink: 0;
    z-index: 10;
}

.panel-tab {
    flex-grow: 1; /* Let tabs grow */
    flex-basis: 0; /* Distribute space evenly */
    padding: 12px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    text-align: center;
}

.panel-tab:hover {
    background: #f9fafb;
    color: #111827;
}

.panel-tab.active {
    color: #3b82f6;
    border-bottom-color: #3b82f6;
}

/* Wrapper for content */
.panel-content-wrapper {
    flex: 1;
    overflow-y: auto;
    position: relative; /* Context for the copy button */
}

/* Panel Content */
.panel-content {
    padding: 20px;
}

/* Shared style for textareas */
#dataContent, #descriptionContent {
    width: 100%;
    height: 100%;
    min-height: 400px; /* Ensure it's tall enough */
    border: none;
    outline: none;
    resize: none;
    font-family: monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #374151;
    padding: 20px;
    background-color: #f9fafb; /* Light background for editing */
}

/* This content is now in a modal */
#controlsContent {
    /* display: none; */ /* Handled by modal */
    overflow-y: auto;
}

.panel-section {
    margin-bottom: 32px;
}

.panel-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* NEW: Styles for modal inputs */
.panel-section label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}
.panel-section .modal-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    margin-bottom: 12px;
}
.panel-section .modal-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.control-item {
    padding: 8px 0;
    font-size: 13px;
    color: #4b5563;
    line-height: 1.5;
}

.control-item strong {
    color: #111827;
    font-weight: 600;
}

/* Mobile styles */
@media (max-width: 768px) {
    .right-panel {
        width: 80%;
        max-width: 320px;
    }

    .right-panel.hidden {
        transform: translateX(calc(100% + 35px));
    }

    .panel-handle {
        display: flex;
    }

    .canvas-container.panel-open {
        margin-right: 0;
    }
}

/* Touch support for mobile */
@media (hover: none) and (pointer: coarse) {
    .panel-handle {
        width: 45px;
        left: -45px;
        font-size: 20px;
    }
}


.btn-primary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-share {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #10b981;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.btn-share:hover {
    background: #059669;
}

.btn-danger {
    padding: 6px 12px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-secondary {
    padding: 6px 12px;
    background: white;
    color: #374151;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
}

.btn-secondary:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #f9fafb;
}
.btn-secondary:disabled:hover {
    border-color: #d1d5db;
}

/* NEW: Style for gear button */
.btn-icon {
    padding: 8px;
    background: white;
    color: #6b7280;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-icon:hover {
    background: #f9fafb;
    border-color: #9ca3af;
    color: #111827;
}

/* NEW: Style for corner copy buttons */
.btn-copy-icon {
    position: absolute;
    bottom: 20px;
    left: 20px;
    z-index: 80; /* Below panel/toolbar, above content */
    padding: 10px;
    background: white;
    color: #6b7280;
    border: 1px solid #d1d5db;
    border-radius: 50%; /* Make it circular */
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
.btn-copy-icon:hover {
    background: #f9fafb;
    border-color: #9ca3af;
    color: #111827;
    box-shadow: 0 5px 10px rgba(0,0,0,0.1);
    transform: translateY(-1px);
}
.btn-copy-icon.copied {
    background: #ecfdf5;
    border-color: #10b981;
}
.btn-copy-icon:disabled {
    background: #f9fafb;
    cursor: not-allowed;
}


.connection-type-select {
    padding: 6px 12px;
    background: white;
    color: #374151;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    min-width: 150px;
}

.connection-type-select:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.connection-type-select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

@media (max-width: 768px) {
    #togglePanelBtn {
        display: none !important;
    }
    /* NEW: Adjust copy buttons for mobile */
    .btn-copy-icon {
        bottom: 10px;
        left: 10px;
        padding: 8px;
    }
}


.selected-info {
    margin-top: 16px;
    padding: 12px;
    background: #dbeafe;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap; /* Allow wrapping for annotation */
}

.selected-info-content {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    margin-bottom: 8px; /* Add space for controls below */
    width: 100%; /* Take full width */
}

#connectionAnnotationInput {
    margin-left: 8px;
    font-size: 12px;
    padding: 4px 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    flex-grow: 1; /* Allow it to take space */
    min-width: 120px;
}


/* Object elements */
.object-group {
    cursor: move;
}

.object-group.connecting {
    cursor: pointer;
}

.object-group.selected .object-circle {
    stroke: #3b82f6;
    stroke-width: 3;
}

.object-circle {
    fill: white;
    stroke: #333;
    stroke-width: 2;
}

.object-line {
    stroke: #333;
    stroke-width: 2;
}

.object-text {
    fill: #333;
    font-size: 14px;
    text-anchor: middle;
    dominant-baseline: middle;
    user-select: none;
    pointer-events: none;
}

/* NEW: CARDINALITY STYLE */
.object-cardinality {
    font-size: 13px;
    font-weight: 600;
    fill: #a21caf; /* Fuchsia/Purple */
    text-anchor: middle;
    pointer-events: none;
    user-select: none;
}

/* Connection elements */
.connection-line {
    cursor: pointer;
    transition: stroke-width 0.2s, stroke 0.2s;
}

.connection-line.selected {
    stroke: #3b82f6;
    stroke-width: 3;
}

.connection-hitbox {
    stroke: transparent;
    stroke-width: 25; 
    cursor: pointer;
}

.connection-marker {
    pointer-events: none;
}

.connection-annotation {
    fill: #3b82f6;
    font-size: 12px;
    font-weight: 500;
    text-anchor: middle;
    pointer-events: none;
}

.connection-type-label {
    fill: #3b82f6;
    font-size: 10px;
    font-weight: bold;
    text-anchor: middle;
    pointer-events: none;
}

/* Temp line while connecting */
.temp-line {
    stroke: #999;
    stroke-width: 2;
    stroke-dasharray: 5,5;
    pointer-events: none;
}

/* Legend items in panel */
.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 4px 0;
}

.legend-item svg {
    width: 45px;
    height: 20px;
    flex-shrink: 0;
}

.legend-item span {
    font-size: 12px;
    color: #4b5563;
}

/* Share modal */
.share-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    z-index: 1000;
    max-width: 500px;
    width: 90%;
}

.share-modal.active {
    display: block;
}

.share-modal h3 {
    margin: 0 0 16px 0;
    font-size: 18px;
    color: #111827;
}

.share-url-container {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.share-url-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-family: monospace;
}

.btn-copy {
    padding: 8px 16px;
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.btn-copy:hover {
    background: #2563eb;
}

.btn-copy.copied {
    background: #10b981;
}

.share-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.share-modal-overlay.active {
    display: block;
}

/* NEW: Controls Modal */
.controls-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    z-index: 1000;
    max-width: 600px; /* Wider than share modal */
    width: 90%;
    max-height: 80vh; /* Scrollable */
    flex-direction: column; 
}

.controls-modal.active {
    display: flex; /* Use flex to enable scrolling content */
}

.controls-modal h3 {
    margin: 0 0 16px 0;
    font-size: 18px;
    color: #111827;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.controls-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.controls-modal-overlay.active {
    display: block;
}

/* Make #controlsContent scrollable within the modal */
.controls-modal #controlsContent {
    display: block; /* Override display: none */
    overflow-y: auto; /* Make content scrollable */
    flex-grow: 1; /* Allow content to take space */
    padding: 0 12px 0 0; /* Add padding for scrollbar */
    min-height: 300px; /* Give it some min-height */
}

.controls-modal-footer {
    flex-shrink: 0; /* Prevent footer from shrinking */
    margin-top: 20px;
    text-align: right;
}

/* --- NEW: Model Info Popup Styles --- */
.model-info-popup {
    display: none;
    position: fixed;
    top: 80px; /* Position below toolbar */
    right: 60px; /* Align near the icon buttons */
    background: white;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    z-index: 1000;
    max-width: 400px;
    width: 90%;
}

.model-info-popup.active {
    display: block;
}

.model-info-footer {
    margin-top: 20px;
    text-align: right;
}

/* Make its overlay transparent for click-off */
#modelInfoOverlay {
    background: transparent;
}
/* --- End of Model Info Popup Styles --- */


/* NEW: FTU Overlay */
#ftuOverlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2001;
    cursor: pointer;
}
#ftuOverlay.active { 
    display: block; 
}
.ftu-box {
    position: absolute;
    top: 200px;
    right: calc(33.333% + 30px); /* Position left of the panel */
    width: 300px;
    background: white;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    font-size: 16px;
    line-height: 1.6;
    color: #374151;
    cursor: default;
}
.ftu-box h3 {
    font-size: 18px;
    color: #111827;
    margin-bottom: 12px;
}
.ftu-box p { 
    margin-bottom: 16px; 
}
.ftu-box .ftu-arrow {
    position: absolute;
    top: 50%;
    left: 100%;
    transform: translateY(-50%);
    width: 0; 
    height: 0; 
    border-top: 20px solid transparent;
    border-bottom: 20px solid transparent;
    border-left: 20px solid white;
}
.ftu-box .ftu-close {
    font-size: 13px;
    color: #6b7280;
    text-align: center;
    margin-top: 10px;
    font-weight: 500;
}
/* Mobile adjustment for FTU */
@media (max-width: 768px) {
    .ftu-box {
        top: 100px;
        right: 20px;
        width: calc(100% - 40px);
    }
    .ftu-box .ftu-arrow {
        display: none; /* Hide arrow on mobile */
    }
}


/* Read-only mode styles */
body.read-only .btn-primary,
body.read-only .selected-info,
body.read-only #undoBtn {
    display: none !important;
}

/* NEW: Also hide copy buttons in read-only */
body.read-only .btn-copy-icon {
    display: none !important;
}

body.read-only #modelTitleInput {
    border: none;
    background: transparent;
    pointer-events: none;
    color: #111827;
    padding-left: 0;
    font-weight: 600;
}
body.read-only #modelTitleInput::placeholder {
    color: transparent;
}

/* NEW: Disable URL editing in read-only */
body.read-only #modelUrlInput {
    display: none !important;
}
body.read-only #modelLink {
    pointer-events: none;
    color: #6b7280;
}

/* NEW: Disable modal inputs in read-only */
body.read-only #modalModelTitleInput,
body.read-only #modalModelUrlInput {
    background: #f9fafb;
    color: #6b7280;
    pointer-events: none;
}

body.read-only .object-group {
    cursor: default !important;
}

body.read-only .connection-hitbox,
body.read-only .connection-line {
    cursor: default !important;
}

body.read-only #applyPanelChangesBtn {
    display: none !important;
}

body.read-only #dataContent,
body.read-only #descriptionContent {
    background-color: white;
    color: #374151;
    padding: 20px;
}

.read-only-banner {
    display: none;
    background: #fbbf24;
    color: #78350f;
    padding: 8px 16px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
}

body.read-only .read-only-banner {
    display: block;
}

.btn-create-own {
    margin-left: 12px;
    padding: 4px 12px;
    background: white;
    color: #78350f;
    border: 1px solid #78350f;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    text-decoration: none;
}

.btn-create-own:hover {
    background: #fef3c7;
}

/* --- NEW: Feature 1 --- */
/* Animation for newly added object */
@keyframes pulse-highlight {
    0% {
        stroke: #3b82f6; /* Start bright blue */
        stroke-width: 6;
    }
    70% {
        stroke: #a5b4fc; /* Fade to light blue */
        stroke-width: 3;
    }
    100% {
        stroke: #333; /* End at normal color */
        stroke-width: 2;
    }
}

.object-group.newly-added .object-circle {
    /* Run the animation */
    animation: pulse-highlight 1.5s ease-out;
}
/* --- END: Feature 1 --- */