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

:root {
    --bg-base: #060710;
    --bg-s1: #0c0e1a;
    --bg-s2: #131724;
    --bg-s3: #1a1f30;
    --bg-glass: rgba(19, 23, 36, 0.8);
    --bg-glass-h: rgba(26, 31, 48, 0.9);
    --border-s: rgba(255,255,255,0.05);
    --border-d: rgba(255,255,255,0.08);
    --border-st: rgba(255,255,255,0.12);
    --text-1: #e8ecf4;
    --text-2: #8892a8;
    --text-3: #555e73;
    --purple: #7c5cff;
    --blue: #4a9eff;
    --grad: linear-gradient(135deg, var(--purple), var(--blue));
    --st-pending: #5a6175;
    --st-progress: #6366f1;
    --st-blocked: #f59e0b;
    --st-failed: #ef4444;
    --st-done: #22c55e;
    --radius: 10px;
    --dur: 250ms;
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --header-h: 60px;
    --node-w: 230px;
    --node-h: 76px;
}

html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font); background: var(--bg-base); color: var(--text-1); height: 100vh; overflow: hidden; }

/* === Header === */
.header {
    height: var(--header-h); display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; background: var(--bg-s1); border-bottom: 1px solid var(--border-s);
    position: relative; z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 16px; }
.header-center { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.header-right { display: flex; align-items: center; gap: 8px; }
.logo { display: flex; align-items: center; gap: 10px; }
.logo-text { font-size: 16px; font-weight: 700; background: var(--grad); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.project-name { font-size: 13px; color: var(--text-2); padding: 4px 10px; background: var(--bg-s2); border-radius: 6px; }

/* === Stats Bar === */
.stats-bar { display: flex; align-items: center; gap: 12px; }
.stat { display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 16px; font-weight: 700; }
.stat-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-divider { width: 1px; height: 20px; background: var(--border-d); }
.stat-dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-pending { background: var(--st-pending); }
.dot-progress { background: var(--st-progress); animation: pulse-glow 2s ease-in-out infinite; }
.dot-blocked { background: var(--st-blocked); }
.dot-failed { background: var(--st-failed); }
.dot-done { background: var(--st-done); }
.progress-track { width: 200px; height: 4px; background: var(--bg-s3); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--grad); border-radius: 2px; transition: width 0.6s var(--ease); }

/* === Buttons === */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 8px;
    border: none; font-family: var(--font); font-size: 13px; font-weight: 500; cursor: pointer; transition: all var(--dur) var(--ease); }
.btn-primary { background: var(--grad); color: #fff; }
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: 0 4px 20px rgba(124,92,255,0.3); }
.btn-secondary { background: var(--bg-s2); color: var(--text-1); border: 1px solid var(--border-d); }
.btn-secondary:hover { background: var(--bg-s3); border-color: var(--border-st); }
.btn-ghost { background: transparent; color: var(--text-2); padding: 8px; border-radius: 8px; }
.btn-ghost:hover { background: var(--bg-s2); color: var(--text-1); }
.auto-refresh-active { color: var(--st-done) !important; background: rgba(34,197,94,0.1) !important;
    box-shadow: 0 0 12px rgba(34,197,94,0.2); animation: auto-pulse 2s ease-in-out infinite; }
@keyframes auto-pulse { 0%,100% { box-shadow: 0 0 8px rgba(34,197,94,0.15); } 50% { box-shadow: 0 0 16px rgba(34,197,94,0.3); } }
.btn-lg { padding: 12px 24px; font-size: 14px; border-radius: 10px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-icon { background: none; border: none; color: var(--text-3); cursor: pointer; font-size: 18px; padding: 4px; }
.btn-icon:hover { color: var(--text-1); }

/* === Main Layout === */
.main { height: calc(100vh - var(--header-h)); position: relative; overflow: hidden; }

/* === Empty State === */
.empty-state { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; z-index: 10; }
.empty-visual { position: relative; width: 180px; height: 180px; display: flex; align-items: center; justify-content: center; margin-bottom: 8px; }
.empty-orb { width: 80px; height: 80px; border-radius: 50%; background: radial-gradient(circle, rgba(124,92,255,0.35), transparent 70%); filter: blur(16px); animation: orb-float 4s ease-in-out infinite; }
.ring { position: absolute; border: 1px solid rgba(124,92,255,0.12); border-radius: 50%; top: 50%; left: 50%; transform: translate(-50%,-50%); animation: ring-expand 4s ease-out infinite; }
.ring-1 { width: 80px; height: 80px; }
.ring-2 { width: 130px; height: 130px; animation-delay: 1.3s; }
.ring-3 { width: 180px; height: 180px; animation-delay: 2.6s; }
.empty-title { font-size: 22px; font-weight: 700; }
.empty-desc { color: var(--text-2); font-size: 14px; }
.empty-actions { display: flex; gap: 12px; margin-top: 8px; }
.format-example { margin-top: 24px; background: var(--bg-s1); border: 1px solid var(--border-s); border-radius: var(--radius);
    padding: 16px 20px; font-size: 12px; color: var(--text-2); line-height: 1.7; font-family: 'Courier New', monospace; max-width: 380px; }

/* === Canvas === */
.canvas-wrapper { height: 100%; position: relative; overflow: auto; }
.canvas-wrapper::-webkit-scrollbar { width: 8px; height: 8px; }
.canvas-wrapper::-webkit-scrollbar-track { background: transparent; }
.canvas-wrapper::-webkit-scrollbar-thumb { background: var(--bg-s3); border-radius: 4px; }
.canvas { position: relative; min-width: 100%; min-height: 100%; transform-origin: 0 0;
    background-image: radial-gradient(circle, rgba(255,255,255,0.03) 1px, transparent 1px); background-size: 24px 24px;
    cursor: grab; user-select: none; }
.canvas.dragging { cursor: grabbing; }
.connections-layer { position: absolute; top: 0; left: 0; pointer-events: none; }
.nodes-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }

/* === Flow Nodes === */
.flow-node {
    position: absolute; width: var(--node-w); height: var(--node-h);
    background: var(--bg-glass); backdrop-filter: blur(16px);
    border: 1px solid var(--border-d); border-radius: var(--radius);
    display: flex; align-items: center; gap: 12px; padding: 0 16px;
    cursor: pointer; transition: all var(--dur) var(--ease);
    opacity: 0; transform: scale(0.9);
}
.flow-node.visible { opacity: 1; transform: scale(1); }
.flow-node::before {
    content: ''; position: absolute; left: 0; top: 18%; bottom: 18%; width: 3px;
    border-radius: 0 3px 3px 0; transition: background var(--dur);
}
.flow-node:hover { background: var(--bg-glass-h); transform: translateY(-2px) scale(1); box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.flow-node.selected { border-color: var(--purple); box-shadow: 0 0 20px rgba(124,92,255,0.2); }

.status-pending::before { background: var(--st-pending); }
.status-progress::before { background: var(--st-progress); }
.status-blocked::before { background: var(--st-blocked); }
.status-failed::before { background: var(--st-failed); }
.status-done::before { background: var(--st-done); }
.status-progress { animation: pulse-glow 3s ease-in-out infinite; }

.node-icon { font-size: 24px; flex-shrink: 0; }
.node-content { flex: 1; min-width: 0; }
.node-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node-badge { display: flex; align-items: center; gap: 5px; margin-top: 4px; font-size: 11px; color: var(--text-2); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }
.status-pending .badge-dot { background: var(--st-pending); }
.status-progress .badge-dot { background: var(--st-progress); }
.status-blocked .badge-dot { background: var(--st-blocked); }
.status-failed .badge-dot { background: var(--st-failed); }
.status-done .badge-dot { background: var(--st-done); }

/* === Canvas Toolbar === */
.canvas-toolbar { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50;
    display: flex; align-items: center; gap: 4px; padding: 6px 12px;
    background: var(--bg-glass); backdrop-filter: blur(16px); border: 1px solid var(--border-d); border-radius: 12px; }
.tool-btn { background: none; border: none; color: var(--text-2); cursor: pointer; padding: 6px 8px;
    border-radius: 6px; font-size: 16px; transition: all var(--dur); }
.tool-btn:hover { background: var(--bg-s3); color: var(--text-1); }
.zoom-level { font-size: 12px; color: var(--text-3); min-width: 40px; text-align: center; }
.tool-sep { width: 1px; height: 16px; background: var(--border-d); margin: 0 4px; }

/* === Detail Panel === */
.detail-panel {
    position: absolute; top: 0; right: 0; width: 320px; height: 100%;
    background: var(--bg-s1); border-left: 1px solid var(--border-s);
    transform: translateX(100%); transition: transform 0.35s var(--ease);
    z-index: 60; display: flex; flex-direction: column;
}
.detail-panel.open { transform: translateX(0); }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border-s); }
.panel-title { font-size: 15px; font-weight: 600; }
.panel-body { padding: 20px; display: flex; flex-direction: column; gap: 20px; overflow-y: auto; flex: 1; }
.panel-icon { font-size: 40px; text-align: center; padding: 12px 0; }
.panel-field label { display: block; font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.panel-field p { font-size: 13px; color: var(--text-2); line-height: 1.6; }
.status-switcher { display: flex; flex-wrap: wrap; gap: 6px; }
.status-btn { padding: 6px 14px; border-radius: 6px; border: 1px solid var(--border-d); background: transparent;
    color: var(--text-2); font-size: 12px; font-family: var(--font); cursor: pointer; transition: all var(--dur); }
.status-btn:hover { border-color: var(--border-st); color: var(--text-1); }
.status-btn.active { background: var(--grad); border-color: transparent; color: #fff; }
.dep-list { display: flex; flex-wrap: wrap; gap: 6px; }
.dep-tag { padding: 4px 10px; background: var(--bg-s2); border-radius: 6px; font-size: 12px; color: var(--text-2); }
.text-muted { color: var(--text-3); font-size: 12px; }
.panel-record { display: flex; flex-direction: column; gap: 8px; font-size: 12px; color: var(--text-2); line-height: 1.5; }
.record-item { padding: 8px 10px; background: var(--bg-s2); border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* === Modal === */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center; z-index: 200;
    opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal { background: var(--bg-s1); border: 1px solid var(--border-d); border-radius: 16px;
    width: 480px; max-width: 90vw; box-shadow: 0 16px 48px rgba(0,0,0,0.5);
    transform: scale(0.95); transition: transform 0.3s var(--ease); }
.modal-overlay.open .modal { transform: scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; border-bottom: 1px solid var(--border-s); }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-subtitle { color: var(--text-3); font-size: 12px; line-height: 1.5; margin-top: 4px; }
.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 24px; border-top: 1px solid var(--border-s); }
.drop-zone { border: 2px dashed var(--border-d); border-radius: var(--radius); padding: 28px; text-align: center;
    color: var(--text-3); transition: all var(--dur); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.drop-zone.dragover { border-color: var(--purple); background: rgba(124,92,255,0.05); }
.divider-text { text-align: center; color: var(--text-3); font-size: 12px; position: relative; }
.divider-text::before, .divider-text::after { content: ''; position: absolute; top: 50%; width: 40%; height: 1px; background: var(--border-d); }
.divider-text::before { left: 0; }
.divider-text::after { right: 0; }
.json-input { width: 100%; background: var(--bg-s2); border: 1px solid var(--border-d); border-radius: 8px;
    padding: 12px; color: var(--text-1); font-family: 'Courier New', monospace; font-size: 12px;
    resize: vertical; outline: none; transition: border-color var(--dur); }
.json-input:focus { border-color: var(--purple); }
.prompt-modal { width: 680px; }
.prompt-form { max-height: min(65vh, 620px); overflow-y: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-field { display: flex; flex-direction: column; gap: 7px; }
.form-field > span { color: var(--text-2); font-size: 12px; font-weight: 500; }
.text-input { width: 100%; background: var(--bg-s2); border: 1px solid var(--border-d); border-radius: 8px;
    padding: 11px 12px; color: var(--text-1); font-family: var(--font); font-size: 13px;
    outline: none; transition: border-color var(--dur), box-shadow var(--dur); }
.text-input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(124,92,255,0.12); }
.text-input.invalid { border-color: var(--st-failed); box-shadow: 0 0 0 3px rgba(239,68,68,0.1); }
.requirement-input { resize: vertical; min-height: 118px; line-height: 1.6; }
.prompt-tip { display: flex; gap: 9px; padding: 11px 12px; background: rgba(124,92,255,0.08);
    border: 1px solid rgba(124,92,255,0.18); border-radius: 8px; color: var(--text-2); font-size: 12px; line-height: 1.5; }
.copy-status { min-height: 18px; color: var(--st-done); font-size: 12px; text-align: right; }
.copy-status.error { color: var(--st-failed); }
.prompt-footer { justify-content: space-between; }

/* === SVG Connections === */
.connection { transition: stroke 0.4s, opacity 0.4s; }
.conn-progress { stroke-dasharray: 8 4; animation: dash-flow 1s linear infinite; }

/* === Animations === */
@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99,102,241,0); }
    50% { box-shadow: 0 0 16px 2px rgba(99,102,241,0.15); }
}
@keyframes orb-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}
@keyframes ring-expand {
    0% { opacity: 0.6; transform: translate(-50%,-50%) scale(0.6); }
    100% { opacity: 0; transform: translate(-50%,-50%) scale(1.2); }
}
@keyframes dash-flow {
    to { stroke-dashoffset: -12; }
}
@keyframes fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1500px) {
    .header { padding: 0 14px; }
    .header-left { gap: 8px; }
    .project-name { display: none; }
    .stats-bar { gap: 8px; }
    .stat-label { display: none; }
}

@media (max-width: 1050px) {
    .header-center { display: none; }
    .header-right .btn-primary { display: none; }
}

@media (max-width: 650px) {
    .form-grid { grid-template-columns: 1fr; }
    .prompt-footer { align-items: stretch; flex-direction: column-reverse; }
    .prompt-footer .btn { justify-content: center; }
}
