/* =============================================
   RESET & VARIABLES
   ============================================= */
:root {
    --primary:       #4F46E5;
    --primary-light: #EEF2FF;
    --sidebar:       #17172B;
    --sidebar-2:     #1E1E35;
    --border:        rgba(255,255,255,0.08);
    --text-inv:      #C4C9E2;
    --white:         #FFFFFF;
    --bg:            #F0F4FF;
    --card:          #FFFFFF;
    --text:          #111827;
    --muted:         #6B7280;
    --success:       #10B981;
    --danger:        #EF4444;
    --warning:       #F59E0B;
    --shadow:        0 4px 24px rgba(79,70,229,0.10);
    --r:             14px;
    --r-sm:          8px;
    /* node type colors */
    --c-start:       #6366F1;
    --c-text:        #0EA5E9;
    --c-image:       #10B981;
    --c-buttons:     #F59E0B;
    --c-delay:       #8B5CF6;
}

html, body {
    height: 100%; margin: 0; padding: 0;
    overflow: hidden;
    font-family: 'Inter', 'Hanuman', sans-serif;
    background: var(--bg);
    color: var(--text);
}

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

/* =============================================
   APP LAYOUT
   ============================================= */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* =============================================
   LEFT PANEL
   ============================================= */
.left-panel {
    width: 260px;
    flex-shrink: 0;
    background: var(--sidebar);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    border-right: 1px solid var(--border);
}

/* Brand */
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.brand-icon {
    width: 38px; height: 38px;
    background: var(--primary);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; color: #fff;
}
.brand-name { display: block; font-weight: 800; font-size: 15px; color: #fff; }
.brand-sub  { display: block; font-size: 11px; color: var(--text-inv); margin-top: 1px; }

/* Bot Status */
.bot-status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.bot-status-left { display: flex; align-items: center; gap: 8px; flex: 1; }
.status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--muted); transition: all 0.3s;
    flex-shrink: 0;
}
.status-dot.on { background: var(--success); box-shadow: 0 0 0 3px rgba(16,185,129,0.2); }
#statusLabel { font-size: 12px; color: var(--text-inv); font-weight: 500; }

/* Toggle switch */
.toggle-switch { position: relative; width: 34px; height: 20px; cursor: pointer; }
.toggle-switch input { display: none; }
.toggle-track {
    position: absolute; inset: 0;
    background: #444; border-radius: 20px;
    transition: 0.3s;
}
.toggle-track::before {
    content: '';
    position: absolute;
    width: 14px; height: 14px;
    background: #fff; border-radius: 50%;
    top: 3px; left: 3px;
    transition: 0.3s;
}
.toggle-switch input:checked ~ .toggle-track { background: var(--success); }
.toggle-switch input:checked ~ .toggle-track::before { transform: translateX(14px); }

/* Panel Blocks */
.panel-block {
    padding: 14px 14px 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.panel-label {
    font-size: 10px; font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-inv);
    opacity: 0.6;
    margin-bottom: 10px;
}
.panel-label-row {
    display: flex; align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.panel-label-row .panel-label { margin-bottom: 0; }

/* Node Palette */
.node-palette { display: flex; flex-direction: column; gap: 6px; }
.palette-node {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--r-sm);
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    cursor: grab;
    transition: all 0.2s;
    user-select: none;
}
.palette-node:hover {
    background: rgba(79,70,229,0.2);
    border-color: rgba(79,70,229,0.4);
    transform: translateX(2px);
}
.palette-node:active { cursor: grabbing; }
.palette-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; flex-shrink: 0;
}
.start-icon { color: var(--c-start); background: rgba(99,102,241,0.1); }
.text-icon { color: var(--c-text); background: rgba(14,165,233,0.1); }
.image-icon { color: var(--c-image); background: rgba(16,185,129,0.1); }
.buttons-icon { color: var(--c-buttons); background: rgba(245,158,11,0.1); }
.delay-icon { color: var(--c-delay); background: rgba(139,92,246,0.1); }

.palette-name { font-size: 13px; font-weight: 600; color: #fff; }
.palette-desc { font-size: 11px; color: var(--text-inv); opacity: 0.6; }

/* Flow List */
.flow-list-block {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-bottom: none;
}
.flow-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.flow-list::-webkit-scrollbar { width: 4px; }
.flow-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.flow-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid transparent;
}
.flow-item:hover { background: rgba(255,255,255,0.06); }
.flow-item.active { background: rgba(79,70,229,0.2); border-color: rgba(79,70,229,0.4); }
.flow-item-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--success); flex-shrink: 0;
}
.flow-item-dot.off { background: var(--muted); }
.flow-item-name { flex: 1; font-size: 13px; color: #fff; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flow-item-del {
    background: none; border: none; color: rgba(255,255,255,0.3);
    cursor: pointer; padding: 2px 6px; border-radius: 4px; font-size: 12px;
    opacity: 0; transition: opacity 0.2s;
}
.flow-item:hover .flow-item-del { opacity: 1; }
.flow-item-del:hover { color: var(--danger); background: rgba(239,68,68,0.1); }

.btn-new-flow {
    background: rgba(79,70,229,0.2);
    border: 1px solid rgba(79,70,229,0.4);
    color: #a5b4fc;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-new-flow:hover { background: var(--primary); color: #fff; }

/* Loading Skeleton */
.skeleton-item {
    height: 36px; border-radius: 8px;
    background: rgba(255,255,255,0.05);
    animation: shimmer 1.5s infinite;
    margin-bottom: 4px;
}
@keyframes shimmer {
    0%,100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

/* =============================================
   CANVAS AREA
   ============================================= */
.canvas-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100%;
    overflow: hidden;
    position: relative;
}

/* Toolbar */
.canvas-toolbar {
    height: 54px;
    flex-shrink: 0;
    background: #fff;
    border-bottom: 1px solid #E5E7EB;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 20;
}
.toolbar-left { display: flex; align-items: center; gap: 10px; }
.flow-info { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.flow-info i { color: var(--primary); }
#currentFlowName { color: var(--text); }
.flow-badge {
    font-size: 11px; font-weight: 700;
    padding: 2px 8px; border-radius: 12px;
}
.flow-badge.active { background: #D1FAE5; color: #065F46; }
.flow-badge.inactive { background: #F3F4F6; color: var(--muted); }

.toolbar-right { display: flex; align-items: center; gap: 8px; }
.toolbar-divider { width: 1px; height: 24px; background: #E5E7EB; margin: 0 4px; }

.btn-tool {
    width: 34px; height: 34px;
    background: #F9FAFB;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 13px; color: var(--muted);
    transition: all 0.2s;
}
.btn-tool:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }

.btn-save {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 18px;
    background: var(--primary);
    color: #fff;
    border: none; border-radius: 8px;
    font-size: 14px; font-weight: 700;
    cursor: pointer; transition: all 0.2s;
    font-family: inherit;
}
.btn-save:hover:not(:disabled) { background: #4338CA; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(79,70,229,0.3); }
.btn-save:disabled { background: #E5E7EB; color: var(--muted); cursor: not-allowed; transform: none; }
.btn-preview {
    font-size: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px 6px;
    text-align: center;
    color: var(--text-muted);
}
/* =============================================
   PROPERTIES PANEL (SIDEBAR)
   ============================================= */
.props-panel {
    position: absolute;
    top: 54px;
    bottom: 0;
    right: 0;
    width: 320px;
    background: #fff;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 100;
}
.props-panel.hidden {
    transform: translateX(320px);
}
.props-header {
    height: 64px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}
.props-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}
.props-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 18px;
}
.props-close:hover { color: #Ef4444; }
.props-body {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}
.props-group {
    margin-bottom: 20px;
}
.props-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text);
}
.props-group input[type="text"],
.props-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #D1D5DB;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    outline: none;
    box-sizing: border-box;
    transition: 0.2s;
    resize: vertical;
    background: #F9FAFB;
    color: var(--text);
}
.props-group input[type="text"]:focus,
.props-group textarea:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px var(--primary-light);
}
.props-group input[type="range"] {
    width: 100%;
    margin-top: 5px;
}
.var-hints {
    display: flex;
    gap: 10px;
    margin-bottom: 8px;
}
.var-hints span {
    font-size: 11px;
    background: var(--primary-light);
    color: var(--primary);
    padding: 3px 8px;
    border-radius: 12px;
    cursor: pointer;
    user-select: none;
}
.var-hints span:hover { background: var(--primary); color: #fff; }

/* =============================================
   DRAWFLOW CANVAS & NODES
   ============================================= */
#drawflow {
    flex: 1;
    background-color: var(--bg);
    background-image:
        radial-gradient(circle, #C7D2FE 1px, transparent 1px);
    background-size: 28px 28px;
    background-position: 14px 14px;
    overflow: hidden;
    position: relative;
}

/* Override Drawflow defaults */
.drawflow-node {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    width: auto !important;
    min-width: 0 !important;
}
.drawflow-node.selected > .drawflow-node-content,
.drawflow-node.selected .df-node-wrap {
    box-shadow: 0 0 0 2px var(--primary), 0 8px 32px rgba(79,70,229,0.2) !important;
}
.drawflow-node .inputs, .drawflow-node .outputs {
    position: absolute; top: 50%; transform: translateY(-50%);
}
.drawflow-node .inputs { left: -12px; }
.drawflow-node .outputs { right: -12px; }

/* Connection ports */
.drawflow-node .input, .drawflow-node .output {
    width: 14px !important; height: 14px !important;
    border: 2.5px solid #fff !important;
    border-radius: 50% !important;
    background: var(--primary) !important;
    box-shadow: 0 2px 8px rgba(79,70,229,0.4) !important;
    top: 0 !important;
}

/* Connection lines */
.connection .main-path {
    stroke: var(--primary) !important;
    stroke-width: 2.5px !important;
    filter: drop-shadow(0 2px 4px rgba(79,70,229,0.2));
}
.connection .point {
    fill: var(--primary) !important;
    stroke: #fff !important;
    stroke-width: 2px !important;
}

/* =============================================
   CUSTOM NODE CARDS
   ============================================= */
.df-node-wrap {
    background: var(--card);
    border-radius: var(--r);
    box-shadow: 0 4px 20px rgba(0,0,0,0.1), 0 1px 4px rgba(0,0,0,0.06);
    overflow: hidden;
    min-width: 270px;
    max-width: 300px;
    transition: box-shadow 0.2s;
    font-family: 'Inter', 'Hanuman', sans-serif;
}
.df-node-wrap:hover {
    box-shadow: 0 8px 32px rgba(0,0,0,0.15), 0 2px 8px rgba(0,0,0,0.08);
}

/* Node header */
.df-node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.01em;
}
.df-node-header i { font-size: 13px; }

/* Header colors per type */
.node-start .df-node-header { background: var(--c-start); }
.node-text .df-node-header { background: var(--c-text); }
.node-image .df-node-header { background: var(--c-image); }
.node-buttons .df-node-header { background: var(--c-buttons); }
.node-delay .df-node-header { background: var(--c-delay); }

.node-delay-badge {
    margin-left: auto;
    font-size: 11px;
    background: rgba(255,255,255,0.2);
    padding: 2px 6px;
    border-radius: 12px;
    display: none; /* toggled via JS */
}

.node-header-badge {
    margin-left: auto;
    font-size: 11px;
    background: rgba(255,255,255,0.2);
    padding: 2px 6px;
    border-radius: 12px;
}

.df-node-preview {
    padding: 12px;
    font-size: 13px;
    color: var(--text);
    background: #fff;
    border-radius: 0 0 8px 8px;
    word-break: break-word;
}
.img-preview {
    padding: 0;
}
.img-preview img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
    border-radius: 0 0 8px 8px;
}
.df-img-placeholder {
    height: 120px;
    display: flex; align-items: center; justify-content: center;
    background: #f3f4f6; color: #9ca3af; font-size: 24px;
    border-radius: 0 0 8px 8px;
}

.df-node-wrap input[type="text"],
.df-node-wrap input[type="number"],
.df-node-wrap textarea {
    display: none; /* Hide internal inputs on canvas */
}

.upload-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-upload {
    width: 38px; height: 35px;
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid rgba(79,70,229,0.2);
    border-radius: 7px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.btn-upload:hover {
    background: var(--primary);
    color: #fff;
}

.df-node-wrap textarea { min-height: 72px; }

.df-hint {
    font-size: 11px; color: var(--muted);
    margin-top: 6px;
}

/* Image preview in node */
.df-img-preview {
    margin-top: 8px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #E5E7EB;
    max-height: 100px;
    display: flex; align-items: center; justify-content: center;
    background: #F3F4F6;
}
.df-img-preview img { width: 100%; object-fit: cover; }
.df-img-placeholder {
    height: 60px;
    display: flex; align-items: center; justify-content: center;
    color: #D1D5DB; font-size: 24px;
}

/* Buttons node */
.btn-input-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 5px;
}
.btn-input-row span {
    width: 20px; height: 20px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 50%;
    font-size: 10px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.btn-input-row input { flex: 1; margin: 0; }

/* =============================================
   EMPTY STATE
   ============================================= */
.canvas-empty {
    position: absolute;
    inset: 54px 0 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 5;
    transition: opacity 0.3s;
}
.canvas-empty.hidden { opacity: 0; }
.empty-icon {
    width: 72px; height: 72px;
    background: var(--primary-light);
    border-radius: 20px;
    display: flex; align-items: center; justify-content: center;
    font-size: 32px; color: var(--primary);
    margin-bottom: 16px;
}
.canvas-empty h2 { font-size: 20px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.canvas-empty p { font-size: 14px; color: var(--muted); }
.canvas-empty strong { color: var(--primary); }

/* =============================================
   TOAST
   ============================================= */
.toast {
    position: fixed;
    bottom: -80px; right: 24px;
    background: #111827;
    color: #fff;
    padding: 13px 20px;
    border-radius: 10px;
    font-size: 14px; font-weight: 500;
    display: flex; align-items: center; gap: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    transition: bottom 0.35s cubic-bezier(0.34,1.56,0.64,1);
    z-index: 9999;
    max-width: 320px;
}
.toast.show { bottom: 24px; }
.toast.success { border-left: 4px solid var(--success); }
.toast.error   { border-left: 4px solid var(--danger); }
.toast.success::before { content: '✅'; }
.toast.error::before   { content: '❌'; }
