:root {
    --sidebar-width: 260px;
    --sidebar-collapsed: 0px;
    --topbar-height: 64px;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --dark: #1f2937;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius: 0.5rem;
    --transition: 200ms ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--gray-50); color: var(--gray-800); }

/* Sidebar */
.sidebar {
    position: fixed; top: 0; left: 0; height: 100vh;
    width: var(--sidebar-width); background: var(--dark);
    color: #fff; z-index: 1000; transition: margin-left var(--transition);
    display: flex; flex-direction: column; overflow-y: auto;
}
.sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-width)); }
.sidebar-brand {
    padding: 1.25rem 1.5rem; font-size: 1.1rem; font-weight: 700;
    border-bottom: 1px solid rgba(255,255,255,0.08); display: flex; align-items: center; gap: 0.75rem;
    letter-spacing: -0.01em;
}
.sidebar-brand i { color: var(--primary); font-size: 1.25rem; }
.sidebar-menu { flex: 1; padding: 0.75rem 0; }
.sidebar-menu .nav-item {
    display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1.5rem;
    color: rgba(255,255,255,0.7); text-decoration: none; transition: all var(--transition);
    font-size: 0.9rem; border-left: 3px solid transparent; cursor: pointer;
}
.sidebar-menu .nav-item:hover { color: #fff; background: rgba(255,255,255,0.05); }
.sidebar-menu .nav-item.active {
    color: #fff; background: rgba(37,99,235,0.15); border-left-color: var(--primary);
}
.sidebar-menu .nav-item i { width: 20px; text-align: center; font-size: 0.95rem; }
.sidebar-footer { padding: 1rem 1.5rem; border-top: 1px solid rgba(255,255,255,0.08); }

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width); min-height: 100vh;
    transition: margin-left var(--transition); display: flex; flex-direction: column;
}
.top-bar {
    height: var(--topbar-height); background: #fff; border-bottom: 1px solid var(--gray-200);
    display: flex; align-items: center; padding: 0 1.5rem; gap: 1rem;
    position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow-sm);
}
.sidebar-toggle { background: none; border: none; font-size: 1.25rem; color: var(--gray-600); cursor: pointer; }
.top-bar-title h5 { margin: 0; font-weight: 600; color: var(--gray-800); font-size: 1.1rem; }
.top-bar-actions { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }
.search-box { width: 320px; }
.search-box input { font-size: 0.875rem; }

.page-content { flex: 1; padding: 1.5rem; }

/* Cards */
.card {
    background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
    box-shadow: var(--shadow); transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--gray-200);
    font-weight: 600; font-size: 0.9rem; display: flex; align-items: center; gap: 0.5rem;
}
.card-body { padding: 1.25rem; }
.card-footer { padding: 0.75rem 1.25rem; border-top: 1px solid var(--gray-200); background: var(--gray-50); }

/* Stats Grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
    background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
    padding: 1.25rem; box-shadow: var(--shadow); display: flex; align-items: center; gap: 1rem;
}
.stat-icon {
    width: 48px; height: 48px; border-radius: 12px; display: flex;
    align-items: center; justify-content: center; font-size: 1.25rem;
}
.stat-info h4 { margin: 0; font-size: 1.5rem; font-weight: 700; color: var(--gray-900); }
.stat-info p { margin: 0; font-size: 0.8rem; color: var(--gray-500); }

/* Tables */
.table { margin-bottom: 0; }
.table thead th { background: var(--gray-50); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--gray-500); border-bottom: 2px solid var(--gray-200); }
.table tbody td { vertical-align: middle; font-size: 0.875rem; }

/* Badges */
.badge { font-weight: 500; font-size: 0.75rem; padding: 0.35em 0.65em; border-radius: 0.375rem; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: #f3f4f6; color: #374151; }

/* Buttons */
.btn { font-size: 0.875rem; font-weight: 500; border-radius: var(--radius); }
.btn-sm { font-size: 0.8rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }

/* Forms */
.form-control, .form-select { font-size: 0.875rem; border-radius: var(--radius); border-color: var(--gray-300); }
.form-control:focus, .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.form-label { font-weight: 500; font-size: 0.85rem; color: var(--gray-700); margin-bottom: 0.35rem; }

/* Workflow Canvas */
.canvas-container {
    background: #f8fafc; border: 2px dashed var(--gray-300); border-radius: var(--radius);
    min-height: 500px; position: relative; overflow: hidden;
    background-image: radial-gradient(circle, var(--gray-300) 1px, transparent 1px);
    background-size: 20px 20px;
}
.canvas-toolbar {
    background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
    padding: 0.75rem 1rem; margin-bottom: 1rem; display: flex; align-items: center; gap: 0.75rem;
    box-shadow: var(--shadow-sm); flex-wrap: wrap;
}
.workflow-node {
    position: absolute; min-width: 160px; background: #fff;
    border: 2px solid var(--gray-300); border-radius: var(--radius);
    box-shadow: var(--shadow); cursor: move; user-select: none;
    transition: box-shadow var(--transition), border-color var(--transition);
    z-index: 10;
}
.workflow-node:hover { box-shadow: var(--shadow-lg); }
.workflow-node.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.workflow-node-header {
    padding: 0.5rem 0.75rem; border-radius: calc(var(--radius) - 2px) calc(var(--radius) - 2px) 0 0;
    font-size: 0.8rem; font-weight: 600; color: #fff; display: flex; align-items: center; gap: 0.5rem;
}
.workflow-node-body { padding: 0.6rem 0.75rem; font-size: 0.8rem; color: var(--gray-600); }
.node-port {
    width: 12px; height: 12px; border-radius: 50%; background: var(--gray-400);
    border: 2px solid #fff; position: absolute; cursor: crosshair; z-index: 20;
}
.node-port.input { top: 50%; left: -6px; transform: translateY(-50%); }
.node-port.output { top: 50%; right: -6px; transform: translateY(-50%); }

/* Node Palette */
.node-palette {
    background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
    box-shadow: var(--shadow); max-height: 400px; overflow-y: auto;
}
.palette-item {
    padding: 0.6rem 0.75rem; display: flex; align-items: center; gap: 0.6rem;
    cursor: grab; border-bottom: 1px solid var(--gray-100); transition: background var(--transition);
    font-size: 0.85rem;
}
.palette-item:hover { background: var(--gray-50); }
.palette-item:active { cursor: grabbing; }
.palette-icon {
    width: 28px; height: 28px; border-radius: 6px; display: flex;
    align-items: center; justify-content: center; color: #fff; font-size: 0.75rem; flex-shrink: 0;
}

/* Code Editor */
.code-editor {
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    font-size: 0.85rem; line-height: 1.6; tab-size: 4;
    background: #1e1e1e; color: #d4d4d4; border-radius: var(--radius);
    border: 1px solid var(--gray-300);
}
.code-editor:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }

/* Diff Viewer */
.diff-viewer {
    font-family: 'Cascadia Code', 'Fira Code', monospace; font-size: 0.8rem;
    background: #1e1e1e; color: #d4d4d4; border-radius: var(--radius);
    padding: 1rem; max-height: 400px; overflow: auto; white-space: pre-wrap; word-break: break-all;
}
.diff-add { background: rgba(16,185,129,0.2); color: #6ee7b7; }
.diff-remove { background: rgba(239,68,68,0.2); color: #fca5a5; }

/* Modals */
.modal-content { border-radius: var(--radius); border: none; box-shadow: var(--shadow-lg); }
.modal-header { border-bottom: 1px solid var(--gray-200); padding: 1rem 1.25rem; }
.modal-body { padding: 1.25rem; }
.modal-footer { border-top: 1px solid var(--gray-200); padding: 0.75rem 1.25rem; }

/* Tabs */
.nav-tabs .nav-link { color: var(--gray-600); font-weight: 500; font-size: 0.875rem; }
.nav-tabs .nav-link.active { color: var(--primary); font-weight: 600; }

/* Empty States */
.empty-state { text-align: center; padding: 3rem; color: var(--gray-400); }
.empty-state i { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h5 { color: var(--gray-500); font-weight: 500; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { margin-left: calc(-1 * var(--sidebar-width)); }
    .sidebar.open { margin-left: 0; }
    .main-content { margin-left: 0 !important; }
    .stats-grid { grid-template-columns: 1fr; }
    .search-box { width: 180px; }
    .canvas-toolbar { flex-direction: column; align-items: stretch; }
}

/* Utility */
.text-primary { color: var(--primary) !important; }
.bg-primary { background: var(--primary) !important; }
.mb-0 { margin-bottom: 0 !important; }
.mt-3 { margin-top: 1rem !important; }
.gap-2 { gap: 0.5rem !important; }
.flex-wrap { flex-wrap: wrap; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.pointer { cursor: pointer; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--gray-100); border-radius: 4px; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* Loading spinner */
.spinner-border-sm { width: 1rem; height: 1rem; }

/* Tab content sections */
.tab-pane-section { display: none; }
.tab-pane-section.active { display: block; }
