/* =========================================
   Database ERD Designer — Styles
   Cyber Violet: #6C5CE7 / #A29BFE / #00CEC9
   Background: #0A0A1A
   ========================================= */

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

:root {
    --primary: #6C5CE7;
    --primary-light: #A29BFE;
    --primary-glow: rgba(108, 92, 231, 0.15);
    --accent: #00CEC9;
    --accent-glow: rgba(0, 206, 201, 0.15);

    --bg-base: #0A0A1A;
    --bg-surface: #14142B;
    --bg-elevated: #1C1C3A;
    --bg-hover: #262650;
    --bg-input: #080818;

    --text-primary: #F1F5F9;
    --text-secondary: #A29BFE;
    --text-muted: #6B7294;

    --border: #2A2A50;
    --success: #10B981;
    --error: #EF4444;
    --warning: #F59E0B;

    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Inter', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --transition: 200ms ease;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

body {
    font-family: var(--font);
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-wrap: wrap;
    z-index: 10;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

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

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

.logo {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius-sm);
    display: grid;
    place-items: center;
    font-size: 0.9rem;
    color: #fff;
    font-weight: 700;
}

h1 {
    font-size: 1.1rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--text-primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.divider {
    width: 1px;
    height: 24px;
    background: var(--border);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    padding: 7px 14px;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

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

.btn-sm {
    font-size: 0.75rem;
    padding: 5px 10px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #5B4BD5);
    color: #fff;
    box-shadow: 0 0 12px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--primary-light);
    border: 1px solid var(--border);
}

.btn-accent {
    background: linear-gradient(135deg, var(--accent), #00B5B0);
    color: var(--bg-base);
    font-weight: 600;
}

.btn-danger {
    color: var(--error);
}

/* Inputs */
.input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    padding: 8px 12px;
    transition: border-color var(--transition);
}

.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.select {
    font-family: var(--font);
    cursor: pointer;
}

.textarea {
    font-family: var(--font-mono);
    resize: vertical;
    min-height: 120px;
    width: 100%;
}

.input-color {
    width: 36px;
    height: 36px;
    border: none;
    cursor: pointer;
    background: none;
    border-radius: var(--radius-sm);
}

/* Canvas */
.canvas-container {
    flex: 1;
    overflow: auto;
    position: relative;
}

.canvas {
    position: relative;
    min-width: 3000px;
    min-height: 2000px;
    background:
        radial-gradient(circle at 20% 30%, rgba(108, 92, 231, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(0, 206, 201, 0.05) 0%, transparent 50%),
        var(--bg-base);
    background-size: cover;
}

.canvas::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 40px 40px;
    opacity: 0.3;
    pointer-events: none;
}

/* Relationship Lines SVG */
.relations-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.relation-line {
    stroke: var(--primary-light);
    stroke-width: 2;
    fill: none;
    opacity: 0.7;
}

.relation-line:hover {
    opacity: 1;
    stroke-width: 3;
}

/* Table Nodes */
.table-node {
    position: absolute;
    min-width: 200px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 2;
    cursor: grab;
    user-select: none;
    transition: box-shadow 200ms ease;
}

.table-node:hover {
    box-shadow: 0 0 25px var(--primary-glow);
}

.table-node.selected {
    border-color: var(--primary);
    box-shadow: 0 0 25px var(--primary-glow);
}

.table-node.dragging {
    cursor: grabbing;
    z-index: 50;
    opacity: 0.9;
}

.table-header {
    padding: 10px 14px;
    border-radius: var(--radius) var(--radius) 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 0.85rem;
    background: linear-gradient(135deg, var(--primary), #5B4BD5);
    color: #fff;
}

.table-columns {
    padding: 4px 0;
    max-height: 200px;
    overflow-y: auto;
}

.table-col {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 14px;
    font-size: 0.78rem;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(42, 42, 80, 0.5);
}

.table-col:last-child {
    border-bottom: none;
}

.col-icon {
    font-size: 0.7rem;
    width: 14px;
    text-align: center;
}

.col-icon.pk {
    color: var(--warning);
}

.col-icon.fk {
    color: var(--accent);
}

.col-name {
    flex: 1;
    font-family: var(--font-mono);
    font-weight: 500;
}

.col-type {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.72rem;
}

/* Side Panel */
.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 340px;
    max-width: 90vw;
    height: 100vh;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 100;
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.5);
    overflow-y: auto;
    animation: slideInRight 250ms ease;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-header h2 {
    font-size: 1rem;
    font-weight: 700;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

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

.columns-header h3 {
    font-size: 0.85rem;
    font-weight: 600;
}

.columns-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.col-editor {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
}

.col-editor-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 6px;
}

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

.col-editor-row .input {
    font-size: 0.78rem;
    padding: 5px 8px;
}

.col-editor-row .input:first-child {
    flex: 1;
}

.col-check {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.col-check input {
    accent-color: var(--primary);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 26, 0.85);
    display: grid;
    place-items: center;
    z-index: 200;
    animation: fadeIn 200ms ease;
}

.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    min-width: 380px;
    max-width: 90vw;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-lg {
    min-width: 600px;
}

.modal-content h2 {
    font-size: 1.05rem;
    font-weight: 700;
}

.modal-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.code-output {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 16px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--accent);
    line-height: 1.6;
    overflow: auto;
    white-space: pre-wrap;
    max-height: 400px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 20px;
    font-size: 0.85rem;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    z-index: 300;
    opacity: 0;
    transition: transform 250ms ease, opacity 250ms ease;
    pointer-events: none;
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
    }

    to {
        transform: translateX(0);
    }
}

@media (max-width: 768px) {
    .toolbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .modal-content {
        min-width: auto;
    }

    .side-panel {
        width: 100%;
    }
}

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

::-webkit-scrollbar {
    width: 6px;
}

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

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