/* ========== CSS Reset & Variables ========== */
:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --border-color: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --accent-blue: #58a6ff;
    --accent-green: #3fb950;
    --accent-purple: #bc8cff;
    --accent-orange: #d29922;
    --accent-red: #f85149;
    --accent-cyan: #39d2c0;
    --hover-bg: rgba(255, 255, 255, 0.05);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
}

/* ========== Header ========== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.header-left h1.logo {
    font-size: 1.25rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    gap: 10px;
}

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn:hover {
    background: var(--hover-bg);
    border-color: var(--text-secondary);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    border: none;
    color: white;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-tertiary);
}

.btn-success {
    background: var(--accent-green);
    border-color: var(--accent-green);
    color: white;
}

.btn-warning {
    background: var(--accent-orange);
    border-color: var(--accent-orange);
    color: white;
}

.btn-info {
    background: var(--accent-cyan);
    border-color: var(--accent-cyan);
    color: var(--bg-primary);
}

.btn-danger {
    background: var(--accent-red);
    border-color: var(--accent-red);
    color: white;
}

.btn-block {
    width: 100%;
    justify-content: center;
    margin-bottom: 8px;
}

.btn-block:last-child {
    margin-bottom: 0;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.btn-icon.danger:hover {
    border-color: var(--accent-red);
    color: var(--accent-red);
}

/* ========== Badges ========== */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 10px;
}

.badge-info {
    background: rgba(88, 166, 255, 0.2);
    color: var(--accent-blue);
}

.badge-success {
    background: rgba(63, 185, 80, 0.2);
    color: var(--accent-green);
}

/* ========== Main Layout ========== */
.main-content {
    display: flex;
    height: calc(100vh - 57px);
}

/* ========== Sidebars ========== */
.sidebar {
    width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-tertiary) transparent;
}

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

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

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

.sidebar-left {
    border-right: 1px solid var(--border-color);
}

.sidebar-right {
    border-left: 1px solid var(--border-color);
    border-right: none;
}

/* ========== Panels ========== */
.panel {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
    font-size: 0.875rem;
    font-weight: 600;
}

.panel-body {
    padding: 12px;
}

/* ========== Search Box ========== */
.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-bottom: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
}

.search-box svg {
    color: var(--text-secondary);
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.search-box input::placeholder {
    color: var(--text-secondary);
}

/* ========== Rule Categories ========== */
.rule-categories {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rule-category {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.category-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: var(--bg-secondary);
    cursor: pointer;
    transition: background var(--transition-fast);
    user-select: none;
}

.category-header:hover {
    background: var(--hover-bg);
}

.category-icon {
    font-size: 1rem;
}

.category-name {
    flex: 1;
    font-size: 0.8rem;
    font-weight: 500;
}

.category-arrow {
    font-size: 0.7rem;
    color: var(--text-secondary);
    transition: transform var(--transition-normal);
}

.category-items {
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rule-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    cursor: grab;
    transition: all var(--transition-fast);
}

.rule-item:hover {
    background: var(--hover-bg);
    border-color: var(--accent-blue);
}

.rule-item:active {
    cursor: grabbing;
}

.rule-name {
    font-size: 0.8rem;
}

.rule-code {
    font-size: 0.7rem;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    color: var(--text-secondary);
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 3px;
}

/* ========== Node Tabs ========== */
.node-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
}

.tab-btn {
    flex: 1;
    padding: 6px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.tab-btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
}

/* ========== Node List ========== */
.node-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.node-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: grab;
    transition: all var(--transition-fast);
}

.node-item:hover {
    border-color: var(--accent-green);
    background: var(--hover-bg);
}

.node-item:active {
    cursor: grabbing;
}

.node-icon {
    font-size: 1.25rem;
}

.node-info {
    flex: 1;
    min-width: 0;
}

.node-name {
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.node-meta {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* ========== Workspace ========== */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: 
        radial-gradient(circle at 50% 50%, rgba(88, 166, 255, 0.03) 0%, transparent 50%),
        linear-gradient(rgba(48, 54, 61, 0.3) 1px, transparent 1px),
        linear-gradient(90deg, rgba(48, 54, 61, 0.3) 1px, transparent 1px);
    background-size: 100% 100%, 20px 20px, 20px 20px;
}

.canvas-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.canvas-nodes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ========== Canvas Nodes ========== */
.canvas-node {
    position: absolute;
    min-width: 180px;
    max-width: 260px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    cursor: move;
    user-select: none;
    transition: box-shadow var(--transition-fast);
}

.canvas-node:hover {
    box-shadow: var(--shadow-lg);
}

.canvas-node.selected {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2), var(--shadow-lg);
}

.canvas-node.dragging {
    opacity: 0.8;
    z-index: 1000;
}

.canvas-node.drop-target {
    border-color: var(--accent-green);
    box-shadow: 0 0 0 3px rgba(63, 185, 80, 0.3);
}

.node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    cursor: grab;
}

.node-header:active {
    cursor: grabbing;
}

.node-type-icon {
    font-size: 1.1rem;
}

.node-title {
    flex: 1;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.node-body {
    padding: 10px 14px;
}

.node-connection-points {
    display: flex;
    justify-content: space-between;
    padding: 0 14px 10px;
}

.connection-point {
    width: 12px;
    height: 12px;
    background: var(--bg-primary);
    border: 2px solid var(--text-secondary);
    border-radius: 50%;
    cursor: crosshair;
    transition: all var(--transition-fast);
}

.connection-point:hover {
    border-color: var(--accent-blue);
    background: var(--accent-blue);
    transform: scale(1.3);
}

/* ========== Strategy Tags ========== */
.strategy-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.strategy-tag {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    font-size: 0.7rem;
    font-weight: 500;
    border-radius: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
}

.strategy-tag.select {
    background: rgba(88, 166, 255, 0.15);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.strategy-tag.url-test {
    background: rgba(63, 185, 80, 0.15);
    border-color: var(--accent-green);
    color: var(--accent-green);
}

.strategy-tag.fallback {
    background: rgba(210, 153, 34, 0.15);
    border-color: var(--accent-orange);
    color: var(--accent-orange);
}

.strategy-tag.load-balance {
    background: rgba(188, 140, 255, 0.15);
    border-color: var(--accent-purple);
    color: var(--accent-purple);
}

/* ========== Workspace Toolbar ========== */
.workspace-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.toolbar-left,
.toolbar-right {
    display: flex;
    gap: 6px;
}

.zoom-level {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* ========== Properties Panel ========== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state svg {
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 0.85rem;
}

.property-group {
    margin-bottom: 16px;
}

.property-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.property-input {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.85rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    transition: border-color var(--transition-fast);
}

.property-input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

select.property-input {
    cursor: pointer;
}

textarea.property-input {
    resize: vertical;
    min-height: 80px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
}

/* ========== Modal ========== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-lg {
    max-width: 900px;
}

.modal-xl {
    max-width: 1200px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    font-size: 1.25rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.modal-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
}

/* ========== Import Modal ========== */
.import-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
}

.import-content {
    min-height: 300px;
}

.upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 250px;
    padding: 40px;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.upload-area:hover {
    border-color: var(--accent-blue);
    background: rgba(88, 166, 255, 0.05);
}

.upload-area svg {
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.upload-area p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.upload-hint {
    font-size: 0.8rem !important;
    margin-top: 8px;
}

.textarea {
    width: 100%;
    padding: 12px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 0.85rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    resize: vertical;
}

.textarea:focus {
    outline: none;
    border-color: var(--accent-blue);
}

/* ========== Deploy Steps ========== */
.deploy-steps {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.step {
    display: flex;
    gap: 16px;
    padding: 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.step.active {
    border-color: var(--accent-blue);
    background: rgba(88, 166, 255, 0.05);
}

.step.completed {
    border-color: var(--accent-green);
}

.step-number {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.step.active .step-number {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
    background: rgba(88, 166, 255, 0.1);
}

.step-content h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.step-content p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.step-content code {
    display: inline-block;
    padding: 2px 8px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 0.8rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.step-content input[type="text"] {
    width: 100%;
    padding: 10px 14px;
    font-size: 0.9rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    margin-top: 8px;
}

.step-content input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.code-block {
    margin-top: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.code-block pre {
    padding: 16px;
    font-size: 0.8rem;
    line-height: 1.6;
    overflow-x: auto;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    color: var(--text-secondary);
    margin: 0;
}

.code-block code {
    background: none;
    border: none;
    padding: 0;
}

/* ========== Preview ========== */
.preview-content {
    min-height: 400px;
}

.preview-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
}

#previewCode {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    max-height: 500px;
    overflow: auto;
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
}

/* ========== Animations ========== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease;
}

.animate-slide-in {
    animation: slideIn 0.3s ease;
}

/* ========== Responsive ========== */
@media (max-width: 1200px) {
    .sidebar {
        width: 260px;
    }
}

@media (max-width: 900px) {
    .sidebar {
        width: 220px;
    }
    
    .canvas-node {
        min-width: 150px;
        max-width: 220px;
    }
}

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        max-height: 40vh;
    }
    
    .header-actions {
        flex-wrap: wrap;
    }
    
    .btn {
        padding: 6px 12px;
        font-size: 0.8rem;
    }
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ========== Selection ========== */
::selection {
    background: rgba(88, 166, 255, 0.3);
    color: var(--text-primary);
}
