:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --bg-page: #f1f5f9;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --border: #e2e8f0;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', system-ui, sans-serif; }

body { background: var(--bg-page); color: var(--text-main); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

/* Layout Geral */
.container { max-width: 1200px; margin: 20px auto; background: var(--bg-card); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.05); height: calc(100vh - 40px); display: flex; flex-direction: column; overflow: hidden; }

header { padding: 20px 30px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: white; }
.header-title { display: flex; align-items: center; gap: 10px; color: var(--primary); }
.header-title i { font-size: 24px; }

.status { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; background: #f8fafc; padding: 6px 12px; border-radius: 20px; border: 1px solid var(--border); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.status.connected .status-dot { background: var(--success); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2); }

/* Tabs */
.tabs { display: flex; background: white; padding: 0 30px; border-bottom: 1px solid var(--border); }
.tab-button { background: none; border: none; padding: 15px 20px; cursor: pointer; color: var(--secondary); font-weight: 600; display: flex; align-items: center; gap: 8px; transition: 0.2s; border-bottom: 2px solid transparent; }
.tab-button:hover { color: var(--primary); background: #f8fafc; }
.tab-button.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-content { padding: 30px; display: none; overflow-y: auto; flex: 1; }
.tab-content.active { display: block; }

/* Grid & Cards */
.grid-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; margin-top: 20px; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.actions { display: flex; gap: 10px; }

.group-card, .funnel-card { background: white; border: 1px solid var(--border); border-radius: 8px; padding: 20px; transition: 0.3s; position: relative; overflow: hidden; }
.group-card:hover, .funnel-card:hover { transform: translateY(-3px); box-shadow: 0 10px 20px rgba(0,0,0,0.05); border-color: var(--primary); }
.group-card h3, .funnel-card h3 { font-size: 16px; margin-bottom: 10px; color: var(--text-main); }
.card-meta { font-size: 12px; color: var(--secondary); margin-bottom: 15px; display: block; }

.list-container { margin-top: 20px; }
.empty-state { text-align: center; color: var(--secondary); padding: 40px; }

/* Buttons */
.btn { padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer; font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; transition: 0.2s; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-secondary { background: var(--secondary); color: white; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--secondary); }
.btn-sm { padding: 4px 8px; font-size: 11px; }

/* Conexão WhatsApp */
.connection-container { max-width: 600px; margin: 0 auto; text-align: center; }
.connection-container h2 { margin-bottom: 30px; color: var(--text-main); }

.connection-status { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 30px; margin-bottom: 30px; }
.connection-status i { font-size: 48px; color: var(--secondary); margin-bottom: 15px; }
.connection-status p { font-size: 16px; color: var(--secondary); }

.connection-actions { display: flex; gap: 15px; justify-content: center; margin-bottom: 30px; }

.qr-container { background: white; border: 2px solid var(--primary); border-radius: 12px; padding: 30px; margin-top: 30px; }
.qr-container h3 { color: var(--primary); margin-bottom: 20px; }
.qr-container img { max-width: 300px; width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; }
.qr-instructions { margin-top: 15px; color: var(--secondary); font-size: 14px; line-height: 1.5; }

/* Animação de loading */
@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.rotating { animation: rotate 1s linear infinite; }

/* Progress Bar */
.progress-bar-container { width: 100%; height: 30px; background: #e2e8f0; border-radius: 15px; overflow: hidden; margin-bottom: 10px; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--success), var(--primary)); transition: width 0.5s ease; border-radius: 15px; }
.progress-text { text-align: center; color: var(--secondary); font-size: 14px; font-weight: 600; }

.delay-inputs { display: flex; align-items: center; gap: 10px; }
.delay-inputs input { flex: 1; }
.delay-inputs span { color: var(--secondary); font-weight: 600; }

.conversation-box {
    height: 300px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px;
    overflow-y: auto;
    background: #fafafa;
    margin-bottom: 10px;
}

.chat-line {
    margin-bottom: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 14px;
    max-width: 90%;
}

.chat-line.in {
    background: #e8f4ff;
    border: 1px solid #c6e2ff;
}

.chat-line.out {
    background: #e8ffef;
    border: 1px solid #c6ffd7;
    margin-left: auto;
}

.chat-meta {
    font-size: 12px;
    color: #555;
    margin-bottom: 4px;
}

.chat-text {
    white-space: pre-wrap;
}

.conversation-input {
    display: flex;
    gap: 8px;
}

.conversation-input input {
    flex: 1;
}

/* Badges */
.badge { padding: 4px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge-success { background: #d1fae5; color: #065f46; }

/* --- FLOW EDITOR (CANVAS) --- */
.full-screen-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: white; z-index: 1000; display: none; }
.flow-content { width: 100%; height: 100%; display: flex; flex-direction: column; padding: 0 !important; background: #f0f2f5; }

.flow-header { padding: 15px 30px; background: white; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; z-index: 10; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.flow-name-edit { font-size: 18px; font-weight: bold; border: none; background: #f8fafc; padding: 8px 15px; border-radius: 6px; width: 300px; }
.flow-actions { display: flex; gap: 10px; }

.flow-canvas-wrapper { flex: 1; position: relative; overflow: auto; background-image: radial-gradient(#cbd5e1 1px, transparent 1px); background-size: 20px 20px; user-select: none; }
.flow-canvas { position: relative; min-width: 3000px; min-height: 3000px; padding: 50px; transform-origin: 0 0; }

/* SVG Layer para as setas */
#connectionsSvg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
path.connection-line { fill: none; stroke: #94a3b8; stroke-width: 2px; stroke-dasharray: 5; animation: dash 30s linear infinite; }
@keyframes dash { to { stroke-dashoffset: -1000; } }

/* Flow Nodes (Cartões do Fluxo) */
.flow-node {
    width: 280px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05), 0 1px 3px rgba(0,0,0,0.1);
    position: absolute;
    z-index: 2;
    transition: box-shadow 0.2s, border-color 0.2s;
    border: 1px solid var(--border);
}

.flow-node.dragging {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    z-index: 100;
    cursor: grabbing;
}

.flow-node:hover { box-shadow: 0 10px 15px rgba(0,0,0,0.1); border-color: var(--primary); }
.flow-node.start-node { border-top: 4px solid var(--primary); }
.flow-node.end-node { border-top: 4px solid var(--success); }

.node-header { 
    padding: 10px 15px; 
    border-bottom: 1px solid #f1f5f9; 
    background: #f8fafc; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    border-radius: 8px 8px 0 0; 
    cursor: grab;
}
.node-header:active { cursor: grabbing; }

.node-title { font-weight: 600; font-size: 13px; color: var(--secondary); text-transform: uppercase; letter-spacing: 0.5px; pointer-events: none; }
.node-actions i { color: #94a3b8; cursor: pointer; margin-left: 5px; }
.node-actions i:hover { color: var(--danger); }

.node-body { padding: 15px; font-size: 14px; color: var(--text-main); line-height: 1.4; min-height: 60px; cursor: pointer; }
.node-preview { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; color: #475569; pointer-events: none; }
.node-tags { margin-top: 10px; display: flex; gap: 5px; flex-wrap: wrap; pointer-events: none; }
.node-badge { font-size: 10px; padding: 2px 6px; background: #e2e8f0; border-radius: 4px; color: #64748b; }

.node-ports { padding: 10px 15px; background: #f8fafc; border-radius: 0 0 8px 8px; font-size: 12px; color: var(--secondary); border-top: 1px solid #f1f5f9; }
.trigger-item { display: flex; justify-content: space-between; margin-top: 4px; padding: 4px 8px; background: white; border: 1px solid var(--border); border-radius: 4px; }

/* Modal Edição de Passo */
.small-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 2000; display: none; align-items: center; justify-content: center; backdrop-filter: blur(2px); }
.small-modal .modal-content { background: white; width: 500px; max-width: 90%; border-radius: 12px; padding: 25px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.close { font-size: 24px; cursor: pointer; color: var(--secondary); }

.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--secondary); margin-bottom: 5px; }
.form-control, textarea, select { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; transition: 0.2s; }
.form-control:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1); }

.checkbox-group label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-group input[type="checkbox"] { width: auto; }

/* Trigger Row dentro do Modal */
.trigger-row { display: flex; gap: 10px; margin-bottom: 8px; align-items: center; }
.trigger-row input { flex: 1; }
.trigger-row select { width: 100px; }

/* File Upload */
.file-drop-area { border: 2px dashed var(--border); padding: 20px; text-align: center; border-radius: 6px; cursor: pointer; margin-bottom: 10px; transition: 0.2s; }
.file-drop-area:hover { border-color: var(--primary); background: #f8fafc; }
.media-list { display: flex; flex-direction: column; gap: 5px; }
.media-item { display: flex; align-items: center; justify-content: space-between; font-size: 12px; background: #f1f5f9; padding: 6px; border-radius: 4px; }

.modal-footer { margin-top: 20px; display: flex; justify-content: flex-end; }

.loading { text-align: center; padding: 40px; color: var(--secondary); }

/* Login */
.login-container { max-width: 400px; margin: 100px auto; background: white; padding: 30px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.1); text-align: center; }
.login-container input { display: block; width: 100%; margin: 10px 0; padding: 10px; border: 1px solid var(--border); border-radius: 6px; }
.login-container button { margin: 5px; }

/* Delays e Rows */
.delay-row { display: flex; align-items: center; gap: 10px; margin-bottom: 5px; }
.delay-row input { flex: 1; }
