/* =============================================================================
 * AI MARKDOWN STYLES
 * =============================================================================
 * Unified markdown rendering styles for all AI assistant components.
 * This file provides consistent styling for markdown-converted HTML content
 * across the application: chat zone, stat reports, PDF exports, etc.
 * 
 * Usage:
 *   - Apply .ai-markdown-content class to any container with markdown HTML
 *   - Or use the scoped selectors like .ia-assistant-message-bot for specific contexts
 * 
 * ============================================================================= */

/* -----------------------------------------------------------------------------
 * CSS Variables (AI Markdown Theme)
 * ----------------------------------------------------------------------------- */

:root {
    /* Heading colors */
    --ai-md-heading-color: #1a557a;
    --ai-md-heading-weight: 600;
    
    /* Text colors */
    --ai-md-text-color: #333;
    --ai-md-text-secondary: #555;
    --ai-md-text-muted: #888;
    
    /* Link colors */
    --ai-md-link-color: #1a73e8;
    
    /* Code colors */
    --ai-md-code-bg: #f5f5f5;
    --ai-md-code-block-bg: #f8f9fa;
    
    /* Blockquote */
    --ai-md-blockquote-border: #1a73e8;
    --ai-md-blockquote-bg: #f8f9fa;
    
    /* Table */
    --ai-md-table-border: #dee2e6;
    --ai-md-table-header-bg: #f8f9fa;
    
    /* Misc */
    --ai-md-hr-color: #e0e0e0;
}


/* =============================================================================
 * GENERIC MARKDOWN CONTAINER
 * =============================================================================
 * Apply this class to any element containing markdown-converted HTML
 * ============================================================================= */

.ai-markdown-content {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--ai-md-text-color);
}


/* -----------------------------------------------------------------------------
 * Headings
 * ----------------------------------------------------------------------------- */

.ai-markdown-content h1,
.ai-markdown-content h2,
.ai-markdown-content h3,
.ai-markdown-content h4,
.ai-markdown-content h5,
.ai-markdown-content h6 {
    color: var(--ai-md-heading-color);
    font-weight: var(--ai-md-heading-weight);
    margin: 1em 0 0.5em 0;
    line-height: 1.3;
}

.ai-markdown-content h1 { font-size: 1.5em; }
.ai-markdown-content h2 { font-size: 1.3em; }
.ai-markdown-content h3 { font-size: 1.15em; }
.ai-markdown-content h4 { font-size: 1em; }
.ai-markdown-content h5 { font-size: 0.9em; }
.ai-markdown-content h6 { font-size: 0.85em; }

/* First heading should not have top margin */
.ai-markdown-content > h1:first-child,
.ai-markdown-content > h2:first-child,
.ai-markdown-content > h3:first-child,
.ai-markdown-content > h4:first-child,
.ai-markdown-content > h5:first-child,
.ai-markdown-content > h6:first-child {
    margin-top: 0;
}


/* -----------------------------------------------------------------------------
 * Paragraphs
 * ----------------------------------------------------------------------------- */

.ai-markdown-content p {
    margin: 0.6em 0;
}

.ai-markdown-content > p:first-child {
    margin-top: 0;
}

.ai-markdown-content > p:last-child {
    margin-bottom: 0;
}


/* -----------------------------------------------------------------------------
 * Lists (ul, ol)
 * ----------------------------------------------------------------------------- */

.ai-markdown-content ul,
.ai-markdown-content ol {
    margin: 0.6em 0;
    padding-left: 1.5em;
}

.ai-markdown-content ul {
    list-style-type: disc;
}

.ai-markdown-content ol {
    list-style-type: decimal;
}

.ai-markdown-content li {
    margin: 0.3em 0;
}

/* Nested lists */
.ai-markdown-content ul ul,
.ai-markdown-content ol ol,
.ai-markdown-content ul ol,
.ai-markdown-content ol ul {
    margin: 0.2em 0;
}


/* -----------------------------------------------------------------------------
 * Text Formatting (strong, em, del)
 * ----------------------------------------------------------------------------- */

.ai-markdown-content strong {
    font-weight: 600;
    color: var(--ai-md-text-color);
}

.ai-markdown-content em {
    font-style: italic;
}

.ai-markdown-content del {
    text-decoration: line-through;
    color: var(--ai-md-text-muted);
}


/* -----------------------------------------------------------------------------
 * Code (inline and block)
 * ----------------------------------------------------------------------------- */

.ai-markdown-content code {
    background: var(--ai-md-code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    font-size: 0.9em;
}

.ai-markdown-content pre {
    background: var(--ai-md-code-block-bg);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.8em 0;
}

.ai-markdown-content pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
}


/* -----------------------------------------------------------------------------
 * Blockquotes
 * ----------------------------------------------------------------------------- */

.ai-markdown-content blockquote {
    border-left: 4px solid var(--ai-md-blockquote-border);
    margin: 0.8em 0;
    padding: 0.5em 1em;
    background: var(--ai-md-blockquote-bg);
    color: var(--ai-md-text-secondary);
}

.ai-markdown-content blockquote p:first-child {
    margin-top: 0;
}

.ai-markdown-content blockquote p:last-child {
    margin-bottom: 0;
}


/* -----------------------------------------------------------------------------
 * Tables
 * ----------------------------------------------------------------------------- */

.ai-markdown-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.8em 0;
}

.ai-markdown-content th,
.ai-markdown-content td {
    border: 1px solid var(--ai-md-table-border);
    padding: 8px 12px;
    text-align: left;
}

.ai-markdown-content th {
    background: var(--ai-md-table-header-bg);
    font-weight: 600;
}

.ai-markdown-content tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.02);
}


/* -----------------------------------------------------------------------------
 * Horizontal Rules
 * ----------------------------------------------------------------------------- */

.ai-markdown-content hr {
    border: none;
    border-top: 1px solid var(--ai-md-hr-color);
    margin: 1em 0;
}


/* -----------------------------------------------------------------------------
 * Links
 * ----------------------------------------------------------------------------- */

.ai-markdown-content a {
    color: var(--ai-md-link-color);
    text-decoration: none;
}

.ai-markdown-content a:hover {
    text-decoration: underline;
}


/* -----------------------------------------------------------------------------
 * Task Lists (checkbox items)
 * ----------------------------------------------------------------------------- */

.ai-markdown-content input[type="checkbox"] {
    margin-right: 6px;
    vertical-align: middle;
}

.ai-markdown-content li.task-list-item {
    list-style-type: none;
    margin-left: -1.5em;
}


/* -----------------------------------------------------------------------------
 * Images
 * ----------------------------------------------------------------------------- */

.ai-markdown-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}


/* =============================================================================
 * CONTEXT-SPECIFIC STYLES
 * =============================================================================
 * These rules apply the markdown styles to specific AI assistant contexts
 * ============================================================================= */

/* -----------------------------------------------------------------------------
 * Chat Zone Messages (.ia-assistant-message-bot)
 * ----------------------------------------------------------------------------- */

.ia-assistant-message-bot h1,
.ia-assistant-message-bot h2,
.ia-assistant-message-bot h3,
.ia-assistant-message-bot h4,
.ia-assistant-message-bot h5,
.ia-assistant-message-bot h6 {
    color: var(--ai-md-heading-color);
    font-weight: var(--ai-md-heading-weight);
    margin: 0.8em 0 0.4em 0;
    line-height: 1.3;
}

.ia-assistant-message-bot h1 { font-size: 1.4em; }
.ia-assistant-message-bot h2 { font-size: 1.25em; }
.ia-assistant-message-bot h3 { font-size: 1.1em; }
.ia-assistant-message-bot h4 { font-size: 1em; }

.ia-assistant-message-bot > h1:first-child,
.ia-assistant-message-bot > h2:first-child,
.ia-assistant-message-bot > h3:first-child,
.ia-assistant-message-bot > h4:first-child {
    margin-top: 0;
}

.ia-assistant-message-bot p {
    margin: 0.5em 0;
}

.ia-assistant-message-bot > p:first-child {
    margin-top: 0;
}

.ia-assistant-message-bot > p:last-child {
    margin-bottom: 0;
}

.ia-assistant-message-bot ul,
.ia-assistant-message-bot ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.ia-assistant-message-bot ul {
    list-style-type: disc;
}

.ia-assistant-message-bot ol {
    list-style-type: decimal;
}

.ia-assistant-message-bot li {
    margin: 0.25em 0;
}

.ia-assistant-message-bot strong {
    font-weight: 600;
}

.ia-assistant-message-bot em {
    font-style: italic;
}

.ia-assistant-message-bot code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 5px;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

.ia-assistant-message-bot pre {
    background: rgba(0, 0, 0, 0.04);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.6em 0;
}

.ia-assistant-message-bot pre code {
    background: transparent;
    padding: 0;
}

.ia-assistant-message-bot blockquote {
    border-left: 3px solid var(--ai-md-blockquote-border);
    margin: 0.6em 0;
    padding: 0.4em 0.8em;
    background: rgba(0, 0, 0, 0.03);
    color: var(--ai-md-text-secondary);
}

.ia-assistant-message-bot table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.6em 0;
    font-size: 0.95em;
}

.ia-assistant-message-bot th,
.ia-assistant-message-bot td {
    border: 1px solid var(--ai-md-table-border);
    padding: 6px 10px;
    text-align: left;
}

.ia-assistant-message-bot th {
    background: rgba(0, 0, 0, 0.04);
    font-weight: 600;
}

.ia-assistant-message-bot hr {
    border: none;
    border-top: 1px solid var(--ai-md-hr-color);
    margin: 0.8em 0;
}

.ia-assistant-message-bot a {
    color: var(--ai-md-link-color);
    text-decoration: none;
}

.ia-assistant-message-bot a:hover {
    text-decoration: underline;
}

.ia-assistant-message-bot del {
    text-decoration: line-through;
    color: var(--ai-md-text-muted);
}

.ia-assistant-message-bot input[type="checkbox"] {
    margin-right: 5px;
}


/* -----------------------------------------------------------------------------
 * User Messages (light styling for markdown in user input)
 * ----------------------------------------------------------------------------- */

.ia-assistant-message-user code {
    background: rgba(255, 255, 255, 0.3);
    padding: 2px 5px;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

.ia-assistant-message-user strong {
    font-weight: 600;
}

.ia-assistant-message-user em {
    font-style: italic;
}


/* =============================================================================
 * AI ASSISTANT DETAILS VIEW PAGE
 * =============================================================================
 * Styles for the ViewAssistantIaDetailsServlet HTML page.
 * This section provides layout, statistics cards, tables, and UI components.
 * ============================================================================= */

/* -----------------------------------------------------------------------------
 * Base Reset & Body (Details Page)
 * ----------------------------------------------------------------------------- */

.ai-details-page {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #fff;
    padding: 20px 40px;
}

.ai-details-page * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}


/* -----------------------------------------------------------------------------
 * Page Header
 * ----------------------------------------------------------------------------- */

.ai-details-page .page-header {
    border-bottom: 3px solid #1a73e8;
    padding-bottom: 15px;
    margin-bottom: 20px;
}

.ai-details-page .page-title {
    font-size: 1.8rem;
    font-weight: 600;
    color: #1a557a;
}


/* -----------------------------------------------------------------------------
 * Document Info Bar
 * ----------------------------------------------------------------------------- */

.ai-details-page .document-info {
    color: #555;
    font-size: 0.9rem;
    margin-bottom: 25px;
}

.ai-details-page .doc-label {
    font-weight: 600;
}

.ai-details-page .doc-name {
    color: #333;
}

.ai-details-page .doc-separator {
    margin: 0 8px;
    color: #999;
}

.ai-details-page .doc-date,
.ai-details-page .doc-playbook {
    color: #666;
}


/* -----------------------------------------------------------------------------
 * Statistics Cards
 * ----------------------------------------------------------------------------- */

.ai-details-page .stats-container {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.ai-details-page .stat-card {
    padding: 15px 25px;
    border-radius: 8px;
    text-align: center;
    min-width: 100px;
}

.ai-details-page .stat-number {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
}

.ai-details-page .stat-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 5px;
}

.ai-details-page .stat-total {
    background: #e3f2fd;
    color: #1565c0;
}

.ai-details-page .stat-conforme {
    background: #e8f5e9;
    color: #2e7d32;
}

.ai-details-page .stat-non-conforme {
    background: #ffebee;
    color: #c62828;
}

.ai-details-page .stat-critical {
    background: #fff3e0;
    color: #ef6c00;
}

.ai-details-page .stat-info {
    background: #f5f5f5;
    color: #616161;
}


/* -----------------------------------------------------------------------------
 * Section Headers
 * ----------------------------------------------------------------------------- */

.ai-details-page .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 30px 0 15px 0;
    padding-bottom: 10px;
    border-bottom: 1px solid #e0e0e0;
}

.ai-details-page .section-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
    color: #1a557a;
}

.ai-details-page .toggle-btn {
    padding: 6px 12px;
    font-size: 0.8rem;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
}

.ai-details-page .toggle-btn:hover {
    background: #e8e8e8;
}


/* -----------------------------------------------------------------------------
 * Table Toolbar (Search & Filters)
 * ----------------------------------------------------------------------------- */

.ai-details-page .table-toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    margin: 10px 0 15px 0;
    flex-wrap: wrap;
}

.ai-details-page .search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1 1 320px;
}

.ai-details-page .search-input {
    width: 100%;
    max-width: 520px;
    padding: 10px 12px;
    border: 1px solid #dcdfe3;
    border-radius: 8px;
    font-size: 0.95rem;
    outline: none;
}

.ai-details-page .search-input:focus {
    border-color: #1a73e8;
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.12);
}

.ai-details-page .search-hint {
    color: #666;
    font-size: 0.85rem;
    white-space: nowrap;
}

.ai-details-page .filter-box {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
}

.ai-details-page .filter-select {
    padding: 9px 10px;
    border: 1px solid #dcdfe3;
    border-radius: 8px;
    background: #fff;
    font-size: 0.9rem;
    cursor: pointer;
}

.ai-details-page .clear-btn {
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid #ddd;
    background: #f5f5f5;
    cursor: pointer;
    font-size: 0.9rem;
}

.ai-details-page .clear-btn:hover {
    background: #e8e8e8;
}


/* -----------------------------------------------------------------------------
 * Clauses Table
 * ----------------------------------------------------------------------------- */

.ai-details-page .clauses-container {
    overflow-x: auto;
}

.ai-details-page .clauses-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.ai-details-page .clauses-table th {
    background: #f8f9fa;
    padding: 12px 15px;
    text-align: left;
    font-weight: 600;
    color: #555;
    border-bottom: 2px solid #dee2e6;
}

.ai-details-page .clauses-table td {
    padding: 15px;
    border-bottom: 1px solid #eee;
    vertical-align: top;
}

.ai-details-page .clauses-table tr:hover {
    background: #f8f9fa;
}

.ai-details-page .col-num {
    width: 40px;
    text-align: center;
    color: #888;
}

.ai-details-page .col-clause {
    width: 150px;
}

.ai-details-page .col-status {
    width: 120px;
}

.ai-details-page .col-risk {
    width: 80px;
    text-align: center;
}

.ai-details-page .col-analysis {
    min-width: 300px;
}

.ai-details-page .clause-title {
    font-weight: 600;
    color: #333;
}

.ai-details-page .clause-content {
    color: #555;
    line-height: 1.7;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
}


/* -----------------------------------------------------------------------------
 * Status Badges
 * ----------------------------------------------------------------------------- */

.ai-details-page .status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
}

.ai-details-page .status-conforme {
    background: #e8f5e9;
    color: #2e7d32;
}

.ai-details-page .status-non-conforme {
    background: #ffebee;
    color: #c62828;
}

.ai-details-page .status-warning {
    background: #fff3e0;
    color: #ef6c00;
}

.ai-details-page .status-info {
    background: #e3f2fd;
    color: #1565c0;
}


/* -----------------------------------------------------------------------------
 * Risk Indicators
 * ----------------------------------------------------------------------------- */

.ai-details-page .risk-indicator {
    display: inline-block;
    font-size: 1.2rem;
}

.ai-details-page .risk-high {
    color: #c62828;
}

.ai-details-page .risk-medium {
    color: #ef6c00;
}

.ai-details-page .risk-low {
    color: #2e7d32;
}

.ai-details-page .risk-none {
    color: #999;
}


/* -----------------------------------------------------------------------------
 * Content Keyword Highlights
 * ----------------------------------------------------------------------------- */

.ai-details-page .kw-obligation {
    background: #e3f2fd;
    padding: 0 3px;
    border-radius: 2px;
}

.ai-details-page .kw-confidential {
    background: #fce4ec;
    padding: 0 3px;
    border-radius: 2px;
}

.ai-details-page .kw-forbidden {
    background: #ffebee;
    padding: 0 3px;
    border-radius: 2px;
    color: #c62828;
}

.ai-details-page .kw-allowed {
    background: #e8f5e9;
    padding: 0 3px;
    border-radius: 2px;
}


/* -----------------------------------------------------------------------------
 * User Prompt Box
 * ----------------------------------------------------------------------------- */

.ai-details-page .user-prompt-box {
    background: #e3f2fd;
    border-left: 4px solid #1a73e8;
    padding: 15px 20px;
    margin-bottom: 20px;
    border-radius: 0 8px 8px 0;
}


/* -----------------------------------------------------------------------------
 * Raw Response Box
 * ----------------------------------------------------------------------------- */

.ai-details-page .raw-response-box {
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.ai-details-page .raw-response-box pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
}


/* -----------------------------------------------------------------------------
 * Footer
 * ----------------------------------------------------------------------------- */

.ai-details-page .page-footer {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
    text-align: center;
    color: #888;
    font-size: 0.85rem;
}


/* -----------------------------------------------------------------------------
 * Print Styles
 * ----------------------------------------------------------------------------- */

@media print {
    .ai-details-page {
        padding: 10px;
    }

    .ai-details-page .toggle-btn {
        display: none;
    }

    .ai-details-page .raw-response-box {
        display: block !important;
    }

    .ai-details-page .table-toolbar {
        display: none;
    }
}


/* -----------------------------------------------------------------------------
 * Responsive Styles
 * ----------------------------------------------------------------------------- */

@media (max-width: 768px) {
    .ai-details-page {
        padding: 15px;
    }

    .ai-details-page .stats-container {
        justify-content: center;
    }

    .ai-details-page .stat-card {
        flex: 1 1 80px;
    }

    .ai-details-page .clauses-table th,
    .ai-details-page .clauses-table td {
        padding: 10px;
    }

    .ai-details-page .filter-box {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .ai-details-page .search-input {
        max-width: 100%;
    }
}