/* ===== Reset & Variables ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-base: #030014;
    --bg-card: #0A0A1A;
    --bg-card-hover: #0F0F22;
    --bg-input: #14142B;
    --border: rgba(55, 55, 80, 0.5);
    --border-hover: rgba(139, 92, 246, 0.3);
    --text-primary: #FFFFFF;
    --text-secondary: #9CA3AF;
    --text-muted: #6B7280;
    --text-dim: #4B5563;
    --purple: #8B5CF6;
    --cyan: #06B6D4;
    --pink: #EC4899;
    --green: #10B981;
    --yellow: #FBBF24;
    --red: #EF4444;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 16px;
    --transition: 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ===== Top Nav ===== */
.topnav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    padding: 0 40px;
    background: rgba(2, 0, 6, 0.95);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #8B5CF6, #06B6D4);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.nav-center {
    display: flex;
    gap: 32px;
}

.nav-item {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-secondary);
    transition: color var(--transition);
    cursor: pointer;
}

.nav-item:hover {
    color: var(--text-primary);
}

.nav-item.active {
    font-weight: 500;
    color: var(--purple);
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.nav-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: rgba(10, 10, 26, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--transition);
}

.nav-icon-btn:hover {
    background: rgba(20, 20, 43, 1);
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 18px;
    background: linear-gradient(135deg, #EB4899, #8B5CF6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: white;
    cursor: pointer;
}

/* ===== Hero ===== */
.hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 36px 48px 20px;
}

.hero-left {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.hero-title {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -1px;
    color: var(--text-primary);
}

.hero-desc {
    font-size: 15px;
    color: var(--text-secondary);
}

.hero-right {
    display: flex;
    gap: 16px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 140px;
    height: 88px;
    padding: 16px 18px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-value.purple { color: var(--purple); }
.stat-value.cyan { color: var(--cyan); }
.stat-value.pink { color: var(--pink); }

/* ===== Content ===== */
.content {
    padding: 0 48px 40px;
}

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

.section-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.section-link {
    font-size: 13px;
    font-weight: 500;
    color: var(--purple);
    cursor: pointer;
    transition: opacity var(--transition);
}

.section-link:hover {
    opacity: 0.8;
}

/* ===== Workflow Grid ===== */
.workflow-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 20px;
}

.workflow-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 24px 24px 20px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.03);
    transition: all var(--transition);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.workflow-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: transparent;
    transition: background var(--transition);
}

.workflow-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border);
    transform: translateY(-2px);
}

.workflow-card.deployed::before {
    background: linear-gradient(90deg, var(--purple), var(--cyan));
}

.workflow-card.deployed:hover {
    border-color: rgba(139, 92, 246, 0.2);
}

.card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.card-icon.purple {
    background: linear-gradient(135deg, #8B5CF6, #06B6D4);
}

.card-icon.cyan {
    background: linear-gradient(135deg, #06B6D4, #4093FF);
}

.card-icon.pink {
    background: linear-gradient(135deg, #EB4899, #F67428);
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

.status-badge.deployed {
    background: rgba(6, 18, 12, 1);
    color: var(--green);
}

.status-badge.dev {
    background: rgba(18, 14, 4, 1);
    color: var(--yellow);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 3px;
}

.status-dot.green { background: var(--green); }
.status-dot.yellow { background: var(--yellow); }

.card-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
}

.card-desc {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.6;
    flex: 1;
}

.card-tags {
    font-size: 11px;
    font-weight: 500;
}

.card-tags.purple { color: var(--purple); }
.card-tags.cyan { color: var(--cyan); }
.card-tags.pink { color: var(--pink); }

.card-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 40px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    transition: all var(--transition);
    cursor: pointer;
    border: none;
    width: 100%;
}

.card-btn.active {
    background: linear-gradient(135deg, #8B5CF6, #663DCC);
    color: white;
}

.card-btn.active:hover {
    background: linear-gradient(135deg, #9D6FFF, #7748E0);
    transform: translateY(-1px);
}

.card-btn.disabled {
    background: rgba(8, 8, 15, 1);
    color: var(--text-dim);
    cursor: not-allowed;
}

/* Add new card */
.workflow-card.add-new {
    border: 1px dashed rgba(48, 48, 64, 0.5);
    background: transparent;
    align-items: center;
    justify-content: center;
    min-height: 260px;
}

.workflow-card.add-new:hover {
    border-color: rgba(139, 92, 246, 0.3);
    background: rgba(10, 10, 26, 0.5);
}

.add-new-icon {
    width: 48px;
    height: 48px;
    border-radius: 24px;
    background: rgba(18, 14, 40, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
}

.add-new-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--purple);
}

.add-new-sub {
    font-size: 12px;
    color: var(--text-dim);
}

/* ===== API Status Grid ===== */
.api-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.api-item {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 52px;
    padding: 0 16px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.api-dot {
    width: 8px;
    height: 8px;
    border-radius: 4px;
    flex-shrink: 0;
}

.api-dot.green { background: var(--green); }
.api-dot.gray { background: #666; }

.api-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.api-status {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: auto;
}

.api-item.connected .api-status { color: var(--green); }
.api-item.disconnected .api-name { color: var(--text-secondary); }

/* ===== Recent Runs ===== */
.recent-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.recent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    padding: 0 16px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.03);
    transition: background var(--transition);
}

.recent-item:hover {
    background: var(--bg-card-hover);
}

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

.recent-dot {
    width: 8px;
    height: 8px;
    border-radius: 4px;
}

.recent-dot.green { background: var(--green); }
.recent-dot.red { background: var(--red); }

.recent-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.recent-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.recent-time {
    font-size: 11px;
    color: var(--text-muted);
}

.recent-status {
    font-size: 11px;
    font-weight: 600;
}

.recent-status.success { color: var(--green); }
.recent-status.error { color: var(--red); }

.recent-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-dim);
}

.recent-empty p {
    font-size: 14px;
    margin-bottom: 4px;
}

.recent-empty span {
    font-size: 12px;
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
}

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

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

.config-section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.config-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.config-section h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--purple);
    margin-bottom: 4px;
}

.config-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--purple);
}

/* ===== Backend Section ===== */
.backend-section {
    background: rgba(139, 92, 246, 0.04);
    border-radius: 12px;
    padding: 16px 20px !important;
    margin-bottom: 24px;
    border: 1px solid rgba(139, 92, 246, 0.12);
}

.backend-input-group {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

.backend-input-group input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--transition);
}

.backend-input-group input:focus {
    outline: none;
    border-color: var(--purple);
}

.btn-test-backend {
    padding: 10px 18px;
    border-radius: 8px;
    border: 1px solid var(--purple);
    background: transparent;
    color: var(--purple);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    transition: all var(--transition);
}

.btn-test-backend:hover {
    background: rgba(139, 92, 246, 0.1);
}

.backend-status {
    margin-top: 10px;
    font-size: 12px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.backend-status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.backend-status.connected {
    color: var(--green);
    background: rgba(16, 185, 129, 0.08);
}
.backend-status.connected::before { background: var(--green); }

.backend-status.disconnected {
    color: var(--text-muted);
    background: rgba(107, 114, 128, 0.08);
}
.backend-status.disconnected::before { background: var(--text-muted); }

.backend-status.testing {
    color: var(--yellow);
    background: rgba(251, 191, 36, 0.08);
}
.backend-status.testing::before {
    background: var(--yellow);
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    display: flex;
    justify-content: flex-end;
}

.btn-save {
    padding: 10px 24px;
    border-radius: var(--radius-sm);
    border: none;
    background: linear-gradient(135deg, #8B5CF6, #663DCC);
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
}

.btn-save:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(139, 92, 246, 0.3);
}

/* ===== New Button ===== */
.btn-new {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: none;
    background: linear-gradient(135deg, #8B5CF6, #6633CC);
    color: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all var(--transition);
}

.btn-new:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(139, 92, 246, 0.3);
}

/* ===== Toast ===== */
#toast-container {
    position: fixed;
    top: 80px;
    right: 32px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    animation: slideIn 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.toast.success { background: var(--green); color: white; }
.toast.error { background: var(--red); color: white; }
.toast.info { background: var(--purple); color: white; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

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

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

::-webkit-scrollbar-thumb {
    background: rgba(55, 55, 80, 0.5);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.3);
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .hero {
        flex-direction: column;
        align-items: flex-start;
        gap: 24px;
    }

    .hero-right {
        flex-wrap: wrap;
    }
}

@media (max-width: 768px) {
    .topnav {
        padding: 0 16px;
    }

    .nav-center {
        display: none;
    }

    .hero {
        padding: 24px 16px 16px;
    }

    .content {
        padding: 0 16px 40px;
    }

    .hero-title {
        font-size: 24px;
    }

    .workflow-grid {
        grid-template-columns: 1fr;
    }

    .api-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        width: calc(50% - 8px);
    }
}
