/**
 * Flow Map - Vertical Sidebar Style
 */

/* === Sidebar Container === */
.flow-map-sidebar {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 90;
    font-family: var(--font-family-main);
}

/* === Minimized Tab === */
.flow-map-tab {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    background: var(--color-panel);
    border: 1px solid var(--color-border);
    border-right: none;
    border-radius: 8px 0 0 8px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: -2px 0 8px rgba(0,0,0,0.1);
}

.flow-map-tab:hover {
    padding-right: 12px;
    background: var(--color-background-hover);
}

.flow-map-tab .material-symbols-outlined {
    font-size: 20px;
    color: var(--color-primary);
}

.flow-map-tab-count {
    font-size: 10px;
    font-weight: 600;
    color: var(--color-text);
    background: var(--color-highlight);
    padding: 2px 6px;
    border-radius: 8px;
}

/* === Main Panel === */
.flow-map-panel {
    width: 56px;
    max-height: 320px;
    background: var(--color-panel);
    border: 1px solid var(--color-border);
    border-right: none;
    border-radius: 12px 0 0 12px;
    box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header - compact for sidebar */
.flow-map-header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 4px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-background);
    flex-shrink: 0;
}

.flow-map-title {
    display: none;
}

/* Scrollable area */
.flow-map-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
}

.flow-map-scroll::-webkit-scrollbar {
    width: 4px;
}

.flow-map-scroll::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 2px;
}

/* Track */
.flow-map-track {
    padding: 0 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Item - compact icon-only in sidebar */
.flow-map-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px 0;
    cursor: pointer;
    transition: all 0.15s;
    border-radius: 6px;
}

.flow-map-item:hover {
    background: var(--color-background-hover);
    padding: 4px 6px;
    margin: 0 -6px;
}

/* Connector line */
.flow-map-line {
    position: absolute;
    left: 50%;
    top: -4px;
    transform: translateX(-50%);
    width: 2px;
    height: 8px;
    background: rgba(150, 150, 150, 0.6);
}

.flow-map-line-branch {
    background: linear-gradient(to bottom, rgba(150, 150, 150, 0.6), #673AB7);
}

/* Node circle - compact */
.flow-map-node {
    position: relative;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: transform 0.2s;
}

.flow-map-item:hover .flow-map-node {
    transform: scale(1.1);
}

.flow-map-node .material-symbols-outlined {
    font-size: 14px;
    color: white;
}

/* Pulse animation */
.flow-map-pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid currentColor;
    animation: flowPulse 1.5s ease-out infinite;
}

/* Labels - hidden in compact sidebar, only show on hover */
.flow-map-label {
    display: none;
}

.flow-map-type {
    font-size: 8px;
    font-weight: 500;
    color: var(--color-text);
    opacity: 0.7;
    text-align: center;
    max-width: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Show short label below icon */
.flow-map-short-label {
    font-size: 8px;
    font-weight: 500;
    color: var(--color-text);
    opacity: 0.6;
    text-align: center;
}

.flow-map-sub {
    display: none;
}

/* Active state */
.flow-map-item-active .flow-map-node {
    animation: nodeGlow 1.5s ease-in-out infinite;
}

/* New node animation */
.flow-map-item-new {
    animation: nodeSlideIn 0.3s ease-out;
}

/* === Parallel Branch Styles (Sidebar) === */
.flow-map-item-branch {
    position: relative;
}

/* Branch indicator bar - left side colored bar */
.flow-map-branch-bar {
    position: absolute;
    left: -6px;
    top: 0;
    bottom: 0;
    width: 3px;
    border-radius: 2px;
    opacity: 0.6;
}

/* Branch split indicator */
.flow-map-branch-split {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.flow-map-branch-split .material-symbols-outlined {
    font-size: 12px;
    color: #FF9800;
    opacity: 0.8;
    transform: rotate(180deg);
}

/* Branch merge indicator */
.flow-map-branch-merge {
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.flow-map-branch-merge .material-symbols-outlined {
    font-size: 12px;
    color: #4CAF50;
    opacity: 0.8;
    transform: rotate(180deg);
}

/* Parallel line style */
.flow-map-line-parallel {
    background: linear-gradient(to bottom, rgba(255, 152, 0, 0.6), rgba(255, 152, 0, 0.4)) !important;
    width: 2px;
}

/* Branch start/end spacing */
.flow-map-item-branch-start {
    margin-top: 16px;
}

.flow-map-item-branch-end {
    margin-bottom: 16px;
}

/* Footer - compact with button */
.flow-map-footer {
    padding: 4px;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: center;
    flex-shrink: 0;
}

/* Panel buttons */
.flow-map-btn {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--color-text);
    opacity: 0.5;
    border-radius: 4px;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flow-map-btn:hover {
    opacity: 1;
    background: var(--color-background-hover);
}

.flow-map-btn .material-symbols-outlined {
    font-size: 14px;
}

/* === Modal === */
.flow-map-modal-bg {
    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: 9999;
    padding: 20px;
}

.flow-map-modal {
    background: var(--color-panel);
    border: 1px solid var(--color-border);
    border-radius: 16px;
    width: 500px;
    height: 650px;
    max-width: calc(100vw - 40px);
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    overflow: hidden;
}

/* Modal header - compact */
.flow-map-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.flow-map-modal-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
}

.flow-map-modal-title .material-symbols-outlined {
    font-size: 18px;
    color: var(--color-primary);
}

.flow-map-badge {
    font-size: 10px;
    font-weight: normal;
    padding: 2px 8px;
    background: var(--color-highlight);
    border-radius: 8px;
    opacity: 0.7;
}

.flow-map-modal-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.flow-map-checkbox {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--color-text);
    cursor: pointer;
}

.flow-map-checkbox input {
    width: 12px;
    height: 12px;
    accent-color: var(--color-primary);
}

.flow-map-modal-actions button {
    background: none;
    border: 1px solid var(--color-border);
    padding: 4px;
    border-radius: 4px;
    cursor: pointer;
    color: var(--color-text);
    transition: all 0.15s;
}

.flow-map-modal-actions button:hover {
    background: var(--color-background-hover);
}

.flow-map-modal-actions button .material-symbols-outlined {
    font-size: 16px;
}

/* Modal body */
.flow-map-modal-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    background: var(--color-background);
}

/* Modal track - vertical list */
.flow-map-modal-track {
    padding: 0 8px;
}

/* Modal item - vertical layout */
.flow-map-modal-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 8px;
    cursor: pointer;
    transition: all 0.15s;
    border-radius: 8px;
}

.flow-map-modal-item:hover {
    background: var(--color-background-hover);
}

/* Modal node - larger in expanded view */
.flow-map-modal-node {
    width: 36px;
    height: 36px;
}

.flow-map-modal-node .material-symbols-outlined {
    font-size: 18px;
}

/* Modal connector line */
.flow-map-modal-line {
    position: absolute;
    left: 26px;
    top: -5px;
    width: 2px;
    height: 10px;
    background: rgba(150, 150, 150, 0.6);
}

/* Modal label - expanded view with full details */
.flow-map-modal-label {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.flow-map-modal-type {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text);
}

.flow-map-modal-sub {
    font-size: 11px;
    color: var(--color-text);
    opacity: 0.6;
    font-family: var(--font-family-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

/* Agent badge for modal */
.flow-map-agent-badge {
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 9px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

/* === Horizontal Branch Styles (Modal) === */

/* Branch group container */
.flow-map-branch-group {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 0;
    margin-left: 8px;
}

/* Main vertical line through the left side - matches modal item line position */
.flow-map-branch-group::before {
    content: '';
    position: absolute;
    left: 18px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgba(150, 150, 150, 0.6);
}

/* Top connector - split point */
.flow-map-branch-connector-top {
    position: relative;
    display: flex;
    align-items: center;
    height: 28px;
    width: 100%;
}

/* Horizontal line from vertical line to split icon */
.flow-map-branch-connector-top::before {
    content: '';
    position: absolute;
    left: 17px;
    top: 50%;
    width: 32px;
    height: 2px;
    background: rgba(255, 152, 0, 0.7);
}

/* Hide the old vertical line element */
.flow-map-branch-line-v {
    display: none;
}

.flow-map-branch-split-icon {
    position: absolute;
    left: 44px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px 6px;
    background: var(--color-panel);
    border-radius: 4px;
    border: 1px solid rgba(255, 152, 0, 0.5);
    z-index: 2;
}

.flow-map-branch-split-icon .material-symbols-outlined {
    font-size: 12px;
    color: #FF9800;
    transform: rotate(180deg);
}

/* Horizontal container for branch items */
.flow-map-branch-horizontal {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 8px;
    padding: 12px 16px;
    margin-left: 80px;
    background: rgba(255, 152, 0, 0.05);
    border-radius: 10px;
    border: 1px dashed rgba(255, 152, 0, 0.3);
    position: relative;
}

/* Connector line from split icon to tool box */
.flow-map-branch-horizontal::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 50%;
    width: 12px;
    height: 2px;
    background: rgba(255, 152, 0, 0.6);
}

/* Individual branch item */
.flow-map-branch-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s;
    min-width: 65px;
}

/* No connector lines on items */
.flow-map-branch-item::before {
    display: none;
}

.flow-map-branch-item:hover {
    background: rgba(255, 152, 0, 0.15);
}

/* Label box under branch node */
.flow-map-branch-label-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-align: center;
}

.flow-map-branch-label-box .flow-map-modal-type {
    font-size: 10px;
}

.flow-map-branch-label-box .flow-map-modal-sub {
    font-size: 9px;
    max-width: 70px;
}

/* Bottom connector - merge point */
.flow-map-branch-connector-bottom {
    position: relative;
    display: flex;
    align-items: center;
    height: 28px;
    width: 100%;
}

/* Horizontal line from merge icon back to vertical line */
.flow-map-branch-connector-bottom::before {
    content: '';
    position: absolute;
    left: 17px;
    top: 50%;
    width: 32px;
    height: 2px;
    background: rgba(76, 175, 80, 0.7);
}

.flow-map-branch-merge-icon {
    position: absolute;
    left: 44px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px 6px;
    background: var(--color-panel);
    border-radius: 4px;
    border: 1px solid rgba(76, 175, 80, 0.5);
    z-index: 2;
}

.flow-map-branch-merge-icon .material-symbols-outlined {
    font-size: 12px;
    color: #4CAF50;
    transform: rotate(180deg);
}

/* Modal footer - compact stats */
.flow-map-modal-footer {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1px solid var(--color-border);
    flex-wrap: wrap;
    flex-shrink: 0;
}

.flow-map-stat {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 3px 6px;
    background: color-mix(in srgb, var(--c) 12%, transparent);
    border-radius: 6px;
    font-size: 10px;
    color: var(--color-text);
}

.flow-map-stat .material-symbols-outlined {
    font-size: 12px;
    color: var(--c);
}

/* === Animations === */
@keyframes flowPulse {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.8); opacity: 0; }
}

@keyframes nodeGlow {
    0%, 100% { box-shadow: 0 2px 6px rgba(0,0,0,0.2); }
    50% { box-shadow: 0 0 20px currentColor; }
}

@keyframes nodeSlideIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Message highlight - scoped to chat history only */
#chat-history .flow-map-highlight {
    animation: flowHighlight 2s ease-out forwards;
}

@keyframes flowHighlight {
    0% { background: rgba(33, 150, 243, 0.3); }
    100% { background: transparent; }
}

/* === Responsive === */
@media (max-width: 768px) {
    .flow-map-panel {
        width: 160px;
        max-height: 50vh;
    }

    .flow-map-modal {
        width: 95vw;
        max-height: 85vh;
    }
}

/* === Theme === */
.light-mode .flow-map-panel,
.light-mode .flow-map-modal {
    box-shadow: -4px 0 20px rgba(0,0,0,0.08);
}
