/* =======================================================================
   FIT PII Scanner — Dark Theme CSS
   No external frameworks.
   ======================================================================= */

/* --- Reset & Base ---------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-card: #16213e;
    --bg-input: #1a1a2e;
    --bg-hover: #1e2a4a;

    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b8;
    --text-muted: #6c6c8a;
    --text-link: #64b5f6;

    --accent: #0f3460;
    --accent-light: #1a4a8a;
    --success: #2ecc71;
    --success-bg: rgba(46, 204, 113, 0.15);
    --warning: #f39c12;
    --warning-bg: rgba(243, 156, 18, 0.15);
    --danger: #e74c3c;
    --danger-bg: rgba(231, 76, 60, 0.15);
    --info: #3498db;
    --info-bg: rgba(52, 152, 219, 0.15);
    --muted-badge: #4a4a6a;

    --border: #2a2a4a;
    --border-light: #3a3a5a;
    --radius: 6px;
    --radius-sm: 4px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Consolas", monospace;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--text-link);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* --- Navigation ------------------------------------------------------ */
.main-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 56px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-logo {
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--info);
    letter-spacing: 1px;
}

.nav-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.nav-version {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 2px 6px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
}

.nav-links {
    display: flex;
    gap: 0.25rem;
}

.nav-link {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-link.active {
    background: var(--accent);
    color: #fff;
}

.nav-status {
    display: flex;
    align-items: center;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.3s;
}
.status-dot.status-ok { background: var(--success); }
.status-dot.status-error { background: var(--danger); }

/* --- Main Content ---------------------------------------------------- */
.content {
    flex: 1;
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* --- Footer ---------------------------------------------------------- */
.main-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

/* --- Page Header ----------------------------------------------------- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

/* --- Stats Grid ------------------------------------------------------ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
}

.stat-card-info { border-left: 3px solid var(--info); }
.stat-card-success { border-left: 3px solid var(--success); }
.stat-card-danger { border-left: 3px solid var(--danger); }
.stat-card-warning { border-left: 3px solid var(--warning); }

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* --- Cards ----------------------------------------------------------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

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

.card-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: 1.25rem;
}

/* --- Tables ---------------------------------------------------------- */
.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.monospace { font-family: var(--font-mono); font-size: 0.85em; }

/* --- Badges / Pills -------------------------------------------------- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(46, 204, 113, 0.3);
}

.badge-info {
    background: var(--info-bg);
    color: var(--info);
    border: 1px solid rgba(52, 152, 219, 0.3);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border: 1px solid rgba(243, 156, 18, 0.3);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(231, 76, 60, 0.3);
}

.badge-muted {
    background: rgba(100, 100, 140, 0.15);
    color: var(--text-muted);
    border: 1px solid rgba(100, 100, 140, 0.3);
}

.badge-pii {
    background: rgba(155, 89, 182, 0.15);
    color: #bb86fc;
    border: 1px solid rgba(155, 89, 182, 0.3);
}

.badge-masked {
    background: rgba(52, 73, 94, 0.3);
    color: #95a5a6;
    border: 1px solid rgba(149, 165, 166, 0.3);
    font-style: italic;
}

.badge-paired {
    background: rgba(26, 188, 156, 0.15);
    color: #1abc9c;
    border: 1px solid rgba(26, 188, 156, 0.3);
}

/* Summary pills row */
.summary-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.summary-pill {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.pill-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.pill-count {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}

/* --- Confidence Score ------------------------------------------------ */
.confidence-score {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

.conf-high {
    background: var(--success-bg);
    color: var(--success);
}

.conf-medium {
    background: var(--warning-bg);
    color: var(--warning);
}

.conf-low {
    background: var(--danger-bg);
    color: var(--danger);
}

/* --- Progress Bar ---------------------------------------------------- */
.progress-bar-container {
    position: relative;
    width: 100%;
    height: 6px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 3px;
    margin-top: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--info);
    border-radius: 3px;
    transition: width 0.5s ease;
}

.progress-text {
    position: absolute;
    right: 0;
    top: -16px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.scan-status-cell {
    min-width: 100px;
}

/* --- Buttons --------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    text-decoration: none;
    white-space: nowrap;
    font-family: var(--font-sans);
}

.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--accent-light);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover {
    background: #2060b0;
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-light);
}
.btn-secondary:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-warning {
    background: rgba(243, 156, 18, 0.2);
    color: var(--warning);
    border-color: rgba(243, 156, 18, 0.4);
}
.btn-warning:hover {
    background: rgba(243, 156, 18, 0.3);
}

.btn-danger {
    background: rgba(231, 76, 60, 0.2);
    color: var(--danger);
    border-color: rgba(231, 76, 60, 0.4);
}
.btn-danger:hover {
    background: rgba(231, 76, 60, 0.3);
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}
.btn-close:hover {
    color: var(--text-primary);
}

.actions-cell {
    display: flex;
    gap: 0.25rem;
    white-space: nowrap;
}

/* --- Forms ----------------------------------------------------------- */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
}

.form-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: var(--font-sans);
    transition: border-color 0.15s;
}

.form-input:focus {
    outline: none;
    border-color: var(--info);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.form-input-sm {
    width: auto;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-actions {
    margin-top: 1.25rem;
}

/* Radio group */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.15s;
}

.radio-label:hover {
    border-color: var(--border-light);
}

.radio-label input[type="radio"] {
    accent-color: var(--info);
}

.radio-text {
    display: flex;
    flex-direction: column;
}

.radio-text strong {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.radio-text small {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Checkbox */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.checkbox-label input[type="checkbox"] {
    accent-color: var(--info);
}

/* Inline form */
.inline-form {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
}

.inline-form .form-group {
    margin-bottom: 0;
}

/* Filter controls */
.filter-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* --- Alerts ---------------------------------------------------------- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-top: 1rem;
    font-size: 0.875rem;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(46, 204, 113, 0.3);
}

.alert-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(231, 76, 60, 0.3);
}

.alert-info {
    background: var(--info-bg);
    color: var(--info);
    border: 1px solid rgba(52, 152, 219, 0.3);
}

/* --- Modal ----------------------------------------------------------- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal.visible {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

/* --- Tree View ------------------------------------------------------- */
.tree-node {
    margin-left: 0;
}

.tree-children {
    margin-left: 1.5rem;
    border-left: 1px solid var(--border);
    padding-left: 0.75rem;
}

.tree-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.5rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.1s;
    list-style: none;
}

.tree-label::-webkit-details-marker { display: none; }
.tree-label::marker { content: ''; }

.tree-label:hover {
    background: var(--bg-hover);
}

.tree-icon {
    font-size: 1rem;
    min-width: 1.25rem;
    text-align: center;
}

.tree-name {
    font-weight: 500;
    color: var(--text-primary);
}

.tree-count {
    font-size: 0.75rem;
}

/* --- Finding Cards --------------------------------------------------- */
.finding-card {
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    margin: 0.5rem 0;
}

.finding-header {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.finding-details {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.85rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(255,255,255,0.05);
}

.detail-row {
    display: flex;
    gap: 0.5rem;
    align-items: baseline;
    flex-wrap: wrap;
}

.detail-label {
    color: var(--text-muted);
    font-weight: 500;
    min-width: 160px;
    flex-shrink: 0;
}

.detail-value {
    color: var(--text-primary);
    word-break: break-all;
}

/* Detection breakdown */
.breakdown-details {
    margin-top: 0.5rem;
}

.breakdown-toggle {
    font-size: 0.8rem;
    color: var(--text-link);
    cursor: pointer;
    list-style: none;
}
.breakdown-toggle::-webkit-details-marker { display: none; }
.breakdown-toggle::marker { content: ''; }

.breakdown-content {
    margin-top: 0.375rem;
}

.breakdown-table {
    width: 100%;
    font-size: 0.8rem;
}

.breakdown-table td {
    padding: 0.25rem 0.5rem;
    border: none;
}

.breakdown-bar-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.breakdown-bar {
    height: 4px;
    background: var(--info);
    border-radius: 2px;
    min-width: 2px;
}

/* --- Code Blocks ----------------------------------------------------- */
.code-block {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-secondary);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 400px;
    overflow-y: auto;
}

.stacktrace {
    color: var(--danger);
    max-height: 300px;
}

/* --- Error Details --------------------------------------------------- */
.error-details {
    display: inline;
}

.error-details-content {
    margin-top: 0.5rem;
}

.detail-section {
    margin-bottom: 0.75rem;
}

.detail-section h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.error-message {
    max-width: 400px;
    word-break: break-word;
}

/* --- Timeline -------------------------------------------------------- */
.timeline {
    position: relative;
    padding-left: 2rem;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    margin-bottom: 1.5rem;
}

.timeline-marker {
    position: absolute;
    left: -2rem;
    top: 0.25rem;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-light);
    border: 2px solid var(--info);
    z-index: 1;
}

.timeline-content {
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.375rem;
}

.timeline-date {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.timeline-body {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.snapshot-details {
    margin-top: 0.5rem;
}

/* --- Drift Changes --------------------------------------------------- */
.drift-changes {
    display: inline;
}

.changes-content {
    margin-top: 0.5rem;
}

.change-section {
    margin-bottom: 0.75rem;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
}

.change-section h4 {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.change-section ul {
    list-style: none;
    padding: 0;
}

.change-section li {
    padding: 0.125rem 0;
    font-size: 0.8rem;
}

.change-added {
    background: var(--success-bg);
    border: 1px solid rgba(46, 204, 113, 0.2);
}
.change-added h4 { color: var(--success); }

.change-removed {
    background: var(--danger-bg);
    border: 1px solid rgba(231, 76, 60, 0.2);
}
.change-removed h4 { color: var(--danger); }

.change-modified {
    background: var(--warning-bg);
    border: 1px solid rgba(243, 156, 18, 0.2);
}
.change-modified h4 { color: var(--warning); }

/* --- Grid Layouts ---------------------------------------------------- */
.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* --- Refresh Indicator ----------------------------------------------- */
.refresh-indicator {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 2px 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
}

/* --- Link styling ---------------------------------------------------- */
.link {
    color: var(--text-link);
}
.link:hover {
    color: #90caf9;
}

/* --- Responsive ------------------------------------------------------ */
@media (max-width: 1024px) {
    .grid-2col {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .main-nav {
        flex-wrap: wrap;
        height: auto;
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    .nav-links {
        order: 3;
        width: 100%;
        justify-content: center;
    }

    .content {
        padding: 1rem;
    }

    .page-header {
        flex-direction: column;
        gap: 0.75rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .finding-details {
        grid-template-columns: 1fr;
    }

    .inline-form {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-controls {
        flex-direction: column;
    }

    .data-table {
        font-size: 0.8rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.5rem;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .modal-content {
        margin: 1rem;
    }
}
