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

:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-sidebar: #161822;
    --bg-input: #232636;
    --bg-hover: #272b3d;
    --border: #2a2e3f;
    --border-focus: #5c6bc0;
    --text: #e0e0e0;
    --text-dim: #8890a8;
    --text-bright: #ffffff;
    --primary: #5c6bc0;
    --primary-hover: #7986cb;
    --primary-bg: rgba(92,107,192,0.12);
    --danger: #ef5350;
    --danger-hover: #f44336;
    --success: #66bb6a;
    --warning: #ffa726;
    --info: #42a5f5;

    /* ER Diagram colors */
    --er-entity-fill: #1e3a5f;
    --er-entity-stroke: #42a5f5;
    --er-entity-text: #e3f2fd;
    --er-weak-stroke: #42a5f5;
    --er-attr-fill: #2d1b4e;
    --er-attr-stroke: #ab47bc;
    --er-attr-text: #f3e5f5;
    --er-pk-fill: #1b3a2d;
    --er-pk-stroke: #66bb6a;
    --er-mv-fill: #1b3a2d;
    --er-mv-stroke: #66bb6a;
    --er-derived-fill: #3e2723;
    --er-derived-stroke: #ef5350;
    --er-rel-fill: #3e2a00;
    --er-rel-stroke: #ffa726;
    --er-rel-text: #fff3e0;
    --er-line: #546e7a;
    --er-line-total: #42a5f5;
    --er-card-text: #ef5350;
    --er-canvas-bg: #0c0e14;
    --er-grid: #1a1d27;
}

body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* ===== Navbar ===== */
.navbar { display: flex; align-items: center; padding: 0 24px; height: 52px; background: var(--bg-sidebar); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
.nav-brand a { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; color: var(--text-bright); }
.nav-links { margin-left: auto; display: flex; gap: 16px; }
.nav-links a { color: var(--text-dim); font-size: 14px; }
.nav-links a:hover { color: var(--text-bright); }

/* ===== Main Content ===== */
.main-content { min-height: calc(100vh - 52px); }

/* ===== Alerts ===== */
.alert { padding: 12px 20px; border-radius: 6px; margin: 16px 24px; font-size: 14px; }
.alert-error { background: rgba(239,83,80,0.15); border: 1px solid var(--danger); color: var(--danger); }
.alert-success { background: rgba(102,187,106,0.15); border: 1px solid var(--success); color: var(--success); }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 18px; border: none; border-radius: 6px; font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--text-dim); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 12px 28px; font-size: 15px; width: 100%; justify-content: center; }
.btn-icon { background: none; border: none; color: var(--text-dim); cursor: pointer; padding: 4px; border-radius: 4px; display: inline-flex; }
.btn-icon:hover { color: var(--text-bright); background: var(--bg-hover); }
.btn-icon.btn-danger { color: var(--danger); background: none; }
.btn-icon.btn-danger:hover { background: rgba(239,83,80,0.15); }

/* ===== Forms ===== */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-dim); margin-bottom: 5px; }
.form-group input[type="text"],
.form-group input[type="file"],
.form-group select,
.form-group textarea {
    width: 100%; padding: 9px 12px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 14px; font-family: inherit; transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: none; border-color: var(--border-focus); }
.form-group textarea { resize: vertical; min-height: 80px; }
.inline-form { display: inline; }

/* ===== Cards ===== */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 24px; }

/* ===== Home Page ===== */
.home-container { max-width: 1000px; margin: 0 auto; padding: 40px 24px; }
.hero { text-align: center; margin-bottom: 40px; }
.hero h1 { font-size: 32px; color: var(--text-bright); margin-bottom: 10px; }
.hero p { color: var(--text-dim); font-size: 16px; max-width: 600px; margin: 0 auto; }
.home-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; margin-bottom: 40px; }
.section { margin-top: 32px; }
.section h2 { color: var(--text-bright); font-size: 20px; margin-bottom: 16px; }

/* Caution banner */
.caution-banner { display: flex; align-items: flex-start; gap: 12px; padding: 16px 20px; background: rgba(255,167,38,0.08); border: 1px solid rgba(255,167,38,0.3); border-radius: 8px; margin-bottom: 32px; }
.caution-banner svg { flex-shrink: 0; color: var(--warning); margin-top: 2px; }
.caution-banner p { font-size: 13px; line-height: 1.6; color: var(--text-dim); }

/* Section Divider */
.section-divider { border: none; border-top: 1px solid var(--border); margin: 40px 0 24px; }

/* Footer */
.site-footer { text-align: center; padding: 24px 0 8px; margin-top: 16px; }
.site-footer p { font-size: 13px; color: var(--text-dim); }
.site-footer strong { color: var(--text); font-weight: 600; }

/* ===== SEO Content Sections ===== */
.seo-section { margin-top: 48px; }
.seo-section h2 { color: var(--text-bright); font-size: 22px; margin-bottom: 24px; text-align: center; }

/* Steps / How It Works */
.steps-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.step-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 24px; position: relative; }
.step-number { position: absolute; top: -14px; left: 20px; width: 28px; height: 28px; background: var(--primary); color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; }
.step-card h3 { color: var(--text-bright); font-size: 16px; margin-bottom: 10px; margin-top: 4px; }
.step-card p { color: var(--text-dim); font-size: 14px; line-height: 1.65; }
.step-card code { background: var(--bg-input); padding: 1px 5px; border-radius: 3px; font-size: 13px; color: var(--primary); }

/* Features Grid */
.features-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.feature-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 20px; }
.feature-item h3 { color: var(--text-bright); font-size: 15px; margin-bottom: 8px; }
.feature-item p { color: var(--text-dim); font-size: 13px; line-height: 1.65; }
.feature-item code { background: var(--bg-input); padding: 1px 5px; border-radius: 3px; font-size: 12px; color: var(--primary); }

/* Benefits List */
.benefits-list { display: grid; grid-template-columns: 1fr; gap: 16px; }
.benefit-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 20px 24px; }
.benefit-item h3 { color: var(--text-bright); font-size: 15px; margin-bottom: 6px; }
.benefit-item p { color: var(--text-dim); font-size: 14px; line-height: 1.65; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.project-card { position: relative; }
.project-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.project-card h3 a { color: var(--text-bright); font-size: 16px; }
.project-card h3 a:hover { color: var(--primary); }
.project-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }
.project-meta { font-size: 12px; color: var(--text-dim); margin-bottom: 12px; }

/* Upload area */
.upload-tabs { display: flex; gap: 0; margin-bottom: 0; border-bottom: 1px solid var(--border); }
.tab-btn { background: none; border: none; color: var(--text-dim); padding: 10px 16px; font-size: 13px; cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.15s; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; padding: 16px 0; }
.tab-content.active { display: block; }
.file-upload { border: 2px dashed var(--border); border-radius: 8px; padding: 32px; text-align: center; cursor: pointer; transition: all 0.15s; }
.file-upload:hover, .file-upload.dragover { border-color: var(--primary); background: var(--primary-bg); }
.file-upload p { color: var(--text-dim); margin-top: 8px; font-size: 14px; }
.file-upload.small { padding: 20px; }
.file-upload.small p { margin: 0 0 12px; }
.file-name { display: block; margin-top: 8px; color: var(--primary); font-size: 13px; }
.empty-hint { color: var(--text-dim); font-size: 14px; text-align: center; padding: 20px; }

/* ===== Editor Layout ===== */
.editor-layout { display: flex; height: calc(100vh - 52px); overflow: hidden; }

/* Sidebar */
.sidebar { width: 320px; min-width: 260px; background: var(--bg-sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; transition: width 0.2s; }
.sidebar.collapsed { width: 0; min-width: 0; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: 15px; color: var(--text-bright); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-tabs { display: flex; border-bottom: 1px solid var(--border); }
.stab { flex: 1; background: none; border: none; color: var(--text-dim); font-size: 12px; padding: 10px 4px; cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.15s; white-space: nowrap; }
.stab.active { color: var(--primary); border-bottom-color: var(--primary); }
.stab:hover { color: var(--text); }
.sidebar-panel { display: none; flex: 1; overflow-y: auto; padding: 12px; flex-direction: column; }
.sidebar-panel.active { display: flex; }
.panel-toolbar { margin-bottom: 10px; }
.panel-list { flex: 1; overflow-y: auto; }

/* Entity list items */
.entity-item { background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; transition: all 0.15s; }
.entity-item:hover { border-color: var(--primary); background: var(--bg-hover); }
.entity-item.selected { border-color: var(--primary); background: var(--primary-bg); }
.entity-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.entity-item-name { font-weight: 600; font-size: 13px; color: var(--text-bright); }
.entity-item-badge { font-size: 10px; padding: 1px 6px; border-radius: 3px; background: var(--primary-bg); color: var(--primary); }
.entity-item-badge.weak { background: rgba(255,167,38,0.15); color: var(--warning); }
.entity-item-attrs { font-size: 11px; color: var(--text-dim); }
.entity-item-actions { display: flex; gap: 4px; }

/* Relationship list items */
.rel-item { background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; transition: all 0.15s; }
.rel-item:hover { border-color: var(--warning); }
.rel-item-header { display: flex; justify-content: space-between; align-items: center; }
.rel-item-name { font-weight: 600; font-size: 13px; color: var(--text-bright); }
.rel-item-detail { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.rel-item-card { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 3px; background: rgba(239,83,80,0.15); color: var(--danger); font-weight: 600; }

/* SQL Editor */
.sql-editor { width: 100%; flex: 1; min-height: 300px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace; font-size: 12px; padding: 12px; resize: none; line-height: 1.6; }
.sql-editor:focus { outline: none; border-color: var(--border-focus); }

/* Properties panel */
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel-header h3 { font-size: 14px; color: var(--text-bright); }
.prop-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.prop-row label { font-size: 12px; color: var(--text-dim); min-width: 80px; }
.prop-row input, .prop-row select { flex: 1; padding: 5px 8px; background: var(--bg-input); border: 1px solid var(--border); border-radius: 4px; color: var(--text); font-size: 12px; }
.prop-row input:focus, .prop-row select:focus { outline: none; border-color: var(--border-focus); }
.prop-section { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.prop-section h4 { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.attr-list-item { display: flex; align-items: center; gap: 6px; padding: 4px 6px; background: var(--bg); border-radius: 4px; margin-bottom: 4px; font-size: 12px; }
.attr-list-item .attr-name { flex: 1; }
.attr-list-item .attr-badges { display: flex; gap: 3px; }
.attr-badge { font-size: 9px; padding: 0 4px; border-radius: 2px; }
.attr-badge.pk { background: rgba(102,187,106,0.2); color: var(--success); }
.attr-badge.mv { background: rgba(102,187,106,0.2); color: var(--success); }
.attr-badge.dv { background: rgba(239,83,80,0.2); color: var(--danger); }

/* ===== Diagram Area ===== */
.diagram-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* Toolbar */
.diagram-toolbar { display: flex; align-items: center; gap: 4px; padding: 6px 12px; background: var(--bg-sidebar); border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap; }
.toolbar-group { display: flex; align-items: center; gap: 2px; }
.toolbar-separator { width: 1px; height: 24px; background: var(--border); margin: 0 6px; }
.tool-btn { display: inline-flex; align-items: center; gap: 5px; background: none; border: 1px solid transparent; color: var(--text-dim); padding: 5px 10px; border-radius: 5px; font-size: 12px; cursor: pointer; transition: all 0.15s; white-space: nowrap; }
.tool-btn:hover { background: var(--bg-hover); color: var(--text-bright); border-color: var(--border); }
.tool-btn:active { background: var(--primary-bg); }
.zoom-display { font-size: 12px; color: var(--text-dim); min-width: 40px; text-align: center; }

/* Dropdown */
.dropdown-group { position: relative; }
.dropdown-menu { display: none; position: absolute; top: 100%; left: 0; background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; padding: 4px; min-width: 160px; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.dropdown-menu.show { display: block; }
.dropdown-item { display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text); padding: 8px 12px; font-size: 13px; cursor: pointer; border-radius: 4px; }
.dropdown-item:hover { background: var(--bg-hover); color: var(--text-bright); }

/* Canvas */
.canvas-wrapper { flex: 1; overflow: hidden; position: relative; background: var(--er-canvas-bg); }
#erdCanvas { width: 100%; height: 100%; }

/* Grid pattern */
.grid-pattern { stroke: var(--er-grid); stroke-width: 0.5; }

/* ===== ER Diagram Elements ===== */
/* Entity rectangles */
.er-entity rect { transition: stroke-width 0.15s; }
.er-entity:hover rect { stroke-width: 2.5; filter: brightness(1.15); }
.er-entity.selected rect { stroke-width: 3; stroke-dasharray: none; }
.er-entity text { font-size: 14px; font-weight: 600; fill: var(--er-entity-text); pointer-events: none; }

/* Attribute ellipses */
.er-attribute ellipse { transition: stroke-width 0.15s; }
.er-attribute:hover ellipse { stroke-width: 2; filter: brightness(1.15); }
.er-attribute text { font-size: 12px; fill: var(--text); pointer-events: none; }
.er-attribute.pk text { text-decoration: underline; font-weight: 600; }
.er-attribute.partial-key text { text-decoration: underline; font-style: italic; }

/* Relationship diamonds */
.er-relationship polygon { transition: stroke-width 0.15s; }
.er-relationship:hover polygon { stroke-width: 2.5; filter: brightness(1.15); }
.er-relationship.selected polygon { stroke-width: 3; }
.er-relationship text { font-size: 12px; font-weight: 500; fill: var(--er-rel-text); pointer-events: none; }

/* Connector lines */
.er-connector { stroke: var(--er-line); stroke-width: 1.5; fill: none; }
.er-connector.total { stroke: var(--er-line-total); stroke-width: 3; }
.er-connector-double { stroke: var(--er-line-total); stroke-width: 1.5; fill: none; }

/* Cardinality labels */
.er-cardinality { font-size: 13px; font-weight: 700; fill: var(--er-card-text); }

/* ===== Validation Panel ===== */
.validation-panel { position: absolute; bottom: 0; left: 0; right: 0; max-height: 200px; overflow-y: auto; background: var(--bg-card); border-top: 1px solid var(--border); z-index: 20; }
.validation-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-card); }
.validation-header h3 { font-size: 13px; color: var(--text-bright); }
.validation-item { display: flex; align-items: center; gap: 10px; padding: 6px 16px; font-size: 13px; border-bottom: 1px solid var(--border); }
.validation-icon { width: 18px; text-align: center; }
.validation-icon.error { color: var(--danger); }
.validation-icon.warning { color: var(--warning); }
.validation-icon.info { color: var(--info); }
.validation-stats { padding: 8px 16px; font-size: 12px; color: var(--text-dim); }

/* ===== Modals ===== */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-content { position: relative; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 24px; width: 420px; max-width: 90vw; max-height: 80vh; overflow-y: auto; }
.modal-content h3 { color: var(--text-bright); margin-bottom: 16px; font-size: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.modal-divider { text-align: center; color: var(--text-dim); font-size: 13px; margin: 12px 0; }

/* ===== Context Menu ===== */
.context-menu { position: fixed; background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; padding: 4px; min-width: 160px; z-index: 300; box-shadow: 0 8px 24px rgba(0,0,0,0.5); }
.context-menu-item { display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text); padding: 8px 12px; font-size: 13px; cursor: pointer; border-radius: 4px; }
.context-menu-item:hover { background: var(--bg-hover); color: var(--text-bright); }
.context-menu-item.danger { color: var(--danger); }
.context-menu-item.danger:hover { background: rgba(239,83,80,0.15); }
.context-menu-separator { height: 1px; background: var(--border); margin: 4px 0; }

/* ===== Inline Edit ===== */
.inline-edit-input { background: var(--bg-input); border: 2px solid var(--primary); color: var(--text-bright); padding: 2px 6px; font-size: inherit; font-weight: inherit; font-family: inherit; border-radius: 3px; outline: none; text-align: center; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ===== Responsive ===== */
@media (max-width: 960px) {
    .steps-grid { grid-template-columns: 1fr; }
    .features-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .home-container { padding: 24px 16px; }
    .home-grid { grid-template-columns: 1fr; }
    .hero h1 { font-size: 26px; }
    .features-grid { grid-template-columns: 1fr; }
    .seo-section h2 { font-size: 19px; }
    .sidebar { width: 260px; position: absolute; z-index: 50; height: calc(100vh - 52px); }
    .sidebar.collapsed { width: 0; }
}
