/* ═══════════════════════════════════════════════════
   Audit-IA — Main Stylesheet
   ═══════════════════════════════════════════════════ */

:root {
    --sidebar-bg: #1e1e2e;
    --sidebar-text: #cdd6f4;
    --sidebar-hover: #313244;
    --sidebar-active: #45475a;
    --header-bg: #181825;
    --main-bg: #f5f5f5;
    --card-bg: #ffffff;
    --border: #e0e0e0;
    --primary: #89b4fa;
    --primary-dark: #74c7ec;
    --accent: #f38ba8;
    --success: #a6e3a1;
    --warning: #f9e2af;
    --danger: #f38ba8;
    --text: #1e1e2e;
    --text-muted: #6c7086;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

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

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    background: var(--main-bg);
}

/* ─── Layout ─────────────────────────────────────── */

#app {
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    grid-template-columns: 320px 1fr;
    grid-template-areas:
        "header header"
        "sidebar main"
        "sidebar actlog"
        "footer footer";
    height: 100vh;
}

/* ─── Header ─────────────────────────────────────── */

#app-header {
    grid-area: header;
    background: var(--header-bg);
    color: var(--sidebar-text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    border-bottom: 1px solid #313244;
}

#app-header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 1px;
}

#app-header h1 span {
    color: var(--primary);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-controls label {
    font-size: 12px;
    color: var(--text-muted);
}

.header-controls input {
    background: var(--sidebar-bg);
    border: 1px solid #45475a;
    color: var(--sidebar-text);
    padding: 6px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    width: 160px;
}

/* ─── Sidebar ────────────────────────────────────── */

#sidebar {
    grid-area: sidebar;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tab-bar {
    display: flex;
    border-bottom: 1px solid #313244;
}

.tab-btn {
    flex: 1;
    padding: 10px 0;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--sidebar-text);
    background: var(--sidebar-hover);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* Breadcrumb */

.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px 0;
    font-size: 12px;
    color: var(--text-muted);
    min-height: 32px;
}

.breadcrumb span {
    cursor: pointer;
    color: var(--primary);
}

.breadcrumb span:hover {
    text-decoration: underline;
}

.breadcrumb .sep {
    cursor: default;
    color: var(--text-muted);
}

/* File tree */

.file-tree {
    list-style: none;
    font-size: 13px;
    flex: 1;
    overflow-y: auto;
}

.file-tree li {
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s;
}

.file-tree li:hover {
    background: var(--sidebar-hover);
}

.file-tree li.dir::before {
    content: "\1F4C1";
    font-size: 14px;
}

.file-tree li.file::before {
    content: "\1F4C4";
    font-size: 14px;
}

/* Select folder button */

.select-folder-btn, .run-audit-btn {
    display: block;
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}

.select-folder-btn {
    background: var(--sidebar-active);
    color: var(--sidebar-text);
}

.select-folder-btn:hover {
    background: #585b70;
}

/* ─── Audit Controls (bottom of sidebar) ─────────── */

#audit-controls {
    border-top: 1px solid #313244;
    padding: 12px;
}

#selected-path {
    font-size: 11px;
    color: var(--text-muted);
    word-break: break-all;
    margin-bottom: 8px;
    min-height: 16px;
}

#selected-path strong {
    color: var(--primary);
}

.run-audit-btn {
    background: var(--primary);
    color: var(--header-bg);
}

.run-audit-btn:hover:not(:disabled) {
    background: var(--primary-dark);
}

.run-audit-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ─── Drop zone ──────────────────────────────────── */

.drop-zone {
    border: 2px dashed #45475a;
    border-radius: var(--radius);
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 12px;
}

.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--primary);
    background: rgba(137, 180, 250, 0.08);
    color: var(--primary);
}

.drop-zone p {
    margin: 8px 0;
    font-size: 12px;
}

.drop-zone .icon {
    font-size: 32px;
    display: block;
    margin-bottom: 8px;
}

.upload-list {
    list-style: none;
    font-size: 12px;
}

.upload-list li {
    padding: 6px 0;
    border-bottom: 1px solid #313244;
    display: flex;
    justify-content: space-between;
}

.upload-list .badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--success);
    color: var(--header-bg);
}

/* ─── Workspace tree ─────────────────────────────── */

.workspace-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.workspace-header h3 {
    font-size: 13px;
    font-weight: 600;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 11px;
    border: 1px solid #45475a;
    background: none;
    color: var(--sidebar-text);
    border-radius: 4px;
    cursor: pointer;
}

.btn-sm:hover {
    background: var(--sidebar-hover);
}

.workspace-tree {
    list-style: none;
    font-size: 13px;
}

.workspace-tree li {
    padding: 4px 0;
}

.workspace-tree .tree-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
}

.workspace-tree .tree-item:hover {
    background: var(--sidebar-hover);
}

.workspace-tree .tree-item .icon {
    font-size: 14px;
}

.workspace-tree .children {
    padding-left: 16px;
    list-style: none;
}

.workspace-tree .delete-btn {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.15s;
}

.workspace-tree .tree-item:hover .delete-btn {
    opacity: 1;
}

/* ─── Main Content ───────────────────────────────── */

#main-content {
    grid-area: main;
    overflow-y: auto;
    padding: 24px;
}

/* Empty state */

#empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
}

#empty-state .icon {
    font-size: 64px;
    margin-bottom: 16px;
}

#empty-state h2 {
    font-size: 20px;
    margin-bottom: 8px;
    color: var(--text);
}

#empty-state p {
    font-size: 14px;
    max-width: 400px;
}

/* Audit status / spinner */

#audit-status {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 16px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

#audit-status-text {
    font-size: 14px;
    color: var(--text-muted);
}

/* Results */

#results-container {
    display: none;
}

.result-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}

.result-section h2 {
    font-size: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Summary card */

.summary-stats {
    display: flex;
    gap: 24px;
    margin-bottom: 16px;
}

.stat-box {
    flex: 1;
    background: var(--main-bg);
    padding: 16px;
    border-radius: var(--radius);
    text-align: center;
}

.stat-box .value {
    font-size: 28px;
    font-weight: 700;
}

.stat-box .label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.risk-low { color: #40a02b; }
.risk-medium { color: #df8e1d; }
.risk-high { color: #d20f39; }

/* Heatmap */

.heatmap-pre {
    background: var(--header-bg);
    color: var(--sidebar-text);
    padding: 16px;
    border-radius: var(--radius);
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.6;
}

/* File result cards */

.file-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    overflow: hidden;
}

.file-card summary {
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    background: var(--main-bg);
    list-style: none;
}

.file-card summary::-webkit-details-marker {
    display: none;
}

.file-card summary::before {
    content: "\25B6";
    font-size: 10px;
    transition: transform 0.2s;
}

.file-card[open] summary::before {
    transform: rotate(90deg);
}

.file-card .risk-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    color: white;
    margin-left: auto;
}

.badge-critical { background: #d20f39; }
.badge-high { background: #e64553; }
.badge-medium { background: #df8e1d; }
.badge-low { background: #40a02b; }
.badge-clean { background: #179299; }

.file-card .card-body {
    padding: 16px;
    font-size: 13px;
    line-height: 1.7;
    white-space: pre-wrap;
    font-family: var(--mono);
    background: white;
    max-height: 500px;
    overflow-y: auto;
}

/* Download button */

.btn-download {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-download:hover {
    background: var(--primary-dark);
}

/* RAG section */

.rag-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.rag-input-group input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
}

.rag-input-group button {
    padding: 10px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
}

.rag-answer {
    background: var(--main-bg);
    padding: 16px;
    border-radius: var(--radius);
    font-size: 13px;
    line-height: 1.7;
    white-space: pre-wrap;
    min-height: 60px;
}

/* ─── Footer ─────────────────────────────────────── */

#app-footer {
    grid-area: footer;
    background: var(--header-bg);
    color: var(--text-muted);
    padding: 6px 24px;
    font-size: 11px;
    border-top: 1px solid #313244;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* ─── System Metrics (header) ────────────────────── */

.system-metrics {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 16px;
}

.metric {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-family: var(--mono);
    font-weight: 600;
    background: #313244;
    color: var(--sidebar-text);
    white-space: nowrap;
}

.metric-ok {
    background: rgba(166, 227, 161, 0.2);
    color: var(--success);
}

.metric-warn {
    background: rgba(249, 226, 175, 0.2);
    color: var(--warning);
}

.metric-danger {
    background: rgba(243, 139, 168, 0.2);
    color: var(--danger);
}

/* ─── Activity Log Panel ─────────────────────────── */

#activity-log-panel {
    grid-area: actlog;
    background: var(--header-bg);
    border-top: 1px solid #313244;
    display: flex;
    flex-direction: column;
    min-height: 40px;
    max-height: 200px;
}

#activity-log-panel .log-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--sidebar-text);
    border-bottom: 1px solid #313244;
    flex-shrink: 0;
}

#activity-log-panel .log-actions {
    display: flex;
    gap: 6px;
}

#activity-log-panel .log-actions .btn-sm {
    padding: 2px 8px;
    font-size: 10px;
}

.activity-log {
    flex: 1;
    overflow-y: auto;
    padding: 4px 12px;
    font-family: var(--mono);
    font-size: 11px;
    line-height: 1.6;
}

.log-entry {
    padding: 1px 0;
    color: #a6adc8;
}

.log-entry .log-time {
    color: #585b70;
    margin-right: 8px;
}

.log-entry .log-msg {
    word-break: break-word;
}

.log-info { color: #a6adc8; }
.log-progress { color: var(--primary); }
.log-success { color: var(--success); }
.log-error { color: var(--danger); }

/* Collapsed state */
#activity-log-panel.log-collapsed {
    max-height: 32px;
    min-height: 32px;
}

#activity-log-panel.log-collapsed .activity-log {
    display: none;
}

/* ─── Responsive ─────────────────────────────────── */

@media (max-width: 768px) {
    #app {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "sidebar"
            "main"
            "actlog"
            "footer";
    }

    #sidebar {
        max-height: 40vh;
    }

    .system-metrics {
        display: none;
    }
}

/* ─── Scrollbar ──────────────────────────────────── */

::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: #45475a;
    border-radius: 3px;
}

#sidebar ::-webkit-scrollbar-thumb {
    background: #585b70;
}
