:root {
    --bg-base: #0f1115;
    --bg-surface: #1a1d24;
    --bg-surface-hover: #232730;
    --bg-panel: #232730;

    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --border-color: #334155;
    --border-light: #475569;

    --primary: #3b82f6;
    --primary-hover: #2563eb;

    --color-added: #10b981;
    --color-added-bg: rgba(16, 185, 129, 0.1);
    --color-removed: #ef4444;
    --color-removed-bg: rgba(239, 68, 68, 0.1);
    --color-modified: #f59e0b;
    --color-modified-bg: rgba(245, 158, 11, 0.1);

    --color-fk: #8b5cf6;
    --color-pk: #eab308;

    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

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

body {
    font-family: 'Inter', system-ui, sans-serif;
    color: var(--text-primary);
    background-color: var(--bg-base);
    height: 100vh;
    overflow: hidden;
}

button {
    font-family: inherit;
    cursor: pointer;
    outline: none;
}

.w-full {
    width: 100%;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mr-1 {
    margin-right: 0.25rem;
}

.hidden {
    display: none !important;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.btn-icon {
    background: transparent;
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
}

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

.btn-primary {
    background: var(--primary);
    color: white;
}

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

.btn-outline {
    background: transparent;
    border-color: var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover {
    border-color: var(--border-light);
    background: var(--bg-surface-hover);
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 320px;
    flex-shrink: 0;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.panel-header {
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
    position: sticky;
    top: 0;
}

.panel-header h2 {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin: 0;
}

/* Migrations List */
.migration-list {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.migration-item {
    padding: 0.75rem 1rem;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.migration-item.active {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
}

.migration-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.migration-name {
    font-weight: 500;
    font-size: 0.875rem;
}

.migration-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.migration-actions {
    opacity: 0;
    transition: opacity 0.2s;
}

.migration-item:hover .migration-actions {
    opacity: 1;
}

/* SQL Editor */
.section-editor {
    position: absolute;
    inset: 0;
    background: var(--bg-surface);
    z-index: 20;
}

.sql-editor {
    flex: 1;
    background: var(--bg-base);
    color: var(--text-primary);
    border: none;
    padding: 1rem;
    font-family: 'Fira Code', monospace;
    font-size: 0.875rem;
    resize: none;
    outline: none;
    line-height: 1.5;
}

.editor-actions {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Details Panel */
.section-details {
    position: absolute;
    inset: 50% 0 0 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    z-index: 15;
}

.details-content {
    padding: 1rem;
    overflow-y: auto;
    font-size: 0.875rem;
}

.details-row {
    display: flex;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
    justify-content: space-between;
}

.details-row:last-child {
    border-bottom: none;
}

.details-label {
    color: var(--text-secondary);
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-surface);
}

/* Main View */
.main-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-base);
    /* Grid Pattern */
    background-image: radial-gradient(var(--border-color) 1px, transparent 1px);
    background-size: 20px 20px;
}

/* Top Bar */
.top-bar {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
    right: 1.5rem;
    display: flex;
    gap: 1rem;
    z-index: 10;
    pointer-events: none;
    /* Let clicks pass through empty areas */
}

.toolbar,
.timeline-container {
    background: rgba(26, 29, 36, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 0.5rem;
    pointer-events: auto;
    box-shadow: var(--shadow-md);
}

.toolbar {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.divider {
    width: 1px;
    height: 1.5rem;
    background: var(--border-color);
    margin: 0 0.25rem;
}

.timeline-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0.75rem 1.5rem;
    gap: 0.5rem;
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.875rem;
    font-weight: 500;
}

.slider-wrapper {
    position: relative;
    height: 24px;
    display: flex;
    align-items: center;
}

#timelineSlider {
    width: 100%;
    margin: 0;
    appearance: none;
    background: transparent;
    z-index: 2;
    cursor: pointer;
}

#timelineSlider::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
}

#timelineSlider::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    margin-top: -6px;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
    transition: transform 0.1s;
}

#timelineSlider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.timeline-ticks {
    position: absolute;
    top: 50%;
    left: 8px;
    right: 8px;
    height: 4px;
    transform: translateY(-50%);
    display: flex;
    justify-content: space-between;
    z-index: 1;
    pointer-events: none;
}

.tick {
    width: 2px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 1px;
    transform: translateY(-2px);
}

.tick.active {
    background: var(--primary);
}

/* Workspace & Canvas */
.workspace {
    flex: 1;
    overflow: hidden;
    position: relative;
    cursor: grab;
}

.workspace:active {
    cursor: grabbing;
}

.canvas-container {
    position: absolute;
    transform-origin: 0 0;
    width: 0;
    height: 0;
    /* Transformation applied via JS */
}

/* Connections Layer (SVG) */
.connections-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 10000px;
    height: 10000px;
    /* Arbitrarily large, overflow hidden anyway */
    pointer-events: none;
    z-index: 1;
}

.connection-path {
    fill: none;
    stroke: var(--color-fk);
    stroke-width: 2;
    opacity: 0.7;
    stroke-dasharray: 4;
}

/* Tables Layer (DOM) */
.tables-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 10000px;
    height: 10000px;
    z-index: 2;
    pointer-events: none;
    /* Let container handle pan, enable pointer events on children */
}

/* ERD Table Node */
.erd-table {
    position: absolute;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    width: 260px;
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s ease, opacity 0.3s ease, border-color 0.2s, box-shadow 0.2s;
    /* Added/Removed animation states applied via JS classes */
}

.erd-table:hover {
    box-shadow: 0 0 0 2px var(--primary);
    z-index: 10;
    cursor: default;
}

.erd-table-header {
    background: var(--bg-panel);
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-light);
    font-weight: 600;
    font-size: 0.875rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: move;
    /* Draggable handle */
}

.erd-table-actions {
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    gap: 0.25rem;
}

.erd-table:hover .erd-table-actions {
    opacity: 1;
}

.erd-columns {
    display: flex;
    flex-direction: column;
    max-height: 300px;
    overflow-y: auto;
}

.erd-column {
    display: flex;
    padding: 0.4rem 1rem;
    font-size: 0.8125rem;
    font-family: 'Fira Code', monospace;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    align-items: center;
    position: relative;
    transition: background-color 0.3s;
}

.erd-column:last-child {
    border-bottom: none;
}

.erd-col-name {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.erd-col-type {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* Status Indicators */
.status-added {
    background-color: var(--color-added-bg);
}

.status-removed {
    background-color: var(--color-removed-bg);
    text-decoration: line-through;
    opacity: 0.6;
}

.status-modified {
    background-color: var(--color-modified-bg);
}

.status-badge {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.badge-added {
    background: var(--color-added);
    box-shadow: 0 0 4px var(--color-added);
}

.badge-modified {
    background: var(--color-modified);
    box-shadow: 0 0 4px var(--color-modified);
}

.badge-removed {
    background: var(--color-removed);
    box-shadow: 0 0 4px var(--color-removed);
}

/* Keys */
.key-icon {
    font-size: 0.7rem;
}

.key-pk {
    color: var(--color-pk);
}

.key-fk {
    color: var(--color-fk);
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}