:root {
    color-scheme: dark;
    --bg: #0f1115;
    --panel: #171a21;
    --panel-alt: #1d222b;
    --line: #2a313d;
    --text: #e8edf3;
    --muted: #9aa7b6;
    --accent: #6ea8fe;
    --good: #61d095;
    --warn: #ffca6b;
    --bad: #ff7b7b;
    --chip: #242b36;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

button,
input,
select {
    font: inherit;
}

button,
input,
select {
    color: var(--text);
}

button {
    cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.hidden {
    display: none !important;
}

.app-shell {
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    background: var(--bg);
}

.topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 1rem;
    min-height: 4.25rem;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--line);
    background: #11141a;
}

.brand {
    min-width: 0;
}

.brand h1 {
    margin: 0;
    font-size: 1.25rem;
    line-height: 1.1;
}

.eyebrow {
    margin: 0 0 0.18rem;
    color: var(--accent);
    font-size: 0.64rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.file-summary {
    display: flex;
    min-width: 0;
    justify-content: flex-end;
    gap: 0.9rem;
    overflow: hidden;
    color: var(--muted);
    font-size: 0.7rem;
}

.file-summary span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-summary strong {
    color: var(--text);
}

.topbar-actions {
    display: flex;
    gap: 0.45rem;
}

.button,
.icon-button,
.segment {
    border: 1px solid var(--line);
    border-radius: 0.45rem;
    background: var(--panel-alt);
    color: var(--text);
}

.button {
    min-height: 2rem;
    padding: 0.4rem 0.7rem;
}

.button-small {
    min-height: 1.9rem;
    padding: 0.32rem 0.6rem;
}

.button-primary {
    border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
    background: color-mix(in srgb, var(--accent) 16%, var(--panel-alt));
}

.button:hover:not(:disabled),
.icon-button:hover:not(:disabled),
.segment:hover:not(:disabled) {
    border-color: var(--accent);
}

.icon-button {
    display: grid;
    place-items: center;
    width: 1.9rem;
    height: 1.9rem;
    padding: 0;
}

.drop-zone {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
    margin: 0.55rem 1rem 0;
    padding: 0.45rem 0.65rem;
    border: 1px dashed var(--line);
    border-radius: 0.55rem;
    background: #141820;
    outline: none;
}

.drop-zone.drag-over,
.drop-zone:focus-visible {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, #141820);
}

.drop-zone-icon {
    display: grid;
    place-items: center;
    width: 1.65rem;
    height: 1.65rem;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--chip);
    color: var(--accent);
}

.drop-zone-main {
    color: var(--text);
    font-size: 0.74rem;
    font-weight: 650;
}

.drop-zone-sub {
    color: var(--muted);
    font-size: 0.68rem;
}

.filterbar {
    display: grid;
    grid-template-columns:
        minmax(14rem, 1.7fr)
        minmax(9rem, 0.8fr)
        minmax(10rem, 0.9fr)
        minmax(8rem, 0.7fr)
        auto
        6.5rem
        8rem
        auto;
    align-items: end;
    gap: 0.45rem;
    min-width: 0;
    margin: 0.55rem 1rem;
    padding: 0.55rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 0.6rem;
    background: var(--panel);
}

.filter-item {
    display: grid;
    min-width: 0;
    gap: 0.2rem;
}

.filter-item > span {
    color: var(--muted);
    font-size: 0.62rem;
}

.filter-check {
    display: flex;
    align-items: center;
    align-self: end;
    gap: 0.35rem;
    height: 1.9rem;
    color: var(--muted);
    font-size: 0.68rem;
    white-space: nowrap;
}

.filter-check input {
    width: auto;
}

input,
select {
    width: 100%;
    min-width: 0;
    height: 1.9rem;
    border: 1px solid var(--line);
    border-radius: 0.4rem;
    outline: none;
    background: var(--panel-alt);
}

input {
    padding: 0 0.5rem;
}

select {
    padding: 0 1.6rem 0 0.45rem;
}

input:focus,
select:focus {
    border-color: var(--accent);
}

.table-panel {
    min-width: 0;
    min-height: 0;
    margin: 0 1rem 0.55rem;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 0.6rem;
    background: var(--panel);
}

.table-shell {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    scrollbar-gutter: stable both-edges;
}

.event-table {
    width: 100%;
    min-width: 82rem;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    font-size: 0.72rem;
}

.event-table th,
.event-table td {
    height: 2rem;
    padding: 0 0.52rem;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.event-table th {
    position: sticky;
    top: 0;
    z-index: 4;
    background: #131820;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    text-align: left;
    user-select: none;
}

.event-table th[data-sort-key] {
    cursor: pointer;
}

.event-table th[data-sort-key]:hover {
    color: var(--text);
}

.event-table tbody tr {
    background: var(--panel);
}

.event-table tbody tr:nth-child(even) {
    background: #191e26;
}

.event-table tbody tr:hover {
    background: color-mix(in srgb, var(--accent) 8%, var(--panel));
}

.event-table th:nth-child(1),
.event-table td:nth-child(1) {
    width: 4.4rem;
}

.event-table th:nth-child(2),
.event-table td:nth-child(2) {
    width: 9rem;
}

.event-table th:nth-child(3),
.event-table td:nth-child(3) {
    width: 10rem;
}

.event-table th:nth-child(4),
.event-table td:nth-child(4) {
    width: 5rem;
}

.event-table th:nth-child(5),
.event-table td:nth-child(5) {
    width: 11rem;
}

.event-table th:nth-child(6),
.event-table td:nth-child(6) {
    width: 27rem;
}

.event-table th:nth-child(7),
.event-table td:nth-child(7) {
    width: 9rem;
}

.event-table th:nth-child(8),
.event-table td:nth-child(8) {
    width: 27rem;
}

.event-table th:nth-child(9),
.event-table td:nth-child(9) {
    width: 6rem;
    text-align: center;
}

.empty-row td {
    height: 10rem;
    color: var(--muted);
    text-align: center;
}

.result-good {
    color: var(--good);
}

.result-warn {
    color: var(--warn);
}

.result-bad {
    color: var(--bad);
}

.stack-button {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--chip);
    color: var(--accent);
    padding: 0.16rem 0.42rem;
    font-size: 0.64rem;
}

.stack-button:hover {
    border-color: var(--accent);
}

.statusbar {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 0.8rem;
    min-height: 2rem;
    padding: 0.3rem 1rem;
    border-top: 1px solid var(--line);
    background: #0c0f14;
    color: var(--muted);
    font-size: 0.68rem;
}

.status-left {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 0.4rem;
}

.status-left span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-center {
    white-space: nowrap;
}

.status-center strong {
    color: var(--text);
}

.status-right {
    display: flex;
    justify-content: flex-end;
}

.status-dot {
    width: 0.45rem;
    height: 0.45rem;
    flex: 0 0 auto;
    border-radius: 50%;
    background: var(--muted);
}

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

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

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

.pagination {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.page-indicator {
    min-width: 4.5rem;
    text-align: center;
}

.progress-wrap {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 0.18rem;
    background: var(--panel-alt);
}

.progress-bar {
    width: 0;
    height: 100%;
    background: var(--accent);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(4, 6, 9, 0.76);
    backdrop-filter: blur(4px);
}

.modal {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 0.7rem;
    background: var(--panel);
    box-shadow: 0 1.5rem 5rem rgba(0, 0, 0, 0.55);
}

.modal-event {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: min(60rem, 96vw);
    max-height: 88vh;
}

.modal-stack {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    width: min(70rem, 96vw);
    height: min(46rem, 88vh);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.7rem 0.8rem;
    border-bottom: 1px solid var(--line);
    background: #141820;
}

.modal-header h2 {
    margin: 0;
    font-size: 0.98rem;
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.modal-close {
    font-size: 1rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    min-height: 1.4rem;
    padding: 0.1rem 0.42rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--chip);
    color: var(--muted);
    font-size: 0.64rem;
}

.event-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
    min-height: 0;
    overflow: auto;
    padding: 0.7rem;
}

.detail-field {
    display: grid;
    grid-template-columns: 7rem minmax(0, 1fr);
    gap: 0.45rem;
    padding: 0.45rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: 0.45rem;
    background: var(--panel-alt);
}

.detail-field span:first-child {
    color: var(--muted);
    font-size: 0.66rem;
}

.detail-field span:last-child {
    overflow-wrap: anywhere;
    font-size: 0.7rem;
}

.raw-details {
    margin: 0 0.7rem 0.7rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--line);
}

.raw-details summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 0.68rem;
}

.raw-details pre {
    max-height: 15rem;
    overflow: auto;
    margin-bottom: 0;
    padding: 0.6rem;
    border: 1px solid var(--line);
    border-radius: 0.45rem;
    background: #0b0e13;
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.65rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.stack-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.7rem;
    padding: 0.55rem 0.7rem;
    border-bottom: 1px solid var(--line);
}

.segmented-control {
    display: inline-flex;
    padding: 0.15rem;
    border: 1px solid var(--line);
    border-radius: 0.5rem;
    background: #0f1319;
}

.segment {
    min-width: 4rem;
    padding: 0.3rem 0.55rem;
    border-color: transparent;
    background: transparent;
    color: var(--muted);
}

.segment.active {
    border-color: var(--line);
    background: var(--panel-alt);
    color: var(--text);
}

.stack-search {
    width: min(22rem, 45vw);
}

.stack-content {
    min-height: 0;
    overflow: auto;
    padding: 0.7rem;
}

.stack-list {
    display: grid;
    gap: 0.35rem;
}

.stack-frame {
    display: grid;
    grid-template-columns: 2.4rem minmax(0, 1fr);
    gap: 0.5rem;
    padding: 0.46rem 0.55rem;
    border: 1px solid var(--line);
    border-radius: 0.45rem;
    background: #11151c;
}

.frame-index {
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.64rem;
}

.frame-content {
    display: grid;
    min-width: 0;
    gap: 0.1rem;
}

.frame-symbol,
.tree-symbol {
    overflow-wrap: anywhere;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.7rem;
}

.frame-meta,
.tree-meta {
    overflow-wrap: anywhere;
    color: var(--muted);
    font-size: 0.64rem;
}

.stack-tree {
    margin: 0;
    padding: 0;
    list-style: none;
}

.tree-row {
    display: grid;
    grid-template-columns: 2.4rem 1.2rem minmax(0, 1fr);
    align-items: start;
    min-height: 2.3rem;
}

.tree-index {
    padding-top: 0.42rem;
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.64rem;
}

.tree-rail {
    position: relative;
    height: 100%;
}

.tree-rail::before {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0.52rem;
    width: 1px;
    background: var(--line);
    content: "";
}

.tree-rail::after {
    position: absolute;
    top: 0.8rem;
    left: 0.52rem;
    width: 0.55rem;
    height: 1px;
    background: var(--line);
    content: "";
}

.tree-row:last-child .tree-rail::before {
    bottom: calc(100% - 0.8rem);
}

.tree-card {
    display: grid;
    gap: 0.1rem;
    margin-bottom: 0.35rem;
    padding: 0.42rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: 0.45rem;
    background: #11151c;
}

@media (max-width: 1180px) {
    .topbar {
        grid-template-columns: auto 1fr auto;
    }

    .file-summary span:nth-child(2),
    .file-summary span:nth-child(4) {
        display: none;
    }

    .filterbar {
        grid-template-columns:
            minmax(12rem, 1.5fr)
            minmax(8rem, 0.8fr)
            minmax(9rem, 0.9fr)
            minmax(7rem, 0.7fr)
            auto
            6rem
            7rem
            auto;
    }
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    }

    .topbar {
        grid-template-columns: 1fr auto;
    }

    .file-summary {
        display: none;
    }

    .filterbar {
        grid-template-columns: repeat(4, minmax(8rem, 1fr));
        overflow-x: auto;
    }

    .filter-search {
        grid-column: span 2;
    }
}

@media (max-width: 620px) {
    .topbar {
        align-items: start;
    }

    .topbar-actions {
        flex-direction: column;
    }

    .drop-zone-sub {
        display: none;
    }

    .filterbar {
        grid-template-columns: repeat(2, minmax(8rem, 1fr));
        margin-right: 0.5rem;
        margin-left: 0.5rem;
    }

    .filter-search {
        grid-column: 1 / -1;
    }

    .table-panel {
        margin-right: 0.5rem;
        margin-left: 0.5rem;
    }

    .statusbar {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .status-center {
        display: none;
    }

    .event-detail-grid {
        grid-template-columns: 1fr;
    }

    .stack-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .stack-search {
        width: 100%;
    }
}


/* Authoritative ProcMon-style stack table */
.modal-stack {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    width: min(72rem, calc(100vw - 2rem));
    height: min(44rem, calc(100vh - 2rem));
    max-height: calc(100vh - 2rem);
    min-height: 20rem;
    overflow: hidden;
}

.stack-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-width: 0;
    min-height: 3rem;
    padding: 0.55rem 0.7rem;
    border-bottom: 1px solid var(--line);
    background: #12161d;
}

.stack-search {
    width: min(28rem, 100%);
    max-width: 100%;
}

.stack-table-shell {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow-x: auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable both-edges;
    background: var(--panel);
}

.stack-table {
    width: 100%;
    min-width: 64rem;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    font-size: 0.7rem;
}

.stack-table thead {
    position: relative;
    z-index: 4;
}

.stack-table th {
    position: sticky;
    top: 0;
    z-index: 5;
    height: 2rem;
    padding: 0 0.55rem;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: #131820;
    color: var(--muted);
    font-size: 0.66rem;
    font-weight: 700;
    text-align: left;
    white-space: nowrap;
}

.stack-table td {
    height: 2rem;
    padding: 0 0.55rem;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

.stack-table tbody tr {
    background: var(--panel);
}

.stack-table tbody tr:nth-child(even) {
    background: #191e26;
}

.stack-table tbody tr:hover {
    background: color-mix(in srgb, var(--accent) 8%, var(--panel));
}

.stack-table th:nth-child(1),
.stack-table td:nth-child(1) {
    width: 4rem;
}

.stack-table th:nth-child(2),
.stack-table td:nth-child(2) {
    width: 14rem;
}

.stack-table th:nth-child(3),
.stack-table td:nth-child(3) {
    width: 36rem;
}

.stack-table th:nth-child(4),
.stack-table td:nth-child(4) {
    width: 10rem;
}

.stack-table .empty-row td {
    height: 8rem;
    color: var(--muted);
    text-align: center;
}

.stack-module-button {
    display: inline-block;
    max-width: 100%;
    padding: 0;
    overflow: hidden;
    border: 0;
    background: transparent;
    color: var(--accent);
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

.stack-module-button:hover {
    text-decoration: underline;
    text-underline-offset: 0.16rem;
}

.clickable-cell {
    cursor: pointer;
}

.clickable-cell:hover {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 0.16rem;
}

.modal-value {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: min(54rem, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    overflow: hidden;
}

.value-modal-content {
    min-height: 0;
    overflow: auto;
    padding: 0.75rem;
}

.value-detail-row {
    display: grid;
    grid-template-columns: 9rem minmax(0, 1fr);
    gap: 0.65rem;
    margin-bottom: 0.5rem;
    padding: 0.55rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 0.45rem;
    background: var(--panel-alt);
}

.value-detail-label {
    color: var(--muted);
    font-size: 0.66rem;
}

.value-detail-value {
    overflow-wrap: anywhere;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.7rem;
    white-space: pre-wrap;
}

@media (max-width: 720px) {
    .modal-stack {
        width: calc(100vw - 1rem);
        height: calc(100vh - 1rem);
        max-height: calc(100vh - 1rem);
        min-height: 0;
    }

    .stack-toolbar {
        align-items: stretch;
    }

    .stack-search {
        width: 100%;
    }

    .value-detail-row {
        grid-template-columns: 1fr;
    }
}


/* Row-level interaction */
.event-table tbody tr.event-row,
.stack-table tbody tr.stack-row {
    cursor: pointer;
}

.event-table tbody tr.event-row:hover,
.stack-table tbody tr.stack-row:hover {
    background: color-mix(in srgb, var(--accent) 9%, var(--panel));
}

.event-table tbody tr.selected,
.stack-table tbody tr.selected {
    background: color-mix(in srgb, var(--accent) 16%, var(--panel)) !important;
    box-shadow: inset 3px 0 0 var(--accent);
}

.clickable-cell {
    cursor: default;
    text-decoration: none !important;
}

.clickable-cell:hover {
    color: inherit;
    text-decoration: none !important;
}

.stack-module-button {
    text-decoration: none;
}

.stack-module-button:hover {
    color: var(--text);
    text-decoration: none;
}
