/* TensorTrap Web UI - Dark Theme */
/* Matches existing HTML report styling */

:root {
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --bg-sidebar: #0f1729;
    --bg-input: #1e2a45;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --text-muted: #666;
    --accent: #0f3460;
    --accent-hover: #1a4a80;
    --border: #2a3a5c;
    --critical: #ff4757;
    --high: #ff6b6b;
    --medium: #ffa502;
    --low: #3498db;
    --info: #747d8c;
    --safe: #2ed573;
    --confidence-high: #ff4757;
    --confidence-medium: #ffa502;
    --confidence-low: #2ed573;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */

#sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    font-size: 1.3em;
    font-weight: 700;
    background: linear-gradient(135deg, var(--safe), var(--low));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--safe);
    flex-shrink: 0;
}

.status-dot.offline {
    background: var(--critical);
}

.nav-links {
    list-style: none;
    padding: 10px 0;
    flex: 1;
}

.nav-links li a {
    display: block;
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-links li a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.nav-links li a.active {
    background: rgba(47, 213, 115, 0.1);
    color: var(--safe);
    border-left-color: var(--safe);
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border);
    font-size: 0.8em;
    color: var(--text-muted);
}

/* --- Main Content --- */

#app {
    margin-left: 240px;
    flex: 1;
    padding: 30px;
    min-height: 100vh;
}

.loading {
    color: var(--text-secondary);
    padding: 40px;
    text-align: center;
}

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

.page-header {
    margin-bottom: 30px;
}

.page-header h2 {
    font-size: 1.8em;
    font-weight: 600;
    margin-bottom: 5px;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 0.95em;
}

/* --- Stat Cards --- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 20px;
    border: 1px solid var(--border);
}

.stat-card .stat-value {
    font-size: 2em;
    font-weight: 700;
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 0.85em;
    color: var(--text-secondary);
    margin-top: 5px;
}

.stat-card.critical .stat-value { color: var(--critical); }
.stat-card.high .stat-value { color: var(--high); }
.stat-card.medium .stat-value { color: var(--medium); }
.stat-card.low .stat-value { color: var(--low); }
.stat-card.safe .stat-value { color: var(--safe); }
.stat-card.info .stat-value { color: var(--info); }

/* --- Cards / Panels --- */

.card {
    background: var(--bg-card);
    border-radius: 10px;
    border: 1px solid var(--border);
    margin-bottom: 20px;
    overflow: hidden;
}

.card-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 1.1em;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* --- Report List --- */

.report-list {
    list-style: none;
}

.report-item {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: background 0.2s;
}

.report-item:last-child {
    border-bottom: none;
}

.report-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.report-item .report-date {
    font-weight: 500;
}

.report-item .report-meta {
    color: var(--text-secondary);
    font-size: 0.85em;
    margin-top: 3px;
}

.report-item .report-badges {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* --- Severity Badges --- */

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
}

.badge.critical { background: rgba(255, 71, 87, 0.2); color: var(--critical); }
.badge.high { background: rgba(255, 107, 107, 0.2); color: var(--high); }
.badge.medium { background: rgba(255, 165, 2, 0.2); color: var(--medium); }
.badge.low { background: rgba(52, 152, 219, 0.2); color: var(--low); }
.badge.info { background: rgba(116, 125, 140, 0.2); color: var(--info); }
.badge.safe { background: rgba(46, 213, 115, 0.2); color: var(--safe); }

/* --- Buttons --- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    color: var(--text-primary);
}

.btn-primary {
    background: var(--safe);
    color: #000;
}

.btn-primary:hover {
    background: #27c768;
}

.btn-primary:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--accent);
}

.btn-secondary:hover {
    background: var(--accent-hover);
}

.btn-danger {
    background: rgba(255, 71, 87, 0.2);
    color: var(--critical);
}

.btn-danger:hover {
    background: rgba(255, 71, 87, 0.3);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8em;
}

/* --- Forms --- */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9em;
    color: var(--text-secondary);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="time"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9em;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--safe);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-hint {
    font-size: 0.8em;
    color: var(--text-muted);
    margin-top: 4px;
}

.checkbox-group {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9em;
}

.checkbox-label input[type="checkbox"] {
    accent-color: var(--safe);
    width: 16px;
    height: 16px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    transition: all 0.2s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 2px;
    bottom: 2px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: all 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--safe);
    border-color: var(--safe);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: #000;
}

/* --- Scan Page --- */

.scan-input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.scan-input-group input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

.scan-input-group input:focus {
    outline: none;
    border-color: var(--safe);
}

.scan-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
}

.progress-container {
    margin: 30px 0;
}

.progress-bar-wrapper {
    background: var(--bg-input);
    border-radius: 10px;
    height: 20px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--safe), var(--low));
    border-radius: 10px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.85em;
    color: var(--text-secondary);
}

/* --- Report Detail --- */

.report-detail-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.back-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 5px;
}

.back-link:hover {
    color: var(--text-primary);
}

/* --- Finding Cards --- */

.finding {
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 8px;
    border-left: 4px solid var(--info);
    background: rgba(255, 255, 255, 0.02);
}

.finding.critical { border-left-color: var(--critical); }
.finding.high { border-left-color: var(--high); }
.finding.medium { border-left-color: var(--medium); }
.finding.low { border-left-color: var(--low); }

.finding-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.finding-message {
    font-size: 0.9em;
}

.finding-meta {
    font-size: 0.8em;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* --- Result Cards --- */

.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 15px;
    overflow: hidden;
}

.result-card-header {
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: background 0.2s;
}

.result-card-header:hover {
    background: rgba(255, 255, 255, 0.03);
}

.result-card-header .filepath {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85em;
    word-break: break-all;
}

.result-card-body {
    padding: 0 20px 20px;
    border-top: 1px solid var(--border);
}

.result-card-body.collapsed {
    display: none;
}

.result-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    padding: 15px 0;
    font-size: 0.85em;
}

.result-meta dt {
    color: var(--text-secondary);
}

.result-meta dd {
    font-weight: 500;
}

/* --- Empty State --- */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state h3 {
    font-size: 1.3em;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.empty-state p {
    margin-bottom: 20px;
}

/* --- Modal / Folder Browser --- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 90%;
    max-width: 560px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 1.1em;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4em;
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.modal-footer .current-path {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.8em;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.folder-list {
    list-style: none;
}

.folder-item {
    padding: 10px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    font-size: 0.9em;
    transition: background 0.15s;
}

.folder-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.folder-item.parent-dir {
    color: var(--text-secondary);
    font-style: italic;
}

.folder-icon {
    color: var(--medium);
    flex-shrink: 0;
}

.folder-empty {
    padding: 30px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9em;
}

.show-hidden-toggle {
    font-size: 0.8em;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px 20px;
    display: block;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.show-hidden-toggle:hover {
    color: var(--text-secondary);
}

/* --- Scan Spinner --- */

.scan-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--safe);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* --- Toast --- */

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9em;
    z-index: 1000;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.success { border-color: var(--safe); }
.toast.error { border-color: var(--critical); }

/* --- Section Divider --- */

.section-title {
    font-size: 1.1em;
    font-weight: 600;
    margin: 30px 0 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* --- Scrollbar --- */

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

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* --- Responsive --- */

@media (max-width: 768px) {
    #sidebar {
        width: 60px;
    }

    .sidebar-header h1,
    .nav-links li a span,
    .sidebar-footer {
        display: none;
    }

    .nav-links li a {
        text-align: center;
        padding: 15px;
    }

    #app {
        margin-left: 60px;
        padding: 20px;
    }
}
