:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-app: #f9fafb;
    --bg-panel: #ffffff;
    --border: #e5e7eb;
    --text-main: #111827;
    --text-muted: #6b7280;
    --danger: #ef4444;
    --success: #10b981;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-app);
    height: 100vh;
    overflow: hidden;
    color: var(--text-main);
}

/* --- Layout --- */
.main-container { height: 100vh; display: flex; flex-direction: column; }
.content-area { flex: 1; display: flex; position: relative; overflow: hidden; }

/* CHANGED: Allow scrolling when canvas grows */
.canvas-container { 
    flex: 1; 
    position: relative; 
    background: #fff; 
    transition: margin-right 0.3s ease;
    overflow: auto; /* Enable scrollbars */
}

/* --- Overlay for Mobile --- */
#mobile-overlay {
    display: none; position: fixed; inset: 0; 
    background: var(--bg-app); z-index: 2000;
    align-items: center; justify-content: center; 
    text-align: center; padding: 20px; font-weight: 500;
}
@media (max-width: 768px) { 
    #mobile-overlay { display: flex; } 
    .main-container { display: none; } 
}

/* --- Toolbar --- */
.toolbar {
    background: var(--bg-panel); border-bottom: 1px solid var(--border);
    padding: 8px 16px; box-shadow: 0 1px 2px rgba(0,0,0,0.03); z-index: 100;
    display: flex; flex-direction: column; gap: 8px;
}

.toolbar-content { display: flex; align-items: center; gap: 10px; height: 40px; }
.app-title { font-weight: 700; font-size: 14px; white-space: nowrap; color: var(--text-main); }
.separator { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }
.ml-auto { margin-left: auto; }
.flex-row { display: flex; gap: 8px; align-items: center; }

/* Inputs in Toolbar */
.title-editor { display: flex; flex-direction: column; margin-left: 12px; min-width: 150px; }
#modelTitleInput { font-weight: 600; border: none; background: transparent; font-size: 14px; padding: 2px 4px; border-radius: 4px; }
#modelTitleInput:hover { background: #f3f4f6; }
#modelTitleInput:focus { background: white; box-shadow: 0 0 0 2px var(--primary); }
#modelUrlInput { font-size: 11px; padding: 2px 4px; border: 1px solid transparent; border-radius: 4px; color: var(--text-muted); }
#modelUrlInput:hover, #modelUrlInput:focus { border-color: var(--border); background: white; }
#modelLink { font-size: 11px; color: var(--primary); text-decoration: none; padding-left: 4px; display: none; }

/* --- Contextual Info Bar --- */
.selected-info {
    display: flex; align-items: center; gap: 12px;
    background: #eff6ff; border: 1px solid #dbeafe; border-radius: 6px;
    padding: 6px 12px; animation: slideDown 0.2s ease-out;
}
@keyframes slideDown { from { transform: translateY(-5px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.controls-group { display: flex; gap: 8px; align-items: center; }
.input-sm { padding: 4px 8px; border: 1px solid #cbd5e1; border-radius: 4px; font-size: 13px; height: 28px; }
.input-bold { font-weight: 600; }

/* --- Read Only Banner --- */
.read-only-banner {
    display: none; 
    align-items: center; justify-content: space-between;
    background: #fff7ed; border: 1px solid #ffedd5; 
    color: #9a3412; padding: 6px 12px; border-radius: 6px; font-size: 13px;
}
body.read-only .read-only-banner { display: flex; }
body.read-only .title-editor input,
body.read-only #undoBtn,
body.read-only #addObjectBtn,
body.read-only #clearCanvasBtn,
body.read-only #applyPanelChangesBtn,
body.read-only #snapGridBtn,
body.read-only #alignBottomBtn,
body.read-only .selected-info {
    display: none !important;
}

/* --- Buttons --- */
button { cursor: pointer; font-family: inherit; transition: all 0.1s; }
.btn-primary { background: var(--primary); color: white; border: none; padding: 6px 12px; border-radius: 5px; font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: white; border: 1px solid #d1d5db; color: var(--text-main); padding: 5px 10px; border-radius: 5px; font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.btn-secondary:hover:not(:disabled) { background: #f3f4f6; }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; background: #f9fafb; color: #9ca3af; }
.btn-secondary.active { background: #e0f2fe; border-color: #3b82f6; color: #1d4ed8; } 
.btn-danger { background: var(--danger); color: white; border: none; padding: 5px 10px; border-radius: 5px; font-size: 12px; }
.btn-share { background: var(--success); color: white; border: none; padding: 6px 12px; border-radius: 5px; font-size: 13px; font-weight: 500; }
.btn-icon { background: transparent; border: none; padding: 6px; color: var(--text-muted); border-radius: 4px; }
.btn-icon:hover { background: #e5e7eb; color: var(--text-main); }
.btn-sm { padding: 0 8px; height: 28px; font-size: 12px; }
.full-width { width: 100%; display: flex; justify-content: center; }

/* --- Canvas & SVG --- */
#canvas { width: 100%; height: 100%; cursor: grab; user-select: none; }
#canvas:active { cursor: grabbing; }

.object-group { cursor: move; transition: opacity 0.2s; }
.object-group:hover .object-circle { stroke: var(--primary); }
.object-group.selected .object-circle { stroke: var(--primary); stroke-width: 3px; }
.object-circle { fill: white; stroke: #374151; stroke-width: 2px; }
.object-text { font-size: 13px; font-weight: 600; text-anchor: middle; dominant-baseline: middle; pointer-events: none; fill: var(--text-main); }
.object-cardinality { font-size: 11px; font-weight: 700; fill: #db2777; text-anchor: middle; pointer-events: none; }
.connection-annotation { font-size: 11px; fill: var(--primary); background: white; text-anchor: middle; }

/* --- Zoom Controls --- */
.zoom-controls {
    position: absolute; bottom: 20px; left: 20px;
    display: flex; align-items: center; gap: 4px;
    background: white; padding: 4px; border-radius: 8px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}
.btn-zoom { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; background: white; border: 1px solid transparent; border-radius: 4px; color: #4b5563; font-weight: 600; }
.btn-zoom:hover { background: #f3f4f6; }
.zoom-display { font-size: 12px; min-width: 45px; text-align: center; font-variant-numeric: tabular-nums; }
.separator-vertical { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.pan-hint { font-size: 11px; color: var(--text-muted); padding: 0 8px; cursor: help; }

/* --- Right Panel --- */
.right-panel {
    width: 33.333%; min-width: 300px; background: white; 
    border-left: 1px solid var(--border); display: flex; flex-direction: column;
    position: absolute; right: 0; top: 0; bottom: 0; z-index: 50;
    box-shadow: -4px 0 16px rgba(0,0,0,0.05);
    transform: translateX(0); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.right-panel.hidden { transform: translateX(100%); }

.panel-tabs { display: flex; border-bottom: 1px solid var(--border); }
.panel-tab { flex: 1; padding: 12px; background: none; border: none; border-bottom: 2px solid transparent; color: var(--text-muted); font-weight: 600; font-size: 13px; }
.panel-tab:hover { background: #f9fafb; color: var(--text-main); }
.panel-tab.active { border-bottom-color: var(--primary); color: var(--primary); }

.panel-content-wrapper { flex: 1; position: relative; display: flex; }
.panel-content { flex: 1; resize: none; border: none; padding: 16px; font-family: 'Menlo', monospace; font-size: 12px; line-height: 1.6; color: #334155; background: #f8fafc; }
.btn-float { position: absolute; bottom: 16px; right: 16px; background: white; border: 1px solid var(--border); padding: 8px; border-radius: 50%; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.panel-footer { padding: 12px; border-top: 1px solid var(--border); background: white; }

/* --- Modals --- */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; backdrop-filter: blur(2px); }
.modal { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; padding: 24px; border-radius: 8px; width: 90%; max-width: 400px; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); z-index: 1001; }
.modal.active, .modal-overlay.active { display: block; }
.share-input-group { display: flex; gap: 8px; margin: 16px 0; }
.input-code { flex: 1; background: #f1f5f9; border: 1px solid var(--border); padding: 8px; border-radius: 4px; font-family: monospace; font-size: 12px; color: #475569; }
.btn-create-own { font-weight: bold; color: #c2410c; margin-left: 10px; font-size: 13px; }