/* --- Design System & CSS Variables --- */
:root {
    --bg-dark: #070a13;
    --bg-card: rgba(13, 20, 38, 0.45);
    --bg-card-hover: rgba(22, 32, 59, 0.6);
    --border-color: rgba(255, 255, 255, 0.08);
    
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    /* Brand Accent Colors */
    --color-emerald: #10b981;
    --color-emerald-glow: rgba(16, 185, 129, 0.15);
    --color-indigo: #6366f1;
    --color-indigo-glow: rgba(99, 102, 241, 0.15);
    --color-cyan: #00f2fe;
    --color-gold: #f59e0b;
    --color-red: #ef4444;
    
    --font-heading: 'Outfit', sans-serif;
    --font-sans: 'Plus Jakarta Sans', sans-serif;
    --font-mono: 'JetBrains Mono', sans-serif;
    
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Base Styles --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    position: relative;
}

/* --- Background Glow Effects --- */
.glow-bg {
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    filter: blur(140px);
    opacity: 0.12;
    pointer-events: none;
    z-index: 0;
}

.glow-bg.bg-emerald {
    background: var(--color-emerald);
    top: -200px;
    left: -200px;
}

.glow-bg.bg-indigo {
    background: var(--color-indigo);
    bottom: -200px;
    right: -200px;
}

/* --- Custom Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* --- Header --- */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 2.5rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(7, 10, 19, 0.8);
    backdrop-filter: blur(12px);
    z-index: 10;
    position: relative;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.logo-box {
    background: linear-gradient(135deg, var(--color-emerald), var(--color-indigo));
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.3);
}

.logo-text-a1 {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.15rem;
    color: #fff;
    letter-spacing: -0.5px;
}

.logo-title h1 {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.2px;
}

.agency-tag {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.nav-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: var(--transition-smooth);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid transparent;
}

.nav-back-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--border-color);
}

/* --- Layout Container --- */
.app-container {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 1.5rem;
    padding: 1.5rem 2rem;
    flex: 1;
    z-index: 5;
    position: relative;
    max-height: calc(100vh - 80px);
    overflow: hidden;
}

@media (max-width: 1100px) {
    .app-container {
        grid-template-columns: 1fr;
        max-height: none;
        overflow: auto;
    }
}

/* --- Glass Card Panels --- */
.glass-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    transition: var(--transition-smooth);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.panel-icon.icon-emerald { color: var(--color-emerald); filter: drop-shadow(0 0 5px var(--color-emerald-glow)); }
.panel-icon.icon-indigo { color: var(--color-indigo); filter: drop-shadow(0 0 5px var(--color-indigo-glow)); }

.panel-header h2 {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 600;
}

/* --- Left Column: Ingestion Engine --- */
.ingest-panel {
    display: flex;
    flex-direction: column;
}

.form-container {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
    overflow-y: auto;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.flex-fill {
    flex: 1;
    display: flex;
    flex-direction: column;
}

label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

select, textarea {
    background: rgba(7, 10, 19, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 0.75rem;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
    transition: var(--transition-smooth);
}

select:focus, textarea:focus {
    border-color: var(--color-emerald);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.15);
}

textarea {
    resize: none;
    line-height: 1.45;
    flex: 1;
    min-height: 140px;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.range-val {
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
    text-align: right;
}

input[type="range"] {
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    height: 4px;
    border-radius: 2px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--color-emerald);
    cursor: pointer;
    box-shadow: 0 0 8px var(--color-emerald-glow);
    transition: var(--transition-smooth);
}

/* Button */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.85rem;
    border-radius: 10px;
    border: none;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition-smooth);
    color: #fff;
    width: 100%;
}

.btn-emerald {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.btn-emerald:hover {
    opacity: 0.95;
    transform: translateY(-1px);
}

.btn-glow {
    box-shadow: 0 4px 20px rgba(16, 185, 129, 0.25);
}

.btn-glow:hover {
    box-shadow: 0 6px 25px rgba(16, 185, 129, 0.4);
}

/* --- Right Column: Search Panel --- */
.search-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow: hidden;
}

.query-card {
    padding: 1rem 1.25rem;
}

.query-bar-row {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.query-bar-row input[type="text"] {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
    transition: var(--transition-smooth);
}

.query-bar-row input[type="text"]:focus {
    border-color: var(--color-indigo);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.15);
}

.btn-indigo {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    width: 130px;
    margin: 0;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.25);
}

.btn-indigo:hover:not(:disabled) {
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

/* Chunks Layout Grid */
.grid-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    flex: 1;
    overflow: hidden;
}

@media (max-width: 900px) {
    .grid-layout {
        grid-template-columns: 1fr;
        max-height: none;
        overflow: auto;
    }
}

.chunks-index-card, .matches-card {
    max-height: calc(100vh - 250px);
}

.chunks-grid-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    background: rgba(0, 0, 0, 0.15);
}

/* Chunk Item Cards */
.chunk-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    position: relative;
    transition: var(--transition-smooth);
}

.chunk-item:hover {
    border-color: rgba(255, 255, 255, 0.12);
}

.chunk-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chunk-badge {
    background: rgba(16, 185, 129, 0.08);
    border: 1px solid rgba(16, 185, 129, 0.2);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.65rem;
    font-family: var(--font-mono);
    color: var(--color-emerald);
}

.chunk-words {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.chunk-text {
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--text-primary);
}

/* Highlighting searched matches inside vector index cards */
.chunk-item.matched-highlight {
    border-color: var(--color-indigo);
    background: rgba(99, 102, 241, 0.04);
}

/* Right Panel: Retrieval Match Cards list */
.matches-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
}

.retrieval-results {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    flex: 1;
    animation: fadeIn 0.4s ease-out forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.retrieval-results h3 {
    font-family: var(--font-heading);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.matched-chunks-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Matched Chunk Row styling */
.match-card {
    background: rgba(99, 102, 241, 0.02);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: 10px;
    padding: 0.85rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.match-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.match-id {
    font-size: 0.75rem;
    font-family: var(--font-heading);
    font-weight: 700;
    color: #fff;
}

.match-score {
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: #a5b4fc;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
}

.match-card .match-text {
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--text-primary);
}

.match-card .match-text mark {
    background: rgba(245, 158, 11, 0.25);
    color: #fff;
    padding: 1px 3px;
    border-radius: 2px;
}

/* LLM Synthesis block */
.synthesis-block {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.25rem;
    margin-top: auto;
    border-top: 2px solid var(--color-indigo);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.05);
}

.synthesis-label {
    font-family: var(--font-heading);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--color-indigo);
    margin-bottom: 0.5rem;
    display: block;
}

#synthesis-response {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-primary);
}

.empty-state {
    margin: auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
    max-width: 240px;
}

.muted-icon {
    opacity: 0.3;
}

.empty-state p {
    font-size: 0.8rem;
    line-height: 1.45;
}

/* --- Footer --- */
.app-footer {
    text-align: center;
    padding: 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    background: rgba(7, 10, 19, 0.9);
    z-index: 10;
    position: relative;
}

/* --- Mobile Responsiveness Overrides --- */
@media (max-width: 1100px) {
    .app-container {
        padding: 1.5rem 1rem;
        gap: 1.25rem;
    }
}

@media (max-width: 600px) {
    .app-header {
        padding: 1rem;
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }
    .nav-back-btn {
        width: 100%;
        justify-content: center;
    }
    .form-row {
        flex-direction: column;
        gap: 0.75rem;
    }
    .query-bar-row {
        flex-direction: column;
        gap: 0.75rem;
    }
    .query-bar-row input[type="text"] {
        width: 100%;
    }
    .btn-indigo {
        width: 100% !important;
    }
    .chunks-index-card, .matches-card {
        max-height: none;
    }
}

/* Height-based Responsiveness for Short Screens */
@media (max-height: 768px) {
    .app-container {
        max-height: none;
        overflow: visible;
    }
}

