/* ═══════════════════════════════════════════════
   AI Workflow Panel
   ═══════════════════════════════════════════════ */

/* ── Panel container ── */
#workflowPanel {
    display: none;
    order: 1;
    flex: 1 1 auto;
    flex-direction: column;
    overflow-y: auto;
    padding: 20px 0 24px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
#workflowPanel::-webkit-scrollbar { display: none; }

body.ai-fullscreen #workflowPanel.wf-active {
    display: flex;
}

/* Hide normal response container when workflow is active */
body.workflow-active .caloogy-ai-response {
    display: none !important;
}
body.workflow-active #fsEmptyState {
    display: none !important;
}


/* ── Header ── */
.wf-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 0 4px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    margin-bottom: 28px;
}

.wf-header-icon {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, rgba(34,197,94,0.12), rgba(34,197,94,0.25));
    border: 1px solid rgba(34,197,94,0.3);
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #22c55e;
}

.wf-header-text { flex: 1; }

.wf-header-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #22c55e;
    margin-bottom: 5px;
}

.wf-header-query {
    font-size: 15px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.45;
}


/* ── Node list ── */
.wf-nodes {
    display: flex;
    flex-direction: column;
    padding: 0 2px;
}


/* ── Single node ── */
.wf-node {
    display: flex;
    gap: 14px;
    min-height: 52px;
}

.wf-node-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    width: 20px;
    padding-top: 3px;
}


/* ── Status dot ── */
.wf-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.16);
    background: transparent;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    transition: border-color 0.35s, background 0.35s;
}

.wf-dot.active {
    border-color: #22c55e;
    background: #22c55e;
    animation: wf-pulse 1.4s ease-in-out infinite;
}

.wf-dot.done {
    border-color: #22c55e;
    background: #22c55e;
}

@keyframes wf-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
    50%       { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0);  }
}


/* ── Connector line between nodes ── */
.wf-connector {
    flex: 1;
    width: 2px;
    min-height: 20px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 1px;
    overflow: hidden;
    position: relative;
    transition: background 0.4s;
}

.wf-connector.done {
    background: rgba(34, 197, 94, 0.45);
}

/* Marching-ants flow animation */
.wf-connector.active::after,
.wf-connector.flowing::after {
    content: '';
    position: absolute;
    top: -100%;
    left: 0;
    right: 0;
    height: 55%;
    background: linear-gradient(
        to bottom,
        transparent,
        rgba(34, 197, 94, 0.6),
        #22c55e,
        rgba(34, 197, 94, 0.6),
        transparent
    );
    animation: wf-flow 1.1s linear infinite;
}

@keyframes wf-flow {
    from { top: -100%; }
    to   { top:  200%; }
}


/* ── Node body ── */
.wf-node-body {
    flex: 1;
    padding-bottom: 22px;
}

.wf-node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    min-height: 22px;
}

.wf-node-title {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.55);
    flex: 1;
    transition: color 0.3s;
}

.wf-node.active .wf-node-title { color: rgba(255, 255, 255, 0.92); }
.wf-node.done   .wf-node-title { color: rgba(255, 255, 255, 0.50); }


/* ── Status badge ── */
.wf-badge {
    font-size: 11px;
    font-weight: 500;
    padding: 2px 9px;
    border-radius: 99px;
    flex-shrink: 0;
    transition: background 0.3s, color 0.3s;
}

.wf-badge.pending {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.25);
}

.wf-badge.active {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

.wf-badge.confirm-wait {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
}

.wf-badge.done {
    background: rgba(34, 197, 94, 0.1);
    color: rgba(34, 197, 94, 0.6);
}


/* ── Log lines ── */
.wf-node-log {
    font-size: 12.5px;
    color: rgba(255, 255, 255, 0.42);
    line-height: 1.65;
    max-height: 140px;
    overflow: hidden;
}

.wf-node.active .wf-node-log { color: rgba(255, 255, 255, 0.55); }

/* analyze and execute nodes get unlimited height */
#wf-node-analyze .wf-node-log,
#wf-node-execute .wf-node-log {
    max-height: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    line-height: 1.7;
}

.wf-log-line   { display: block; padding: 1px 0; }
.wf-log-stream { display: block; white-space: pre-wrap; }


/* ── Output summary badge ── */
.wf-node-output {
    display: none;
    margin-top: 7px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    background: rgba(34, 197, 94, 0.06);
    border: 1px solid rgba(34, 197, 94, 0.15);
    border-radius: 8px;
    padding: 6px 12px;
}

.wf-node-output.visible { display: block; }


/* ── Confirmation box ── */
.wf-confirm-box {
    display: none;
    margin-top: 12px;
    padding: 16px 18px;
    background: rgba(34, 197, 94, 0.05);
    border: 1px solid rgba(34, 197, 94, 0.22);
    border-radius: 14px;
    animation: wf-fadein 0.35s ease;
}

.wf-confirm-box.visible { display: block; }

.wf-confirm-question {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.62);
    line-height: 1.55;
    margin-bottom: 14px;
}

.wf-confirm-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 20px;
    background: #22c55e;
    color: #000;
    border: none;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s, transform 0.12s, box-shadow 0.2s;
    box-shadow: 0 2px 12px rgba(34, 197, 94, 0.3);
}

.wf-confirm-btn:hover {
    background: #16a34a;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(34, 197, 94, 0.4);
}

.wf-confirm-btn:active { transform: translateY(0); }


/* ── Ask-for-info box ── */
.wf-ask-box {
    margin-top: 12px;
    padding: 16px 18px;
    background: rgba(34, 197, 94, 0.05);
    border: 1px solid rgba(34, 197, 94, 0.22);
    border-radius: 14px;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.wf-ask-box.wf-ask-box-visible {
    opacity: 1;
    transform: translateY(0);
}
.wf-ask-question {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.72);
    line-height: 1.6;
    margin-bottom: 12px;
    font-weight: 500;
}
.wf-ask-input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}
.wf-ask-input {
    flex: 1;
    background: rgba(34, 197, 94, 0.04);
    border: 1px solid rgba(34, 197, 94, 0.18);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.88);
    font-size: 13px;
    padding: 9px 13px;
    resize: none;
    outline: none;
    font-family: inherit;
    line-height: 1.5;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.wf-ask-input:focus {
    border-color: rgba(34, 197, 94, 0.5);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}
.wf-ask-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    background: #22c55e;
    color: #000;
    border: none;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, transform 0.12s, box-shadow 0.2s;
    flex-shrink: 0;
    box-shadow: 0 2px 12px rgba(34, 197, 94, 0.3);
}
.wf-ask-btn:hover  { background: #16a34a; transform: translateY(-1px); box-shadow: 0 4px 16px rgba(34, 197, 94, 0.4); }
.wf-ask-btn:active { transform: translateY(0); }
.wf-ask-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Light mode overrides */
[data-theme="light"] .wf-ask-question { color: rgba(0,0,0,0.75); }
[data-theme="light"] .wf-ask-input {
    background: rgba(34, 197, 94, 0.04);
    border-color: rgba(34, 197, 94, 0.2);
    color: rgba(0,0,0,0.85);
}
[data-theme="light"] .wf-ask-input:focus {
    border-color: rgba(34, 197, 94, 0.5);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}


/* ── Final result panel ── */
.wf-result-panel {
    display: none;
    margin-top: 20px;
    padding: 22px 24px 18px;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    animation: wf-fadein 0.45s ease;
}

.wf-result-panel.visible { display: block; }

.wf-result-header {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.28);
    margin-bottom: 14px;
}

.wf-result-content {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.82);
    line-height: 1.75;
    white-space: pre-wrap;
}

.wf-result-copy {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 18px;
    padding: 4px 10px 4px 8px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.35);
    font-size: 12px;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
}

.wf-result-copy:hover {
    color: rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.08);
}


/* ── Shared animation ── */
@keyframes wf-fadein {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0);   }
}


/* ── Light theme ── */
[data-theme="light"] .wf-header { border-color: rgba(0,0,0,0.07); }
[data-theme="light"] .wf-header-query { color: rgba(0,0,0,0.85); }
[data-theme="light"] .wf-dot { border-color: rgba(0,0,0,0.15); }
[data-theme="light"] .wf-connector { background: rgba(0,0,0,0.07); }
[data-theme="light"] .wf-connector.done { background: rgba(34,197,94,0.35); }
[data-theme="light"] .wf-node-title { color: rgba(0,0,0,0.5); }
[data-theme="light"] .wf-node.active .wf-node-title { color: rgba(0,0,0,0.88); }
[data-theme="light"] .wf-node.done  .wf-node-title { color: rgba(0,0,0,0.42); }
[data-theme="light"] .wf-badge.pending { background: rgba(0,0,0,0.05); color: rgba(0,0,0,0.25); }
[data-theme="light"] .wf-node-log { color: rgba(0,0,0,0.42); }
[data-theme="light"] .wf-node.active .wf-node-log { color: rgba(0,0,0,0.58); }
[data-theme="light"] #wf-node-analyze .wf-node-log,
[data-theme="light"] #wf-node-execute .wf-node-log { color: rgba(0,0,0,0.75); }
[data-theme="light"] .wf-node-output { color: rgba(0,0,0,0.55); }
[data-theme="light"] .wf-confirm-question { color: rgba(0,0,0,0.62); }
[data-theme="light"] .wf-confirm-box { background: rgba(34,197,94,0.04); border-color: rgba(34,197,94,0.2); }
[data-theme="light"] .wf-result-panel { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.07); }
[data-theme="light"] .wf-result-content { color: rgba(0,0,0,0.82); }
[data-theme="light"] .wf-result-header { color: rgba(0,0,0,0.3); }
[data-theme="light"] .wf-result-copy { color: rgba(0,0,0,0.35); }
[data-theme="light"] .wf-result-copy:hover { color: rgba(0,0,0,0.7); background: rgba(0,0,0,0.06); }


/* ── Mobile ── */
@media (max-width: 768px) {
    .wf-header-query { font-size: 14px; }
    .wf-node-title   { font-size: 13px; }
    .wf-result-content { font-size: 14px; }
    .wf-header { padding: 0 0 14px; }
}
