/* ==========================================================================
   EVIDENCE.CSS - Evidence Panel, Connection Lines, Grid Layout
   ========================================================================== */

/* Evidence Resize */
#source-dropdown {
    /* Position Fixed (Center Screen) */
    position: fixed;
    top: 15vh;
    left: calc(50vw - 450px);
    right: auto;
    z-index: 10003;

    /* Visual Styles */
    background: var(--card-bg, rgba(15, 23, 42, 0.6));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);

    /* Flex Container for Scrolling Inner + Fixed Handle */
    display: none;
    flex-direction: column;
    overflow: hidden;
    min-width: 900px;
    width: 900px;
    min-height: 250px;
    max-width: 95vw;
    max-height: 80vh;

    /* Smooth scale animation (zoom-in / pop effect) */
    transform: scale(0.85) translateY(-10px);
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease-out;
    transform-origin: center top;
}

#source-dropdown.active,
#source-dropdown[style*="display: block"] {
    display: flex;
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* --- Evidence Grid (Horizontal Matching Layout) --- */
.evidence-grid {
    display: flex;
    flex: 1;
    position: relative;
    gap: 120px;
    padding: 10px;
    overflow: hidden;
    min-height: 0;
}

.evidence-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 180px;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 100%;
    padding-right: 4px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    position: relative;
    z-index: 2;
}

/* Hide scrollbar for Chrome/Safari */
.evidence-column::-webkit-scrollbar {
    display: none;
}

.evidence-column-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.85rem;
    text-transform: uppercase;
    font-weight: 800;
    padding: 8px 10px;
    border-bottom: 1px solid #334155;
    margin-bottom: 8px;
    text-align: center;
    /* Theme Gradient */
    background: var(--g);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: 0.05em;
}

.evidence-column-header.has-action {
    justify-content: space-between;
    gap: 12px;
}

.evidence-column-header-main {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.evidence-column-title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.evidence-column-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.65rem;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.02em;
    color: #93c5fd;
    background: rgba(96, 165, 250, 0.14);
    border: 1px solid rgba(96, 165, 250, 0.4);
    text-transform: none;
}

.evidence-column-action {
    border: 1px solid rgba(167, 139, 250, 0.24);
    background: rgba(167, 139, 250, 0.08);
    color: #c4b5fd;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.68rem;
    font-weight: 700;
    font-family: inherit;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
    white-space: nowrap;
}

.evidence-column-action:hover {
    transform: translateY(-1px) scale(1.02);
    box-shadow: 0 0 14px rgba(167, 139, 250, 0.18);
    border-color: rgba(167, 139, 250, 0.48);
    background: rgba(167, 139, 250, 0.16);
    color: #e9d5ff;
}

.evidence-column-action.disabled,
.evidence-column-action:disabled {
    cursor: default;
    opacity: 0.55;
    box-shadow: none;
    transform: none;
}

.evidence-column-action.disabled:hover,
.evidence-column-action:disabled:hover {
    transform: none;
    box-shadow: none;
    border-color: rgba(167, 139, 250, 0.24);
    background: rgba(167, 139, 250, 0.08);
    color: #c4b5fd;
}

.evidence-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
    position: relative;
}

.evidence-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.evidence-item.active {
    background: rgba(96, 165, 250, 0.15);
    border-color: rgba(96, 165, 250, 0.4);
}

.evidence-item.linking {
    border: 1px dashed #fbbf24;
    background: rgba(251, 191, 36, 0.1);
    animation: pulse-border 1.5s infinite;
}

/* Unlinked PDFs (no connection to any quiz) - dimmed */
.evidence-item.unlinked {
    opacity: 0.5;
    border: 1px dashed rgba(148, 163, 184, 0.3);
}

.evidence-item.unlinked:hover {
    opacity: 0.8;
}

.evidence-item.unlinked .evidence-item-name {
    background: none;
    -webkit-background-clip: unset;
    background-clip: unset;
    color: #64748b !important;
}

/* Inactive JSONs (toggled off) - dimmed */
.evidence-item.inactive {
    opacity: 0.5;
    border: 1px dashed rgba(148, 163, 184, 0.3);
}

.evidence-item.inactive:hover {
    opacity: 0.8;
}

.evidence-item.inactive .evidence-item-name {
    background: none;
    -webkit-background-clip: unset;
    background-clip: unset;
    color: #64748b !important;
}

.evidence-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 8px;
    font-weight: 700;
    background: var(--g);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent !important;
    font-size: 0.85rem;
    letter-spacing: 0.01em;
    transition: opacity 0.2s;
}

.evidence-item-name:hover {
    color: #f1f5f9 !important;
}

.evidence-item-meta {
    font-size: 0.7rem;
    color: #64748b;
    white-space: nowrap;
}

.evidence-item-meta-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    padding-left: 8px;
}

.evidence-item-meta-link {
    border: 1px solid rgba(167, 139, 250, 0.24);
    background: rgba(167, 139, 250, 0.08);
    color: #c4b5fd;
    border-radius: 999px;
    padding: 3px 9px;
    font-size: 0.68rem;
    font-weight: 700;
    font-family: inherit;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
    white-space: nowrap;
}

.evidence-item-meta-link:hover {
    transform: translateY(-1px) scale(1.02);
    box-shadow: 0 0 14px rgba(167, 139, 250, 0.18);
    border-color: rgba(167, 139, 250, 0.48);
    background: rgba(167, 139, 250, 0.16);
    color: #e9d5ff;
}

.evidence-item-meta-link.disabled,
.evidence-item-meta-link:disabled {
    cursor: default;
    opacity: 0.55;
    box-shadow: none;
    transform: none;
}

.evidence-item-meta-link.disabled:hover,
.evidence-item-meta-link:disabled:hover {
    transform: none;
    box-shadow: none;
    border-color: rgba(167, 139, 250, 0.24);
    background: rgba(167, 139, 250, 0.08);
    color: #c4b5fd;
}

.evidence-item-actions {
    display: flex;
    gap: 4px;
    margin-left: 6px;
}

.evidence-action-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    background: transparent;
    color: #94a3b8;
}

.evidence-action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.evidence-action-btn.link-btn {
    color: #60a5fa;
}

.evidence-action-btn.link-btn.linked {
    color: #4ade80;
}

.evidence-action-btn.link-btn.waiting {
    color: #fbbf24;
    animation: pulse-yellow 1s infinite;
}

.evidence-action-btn.del-btn:hover {
    color: #ef4444;
}

/* SVG Connection Lines */
#evidence-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.connection-line {
    fill: none;
    stroke-width: 1.9;
    opacity: 0.82;
    vector-effect: non-scaling-stroke;
    animation: connection-line-breathe 1.6s ease-in-out infinite;
    animation-delay: var(--sync-delay, 0s);
}

.connection-line-glow {
    fill: none;
    stroke-width: 6;
    opacity: 0.24;
    filter: blur(1.4px);
    vector-effect: non-scaling-stroke;
    animation: connection-glow-breathe 1.6s ease-in-out infinite;
    animation-delay: var(--sync-delay, 0s);
}

.connection-endpoint {
    opacity: 0.9;
    filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.18));
    animation: connection-node-breathe 1.6s ease-in-out infinite;
    animation-delay: var(--sync-delay, 0s);
}

.connection-flow-dot {
    opacity: 0.82;
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.65));
    animation: connection-node-breathe 1.6s ease-in-out infinite;
    animation-delay: var(--sync-delay, 0s);
}

/* Keep compatibility with existing JS class hooks */
.connection-line.syncing,
.connection-line-glow.syncing,
.connection-endpoint.syncing,
.connection-flow-dot.syncing {
    animation-duration: 1.6s;
    animation-delay: var(--sync-delay, 0s);
}

/* Stronger emphasis while actively linking */
.connection-line.pulsing {
    stroke-width: 2.2;
    opacity: 0.96;
}

.connection-line-glow.pulsing {
    stroke-width: 7;
    opacity: 0.36;
    filter: blur(2px);
}

.connection-endpoint.pulsing,
.connection-flow-dot.pulsing {
    opacity: 1;
}

@keyframes connection-sync-pulse {

    0%,
    100% {
        opacity: 0.66;
    }

    50% {
        opacity: 1;
    }
}

@keyframes connection-line-breathe {

    0%,
    100% {
        opacity: 0.38;
        stroke-width: 1.55;
    }

    50% {
        opacity: 0.98;
        stroke-width: 2.6;
    }
}

@keyframes connection-glow-breathe {

    0%,
    100% {
        opacity: 0.06;
        stroke-width: 4.8;
    }

    50% {
        opacity: 0.52;
        stroke-width: 9.2;
    }
}

@keyframes connection-node-breathe {

    0%,
    100% {
        opacity: 0.48;
    }

    50% {
        opacity: 1;
    }
}

/* Hide scrollbar in source dropdown inner scroll */
#source-inner-scroll {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#source-inner-scroll::-webkit-scrollbar {
    display: none;
}

/* Custom Resize Handle for Evidence Dropdown */
#source-resize-handle {
    position: absolute;
    bottom: 0px;
    left: 0px;
    width: 20px;
    height: 20px;
    cursor: sw-resize;
    z-index: 5000;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    padding: 2px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    user-select: none;
    background: linear-gradient(45deg, rgba(255, 255, 255, 0.2) 0%, transparent 50%);
    border-bottom-left-radius: 16px;
    pointer-events: auto;
}

#source-resize-handle:hover {
    background: linear-gradient(45deg, rgba(255, 255, 255, 0.5) 0%, transparent 50%);
    color: #fff;
}

/* Source Row Styles */
.source-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2px;
    gap: 4px;
    transition: transform 0.2s ease;
    min-height: 36px;
}

.source-row.dragging {
    opacity: 0.5;
    transform: scale(0.98);
}

.source-row.drag-over {
    border-top: 2px solid var(--st-fam);
}

.source-item {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: grab;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid transparent;
    transition: all 0.2s;
    font-size: 0.8rem;
    min-width: 0;
    overflow: hidden;
}

.source-item:active {
    cursor: grabbing;
}

.source-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.source-item.active {
    background: rgba(96, 165, 250, 0.15);
    border-color: rgba(96, 165, 250, 0.4);
    color: #e2e8f0;
}

.source-item.is-paired {
    border-left: 4px solid transparent;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.03), transparent);
}

.source-item.is-paired::before {
    content: "LINKED";
    font-family: "Courier New", monospace;
    font-size: 0.6rem;
    opacity: 0.6;
    margin-right: 8px;
    font-weight: bold;
    letter-spacing: 0.5px;
}

.source-item.linking-target {
    border: 1px dashed #fbbf24;
    background: rgba(251, 191, 36, 0.1);
    animation: pulse-border 1.5s infinite;
}

.source-btn-group {
    display: flex;
    gap: 4px;
}

.source-action-btn {
    width: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    transition: all 0.2s;
}

.btn-del {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.btn-del:hover {
    background: rgba(239, 68, 68, 0.25);
    border-color: #ef4444;
    color: #fff;
}

.btn-link {
    background: rgba(96, 165, 250, 0.1);
    color: #60a5fa;
}

.btn-link:hover {
    background: rgba(96, 165, 250, 0.25);
    border-color: #60a5fa;
    color: #fff;
}

.btn-link.is-linked {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
    border-color: rgba(34, 197, 94, 0.5);
}

.btn-link.is-linked:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border-color: #ef4444;
}

.btn-link.waiting {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.5);
    animation: pulse-yellow 1s infinite;
}

.si-name {
    font-size: 0.85rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    max-width: 160px;
}

.si-count {
    font-size: 0.75rem;
    color: #64748b;
    font-weight: bold;
}

/* ==========================================================================
   NEW IMPORT FLASH ANIMATION (Canvas imports)
   ========================================================================== */

@keyframes newImportFlash {
    0% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
        background: rgba(255, 255, 255, 0.03);
    }

    20% {
        box-shadow: 0 0 20px 8px rgba(245, 158, 11, 0.6);
        background: rgba(245, 158, 11, 0.2);
    }

    40% {
        box-shadow: 0 0 10px 4px rgba(245, 158, 11, 0.3);
        background: rgba(245, 158, 11, 0.1);
    }

    60% {
        box-shadow: 0 0 20px 8px rgba(245, 158, 11, 0.5);
        background: rgba(245, 158, 11, 0.15);
    }

    80% {
        box-shadow: 0 0 10px 4px rgba(245, 158, 11, 0.2);
        background: rgba(245, 158, 11, 0.08);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
        background: rgba(255, 255, 255, 0.03);
    }
}

.evidence-item.new-import-flash,
.evidence-flash {
    animation: newImportFlash 4.5s ease-out !important;
}
