/* --- THEME VARIABLES (From demo.html) --- */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #0f172a;
    --text-secondary: #64748b;
    --border: #cbd5e1;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
    --highlight: #fff7ed;
    --highlight-error: #ffe4e6;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
html {
    scroll-behavior: smooth;
}
body {
    font-family:
        system-ui,
        -apple-system,
        sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- LAYOUT --- */
.container {
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    padding: 2rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
}

/* --- NAVIGATION TABS (App-level: Upload/Dashboard/Review/Import) --- */
.nav-tabs {
    display: flex;
    gap: 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2rem;
}
.nav-tab {
    padding: 1rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}
.nav-tab:hover {
    color: var(--primary);
}
.nav-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.nav-tab:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* View Container */
.view-section {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding-bottom: 2rem;
}
.view-section.active {
    display: block;
}

/* --- DASHBOARD CARDS --- */
.overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.card {
    background: var(--surface);
    padding: 1.5rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.card-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}
.card-value {
    font-size: 2rem;
    font-weight: 700;
}

/* --- BADGES --- */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.875rem;
    font-weight: 600;
}
.badge.success {
    background: var(--success-bg);
    color: var(--success-text);
}
.badge.failed {
    background: var(--error-bg);
    color: var(--error-text);
}

/* --- UPLOAD ZONE --- */
.upload-container {
    background: var(--surface);
    border: 2px dashed var(--border);
    border-radius: 1rem;
    padding: 4rem;
    text-align: center;
    transition: border-color 0.2s;
    cursor: pointer;
    max-width: 600px;
    margin: 2rem auto;
}
.upload-container:hover,
.upload-container.drag-active {
    border-color: var(--primary);
    background-color: #f0f9ff;
}
.upload-icon {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 1rem;
}
.btn-reset {
    margin-top: 2rem;
    padding: 0.5rem 1rem;
    background: var(--error-bg);
    color: var(--error-text);
    border: 1px solid var(--error-text);
    border-radius: 4px;
    cursor: pointer;
}

/* --- MODAL --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}
.modal-overlay.open {
    display: flex;
    opacity: 1;
}
.modal {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    width: 400px;
    max-width: 90%;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    transform: translateY(20px);
    transition: transform 0.2s;
}
.modal-overlay.open .modal {
    transform: translateY(0);
}
.modal h2 {
    margin-top: 0;
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
}
.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.modal-btn {
    padding: 0.8rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: white;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--text-secondary);
}
.modal-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}
.modal-btn.primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.modal-btn.primary:hover {
    background: var(--primary-hover);
    color: white;
}
.modal-btn.secondary:hover {
    background: #f8fafc;
    color: var(--primary);
    border-color: var(--border);
}
.modal-btn.cancel {
    margin-top: 1rem;
    color: var(--text-secondary);
    border: none;
}
.modal-btn.cancel:hover {
    background: #f1f5f9;
    color: var(--text);
}
/* Legacy block-style modal buttons (template picker) */
.modal-btn-block {
    display: block;
    width: 100%;
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
}
.modal-btn-block:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* --- TABLE TABS (Review: per-table tab bar) --- */
.tabs-container {
    position: relative;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
    background: var(--surface);
    padding: 0 2.5rem;
    border-radius: 0.5rem 0.5rem 0 0;
    display: flex;
    align-items: center;
}
.tabs-scroll-area {
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    white-space: nowrap;
    width: 100%;
    scroll-behavior: smooth;
}
.tabs-scroll-area::-webkit-scrollbar {
    display: none;
}
.tabs {
    display: flex;
    gap: 1.5rem;
}
.tab {
    padding: 1rem 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-weight: 500;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    transition: all 0.2s;
}
.tab:hover {
    color: var(--primary);
}
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}
.tab-count {
    background: var(--error-bg);
    color: var(--error-text);
    padding: 0.1rem 0.5rem;
    border-radius: 99px;
    font-size: 0.7rem;
    margin-left: 0.4rem;
    font-weight: 700;
}
.tab-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    color: var(--text-secondary);
    font-size: 1.2rem;
    line-height: 1;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.tab-arrow.visible {
    opacity: 1;
    pointer-events: auto;
}
.tab-arrow.left {
    left: 0.5rem;
}
.tab-arrow.right {
    right: 0.5rem;
}
.tab-arrow:hover {
    color: var(--primary);
    border-color: var(--primary);
}

/* --- TAB CONTENT AREA --- */
.tab-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 0.5rem 0.5rem;
    min-height: 500px;
    padding-bottom: 2rem;
}

/* --- STICKY HEADER --- */
.sticky-header {
    position: sticky;
    top: 0;
    z-index: 90;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1.5rem;
    box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.05);
}

/* --- DIAGNOSTICS LAYOUT --- */
.diagnostics-layout {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

/* --- HEATMAP --- */
.heatmap-container {
    width: 300px;
    flex-shrink: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    position: relative;
    z-index: 5;
}
.heatmap-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0.5rem;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    text-align: center;
    border-radius: 6px 6px 0 0;
}
.heatmap-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(12, 1fr);
    gap: 1px;
    background: #cbd5e1;
    border: 1px solid #cbd5e1;
    height: 140px;
    padding: 1px;
    border-radius: 0 0 6px 6px;
    overflow: visible;
}
.heatmap-cell {
    position: relative;
    background: #fff;
    cursor: default;
}
.heatmap-cell.header-row {
    background: #f1f5f9;
}
.heatmap-cell[data-intensity]:not([data-intensity="0"]) {
    cursor: pointer;
}

/* Heatmap Bloom Effect */
.heatmap-cell[data-intensity]::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(
        circle,
        var(--heat-color) 0%,
        transparent 75%
    );
    opacity: var(--heat-opacity);
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1;
    pointer-events: none;
}
.heatmap-cell:hover {
    z-index: 100;
}
.heatmap-cell:hover::before {
    transform: scale(2.5);
    opacity: 1;
}

/* Heatmap Intensity Colors */
.heatmap-cell[data-intensity="0"] {
    --heat-color: transparent;
    --heat-opacity: 0;
}
.heatmap-cell[data-intensity="1"] {
    --heat-color: #fcd34d;
    --heat-opacity: 0.6;
}
.heatmap-cell[data-intensity="2"] {
    --heat-color: #fbbf24;
    --heat-opacity: 0.7;
}
.heatmap-cell[data-intensity="3"] {
    --heat-color: #f59e0b;
    --heat-opacity: 0.8;
}
.heatmap-cell[data-intensity="4"] {
    --heat-color: #ef4444;
    --heat-opacity: 0.9;
}
.heatmap-cell[data-intensity="5"] {
    --heat-color: #dc2626;
    --heat-opacity: 1;
}

/* --- HEATMAP TOOLTIPS --- */
.heatmap-cell .tooltip {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #ffffff;
    color: var(--text);
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    z-index: 1000;
    display: none;
    width: 240px;
    border: 1px solid var(--border);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
    margin-top: 10px;
    text-align: left;
    pointer-events: auto;
}
.heatmap-cell:nth-child(9n) .tooltip,
.heatmap-cell:nth-child(9n-1) .tooltip {
    left: auto;
    right: 0;
    transform: translateX(10%);
}
.heatmap-cell:nth-child(9n) .tooltip::before,
.heatmap-cell:nth-child(9n-1) .tooltip::before {
    left: auto;
    right: 20px;
    transform: rotate(45deg);
}
.heatmap-cell .tooltip::after {
    content: "";
    position: absolute;
    top: -15px;
    left: 0;
    width: 100%;
    height: 15px;
    background: transparent;
}
.heatmap-cell:hover .tooltip {
    display: block;
}
.tooltip-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem;
    color: var(--text);
    text-decoration: none;
    border-bottom: 1px solid var(--bg);
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.1s;
}
.tooltip-link:hover {
    background-color: #f1f5f9;
}
.tooltip-link strong {
    color: var(--primary);
    font-family: monospace;
}

/* --- FILTER CONTROLS --- */
.filter-controls {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.header-row-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
    gap: 1.5rem;
}
.filter-controls h3 {
    font-size: 1rem;
    margin: 0;
    color: var(--text);
    white-space: nowrap;
    flex-shrink: 0;
}
.filter-controls input,
.filter-controls select {
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    width: 100%;
    font-size: 0.9rem;
}

/* --- EXPORT BUTTON --- */
.export-btn {
    padding: 0.4rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}
.export-btn svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
    transition: fill 0.2s;
}
.export-btn:hover {
    background: #f1f5f9;
    color: var(--primary);
    border-color: var(--primary);
}

/* --- TABLES --- */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
th {
    cursor: pointer;
    user-select: none;
    position: relative;
    white-space: nowrap;
}
th:hover {
    background: #f1f5f9;
}
th::after {
    content: " \2195";
    opacity: 0.3;
    font-size: 0.7rem;
}
th.asc::after {
    content: " \25B2";
    opacity: 1;
    color: var(--primary);
}
th.desc::after {
    content: " \25BC";
    opacity: 1;
    color: var(--primary);
}

.main-table th {
    position: sticky;
    top: 0;
    text-align: left;
    padding: 0.75rem 1rem;
    background: #fff;
    border-bottom: 2px solid var(--border);
    color: var(--text-secondary);
    white-space: nowrap;
    z-index: 10;
}
.main-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    color: var(--text-secondary);
}
.main-table td.has-value {
    color: var(--text);
}

.error-table th {
    position: sticky;
    top: 0;
    text-align: left;
    padding: 0.75rem 1.5rem;
    border-bottom: 2px solid var(--border);
    background: #fff;
    color: var(--text-secondary);
    z-index: 10;
}
.error-table th:nth-child(2) {
    min-width: 100px;
}
.error-table td {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.error-table tr:hover {
    background: #f1f5f9;
    cursor: pointer;
}

/* --- BADGES --- */
.code-badge {
    background: #fee2e2;
    color: #991b1b;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.75rem;
    font-family: monospace;
}
.loc-badge {
    font-family: monospace;
    font-weight: 600;
    color: var(--text);
    background: #f1f5f9;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}
.val-cell {
    font-family: monospace;
    color: var(--text);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- ROW HIGHLIGHTS --- */
tr.highlighted-error {
    background-color: var(--highlight-error) !important;
    transition: background-color 0.5s;
}
tr.highlighted-data {
    background-color: var(--highlight) !important;
    transition: background-color 0.5s;
}

/* --- ABOUT TABLE --- */
.about-table th {
    cursor: default;
    width: 25%;
    background: #f8fafc;
    color: var(--text-secondary);
    text-align: left;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    font-weight: 600;
}
.about-table th::after {
    content: none;
}
.about-table td {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: top;
}

/* --- COLLAPSIBLE DATA DETAILS --- */
details.data-details {
    border-bottom: 1px solid var(--border);
    background: #fff;
    margin-bottom: 0;
}
details.data-details summary {
    padding: 1rem 1.5rem;
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
    border: 1px solid var(--border);
    border-left: none;
    border-right: none;
    border-top: none;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    background: #f8fafc;
    transition: background 0.2s;
}
details.data-details summary:hover {
    background: #e2e8f0;
}
details.data-details summary::-webkit-details-marker {
    display: none;
}
details.data-details summary::before {
    content: "\25BA";
    font-size: 0.8rem;
    color: var(--text-secondary);
    width: 1rem;
}
details.data-details[open] summary::before {
    content: "\25BC";
}
details.data-details summary span.hint {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-left: auto;
}
.data-content {
    padding: 0;
    max-height: 600px;
    overflow-y: auto;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

/* --- STATES --- */
.loading,
.empty-state {
    padding: 4rem;
    text-align: center;
    color: var(--text-secondary);
}
.success-state {
    padding: 3rem;
    text-align: center;
    color: var(--success-text);
    background: #f0fdf4;
    margin: 1rem;
    border-radius: 8px;
    border: 1px dashed var(--success-bg);
}

/* --- RETURN TO TOP --- */
#returnTop {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--primary);
    color: white;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    font-size: 1.5rem;
    z-index: 500;
    border: none;
}
#returnTop.visible {
    opacity: 1;
    pointer-events: auto;
}
#returnTop:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

/* --- IMPORT TAB --- */
.import-gate {
    text-align: center;
    max-width: 600px;
    margin: 4rem auto;
}

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
    .diagnostics-layout {
        flex-direction: column;
    }
    .heatmap-container {
        width: 100%;
    }
}
