:root {
    --bg: #f5f6fa;
    --card-bg: #ffffff;
    --primary: #4f6ef7;
    --primary-hover: #3b54db;
    --text: #2c3e50;
    --text-secondary: #6b7d8e;
    --border: #e2e8f0;
    --danger: #e74c3c;
    --success: #27ae60;
    --warning: #f39c12;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1);
    --radius: 10px;
    --radius-sm: 6px;
    --transition: 0.2s ease;
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', 'Monaco', monospace;
    --sidebar-width: 220px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    line-height: 1.5;
}

/* Header */
.header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}
.header .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
}
.header .logo svg {
    width: 28px;
    height: 28px;
}
.header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    color: var(--text);
}
.btn:hover {
    background: #f8f9fc;
    border-color: #c8cdd8;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}
.btn-danger {
    color: var(--danger);
    border-color: #fdd;
}
.btn-danger:hover {
    background: #fff5f5;
    border-color: var(--danger);
}
.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}
.btn-success:hover {
    background: #219a52;
    border-color: #219a52;
}

/* Main Layout */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    flex-shrink: 0;
    overflow-y: auto;
    padding: 12px 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.sidebar-item {
    padding: 10px 20px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: var(--transition);
    border-left: 3px solid transparent;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
}
.sidebar-item:hover {
    background: #f8f9fc;
    color: var(--text);
}
.sidebar-item.active {
    background: #eef1ff;
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}

/* Content */
.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.section-panel {
    display: none;
    flex-direction: column;
    gap: 20px;
}
.section-panel.active {
    display: flex;
}

/* Cards & Forms */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.card-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 16px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 14px;
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.form-group.full-width {
    grid-column: 1 / -1;
}
.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-family: inherit;
    transition: var(--transition);
    background: #fafbfc;
    color: var(--text);
}
.form-group input:not([type="checkbox"]):not([type="radio"]):focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.1);
    background: #fff;
}
.form-group textarea {
    resize: vertical;
    min-height: 120px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
}
.form-group .hint {
    font-size: 0.75rem;
    color: #999;
    margin-top: 4px;
}

/* Toast */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    color: #fff;
    font-weight: 500;
    font-size: 0.875rem;
    animation: slideInRight 0.3s ease;
    box-shadow: var(--shadow-lg);
    display: none;
}
.toast.active {
    display: block;
}
.toast-success {
    background: var(--success);
}
.toast-error {
    background: var(--danger);
}
@keyframes slideInRight {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Login Overlay */
.login-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(245, 246, 250, 0.95);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
}
.login-overlay.active {
    display: flex;
}
.login-card {
    background: var(--card-bg);
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 360px;
    text-align: center;
    border: 1px solid var(--border);
}
.login-card h2 {
    margin-bottom: 24px;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.login-card input {
    width: 100%;
    padding: 12px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    text-align: center;
}
.login-card input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.1);
}
.login-card button {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
}
.shake {
    animation: shake 0.4s;
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

/* List Items */
.list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #fafbfc;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    transition: var(--transition);
    flex-wrap: wrap;
}
.list-item:hover {
    border-color: #c8cdd8;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.list-item .item-info {
    flex: 1;
    min-width: 150px;
}
.list-item .item-name {
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
}
.list-item .item-detail {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
}
.list-item .item-actions {
    display: flex;
    gap: 4px;
}

.rule-search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
}
.rule-search-bar input {
    flex: 1;
    min-width: 180px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fafbfc;
    color: var(--text);
    font-size: 0.875rem;
}
.rule-search-bar input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.1);
    background: #fff;
}
.rule-search-count {
    color: var(--text-secondary);
    font-size: 0.8rem;
    white-space: nowrap;
}

@media (max-width: 640px) {
    .rule-search-bar {
        flex-wrap: wrap;
    }
    .rule-search-bar input {
        flex-basis: 100%;
    }
}

/* Badges */
.type-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.badge-select { background: #eef1ff; color: var(--primary); }
.badge-url-test { background: #f3e5f5; color: #7b1fa2; }
.badge-fallback { background: #fff3e0; color: #e65100; }
.badge-load-balance { background: #e0f7fa; color: #00838f; }
.badge-default { background: #f5f5f5; color: #555; }
.badge-node { background: #e8f5e9; color: #2e7d32; }

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #bbb;
    background: #fafbfc;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}
.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}
.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 640px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    transform: translateY(20px);
    transition: var(--transition);
}
.modal-overlay.active .modal {
    transform: translateY(0);
}
.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 1.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-close {
    cursor: pointer;
    color: #999;
    font-size: 1.2rem;
}
.modal-close:hover { color: var(--danger); }
.modal-body {
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-item span { display: none; }
    .sidebar-item { justify-content: center; padding: 12px; }
    .form-grid { grid-template-columns: 1fr; }
}

/* Filter Tags (Smart Visual Filter) */
.filter-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}
.filter-tag {
    padding: 6px 12px;
    border-radius: 20px;
    background: #f0f2f5;
    border: 1px solid #d1d5db;
    font-size: 0.85rem;
    cursor: pointer;
    user-select: none;
    transition: var(--transition);
}
.filter-tag:hover {
    background: #e5e7eb;
}
.filter-tag.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    font-weight: 500;
}
.filter-tag.active:hover {
    background: var(--primary-hover);
}
.preview-list {
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    background: #fafbfc;
}
.preview-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    font-size: 0.85rem;
    border-bottom: 1px solid #eee;
}
.preview-item:last-child {
    border-bottom: none;
}
.preview-item input[type="checkbox"] {
    cursor: pointer;
}
.list-item.dragging { opacity: 0.5; border: 2px dashed var(--primary); }
.list-item.drag-over { border-top: 3px solid var(--primary); padding-top: 15px; }

img.emoji {
    height: 1em;
    width: 1em;
    margin: 0 .05em 0 .1em;
    vertical-align: -0.1em;
}
