/* ============================================
   NOTES.CSS - Note Generation RAG Panel Styles
   ============================================
   ARCHITECTURE: Separate styling for note display and RAG knowledge panel
   WHY: Clean separation between copyable note content and reference RAG sources
   TRADEOFF: Additional CSS file vs organized, maintainable styling
   ============================================ */

/* Two-Column Layout for Note + RAG */
/* ARCHITECTURE: Wider note editor with collapsible RAG panel */
/* WHY: User requested more space for note editing vs cramped 380px */
/* TRADEOFF: Fixed RAG width vs responsive - fixed is simpler and predictable */
/* NOTE: RAG panel can collapse to give editor 100% width */
.note-display-wrapper {
    display: grid;
    grid-template-columns: 1fr 400px;  /* ~70% editor, ~30% RAG */
    gap: 1.5rem;
    height: calc(100vh - 200px);
    overflow: hidden;
    transition: grid-template-columns 0.3s ease, gap 0.3s ease;
}

/* When RAG panel is collapsed */
.note-display-wrapper.rag-collapsed {
    grid-template-columns: 1fr 0px;
    gap: 0;
}

.note-display-wrapper.rag-collapsed .rag-knowledge-panel {
    display: none;
}

/* Left Column: Clean Note Output (Copyable) */
/* ARCHITECTURE: Elevated surface with dual shadows for depth */
/* WHY: Note content should appear as raised card above base surface */
/* TRADEOFF: Subtle shadows vs clear visual separation from background */
.note-output-section {
    display: flex;
    flex-direction: column;
    background: var(--surface-raised);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--elevation-medium);
    position: relative;
}

.note-output-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100%;
    background: var(--gradient-card-subtle);
    pointer-events: none;
    opacity: 0.3;
    z-index: 0;
}

.note-content-clean {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    /* white-space: pre-wrap; */  /* Removed: HTML rendering handles line breaks */
    word-wrap: break-word;
    font-family: var(--font-sans);  /* Use proportional font for rendered markdown */
    font-size: 0.95rem;
    line-height: 1.7;
    background: var(--bg-primary);
}

/* Style rendered markdown headers in note content */
.note-content-clean h1, .note-content-clean h2, .note-content-clean h3 {
    font-weight: 600;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.note-content-clean h3 {
    font-size: 1.1rem;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 0.25rem;
}

.note-content-clean strong {
    font-weight: 600;
    color: var(--text-primary);
}

.note-content-clean li {
    margin-left: 1.5rem;
    margin-bottom: 0.25rem;
}

/* Right Column: RAG Knowledge Panel (Reference Only) */
/* ARCHITECTURE: Distinct elevated panel alongside note content */
/* WHY: RAG panel needs visual distinction but shouldn't compete with note */
/* NOTE: Use --surface-elevated background + --elevation-medium shadow */
.rag-knowledge-panel {
    display: flex;
    flex-direction: column;
    background: var(--surface-elevated);
    border: 2px solid var(--primary-200);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--elevation-medium);
    position: relative;
}

.rag-knowledge-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--gradient-card);
    pointer-events: none;
    opacity: 0.15;
}

.rag-knowledge-header {
    padding: 0.875rem 1rem;
    background: var(--primary-100);
    border-bottom: 1px solid var(--primary-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.rag-knowledge-header h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary-700);
}

.rag-count-badge {
    background: var(--primary-200);
    color: var(--primary-800);
    padding: 0.125rem 0.5rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
}

.rag-reference-label {
    font-size: 0.65rem;
    color: var(--warning-700);
    background: var(--warning-100);
    padding: 0.25rem 0.625rem;
    border-radius: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid var(--warning-300);
}

/* RAG Toggle Button */
/* ARCHITECTURE: Toggle button to collapse/expand RAG panel */
/* WHY: Maximizes editor space when knowledge sources not needed */
.rag-toggle-btn {
    background: transparent;
    border: 1px solid var(--primary-300);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rag-toggle-btn:hover {
    background: var(--primary-200);
}

.rag-toggle-btn i {
    font-size: 1rem;
    color: var(--primary-700);
    transition: transform 0.3s ease;
}

/* Rotate icon when RAG is collapsed */
.note-display-wrapper.rag-collapsed .rag-toggle-btn i {
    transform: rotate(180deg);
}

.rag-knowledge-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    background: var(--bg-secondary);
}

/* RAG Source Cards */
/* ARCHITECTURE: Layered cards within panel (lighter tint = higher hierarchy) */
/* WHY: Source cards appear raised above panel background */
/* TRADEOFF: Multiple elevation levels vs clear visual grouping */
.rag-source-card {
    padding: 0.875rem;
    background: var(--surface-raised);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    margin-bottom: 0.625rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--elevation-low);
    position: relative;
}

.rag-source-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--gradient-card-subtle);
    border-radius: 6px;
    pointer-events: none;
    opacity: 0.3;
}

.rag-source-card:hover {
    border-color: var(--primary-400);
    box-shadow: var(--elevation-medium);
    transform: translateY(-2px);
    background: var(--surface-overlay);
}

.rag-source-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.rag-source-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.8125rem;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.rag-similarity-badge {
    padding: 0.125rem 0.5rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
}

.rag-similarity-success {
    background: var(--success-100);
    color: var(--success-700);
    border: 1px solid var(--success-300);
}

.rag-similarity-warning {
    background: var(--warning-100);
    color: var(--warning-700);
    border: 1px solid var(--warning-300);
}

.rag-similarity-neutral {
    background: var(--neutral-100);
    color: var(--neutral-700);
    border: 1px solid var(--neutral-300);
}

.rag-source-preview {
    color: var(--text-secondary);
    font-size: 0.75rem;
    line-height: 1.5;
    margin-bottom: 0.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.rag-source-action {
    font-size: 0.7rem;
    color: var(--primary-600);
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-weight: 500;
}

.rag-empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-secondary);
}

.rag-empty-state i {
    font-size: 2.5rem;
    color: var(--neutral-400);
    margin-bottom: 0.75rem;
    display: block;
}

.rag-empty-state p {
    font-size: 0.8125rem;
    margin: 0;
}

/* Enhanced Loading Phases */
.loading-phase-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.loading-phase {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-primary);
    border-radius: 6px;
    margin-bottom: 0.75rem;
}

.loading-phase:last-child {
    margin-bottom: 0;
}

.loading-icon {
    font-size: 2rem;
    animation: pulse 2s ease-in-out infinite;
}

.loading-text {
    flex: 1;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-primary);
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--neutral-300);
    border-top-color: var(--primary-500);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Tablet: Stack Vertically */
@media (max-width: 1024px) {
    .note-display-wrapper {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        gap: 1rem;
    }

    .rag-knowledge-panel {
        max-height: 350px;
        order: -1; /* Show RAG panel above note */
    }

    .note-output-section {
        min-height: 400px;
    }
}

/* Mobile: RAG Panel as Bottom Drawer */
@media (max-width: 768px) {
    .note-display-wrapper {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr;
    }

    .note-output-section {
        height: 100%;
    }

    .rag-knowledge-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 45vh;
        max-height: none;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        z-index: 1000;
        border-radius: 12px 12px 0 0;
        border: none;
        border-top: 2px solid var(--primary-400);
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.2);
    }

    .rag-knowledge-panel.open {
        transform: translateY(0);
    }

    /* Toggle button for mobile RAG panel */
    .rag-mobile-toggle {
        position: fixed;
        bottom: 1rem;
        right: 1rem;
        background: var(--primary-500);
        color: white;
        padding: 0.75rem 1rem;
        border-radius: 24px;
        font-size: 0.8125rem;
        font-weight: 600;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        border: none;
        cursor: pointer;
        z-index: 999;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .rag-mobile-toggle:hover {
        background: var(--primary-600);
    }
}

/* Dark Mode Adjustments */
@media (prefers-color-scheme: dark) {
    .rag-knowledge-panel {
        background: var(--bg-secondary);
    }

    .rag-source-card {
        background: var(--bg-tertiary);
        border-color: var(--border-color);
    }

    .rag-source-card:hover {
        border-color: var(--primary-500);
    }
}
