/* =========================================
   1. VARIABLES & THEMING
   ========================================= */
:root {
    /* Core Colors — warm, muted light theme (easy on the eyes) */
    --primary-color: #3b7dd8;
    --primary-hover: #2a5fa8;
    --bg-color: #e8eaed;
    --card-bg: #f5f5f3;
    --text-main: #2c3440;
    --text-muted: #636d7a;
    --border-color: #c8cdd3;

    /* Component Specifics */
    --upload-bg: #edeee9;
    --upload-border: #a8b2b8;
    --box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    --answer-bg: #ebebea;
    --highlight-row: #d4dfe8;

    /* Toggle & Controls */
    --toggle-inactive-bg: #dde2e8;
    --toggle-inactive-text: #495057;

    /* Scrollbar */
    --scrollbar-track: #e8eaed;
    --scrollbar-thumb: #b0b8c0;
    
    /* Classification Tag Colors */
    --tag-digital: #007bff; /* Blue */
    --tag-risk: #dc3545;    /* Red */
    --tag-rci: #28a745;     /* Green */
    --tag-psd: #ffc107;     /* Yellow */
}

/* Dark Mode Overrides */
[data-theme="dark"] {
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --text-main: #e0e0e0;
    --text-muted: #b0b0b0;
    --border-color: #333333;
    
    --upload-bg: #252525;
    --upload-border: #444;
    --box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    
    --answer-bg: #2a2a2a;
    --highlight-row: #2c3e50; 
    
    --toggle-inactive-bg: #2c2c2c;
    --toggle-inactive-text: #b0b0b0;
    
    --scrollbar-track: #2a2a2a;
    --scrollbar-thumb: #555;
    
    --tag-psd: #ffca2c; 
}

/* =========================================
   2. GLOBAL LAYOUT
   ========================================= */
body {
    font-family: 'Segoe UI', Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden; 
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s, color 0.3s;
}

.hidden { display: none !important; }

.main-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    background: var(--card-bg);
    padding: 40px;
    border-radius: 12px;
    box-shadow: var(--box-shadow);
}

/* Scroll Area for Main Content */
.content-scroll-area {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    width: 100%;
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
.content-scroll-area::-webkit-scrollbar { width: 8px; }
.content-scroll-area::-webkit-scrollbar-track { background: var(--scrollbar-track); }
.content-scroll-area::-webkit-scrollbar-thumb { background-color: var(--scrollbar-thumb); border-radius: 4px; }

/* =========================================
   3. HEADER & NAVIGATION
   ========================================= */
.main-header {
    text-align: center;
    padding-top: 15px;
    background-color: var(--bg-color);
    flex-shrink: 0;
    z-index: 10;
    position: relative;
}

.header-top-row {
    position: absolute;
    right: 20px;
    top: 20px;
    display: flex;
    align-items: center;
}

.header-content h1 {
    margin: 0 0 10px 0;
    font-size: 1.8rem;
    color: var(--text-main);
    font-weight: 700;
}

/* --- THEME SWITCH FIX --- */
.theme-switch-wrapper { display: flex; align-items: center; gap: 10px; }
.theme-label { font-size: 0.9rem; font-weight: 600; color: var(--text-muted); }

.theme-switch { display: inline-block; height: 26px; position: relative; width: 50px; }
.theme-switch input { display: none; }

.slider {
    background-color: #ccc;
    bottom: 0; cursor: pointer; left: 0; position: absolute; right: 0; top: 0;
    transition: .4s; border-radius: 34px;
    display: flex; align-items: center; justify-content: space-between; padding: 0 6px;
    box-sizing: border-box;
}

.slider .sun-icon { color: #f39c12; font-size: 14px; z-index: 15; position: relative; }
.slider .moon-icon { color: #f1c40f; font-size: 14px; z-index: 15; position: relative; }

/* The Ball */
.slider:before {
    background-color: #fff;
    bottom: 3px; content: ""; height: 20px; left: 3px; position: absolute;
    transition: .4s; width: 20px; border-radius: 50%; 
    z-index: 10;
}

input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(24px); }

/* Navigation Tabs */
nav {
    display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0; margin-top: 15px;
    padding-left: 20px; padding-right: 20px;
    box-sizing: border-box;
}
nav a {
    text-decoration: none; color: var(--text-muted); font-weight: 600;
    padding: 10px 20px; border-bottom: 3px solid transparent;
    transition: all 0.2s; font-size: 0.95rem;
}
nav a:hover { color: var(--primary-color); background: rgba(0, 123, 255, 0.05); }
nav a.active { color: var(--primary-color); border-bottom-color: var(--primary-color); }

#history-breadcrumb { font-weight: 400; color: var(--text-muted); margin-left: 5px; font-size: 0.9em; }

/* Notification Bell */
.nav-notifications { position: relative; display: flex; align-items: center; margin-left: auto; }
.notif-bell {
    background: none; border: none; cursor: pointer; color: var(--text-muted);
    font-size: 1rem; padding: 8px 12px; border-radius: 6px; transition: all 0.2s;
    position: relative; display: flex; align-items: center; gap: 6px;
}
.notif-bell-label { font-size: 0.85rem; font-weight: 500; }
.notif-bell:hover { color: var(--primary-color); background: rgba(0,123,255,0.05); }
.notif-badge {
    position: absolute; top: 2px; left: 10px; background: #dc3545; color: #fff;
    font-size: 0.65rem; font-weight: 700; min-width: 16px; height: 16px;
    border-radius: 10px; display: flex; align-items: center; justify-content: center;
    padding: 0 4px; line-height: 1; pointer-events: none;
}
.notif-panel {
    position: absolute; top: 100%; right: 0; width: 360px; max-height: 450px;
    background: var(--card-bg); border: 1px solid var(--border-color);
    border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    z-index: 10002; overflow: hidden; margin-top: 6px;
}
.notif-panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px; border-bottom: 1px solid var(--border-color);
    font-weight: 600; font-size: 0.9rem; color: var(--text-main);
}
.notif-panel-actions { display: flex; align-items: center; gap: 4px; }
.notif-panel-header button {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    font-size: 0.8rem; padding: 4px 8px; border-radius: 4px;
}
.notif-panel-header button:hover { color: #dc3545; background: rgba(220,53,69,0.08); }
.notif-list { overflow-y: auto; max-height: 390px; }
.notif-empty { padding: 30px 14px; text-align: center; color: var(--text-muted); font-size: 0.85rem; }

/* Date group headers */
.notif-group-header {
    padding: 6px 14px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.5px; color: var(--text-muted); background: var(--bg-color);
    border-bottom: 1px solid var(--border-color); position: sticky; top: 0; z-index: 1;
}

.notif-item {
    display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px;
    border-bottom: 1px solid var(--border-color); font-size: 0.83rem;
    transition: background 0.15s;
}
.notif-item:last-child { border-bottom: none; }
.notif-item-clickable { cursor: pointer; }
.notif-item-clickable:hover { background: rgba(0,123,255,0.04); }
.notif-item-icon { margin-top: 2px; flex-shrink: 0; }
.notif-success .notif-item-icon { color: #28a745; }
.notif-error .notif-item-icon { color: #dc3545; }
.notif-item-body { flex: 1; min-width: 0; }
.notif-item-title { font-weight: 600; color: var(--text-main); display: block; }
.notif-item-msg { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; max-width: 200px; }
.notif-item-time { font-size: 0.72rem; color: var(--text-muted); flex-shrink: 0; white-space: nowrap; }
.notif-dismiss-btn {
    background: none; border: none; cursor: pointer; color: var(--text-muted);
    font-size: 0.75rem; padding: 2px 4px; border-radius: 3px; flex-shrink: 0;
    opacity: 0.5; transition: opacity 0.15s, color 0.15s;
}
.notif-dismiss-btn:hover { opacity: 1; color: #dc3545; }

/* =========================================
   4. UPLOAD & PROCESSING
   ========================================= */
#upload-container { max-width: 600px; margin: 0 auto; text-align: center; }

.upload-area {
    border: 2px dashed var(--upload-border);
    border-radius: 12px; padding: 50px 20px;
    cursor: pointer; background-color: var(--upload-bg);
    transition: all 0.3s ease;
}
.upload-area:hover, .upload-area.dragover {
    border-color: var(--primary-color);
    background-color: rgba(0, 123, 255, 0.05);
}
.upload-icon { font-size: 3rem; color: #a0aec0; margin-bottom: 15px; }
.upload-area h3 { margin: 0 0 5px 0; color: var(--text-main); }
.upload-area p { margin: 0; color: var(--text-muted); font-size: 0.9rem; }

/* Upload area — queue active indicator */
.upload-area.queue-active {
    border-color: var(--primary-color);
    border-style: solid;
    background: linear-gradient(135deg, rgba(0,123,255,0.03) 0%, rgba(0,123,255,0.08) 100%);
}
.upload-queue-overlay { margin-top: 16px; }
.upload-queue-status {
    font-size: 0.9rem; font-weight: 600; color: var(--primary-color);
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.upload-queue-filename {
    margin-top: 6px; font-size: 0.85rem; color: var(--text-color);
    display: flex; align-items: center; justify-content: center; gap: 6px;
    font-weight: 500; max-width: 80%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    margin-left: auto; margin-right: auto;
}
.upload-queue-filename .fa-file-pdf { color: #dc3545; font-size: 0.9rem; }
.upload-queue-elapsed {
    margin-top: 4px; font-size: 0.8rem; color: var(--text-muted);
    text-align: center; font-variant-numeric: tabular-nums;
}
.upload-queue-hint {
    margin-top: 8px; font-size: 0.8rem; color: var(--text-muted);
    display: flex; align-items: center; justify-content: center; gap: 6px;
}
.upload-queue-hint .fa-plus-circle { color: var(--primary-color); }

/* Staged file list — inside upload area before analysis starts */
.upload-area.has-staged-files {
    padding: 20px; cursor: default;
    border-color: var(--primary-color); border-style: solid;
}
.upload-area.has-staged-files .upload-icon,
.upload-area.has-staged-files h3,
.upload-area.has-staged-files p { display: none; }

.staged-file-list { text-align: left; }
.staged-files-header {
    font-weight: 700; font-size: 0.9rem; color: var(--text-main);
    margin-bottom: 10px; display: flex; align-items: center; gap: 8px;
}
.staged-items-container {
    display: flex; flex-direction: column; gap: 4px;
    max-height: 240px; overflow-y: auto;
}
.staged-item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 10px; border-radius: 8px;
    background: var(--card-bg); border: 1px solid var(--border-color);
    transition: background 0.15s, box-shadow 0.15s;
    cursor: default;
}
.staged-item:hover { background: rgba(0,123,255,0.04); }
.staged-drag-handle {
    cursor: grab; color: var(--text-muted); font-size: 0.85rem;
    padding: 2px 4px; opacity: 0.4; transition: opacity 0.15s;
}
.staged-item:hover .staged-drag-handle { opacity: 1; }
.staged-drag-handle:active { cursor: grabbing; }
.staged-file-icon { color: #dc3545; font-size: 1rem; flex-shrink: 0; }
.staged-file-name {
    flex: 1; min-width: 0; font-size: 0.85rem; font-weight: 500;
    color: var(--text-main); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.staged-order-num {
    font-size: 0.7rem; font-weight: 700; color: var(--text-muted);
    background: var(--upload-bg); border-radius: 50%;
    width: 20px; height: 20px; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.staged-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.staged-move-btn, .staged-remove-btn {
    background: none; border: none; cursor: pointer; color: var(--text-muted);
    font-size: 0.75rem; padding: 3px 5px; border-radius: 4px; transition: all 0.15s;
}
.staged-move-btn:hover { color: var(--primary-color); background: rgba(0,123,255,0.08); }
.staged-move-btn:disabled { opacity: 0.2; cursor: not-allowed; }
.staged-remove-btn:hover { color: #dc3545; background: rgba(220,53,69,0.08); }

/* Drag states */
.staged-item.staged-dragging { opacity: 0.4; }
.staged-item.staged-drag-over {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0,123,255,0.15);
}

.staged-footer {
    display: flex; align-items: center; justify-content: space-between;
    margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border-color);
}
.staged-count { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.staged-footer-actions { display: flex; gap: 8px; }
.staged-add-more-btn {
    background: none; border: 1px solid var(--border-color); color: var(--text-main);
    padding: 6px 14px; border-radius: 6px; cursor: pointer;
    font-size: 0.8rem; font-weight: 500; transition: all 0.2s;
}
.staged-add-more-btn:hover { border-color: var(--primary-color); color: var(--primary-color); }
.staged-start-btn {
    background: var(--primary-color); color: #fff; border: none;
    padding: 6px 18px; border-radius: 6px; cursor: pointer;
    font-size: 0.8rem; font-weight: 600; transition: background 0.2s;
    display: flex; align-items: center; gap: 6px;
}
.staged-start-btn:hover { background: var(--primary-hover); }

#file-action-area { margin-top: 25px; animation: fadeIn 0.4s ease-out; }

.file-chip {
    display: inline-flex; align-items: center;
    background: var(--upload-bg); padding: 10px 20px;
    border-radius: 50px; font-weight: 500;
    color: var(--text-main); margin-bottom: 20px;
    border: 1px solid var(--border-color);
    max-width: 100%; box-sizing: border-box;
}
.file-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 250px; }
.file-chip i.fa-file-pdf { color: #dc3545; margin-right: 10px; font-size: 1.2rem; }
.file-action-buttons {
    display: flex; justify-content: center; gap: 10px;
}
.file-action-buttons button {
    flex: 1; max-width: 200px; padding: 14px; font-size: 1rem; font-weight: 600;
    border-radius: 8px; cursor: pointer; transition: transform 0.1s, background-color 0.2s, border-color 0.2s;
}
#start-analysis-btn {
    color: #fff; background-color: var(--primary-color); border: none;
    box-shadow: 0 4px 6px rgba(0, 123, 255, 0.2);
}
#start-analysis-btn:hover { background-color: var(--primary-hover); transform: translateY(-1px); }
.btn-outline {
    color: var(--text-muted); background: transparent;
    border: 2px solid var(--border-color);
}
.btn-outline:hover { color: #dc3545; border-color: #dc3545; transform: translateY(-1px); }

#processing-feedback { text-align: center; margin-top: 40px; }
.spinner {
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%; width: 50px; height: 50px;
    animation: spin 1s linear infinite; margin: 0 auto 20px auto;
}
#status-text { font-size: 1.1rem; font-weight: 500; color: var(--text-main); }
.timer-text { color: var(--text-muted); font-size: 0.9rem; margin-top: 5px; }

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

#cancel-analysis-btn {
    margin-top: 20px;
    background: transparent;
    border: 1px solid #dc3545;
    color: #dc3545;
    padding: 8px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem; font-weight: 600;
    transition: all 0.2s;
}
#cancel-analysis-btn:hover { background: #dc3545; color: white; }

/* =========================================
   5. RESULTS DASHBOARD
   ========================================= */
.results-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 25px; padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}
.header-left { display: flex; align-items: center; gap: 15px; }
.results-header h2 { margin: 0; color: var(--text-main); }

#new-analysis-btn, .secondary-btn {
    width: auto; background-color: transparent;
    color: var(--primary-color); border: 1px solid var(--primary-color);
    padding: 8px 16px; font-size: 0.9rem; border-radius: 6px; cursor: pointer;
    white-space: nowrap;
}
#new-analysis-btn:hover, .secondary-btn:hover { background-color: rgba(0, 123, 255, 0.1); }
.danger-btn {
    width: auto; background-color: transparent;
    color: #dc3545; border: 1px solid #dc3545;
    padding: 8px 16px; font-size: 0.9rem; border-radius: 6px; cursor: pointer;
    white-space: nowrap;
}
.danger-btn:hover { background-color: rgba(220, 53, 69, 0.1); }

.metadata-card {
    background-color: var(--upload-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px; padding: 20px;
    margin-bottom: 30px;
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}
.meta-item { display: flex; flex-direction: column; }
.meta-label {
    font-size: 0.75rem; color: var(--text-muted);
    text-transform: uppercase; font-weight: 700; margin-bottom: 4px;
}
.meta-value { font-size: 1rem; font-weight: 500; color: var(--text-main); word-break: break-word; }

.summary-box-container {
    display: grid; grid-template-columns: repeat(2, 1fr);
    gap: 20px; margin: 30px 0;
    overflow: visible;
}
.summary-box { overflow: visible; }
@media (min-width: 900px) { .summary-box-container { grid-template-columns: repeat(4, 1fr); } }

.summary-box {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    padding: 20px; border-radius: 8px;
    text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.03);
    height: 100%; box-sizing: border-box;
}
.summary-box.risk-level { border-top-color: #e53e3e; }
.summary-box.rci-level { border-top-color: #38a169; }
.summary-box.psd-level { border-top-color: #d69e2e; }

.summary-box h4 { margin: 0 0 10px; color: var(--text-muted); font-size: 0.85rem; text-transform: uppercase; }
.summary-box p { margin: 0; font-size: 1.1rem; font-weight: 700; color: var(--text-main); }

.report-section { margin-bottom: 30px; }
.report-section h3 {
    color: var(--primary-color);
    border-bottom: 2px solid rgba(0, 123, 255, 0.2);
    padding-bottom: 8px; margin-bottom: 20px;
    font-size: 1.2rem;
}

.question-block { margin-bottom: 20px; break-inside: avoid; }
.question-text { font-weight: 600; color: var(--text-main); margin-bottom: 8px; font-size: 1rem; }
.answer-text {
    background: var(--answer-bg);
    padding: 15px; border-radius: 6px;
    border: 1px solid var(--border-color);
    line-height: 1.6; color: var(--text-main);
    white-space: normal;
    overflow-wrap: break-word;
    word-break: break-word;
}
.evidence-citation {
    display: block; margin-top: 10px;
    font-size: 0.9em; color: var(--text-muted);
    padding-top: 8px; border-top: 1px dashed var(--border-color);
    font-style: italic;
}

/* Risk Vector Styling */
.risk-vector-block { border-left: 3px solid var(--border-color); padding-left: 12px; }
.risk-severity-tag {
    display: inline-block; font-size: 0.75rem; font-weight: 600;
    padding: 2px 8px; border-radius: 4px; margin-left: 8px;
    vertical-align: middle; text-transform: uppercase; letter-spacing: 0.3px;
}
.severity-critical { background: #dc3545; color: #fff; }
.severity-high { background: #c0392b; color: #fff; }
.severity-substantial { background: #e67e22; color: #fff; }
.severity-moderate { background: #f39c12; color: #333; }
.severity-medium { background: #f39c12; color: #333; }
.severity-low { background: #27ae60; color: #fff; }
.severity-not-applicable { background: var(--toggle-inactive-bg); color: var(--text-muted); }

/* RCI Scorecard Styling */
.rci-question-block { border-left: 3px solid var(--border-color); padding-left: 12px; margin-bottom: 12px; }
.rci-rating-tag {
    display: inline-block; font-size: 0.75rem; font-weight: 600;
    padding: 2px 8px; border-radius: 4px; margin-left: 8px;
    vertical-align: middle; text-transform: uppercase; letter-spacing: 0.3px;
}
.rating-a { background: #28a745; color: #fff; }
.rating-b { background: #f0ad4e; color: #333; }
.rating-c { background: #dc3545; color: #fff; }
.rci-meta-row { display: flex; gap: 16px; flex-wrap: wrap; margin: 8px 0; }
.rci-meta-item { font-size: 0.9rem; }
.rci-meta-item strong { margin-right: 4px; }
.rci-classification-badge {
    display: inline-block; font-size: 0.85rem; font-weight: 600;
    padding: 4px 12px; border-radius: 4px; margin-top: 8px;
}
.rci-yes { background: #28a745; color: #fff; }
.rci-no { background: #dc3545; color: #fff; }

/* PSD Checklist Styling */
.psd-criterion-block { border-left: 3px solid var(--border-color); padding-left: 12px; margin-bottom: 12px; }
.psd-score-tag {
    display: inline-block; font-size: 0.75rem; font-weight: 600;
    padding: 2px 8px; border-radius: 4px; margin-left: 8px;
    vertical-align: middle;
}
.psd-score-0 { background: #dc3545; color: #fff; }
.psd-score-1 { background: #28a745; color: #fff; }
.psd-score-2 { background: #28a745; color: #fff; }
.psd-total-row {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; margin: 12px 0;
    background: var(--upload-bg); border-radius: 6px;
    border: 1px solid var(--border-color); font-weight: 600;
}
.psd-classification-badge {
    display: inline-block; font-size: 0.85rem; font-weight: 600;
    padding: 4px 12px; border-radius: 4px;
}
.psd-no { background: var(--toggle-inactive-bg); color: var(--text-muted); }
.psd-basic { background: #f0ad4e; color: #333; }
.psd-medium { background: #5bc0de; color: #fff; }
.psd-high { background: #28a745; color: #fff; }

/* Info Tooltips */
.has-tooltip {
    position: relative; cursor: help;
}
.has-tooltip::after {
    content: attr(data-tooltip);
    position: absolute; bottom: calc(100% + 6px); left: 50%;
    transform: translateX(-50%); white-space: normal;
    width: max-content; max-width: 260px;
    padding: 6px 10px; border-radius: 6px;
    font-size: 0.72rem; font-weight: 400; line-height: 1.4;
    text-transform: none; letter-spacing: normal;
    color: #fff; background: #333;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
    opacity: 0; pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 9999;
}
.has-tooltip:hover::after { opacity: 1; }
[data-theme="dark"] .has-tooltip::after { background: #1a1a2e; border: 1px solid #444; }
/* Tooltip overflow — accordion-panel uses overflow:visible to avoid clipping */
.accordion-header { overflow: visible; position: relative; z-index: 2; }

/* Confidence Badges */
.confidence-badge {
    display: inline-block; font-size: 0.65rem; font-weight: 600;
    padding: 1px 7px; border-radius: 10px; margin-left: auto;
    text-transform: uppercase; letter-spacing: 0.4px; flex-shrink: 0;
}
.confidence-high { background: #d4edda; color: #155724; }
.confidence-medium { background: #fff3cd; color: #856404; }
.confidence-low { background: #f8d7da; color: #721c24; }
[data-theme="dark"] .confidence-high { background: #1b4332; color: #95d5b2; }
[data-theme="dark"] .confidence-medium { background: #3d2e00; color: #ffd166; }
[data-theme="dark"] .confidence-low { background: #4a1520; color: #f4a0a8; }

/* Data Gaps Note */
.data-gaps-note {
    margin: 10px 0 4px; padding: 8px 12px;
    font-size: 0.82rem; color: #856404;
    background: #fff3cd; border-radius: 6px;
    border-left: 3px solid #ffc107;
}
[data-theme="dark"] .data-gaps-note {
    background: #3d2e00; color: #ffd166; border-left-color: #ffd166;
}

/* Guideline References Block */
.guideline-refs-block {
    margin: 10px 0 4px; padding: 10px 12px;
    font-size: 0.82rem; color: #0c5460;
    background: #d1ecf1; border-radius: 6px;
    border-left: 3px solid #17a2b8;
}
.guideline-refs-title {
    font-weight: 600; font-size: 0.85rem; margin-bottom: 6px;
}
.guideline-refs-title i { margin-right: 4px; }
.guideline-ref-item {
    padding: 4px 0; border-bottom: 1px solid rgba(0,0,0,0.06);
    font-size: 0.8rem;
}
.guideline-ref-item:last-child { border-bottom: none; }
.guideline-ref-detail {
    margin-top: 2px; color: #0c5460; font-style: italic; font-size: 0.78rem;
}
[data-theme="dark"] .guideline-refs-block {
    background: #0d3036; color: #7dd3e0; border-left-color: #7dd3e0;
}
[data-theme="dark"] .guideline-ref-item { border-bottom-color: rgba(255,255,255,0.06); }
[data-theme="dark"] .guideline-ref-detail { color: #7dd3e0;
}

/* DT Role Indicator */
.dt-role-indicator {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 0.85rem; font-weight: 600;
    padding: 5px 12px; border-radius: 6px; margin-bottom: 4px;
}
.dt-role-indicator i { font-size: 0.8rem; }
.dt-core { background: #d4edda; color: #155724; }
.dt-support { background: #e2e3e5; color: #383d41; }
[data-theme="dark"] .dt-core { background: #1b4332; color: #95d5b2; }
[data-theme="dark"] .dt-support { background: #2a2a2a; color: #b0b0b0; }

/* Risk Matrix Info (legacy) */
.risk-matrix-info {
    display: flex; gap: 16px; flex-wrap: wrap;
    padding: 8px 12px; margin-bottom: 10px;
    background: var(--upload-bg); border-radius: 6px;
    border: 1px solid var(--border-color);
}
.risk-matrix-factor { font-size: 0.85rem; }
.risk-factor-value {
    display: inline-block; font-weight: 600;
    padding: 1px 8px; border-radius: 4px;
    background: var(--border-color); color: var(--text-main);
}

/* ESF Matrix Visual */
.risk-esf-matrix-visual {
    padding: 12px 16px; margin-bottom: 12px;
    background: linear-gradient(135deg, #fff5f5, #fff8f0);
    border: 1px solid #e8c4c4; border-radius: 8px;
}
[data-theme="dark"] .risk-esf-matrix-visual {
    background: linear-gradient(135deg, #2a1a1a, #2a2118);
    border-color: #4a3030;
}
.esf-matrix-title {
    font-weight: 700; font-size: 0.9rem; margin-bottom: 8px;
    color: var(--tag-risk);
}
.esf-matrix-title i { margin-right: 6px; }
.esf-matrix-table {
    width: 100%; border-collapse: collapse; font-size: 0.82rem;
    margin-bottom: 8px;
}
.esf-matrix-table th, .esf-matrix-table td {
    padding: 6px 12px; border: 1px solid var(--border-color);
    text-align: center;
}
.esf-matrix-table th { background: var(--upload-bg); font-weight: 600; font-size: 0.78rem; }
.esf-row-label { font-weight: 600; text-align: left !important; background: var(--upload-bg); }
.esf-active {
    background: var(--tag-risk) !important; color: #fff !important;
    font-weight: 700; border-radius: 0;
}
.esf-corner-label {
    position: relative; min-width: 50px; font-size: 0.7rem;
    color: var(--text-muted); font-weight: 400;
}
.esf-corner-label .esf-axis-scale {
    position: absolute; bottom: 2px; left: 4px; font-style: italic;
}
.esf-corner-label .esf-axis-capacity {
    position: absolute; top: 2px; right: 4px; font-style: italic;
}
.esf-factors {
    display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.82rem;
    padding-top: 4px;
}

/* Risk Mitigation Roadmap */
.risk-roadmap-block {
    margin: 10px 0; padding: 10px 12px;
    background: #f0faf0; border-radius: 6px;
    border-left: 3px solid #28a745;
}
[data-theme="dark"] .risk-roadmap-block {
    background: #1a2e1a; border-left-color: #4caf50;
}
.risk-roadmap-block .question-text { font-size: 0.9rem; font-weight: 600; margin-bottom: 6px; }
.roadmap-item {
    padding: 6px 0; border-bottom: 1px solid rgba(0,0,0,0.06);
    font-size: 0.82rem;
}
.roadmap-item:last-child { border-bottom: none; }
[data-theme="dark"] .roadmap-item { border-bottom-color: rgba(255,255,255,0.06); }
.roadmap-priority {
    display: inline-block; font-size: 0.7rem; font-weight: 600;
    padding: 1px 7px; border-radius: 10px; margin-right: 6px;
    text-transform: uppercase; letter-spacing: 0.3px;
}
.priority-immediate { background: #f8d7da; color: #721c24; }
.priority-short-term { background: #fff3cd; color: #856404; }
.priority-medium-term { background: #d4edda; color: #155724; }
[data-theme="dark"] .priority-immediate { background: #4a1520; color: #f4a0a8; }
[data-theme="dark"] .priority-short-term { background: #3d2e00; color: #ffd166; }
[data-theme="dark"] .priority-medium-term { background: #1b4332; color: #95d5b2; }
.roadmap-responsible {
    font-size: 0.78rem; color: var(--text-muted); margin-top: 2px;
}
.roadmap-responsible i { margin-right: 4px; }

/* Accordion Panels for Classification Rationale */
.accordion-container { margin-bottom: 30px; }
.accordion-panel {
    border: 1px solid var(--border-color);
    border-radius: 8px; margin-bottom: 10px;
    overflow: visible; background: var(--card-bg);
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.accordion-header {
    display: flex; align-items: center; gap: 8px;
    width: 100%; padding: 12px 14px;
    background: var(--upload-bg); border: none;
    cursor: pointer; font-size: 0.95rem; font-weight: 600;
    color: var(--text-main); text-align: left;
    transition: background 0.2s;
    border-left: 4px solid var(--primary-color);
    flex-wrap: nowrap;
}
.accordion-header:hover { filter: brightness(0.95); }
.accordion-header .accordion-title {
    flex: 1 1 0; display: flex; align-items: center; gap: 8px;
    min-width: 0; overflow: hidden;
}
.accordion-header .accordion-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.accordion-header .accordion-title i { width: 18px; text-align: center; flex-shrink: 0; }
.accordion-badge {
    display: inline-block; font-size: 0.75rem; font-weight: 600;
    padding: 3px 10px; border-radius: 12px;
    background: var(--primary-color); color: #fff;
    white-space: nowrap; flex-shrink: 0;
}
.accordion-chevron {
    flex-shrink: 0; margin-left: auto;
    transition: transform 0.3s ease; font-size: 0.85rem; color: var(--text-muted);
}
.accordion-panel.open .accordion-chevron { transform: rotate(180deg); }
.accordion-body {
    max-height: 0; overflow: hidden;
    transition: max-height 0.4s ease, padding 0.4s ease;
    padding: 0 16px;
}
.accordion-panel.open .accordion-body {
    max-height: none; padding: 16px; overflow: visible;
}

/* Accordion dimension colors */
.accordion-panel.dim-digital .accordion-header { border-left-color: var(--tag-digital); }
.accordion-panel.dim-digital .accordion-badge { background: var(--tag-digital); }
.accordion-panel.dim-risk .accordion-header { border-left-color: var(--tag-risk); }
.accordion-panel.dim-risk .accordion-badge { background: var(--tag-risk); }
.accordion-panel.dim-rci .accordion-header { border-left-color: var(--tag-rci); }
.accordion-panel.dim-rci .accordion-badge { background: var(--tag-rci); }
.accordion-panel.dim-psd .accordion-header { border-left-color: var(--tag-psd); }
.accordion-panel.dim-psd .accordion-badge { background: var(--tag-psd); color: #333; }
.accordion-panel.dim-dtcomp .accordion-header { border-left-color: var(--primary-color); }
.accordion-panel.dim-dtcomp .accordion-badge { background: var(--primary-color); }
.accordion-panel.dim-questionnaire .accordion-header { border-left-color: #6f42c1; }
.accordion-panel.dim-questionnaire .accordion-badge { background: #6f42c1; }

/* Accordion body subtle background in light mode */
.accordion-body { background: var(--upload-bg); }

/* AI Disclaimer */
.ai-disclaimer {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; margin-bottom: 16px;
    background: #fff8e1; border: 1px solid #ffe082;
    border-radius: 6px; font-size: 0.82rem;
    color: #6d5a00; line-height: 1.5;
}
.ai-disclaimer i { font-size: 1rem; color: #f9a825; flex-shrink: 0; }
[data-theme="dark"] .ai-disclaimer {
    background: #3e2e00; border-color: #5c4500; color: #ffe082;
}
[data-theme="dark"] .ai-disclaimer i { color: #ffca28; }

.doc-warning {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; margin-bottom: 16px;
    background: #fce4ec; border: 1px solid #ef9a9a;
    border-radius: 6px; font-size: 0.82rem;
    color: #8b1a1a; line-height: 1.5;
}
.doc-warning i { font-size: 1rem; color: #e53935; flex-shrink: 0; }
[data-theme="dark"] .doc-warning {
    background: #3e1010; border-color: #5c2020; color: #ef9a9a;
}
[data-theme="dark"] .doc-warning i { color: #ef5350; }

@media (max-width: 480px) {
    .accordion-header { font-size: 0.85rem; padding: 10px 12px; gap: 6px; }
    .accordion-badge { font-size: 0.7rem; padding: 2px 8px; }
    .accordion-header .accordion-title i { display: none; }

    /* ESF Matrix: even more compact on small phones */
    .esf-matrix-table th, .esf-matrix-table td { padding: 4px 4px; font-size: 0.7rem; }
    .esf-row-label { font-size: 0.7rem; }
    .esf-corner-label { min-width: 40px; font-size: 0.6rem; }
}

.action-bar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 25px; flex-wrap: wrap; gap: 15px;
    background: var(--upload-bg); padding: 10px;
    border-radius: 8px; border: 1px solid var(--border-color);
}
.toggle-btn {
    background: var(--toggle-inactive-bg);
    color: var(--toggle-inactive-text);
    border: 1px solid var(--border-color);
    padding: 8px 16px; cursor: pointer;
    font-weight: 500; font-size: 0.9rem;
    transition: background 0.2s, color 0.2s;
}
.toggle-btn:first-child { border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.toggle-btn:last-child { border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-left: none; }
.toggle-btn.active {
    background: var(--primary-color); color: #fff; border-color: var(--primary-color);
}

.export-buttons button {
    width: auto; padding: 8px 16px; margin: 0;
    border: 1px solid #28a745; background: var(--card-bg);
    color: #28a745; font-size: 0.9rem; border-radius: 4px; cursor: pointer;
}
.export-buttons button:hover { background: #28a745; color: white; }

/* =========================================
   6. HISTORY TABLE
   ========================================= */
#history-table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; margin-top: 10px; min-width: 800px; }
th {
    background: var(--upload-bg); text-align: left;
    padding: 15px; border-bottom: 2px solid var(--border-color);
    font-weight: 600; color: var(--text-muted); font-size: 0.9rem;
}
td {
    padding: 15px; border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem; color: var(--text-main);
    vertical-align: middle;
}
tr:hover { background-color: rgba(0,0,0,0.02); cursor: pointer; }
#history-table-body tr.selected-row {
    background-color: var(--highlight-row) !important;
    border-left: 4px solid var(--primary-color);
}

.history-title-cell { display: flex; flex-direction: column; gap: 8px; }
.history-tags-container { display: flex; gap: 6px; flex-wrap: wrap; }
.history-mini-tag {
    font-size: 0.65rem; font-weight: 700;
    padding: 3px 8px; border-radius: 4px;
    background: var(--upload-bg);
    border: 1px solid var(--border-color);
    text-transform: uppercase; white-space: nowrap;
}
.htag-digital { border-top: 3px solid var(--tag-digital); }
.htag-risk { border-top: 3px solid var(--tag-risk); }
.htag-rci { border-top: 3px solid var(--tag-rci); }
.htag-psd { border-top: 3px solid var(--tag-psd); }

/* Batch delete bar */
.batch-delete-bar {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px; margin-bottom: 10px;
    background: var(--card-bg); border: 1px solid var(--border-color);
    border-radius: 8px; font-size: 0.85rem; font-weight: 600;
    color: var(--text-main);
}
.batch-delete-btn {
    background: #dc3545; color: #fff; border: none;
    padding: 6px 14px; border-radius: 6px; cursor: pointer;
    font-size: 0.8rem; font-weight: 600; transition: background 0.2s;
}
.batch-delete-btn:hover { background: #c0392b; }
.batch-export-btn {
    background: #28a745; color: #fff; border: none;
    padding: 6px 14px; border-radius: 6px; cursor: pointer;
    font-size: 0.8rem; font-weight: 600; transition: all 0.2s;
}
.batch-export-btn:hover { background: #218838; }
.batch-export-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.batch-export-txt {
    background: transparent; color: #28a745; border: 1px solid #28a745;
}
.batch-export-txt:hover { background: #28a745; color: #fff; }
.batch-cancel-btn {
    background: none; border: 1px solid var(--border-color); color: var(--text-muted);
    padding: 6px 14px; border-radius: 6px; cursor: pointer;
    font-size: 0.8rem; font-weight: 500; transition: all 0.2s;
}
.batch-cancel-btn:hover { color: var(--text-main); border-color: var(--text-muted); }
.col-checkbox { width: 40px; text-align: center !important; }
.col-checkbox input[type="checkbox"] { cursor: pointer; width: 16px; height: 16px; }

.history-legend {
    display: flex; align-items: center; gap: 15px;
    margin-bottom: 15px; padding: 10px 15px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px; font-size: 0.85rem;
    flex-wrap: wrap;
}
.legend-label { font-weight: 700; color: var(--text-muted); text-transform: uppercase; margin-right: 5px; }
.legend-items { display: flex; gap: 10px; flex-wrap: wrap; }
.history-legend .history-mini-tag { cursor: default; }

#history-table-container td:last-child {
    text-align: center;
    vertical-align: middle;
}

.delete-btn {
    display: inline-flex;
    justify-content: center; align-items: center;
    width: 32px; height: 32px;
    padding: 0; margin: 0 auto;
    background: transparent; color: var(--text-muted);
    border: none; font-size: 1rem; cursor: pointer;
    transition: color 0.2s; border-radius: 4px;
}
.delete-btn:hover { color: #dc3545; background: rgba(220, 53, 69, 0.1); }

/* =========================================
   7. FOOTER
   ========================================= */
footer {
    flex-shrink: 0; text-align: center; padding: 15px 0;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted); font-size: 0.9rem;
    background-color: var(--bg-color); z-index: 10; font-weight: bold;
}
.footer-content { display: flex; align-items: center; justify-content: center; gap: 15px; flex-wrap: wrap; }
#footer-logo { height: 3.6em; vertical-align: middle; margin-bottom: 2px; display: block; }
.footer-divider { width: 1px; height: 25px; background-color: var(--border-color); }
.footer-tagline { display: flex; gap: 4px; font-weight: 600; text-transform: uppercase; font-size: 0.8em; }

/* =========================================
   8. MEDIA QUERIES & MODALS
   ========================================= */
@media (max-width: 768px) {
    .main-header { padding-top: 10px; }
    .header-top-row { position: static; width: 100%; justify-content: center; margin-bottom: 10px; }
    .header-content h1 { font-size: 1.4rem; }
    .container { padding: 20px; }
    .summary-box-container { grid-template-columns: 1fr; }
    .metadata-card { grid-template-columns: 1fr; }
    .action-bar { flex-direction: column; align-items: stretch; }
    .export-buttons { justify-content: center; }
    .col-classifications { display: none; }
    .history-legend { display: none; }

    /* Problem 2: Stack header buttons on mobile */
    .results-header {
        flex-direction: column; gap: 10px;
        align-items: stretch; text-align: center;
    }
    .results-header .header-left {
        flex-direction: column; align-items: center;
        width: 100%; gap: 8px;
    }
    .results-header h2 { font-size: 1.1rem; }
    #new-analysis-btn, .results-header > .secondary-btn,
    .results-header > button {
        width: 100%; text-align: center;
    }

    /* Problem 3: Card layout for history on mobile */
    #history-table-container { overflow-x: visible; }
    #history-table { min-width: 0; }
    #history-table thead { display: none; }
    #history-table tbody,
    #history-table tr,
    #history-table td { display: block; width: 100%; box-sizing: border-box; }
    #history-table tr {
        margin-bottom: 12px; padding: 14px;
        border: 1px solid var(--border-color); border-radius: 8px;
        background: var(--card-bg);
    }
    #history-table td { padding: 4px 0; border-bottom: none; font-size: 0.9rem; }
    #history-table td:first-child { font-weight: 700; font-size: 1rem; color: var(--primary-color); }
    #history-table td:last-child { text-align: left !important; margin-top: 8px; }
    .history-title-cell { gap: 4px; }
    .history-tags-container { margin-top: 8px !important; }

    /* ESF Matrix: compact on mobile */
    .risk-esf-matrix-visual { padding: 10px 12px; }
    .esf-matrix-table th, .esf-matrix-table td { padding: 5px 6px; font-size: 0.75rem; }
    .esf-matrix-title { font-size: 0.82rem; }
    .esf-factors { font-size: 0.75rem; gap: 8px; flex-direction: column; }

    /* Notification panel: full-width on tablet/mobile */
    .notif-panel { width: calc(100vw - 40px); right: -10px; max-height: 60vh; }
    .notif-item-msg { max-width: 100%; }

    /* Nav: ensure flex-wrap for notifications */
    nav { flex-wrap: wrap; }
}

/* Mobile L and below (425px) — queue widget docks to footer */
@media (max-width: 425px) {
    #queue-widget {
        position: fixed; bottom: 0; left: 0; right: 0;
        border-radius: 12px 12px 0 0;
    }
    .queue-widget-expanded { width: 100%; border-radius: 12px 12px 0 0; }

    /* Hide notification label on small screens, show just bell */
    .notif-bell-label { display: none; }
    .notif-badge { right: 0; }

    /* Notification panel full-width */
    .notif-panel { width: calc(100vw - 20px); right: -5px; }
}

.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    z-index: 9999; display: flex; justify-content: center; align-items: center;
}
.modal-content {
    background: var(--card-bg); padding: 30px;
    border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    max-width: 400px; width: 90%; text-align: center;
    border: 1px solid var(--border-color);
}
.modal-details {
    margin: 15px 0; padding: 10px;
    background: var(--upload-bg); border-radius: 6px;
    text-align: left; border: 1px solid var(--border-color);
}
.modal-warning {
    color: #dc3545; font-size: 0.85rem; font-weight: 600;
    margin-top: 10px; text-align: center;
}
.modal-warning i { margin-right: 4px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }
.delete-btn-confirm {
    background: #dc3545; color: white; border: none;
    padding: 10px 20px; border-radius: 6px;
    cursor: pointer; font-weight: 600;
}

/* Export Progress Modal */
.export-progress-content { text-align: center; min-width: 340px; }
.export-progress-content h3 { margin-bottom: 12px; }
.export-progress-content h3 i { margin-right: 8px; color: #28a745; }
.export-progress-bar-container {
    width: 100%; height: 12px; background: var(--upload-bg);
    border-radius: 6px; overflow: hidden; margin: 16px 0 8px;
    border: 1px solid var(--border-color);
}
.export-progress-bar {
    height: 100%; background: #28a745; border-radius: 6px;
    transition: width 0.3s ease;
}
.export-progress-detail {
    font-size: 0.8rem; color: var(--text-muted); margin: 4px 0 0;
}

/* =========================================
   9. QUEUE WIDGET & TOASTS
   ========================================= */

/* Queue Widget Container — positioned above footer via JS */
#queue-widget { position: fixed; bottom: 20px; right: 20px; z-index: 10000; font-family: inherit; }

/* Expanded Panel */
.queue-widget-expanded {
    width: 360px; max-height: 450px;
    background: var(--card-bg); border: 1px solid var(--border-color);
    border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    display: flex; flex-direction: column; overflow: hidden;
    animation: fadeIn 0.3s ease-out;
}
.queue-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; border-bottom: 1px solid var(--border-color);
    background: var(--upload-bg); flex-shrink: 0;
}
.queue-header-title { font-weight: 600; font-size: 0.9rem; color: var(--text-main); }
.queue-header-count { font-size: 0.8rem; color: var(--text-muted); margin-left: 8px; }
.queue-header-actions { display: flex; gap: 4px; }
.queue-header-actions button {
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); font-size: 0.85rem; padding: 4px 6px;
    border-radius: 4px; transition: color 0.2s, background 0.2s;
}
.queue-header-actions button:hover { color: var(--text-main); background: var(--border-color); }

.queue-list {
    overflow-y: auto; max-height: 300px; flex: 1;
    scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}
.queue-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px; border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem; transition: background 0.2s;
}
.queue-item:last-child { border-bottom: none; }
.queue-item:hover { background: rgba(0,0,0,0.02); }

.queue-item-icon { width: 20px; text-align: center; flex-shrink: 0; }
.queue-item-icon .fa-spinner { color: var(--primary-color); }
.queue-item-icon .fa-circle-check { color: #28a745; }
.queue-item-icon .fa-circle-xmark { color: #dc3545; }
.queue-item-icon .fa-clock { color: var(--text-muted); }

.queue-item-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.queue-item-name {
    overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; color: var(--text-main); font-size: 0.85rem;
}
.queue-item-meta { font-size: 0.72rem; color: var(--text-muted); }
.queue-status-pending .queue-item-name { color: var(--text-muted); }
.queue-status-submitting .queue-item-name { color: var(--primary-color); }
.queue-item-icon .fa-cloud-arrow-up { color: var(--primary-color); }
.queue-status-error .queue-item-name { color: #dc3545; }
.queue-item-clickable { cursor: pointer; }
.queue-item-clickable:hover { background: rgba(0, 123, 255, 0.06); }

.queue-item-action button {
    background: none; border: 1px solid var(--border-color);
    color: var(--text-muted); font-size: 0.75rem;
    padding: 3px 8px; border-radius: 4px; cursor: pointer;
    transition: all 0.2s;
}
.queue-item-action .retry-btn:hover { color: var(--primary-color); border-color: var(--primary-color); }
.queue-item-action .remove-btn:hover { color: #dc3545; border-color: #dc3545; }
.queue-item-action .cancel-btn:hover { color: #e67e22; border-color: #e67e22; }

.upload-cancel-btn {
    background: none; border: 1px solid rgba(255,255,255,0.4);
    color: rgba(255,255,255,0.85); font-size: 0.8rem;
    padding: 4px 14px; border-radius: 6px; cursor: pointer;
    margin-top: 6px; transition: all 0.2s;
}
.upload-cancel-btn:hover { background: rgba(220,53,69,0.2); border-color: #dc3545; color: #fff; }

.queue-footer {
    padding: 8px 16px; border-top: 1px solid var(--border-color);
    text-align: center; flex-shrink: 0;
}
.queue-footer button {
    background: none; border: none; color: var(--primary-color);
    font-size: 0.8rem; cursor: pointer; font-weight: 500;
}
.queue-footer button:hover { text-decoration: underline; }

/* Minimized Pill */
.queue-widget-pill {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--card-bg); border: 1px solid var(--border-color);
    padding: 8px 16px; border-radius: 50px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    cursor: pointer; font-size: 0.85rem; font-weight: 500;
    color: var(--text-main); transition: box-shadow 0.2s;
    animation: fadeIn 0.3s ease-out;
}
.queue-widget-pill:hover { box-shadow: 0 6px 20px rgba(0,0,0,0.15); }

/* Toast Container — below header, positioned via JS */
#toast-container {
    position: fixed; top: 120px; right: 20px;
    z-index: 10001; display: flex; flex-direction: column;
    gap: 10px; pointer-events: none;
}
.toast {
    pointer-events: auto;
    display: flex; align-items: flex-start; gap: 12px;
    background: var(--card-bg); border: 1px solid var(--border-color);
    border-radius: 8px; padding: 14px 16px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    min-width: 280px; max-width: 360px;
    animation: slideInRight 0.3s ease-out;
    transition: opacity 0.3s, transform 0.3s;
}
.toast.toast-success { border-left: 4px solid #28a745; }
.toast.toast-error { border-left: 4px solid #dc3545; }

.toast-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 2px; }
.toast-success .toast-icon { color: #28a745; }
.toast-error .toast-icon { color: #dc3545; }

.toast-body { flex: 1; }
.toast-title { font-weight: 600; font-size: 0.85rem; color: var(--text-main); margin-bottom: 2px; }
.toast-message { font-size: 0.8rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }

.toast-close {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: 0.85rem; padding: 2px; flex-shrink: 0;
}
.toast-close:hover { color: var(--text-main); }

.toast-action {
    background: none; border: 1px solid var(--primary-color);
    color: var(--primary-color); font-size: 0.75rem;
    padding: 3px 10px; border-radius: 4px; cursor: pointer;
    margin-top: 6px; font-weight: 500;
}
.toast-action:hover { background: var(--primary-color); color: #fff; }

.toast.dismissing { opacity: 0; transform: translateX(100%); }

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

/* Queue & Toast mobile */
@media (max-width: 768px) {
    #queue-widget { right: 10px; left: 10px; }
    .queue-widget-expanded { width: auto; }
    #toast-container { top: 10px; right: 10px; left: 10px; }
    .toast { max-width: 100%; min-width: 0; }
}

/* History Filter Bar */
.history-filter-bar {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px; margin-bottom: 8px;
    background: var(--card-bg); border: 1px solid var(--border-color);
    border-radius: 8px; flex-wrap: wrap;
}
.filter-search-group { flex: 1; min-width: 200px; }
.filter-search-wrapper {
    position: relative; width: 100%;
}
.filter-search-wrapper i {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    color: var(--text-muted); font-size: 0.85rem;
}
.filter-search-wrapper input {
    width: 100%; padding: 8px 8px 8px 32px;
    border: 1px solid var(--border-color); border-radius: 6px;
    background: var(--card-bg); color: var(--text-main);
    font-size: 0.85rem;
}
.filter-search-wrapper input::placeholder { color: var(--text-muted); }
.filter-group { display: flex; align-items: center; gap: 8px; }
.filter-group label { font-size: 0.82rem; color: var(--text-muted); white-space: nowrap; }
.filter-group input[type="date"] {
    padding: 6px 8px; border: 1px solid var(--border-color);
    border-radius: 6px; background: var(--card-bg); color: var(--text-main);
    font-size: 0.82rem;
}
[data-theme="dark"] .filter-search-wrapper input,
[data-theme="dark"] .filter-group input[type="date"] {
    background: var(--answer-bg); color: var(--text-main);
    border-color: #444;
}
[data-theme="dark"] .filter-group input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.8);
}

/* History Group Headers */
.history-group-header td {
    background: var(--upload-bg, #f8f9fa); font-weight: 600;
    padding: 10px 16px !important; border-bottom: 2px solid var(--border-color);
    font-size: 0.9rem; color: var(--text-main);
}
[data-theme="dark"] .history-group-header td { background: #1e1e2e; }
.group-toggle {
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); margin-right: 8px; padding: 2px 4px;
    transition: transform 0.2s ease;
}
.group-toggle i { transition: transform 0.2s ease; }
.group-toggle.collapsed i { transform: rotate(-90deg); }
.group-label { vertical-align: middle; }
.group-count {
    font-weight: 400; color: var(--text-muted); font-size: 0.82rem;
    margin-left: 4px; vertical-align: middle;
}

/* Failed analysis row in history */
.history-row-failed { opacity: 0.85; }
.history-row-failed td { border-left: 3px solid #dc3545; }
.htag-failed {
    background: #dc3545 !important; color: #fff !important;
    font-size: 0.72rem; padding: 2px 8px; border-radius: 4px;
    display: inline-flex; align-items: center; gap: 4px;
}
.meta-item-full { grid-column: 1 / -1; }
.meta-value-failed { color: #dc3545; font-weight: 600; }
[data-theme="dark"] .meta-value-failed { color: #ff6b6b; }

/* Failed analysis detail view */
.failed-analysis-notice {
    text-align: center; padding: 40px 24px;
    background: var(--card-bg); border: 1px solid var(--border-color);
    border-radius: 12px; margin: 20px 0;
}
.failed-analysis-icon {
    font-size: 3rem; color: #dc3545; margin-bottom: 16px;
}
[data-theme="dark"] .failed-analysis-icon { color: #ff6b6b; }
.failed-analysis-notice h3 {
    margin: 0 0 12px; color: var(--text-main); font-size: 1.3rem;
}
.failed-analysis-notice p {
    color: var(--text-muted); font-size: 0.95rem; max-width: 600px;
    margin: 0 auto 24px; line-height: 1.6;
}
.failed-analysis-tips {
    text-align: left; max-width: 550px; margin: 0 auto;
    background: var(--answer-bg); border-radius: 8px; padding: 16px 20px;
}
.failed-analysis-tips h4 {
    margin: 0 0 10px; font-size: 0.9rem; color: var(--text-main);
    display: flex; align-items: center; gap: 6px;
}
.failed-analysis-tips h4 i { color: #f0ad4e; }
.failed-analysis-tips ul {
    margin: 0; padding-left: 20px;
}
.failed-analysis-tips li {
    font-size: 0.85rem; color: var(--text-muted); line-height: 1.7;
}

/* Back to Top button */
.back-to-top {
    position: fixed;
    bottom: 32px;
    left: 32px;
    z-index: 1100;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0,0,0,0.25);
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px);
    transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease, background 0.15s ease;
}
.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.back-to-top:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 5px 14px rgba(0,0,0,0.3);
}
.back-to-top:active { transform: translateY(0); }

@media print {
    /* Page setup */
    @page { margin: 15mm 12mm; size: A4; }
    body {
        background: white !important; color: black !important;
        overflow: visible !important; height: auto !important;
        font-size: 11pt; line-height: 1.5;
    }
    .main-wrapper, .content-scroll-area {
        height: auto !important; overflow: visible !important; display: block !important;
    }
    .container { box-shadow: none; border: none; padding: 0; max-width: 100%; background: white !important; }

    /* Hide non-print UI elements */
    .main-header, nav, footer, .action-bar, .no-print,
    .summary-box-container, #new-analysis-btn, .secondary-btn,
    .export-buttons, .toggle-btn, #cancel-analysis-btn,
    #queue-widget, #toast-container { display: none !important; }

    /* Metadata card */
    .metadata-card {
        background: #f9f9f9 !important; border: 1px solid #ddd !important;
        color: black !important; break-inside: avoid; page-break-inside: avoid;
    }

    /* Text styling */
    .answer-text { background: #fafafa !important; border: 1px solid #ddd !important; color: black !important; }
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

    /* Page break control */
    .question-block, .metadata-card, .accordion-panel {
        break-inside: avoid; page-break-inside: avoid; margin-bottom: 12px;
    }
    .report-section { break-before: auto; }
    .report-section h3 { break-after: avoid; page-break-after: avoid; }
    .risk-vector-block, .rci-question-block, .psd-criterion-block, .psd-total-row {
        break-inside: avoid; page-break-inside: avoid;
    }

    /* Accordion: force all panels open for print */
    .accordion-body { max-height: none !important; overflow: visible !important; padding: 16px !important; }
    .accordion-chevron { display: none !important; }
    .accordion-header {
        cursor: default !important;
        border-left-width: 4px !important;
        background: #f5f5f5 !important;
    }
    .accordion-panel { break-inside: avoid; page-break-inside: avoid; margin-bottom: 10px; }

    /* Visible sections — show whichever view has content */
    #view-home, #view-history, #results-area, #report-content, #history-detail-view { display: block !important; }
    #upload-container, #processing-feedback, #history-table-view { display: none !important; }

    /* Questionnaire accordion: force open for print */
    .accordion-panel.dim-questionnaire .accordion-body {
        max-height: none !important; overflow: visible !important; padding: 16px !important;
    }
}