:root {
    --bg: #f8f9fa;
    --surface: #ffffff;
    --border: #e9ecef;
    --text: #212529;
    --text-muted: #6c757d;

    --c-success-pastel: #e6f4ea;
    --c-success-text: #1e7e34;
    --c-success-active: #28a745;

    --c-warning-pastel: #fff8e1;
    --c-warning-text: #d39e00;
    --c-warning-active: #ffc107;

    --c-danger-pastel: #fce8e6;
    --c-danger-text: #dc3545;
    --c-danger-active: #dc3545;

    --c-neutral-pastel: #f1f3f5;
    --c-neutral-text: #495057;
    --c-neutral-active: #6c757d;

    --hover: #f8f9fa;
    --active-row: #e7f1ff;

    --primary: #0056b3;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 20px;
    font-size: 13px;
    overflow-x: hidden;
}

.container {
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.02);
    min-height: 80vh;
    box-sizing: border-box;
}

header {
    padding: 15px 25px;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    width: 100%;
    box-sizing: border-box;
}

h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: #343a40;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.meta {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-family: monospace;
}

/* --- Controls --- */
.provider-select {
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #dee2e6;
    color: #495057;
    font-size: 0.85rem;
    background-color: #fff;
    outline: none;
    cursor: pointer;
}

.provider-select:hover {
    border-color: #ced4da;
}

.provider-select.hidden {
    display: none;
}

.reload-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-muted);
    padding: 4px;
    line-height: 1;
    transition: color 0.2s, transform 0.6s ease-in-out;
    outline: none;
}

.reload-btn:hover {
    color: var(--text);
    background: none;
    border-radius: 4px;
}

/* --- Toolbar (Search & Filter) --- */
.app-toolbar {
    display: flex;
    align-items: center;
    padding: 10px 25px;
    background: #f8f9fa;
    border-bottom: 1px solid var(--border);
    gap: 20px;
    flex-wrap: wrap;
}

.search-container {
    position: relative;
    width: 300px;
}

.search-input {
    width: 100%;
    padding: 8px 12px 8px 35px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: #80bdff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #adb5bd;
    pointer-events: none;
}

/* --- Filter Chips --- */
.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: var(--c-neutral-pastel);
    color: var(--c-neutral-text);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
    text-transform: uppercase;
}

.filter-chip[data-status="FAILED"] {
    background-color: var(--c-danger-pastel);
    color: var(--c-danger-text);
}

.filter-chip[data-status="SUCCESSFUL"] {
    background-color: var(--c-success-pastel);
    color: var(--c-success-text);
}

.filter-chip[data-status="INCOMPLETE"] {
    background-color: var(--c-warning-pastel);
    color: var(--c-warning-text);
}

.filter-chip:hover {
    filter: brightness(0.95);
}

.filter-chip.active {
    color: #fff !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.filter-chip.active[data-status="FAILED"] {
    background-color: var(--c-danger-active);
}

.filter-chip.active[data-status="SUCCESSFUL"] {
    background-color: var(--c-success-active);
}

.filter-chip.active[data-status="INCOMPLETE"] {
    background-color: var(--c-warning-active);
    color: #212529 !important;
}

/* --- Content Area --- */
#app-data {
    position: relative;
}

/* --- Table Styles --- */
.section-header {
    background: #f1f3f5;
    padding: 10px 25px;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
    color: #495057;
    border-bottom: 1px solid var(--border);

    position: sticky;
    top: 0;
    z-index: 20;

    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    user-select: none;
}

.section-header:hover {
    background: #e9ecef;
    color: var(--text);
}

.section-arrow {
    font-size: 0.7rem;
    transition: transform 0.2s;
    display: inline-block;
}

.section-header.collapsed .section-arrow {
    transform: rotate(-90deg);
}

.section-content {
    display: block;
    overflow-x: auto;
    width: 100%;
}

.section-content.collapsed {
    display: none;
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    min-width: 1100px;
}

thead th {
    position: static;
    z-index: 10;
}

th {
    text-align: left;
    padding: 12px 10px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    background: #fff;
}

.text-right {
    text-align: right;
}

.text-center {
    text-align: center;
}

.font-bold {
    font-weight: 600;
}

.text-dim {
    color: #aaa;
}

.empty-val {
    color: #aaa;
    font-style: italic;
}

th.col-icon {
    width: 11px;
    text-align: center;
}

th.col-name {
    width: 89px;
}

th.col-status {
    width: 64px;
}

th.col-run {
    width: 55px;
}

th.col-duration {
    width: 44px;
    text-align: right;
}

th.col-date {
    width: 6rem;
}

th.col-size {
    width: 84px;
    text-align: right;
}

td {
    padding: 5px 10px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
    color: #495057;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

td.cell-size, td.cell-duration {
    text-align: right;
    font-family: monospace;
}

td.cell-date {
    font-family: monospace;
    font-size: 0.8rem;
    color: rgba(33, 37, 41, var(--age-opacity, 1));
}

.doc-count {
    color: var(--text-muted);
    font-size: 0.75em;
    margin-right: 6px;
}

td.cell-name[title] {
    text-decoration-line: underline;
    text-decoration-style: dotted;
    text-decoration-color: #aaa;
}

tbody tr.main-row {
    cursor: pointer;
    transition: background 0.15s ease;
}

tbody tr.main-row:hover {
    background: var(--hover);
}

tbody tr.main-row.active {
    background: var(--active-row);
}

.badge {
    display: inline-block;
    width: 90px;
    padding: 4px 0;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
    text-transform: uppercase;
    text-align: center;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.st-success {
    background: var(--c-success-pastel);
    color: var(--c-success-text);
}

.st-warning {
    background: var(--c-warning-pastel);
    color: var(--c-warning-text);
}

.st-danger {
    background: var(--c-danger-pastel);
    color: var(--c-danger-text);
}

.st-neutral {
    background: var(--c-neutral-pastel);
    color: var(--c-neutral-text);
}

tr.detail-row {
    display: none;
}

tr.detail-row.open {
    display: table-row;
}

.detail-wrapper-cell {
    padding: 0;
}

.detail-container {
    background: #fafafa;
    padding: 20px 40px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.03);
    border-bottom: 1px solid var(--border);
}

.detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.detail-table th {
    width: 200px;
    background: transparent;
    border-bottom: 1px solid #eee;
    color: #6c757d;
    font-weight: 600;
    text-align: right;
    padding-right: 20px;
    text-transform: none;
    vertical-align: top;
    padding-top: 8px;
    padding-bottom: 8px;
}

.detail-table td {
    background: transparent;
    border-bottom: 1px solid #eee;
    color: #212529;
    font-family: monospace;
    white-space: pre-wrap;
    word-break: break-all;
    vertical-align: top;
    padding-top: 8px;
    padding-bottom: 8px;
}

.detail-table tr:last-child th,
.detail-table tr:last-child td {
    border-bottom: none;
}

.val-bool-true {
    color: var(--c-danger-text);
    font-weight: bold;
}

.val-bool-false {
    color: var(--c-success-text);
    font-weight: bold;
}

ul.data-list {
    margin: 0;
    padding-left: 18px;
}

ul.data-list li {
    margin-bottom: 2px;
}

.list-warning {
    color: var(--c-warning-text);
    font-weight: bold;
}

.toggle-icon {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.2s;
    display: inline-block;
}

.main-row.active .toggle-icon {
    transform: rotate(90deg);
}

.error-msg, .loading-msg {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.error-msg {
    color: var(--c-danger-text);
}

@media (max-width: 768px) {
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .header-right {
        flex-direction: row-reverse;
        width: 100%;
        justify-content: flex-end;
        flex-wrap: wrap;
    }

    .app-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }

    .search-container {
        width: 100%;
    }

    .filter-group {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 5px;
        white-space: nowrap;
    }

    .hide-on-mobile {
        display: none !important;
    }

    .section-content {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-bottom: 1px solid var(--border);
    }

    .detail-container {
        padding: 15px;
        box-sizing: border-box;
        width: 100%;
    }

    .detail-table, .detail-table tbody, .detail-table tr {
        display: block;
        width: 100%;
    }

    .detail-table th {
        display: block;
        width: 100%;
        text-align: left;
        padding-bottom: 2px;
        border-bottom: none;
    }

    .detail-table td {
        display: block;
        width: 100%;
        padding-top: 0;
        padding-bottom: 12px;
        border-bottom: 1px solid #eee;
    }
}

/* --- Statistics Module Styles --- */

.stats-container {
    margin-bottom: 25px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 25px;
}

.stats-block {
    margin-bottom: 18px;
}

.stats-block:last-child {
    margin-bottom: 0;
}

.stats-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 7px;
}

.stats-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Stats: Alerts (Full Background) */
.stats-alert {
    padding: 12px 18px;
    border-radius: 6px;
    font-size: 0.9rem;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: var(--c-neutral-pastel);
    color: var(--c-neutral-text);
    line-height: 1.5;
}

.stats-alert-warning {
    background: var(--c-warning-pastel);
    color: #856404;
}

.stats-alert-danger {
    background: var(--c-danger-pastel);
    color: #721c24;
}

.stats-alert-success {
    background: var(--c-success-pastel);
    color: var(--c-success-text);
}

.stats-alert-icon {
    font-size: 1.1em;
    line-height: 1.1;
}

/* Stats: Metrics (Pill/Chip) */
.stats-metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 12px;
}

.stats-metric-pill {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    padding: 5px 12px;
    border-radius: 50px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
    max-width: 100%;
    box-sizing: border-box;
}

.stats-metric-pill.stats-pill-success {
    background: var(--c-success-pastel);
    border-color: transparent;
}

.stats-metric-pill.stats-pill-success .value {
    color: var(--c-success-text);
}

.stats-metric-pill.stats-pill-danger {
    background: var(--c-danger-pastel);
    border-color: transparent;
}

.stats-metric-pill.stats-pill-danger .value {
    color: var(--c-danger-text);
}

.stats-metric-pill .label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
    min-width: 0;
}

.stats-metric-pill .value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Stats: Distribution Bar */
.stats-dist-bar {
    display: flex;
    height: 12px;
    border-radius: 6px;
    overflow: hidden;
    background: #e9ecef;
    width: 100%;
    margin-bottom: 8px;
}

.stats-dist-seg {
    height: 100%;
    min-width: 0;
    flex-basis: 0;
    display: flex;
    align-items: center;
    justify-content: start;
    overflow: hidden;
}

.stats-dist-label {
    font-size: 10px;
    color: #ffffff;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 6px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
    max-width: 100%;
    cursor: default;
    box-sizing: border-box;
}

.stats-dist-legend {
    display: flex;
    flex-wrap: wrap;
    column-gap: 15px;
    row-gap: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.stats-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-dot {
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-text {
    line-height: 1.2;
}

.legend-meta {
    color: #999;
    font-size: 0.9em;
}

/* Stats: List */
ul.stats-list, ol.stats-list {
    margin: 0;
    padding-left: 20px;
    font-size: 0.9rem;
    color: var(--text);
}

ul.stats-list li, ol.stats-list li {
    margin-bottom: 4px;
}

/* Stats: Table overrides */
.stats-table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.stats-table-wrapper table {
    min-width: 0;
}

/* Stats: data table */
.stats-custom-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    table-layout: auto;
}

.stats-custom-table th {
    width: auto;
    text-align: left;
    background: #f8f9fa;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.stats-custom-table td {
    padding: 4px 10px;
    background: transparent;
    color: #212529;
    border-bottom: 1px solid #e9ecef;
    vertical-align: top;
    white-space: normal;
}

.stats-custom-table tr:last-child td {
    border-bottom: none;
}

/* Stats: Text/Paragraphs */
.stats-text-wrapper p {
    margin: 0 0 3px 0;
    line-height: 1.5;
    font-size: 0.9rem;
    color: var(--text);
    white-space: wrap;
}

.stats-text-wrapper p:last-child {
    margin-bottom: 0;
}
