:root {
    /* --- Core palette --- */
    --bg0: #070b14;
    --bg1: #0b1220;
    --card: #0f1a2f;
    --card2: #111f39;
    --border: rgba(255,255,255,.08);
    --border2: rgba(255,255,255,.12);
    --text: #eaf1ff;
    --muted: #a8b6d6;
    --muted2: #7f91b6;
    /* Accents (subtle; histogram colors carry “color”) */
    --accent: #7aa2ff;
    --accent2: #46d39a;
    --danger: #ff6b6b;
    /* Shadows / radii */
    --r-xl: 18px;
    --r-lg: 14px;
    --r-md: 12px;
    --r-sm: 10px;
    --shadow-card: 0 16px 44px rgba(0,0,0,.48), 0 1px 0 rgba(255,255,255,.05) inset;
    --shadow-card-hover: 0 18px 52px rgba(0,0,0,.55), 0 1px 0 rgba(255,255,255,.05) inset;
    /* Layout */
    --content-max: 1920px;
    --pad: 18px;
    --gap: 14px;
    --content-gutter: clamp(32px, 6vw, 120px);
    --histogram-max: 2400px; /* how wide histogram is allowed to go on 4K */
    /* =========================
       SCROLLBAR THEME TOKENS
       ========================= */
    --sb-track: rgba(0,0,0,.20);
    --sb-thumb: rgba(255,255,255,.14);
    --sb-thumb-hover: rgba(255,255,255,.22);
    --sb-border: rgba(0,0,0,.20);
}

* {
    box-sizing: border-box;
}

/* =========================
   FORCE DARK UI IN WEBVIEW2
   =========================
   This helps Chromium/WebView2 pick dark-native UI defaults when it decides
   which element is the actual scroll container.
*/
html, body {
    color-scheme: dark;
}

html, body {
    height: 100%;
    margin: 0;
    font-family: ui-sans-serif, system-ui, "Segoe UI", Arial, sans-serif;
    color: var(--text);
    /* Premium “stage” background: your gradients + subtle vignette */
    background: radial-gradient(1200px 700px at 20% -10%, rgba(122,162,255,.14), transparent 55%), radial-gradient(900px 600px at 90% 10%, rgba(70,211,154,.10), transparent 55%), radial-gradient(1200px 900px at 50% 120%, rgba(0,0,0,.55), transparent 60%), linear-gradient(180deg, var(--bg0), var(--bg1));
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.shell {
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

/* --- Topbar: app-like, premium glow --- */
.topbar {
    padding: 16px var(--pad) 14px;
    border-bottom: 1px solid var(--border);
    background: radial-gradient(900px 120px at 20% 0%, rgba(122,162,255,.16), transparent 60%), linear-gradient(180deg, rgba(10,16,30,.92), rgba(10,16,30,.72));
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 50;
}

.brand {
    font-size: 18px;
    font-weight: 750;
    letter-spacing: .2px;
}

.sub {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12.5px;
}

/* --- Content container: wide, premium, 4K-safe --- */
.content {
    padding: var(--pad);
    display: grid;
    gap: var(--gap);
    width: min(var(--content-max), calc(100% - var(--content-gutter)));
    max-width: var(--content-max);
    margin: 0 auto;
    box-sizing: border-box;
}

/* --- Cards / panels --- */
.card {
    background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,0) 28%), linear-gradient(180deg, var(--card), var(--card2));
    border: 1px solid rgba(255,255,255,.085);
    border-radius: var(--r-xl);
    padding: 16px;
    box-shadow: var(--shadow-card);
    position: relative;
    overflow: hidden;
}

    .card::before {
        content: "";
        position: absolute;
        left: 12px;
        right: 12px;
        top: 0;
        height: 1px;
        background: linear-gradient(90deg, transparent, rgba(255,255,255,.16), transparent);
        opacity: .55;
    }

    .card:hover {
        border-color: rgba(255,255,255,.12);
        box-shadow: var(--shadow-card-hover);
    }

/* Titles */
h1, h2, h3 {
    margin: 0 0 10px;
    letter-spacing: .2px;
}

h1 {
    font-size: 18px;
    font-weight: 780;
}

h2 {
    font-size: 15px;
    font-weight: 760;
    color: rgba(234,241,255,.96);
}

h3 {
    font-size: 14px;
    font-weight: 740;
    color: rgba(234,241,255,.94);
}

/* Muted text */
.hint {
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.45;
}

/* Mono */
.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
}

/* Links (if any) */
a {
    color: rgba(160,188,255,.92);
}

    a:hover {
        color: rgba(160,188,255,1);
    }

/* --- Inputs / selects / textarea --- */
input, select, textarea {
    color: var(--text);
    background: rgba(0,0,0,.22);
    border: 1px solid rgba(255,255,255,.10);
    border-radius: var(--r-md);
    padding: 9px 10px;
    outline: none;
    box-shadow: 0 1px 0 rgba(255,255,255,.04) inset;
}

select {
    padding-right: 30px;
}

textarea {
    min-height: 110px;
    resize: vertical;
}

    /* Thread paths textarea: slightly more “pro” */
    textarea#threadPaths {
        line-height: 1.35;
        padding: 12px;
        background: rgba(0,0,0,.26);
        border-color: rgba(255,255,255,.08);
    }

    input:focus, select:focus, textarea:focus {
        border-color: rgba(122,162,255,.55);
        box-shadow: 0 0 0 3px rgba(122,162,255,.18), 0 1px 0 rgba(255,255,255,.04) inset;
    }

    input:disabled, select:disabled, textarea:disabled {
        opacity: .65;
        cursor: not-allowed;
    }

/* ---- Limit width of timezone selects (professional sizing) ---- */
select[id^="t_tz_"],
#sourceTimeZoneId {
    max-width: 480px;
    width: 100%;
}

/* Keep them from stretching inside flex rows */
select[id^="t_tz_"] {
    flex: 0 1 480px;
}

/* On smaller screens, allow full width */
@media (max-width: 900px) {
    select[id^="t_tz_"],
    #sourceTimeZoneId {
        max-width: 100%;
    }
}

/* --- Buttons --- */
.btn {
    border: 1px solid rgba(255,255,255,.14);
    background: rgba(255,255,255,.06);
    color: var(--text);
    border-radius: var(--r-md);
    padding: 10px 12px;
    cursor: pointer;
    transition: transform .06s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}

    .btn:hover {
        border-color: rgba(255,255,255,.22);
        background: rgba(255,255,255,.09);
    }

    .btn:active {
        transform: translateY(1px);
    }

    .btn:focus {
        outline: none;
        box-shadow: 0 0 0 3px rgba(122,162,255,.18);
    }

    /* Optional: If you ever add class="btn primary" */
    .btn.primary {
        border-color: rgba(122,162,255,.45);
        background: linear-gradient(180deg, rgba(122,162,255,.28), rgba(122,162,255,.10));
    }

        .btn.primary:hover {
            border-color: rgba(122,162,255,.60);
            background: linear-gradient(180deg, rgba(122,162,255,.34), rgba(122,162,255,.12));
        }

/* Status */
.ok {
    color: var(--accent2);
}

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

/* Pre blocks */
.pre {
    white-space: pre-wrap;
    background: rgba(0,0,0,0.24);
    padding: 12px;
    border-radius: var(--r-lg);
    border: 1px solid rgba(255,255,255,0.08);
    overflow: auto;
}

/* Health pill */
#health.ok, #health.bad {
    display: inline-block;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(0,0,0,0.22);
}

/* --- Timeline --- */
.timeline {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
    max-height: 420px;
    overflow: auto;
    padding-right: 6px;
}

.tl-item {
    border-left: 3px solid rgba(122,162,255,.65);
    padding: 8px 10px;
    background: rgba(0,0,0,0.18);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--r-md);
}

.tl-ts {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    color: rgba(160,188,255,.92);
}

.tl-title {
    font-size: 13px;
}

.tl-src {
    font-size: 11px;
    color: rgba(169,183,214,.85);
}

/* --- Histogram --- */
.histogram-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.histogram-body {
    position: relative;
    margin-top: 10px;
    padding: 10px;
    border-radius: var(--r-lg);
    background: rgba(0,0,0,0.18);
    border: 1px solid rgba(255,255,255,0.06);
}

#histogram {
    display: block;
    touch-action: none;
    user-select: none;
    height: 320px;
    border-radius: 10px;
}

/* Tooltip */
.hist-tip {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(7,10,16,0.88);
    border: 1px solid rgba(255,255,255,0.14);
    color: rgba(255,255,255,0.94);
    font-family: ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
    font-size: 12px;
    white-space: pre;
    max-width: min(560px, 92vw);
    box-shadow: 0 18px 40px rgba(0,0,0,.45);
}

/* Thread swatch (chips) */
.thread-swatch {
    width: 12px;
    height: 12px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.18);
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.45);
    display: inline-block;
    flex: 0 0 auto;
}

/* If your thread header container exists, make it robust to wrapping */
.thread-header {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Legend chips */
.hist-legend {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 10px;
    align-items: center;
    max-height: 120px;
    overflow: auto;
    padding: 4px;
}

.hist-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    border-radius: 999px;
    background: rgba(0,0,0,0.16);
    border: 1px solid rgba(255,255,255,0.08);
    transition: background .15s ease, border-color .15s ease;
}

    .hist-legend-item:hover {
        border-color: rgba(255,255,255,0.18);
        background: rgba(255,255,255,0.06);
    }

.hist-legend-label {
    font-size: 12px;
    opacity: 0.92;
    max-width: min(360px, 45vw);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Radios */
input[type="radio"] {
    accent-color: var(--accent);
    transform: translateY(1px);
}

/* =========================
   SCROLLBARS (HARDENED)
   =========================
   This is the main fix:
   - Targets ALL scrollable elements, not just body
   - Forces dark “scheme”
   - Adds Firefox styling too
*/
* {
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: var(--sb-thumb) var(--sb-track); /* Firefox */
}

    *::-webkit-scrollbar {
        width: 12px;
        height: 12px;
    }

    *::-webkit-scrollbar-track {
        background: var(--sb-track);
        border-radius: 999px;
    }

    *::-webkit-scrollbar-thumb {
        background: var(--sb-thumb);
        border-radius: 999px;
        border: 3px solid var(--sb-border);
    }

        *::-webkit-scrollbar-thumb:hover {
            background: var(--sb-thumb-hover);
        }

    *::-webkit-scrollbar-corner {
        background: var(--sb-track);
    }

/* Some WebView2 builds “switch” scroll container after auto-load.
   Reinforce common containers without changing layout. */
html, body, .shell, .content,
.timeline, .hist-legend, .pre,
#timeline, #histTip {
    scrollbar-color: var(--sb-thumb) var(--sb-track);
}

/* Small screen tweaks */
@media (max-width: 900px) {
    .content {
        padding: 14px;
    }

    .card {
        padding: 14px;
    }

    #histogram {
        height: 260px;
    }
}

/* --- Index helpers (keeps layout single-column, cleans inline styles) --- */
#threadPaths {
    width: 100%;
    margin-top: 10px;
}

/* consistent spacing blocks */
.stack {
    margin-top: 14px;
}

.toolbar {
    margin-top: 10px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

/* inset “sub-card” inside Threads */
.inset-card {
    margin-top: 14px;
}

/* global form row (wraps cleanly on small laptop screens) */
.form-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-top: 10px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-wide {
    min-width: 320px;
    flex: 1;
}

/* Histogram canvas styling moved from inline -> CSS */
#histogram {
    margin-top: 10px;
    background: rgba(0,0,0,0.22);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 10px;
    cursor: crosshair;
}

/* ================================
   WINDOWS / WEBVIEW SELECT FIXES
   ================================ */

/* Improve contrast inside native dropdown */
select option {
    color: #0b1220; /* dark readable text */
    background-color: #e9ecf2; /* soft neutral gray */
    font-size: 12.5px;
}

    /* Selected option (when menu opens) */
    select option:checked {
        background-color: #cfd7ee;
    }

    /* Hovered option (some browsers support this) */
    select option:hover {
        background-color: #d7def2;
    }

/* ================================
   Thread-card highlighting (hist hover)
   ================================ */

.thread-card {
    transition: opacity .12s ease, transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}

    .thread-card.is-dim {
        opacity: 0.55;
        filter: saturate(0.85);
    }

    .thread-card.is-hot {
        opacity: 1;
        transform: translateY(-1px);
        border-color: rgba(122,162,255,.30);
        box-shadow: 0 14px 34px rgba(0,0,0,.38), 0 0 0 3px rgba(122,162,255,.12);
    }

.hist-legend-item.is-dim {
    opacity: 0.45;
    filter: saturate(0.85);
}

.hist-legend-item.is-hot {
    opacity: 1;
    transform: translateY(-1px);
    border-color: rgba(122,162,255,.35);
    box-shadow: 0 0 0 3px rgba(122,162,255,.14);
}

/* Legend isolate polish */
.hist-legend-item {
    transition: opacity .12s ease, transform .12s ease, box-shadow .12s ease;
}

    .hist-legend-item.is-dim {
        opacity: 0.45;
    }

    .hist-legend-item:hover {
        transform: translateY(-1px);
    }

/* =========================
   Active Filter Summary
   ========================= */

.active-filter {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(0,0,0,0.25);
    border: 1px solid rgba(255,255,255,0.08);
    font-size: 12px;
    max-width: 520px;
}

.af-title {
    font-weight: 600;
    margin-bottom: 6px;
    opacity: 0.85;
}

.af-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 4px;
}

    .af-row span:first-child {
        opacity: 0.6;
    }

.af-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

/* Histogram hover tooltip */
#histTip {
    max-width: 420px;
    max-height: 260px;
    overflow-y: auto;
    white-space: normal; /* allow wrapping */
    line-height: 1.35;
}

    #histTip .ht-title {
        font-weight: 600;
        margin-bottom: 6px;
    }

    #histTip .ht-row {
        display: flex;
        justify-content: space-between;
        gap: 12px;
    }

    #histTip .ht-name {
        overflow-wrap: anywhere; /* break long filenames safely */
    }

    #histTip .ht-count {
        flex-shrink: 0;
        opacity: 0.85;
    }

#histTip {
    white-space: normal;
}

    #histTip .ht-row, #histTip .ht-group-title {
        display: flex;
        justify-content: space-between;
        gap: 12px;
    }

    #histTip .ht-name {
        max-width: 360px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #histTip .ht-count {
        min-width: 42px;
        text-align: right;
    }

.ht-title {
    font-weight: 600;
    margin-bottom: 6px;
}

.ht-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 12px;
    opacity: 0.9;
}

.ht-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ht-count {
    font-variant-numeric: tabular-nums;
    opacity: 0.8;
}

/* =========================
   Timeline split + Details panel
   ========================= */

.timeline-split {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-top: 10px;
}

.timeline-left {
    flex: 1 1 auto;
    min-width: 380px;
}

.event-details {
    flex: 0 0 380px;
    max-width: 460px;
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(0,0,0,0.18);
    border-radius: 14px;
    padding: 10px;
    position: sticky;
    top: 12px;
}

.ed-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.ed-title {
    font-weight: 700;
}

.ed-body {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ed-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
}

.ed-k {
    opacity: 0.75;
    white-space: nowrap;
}

.ed-v {
    text-align: right;
    word-break: break-word;
}

.ed-pre {
    white-space: pre-wrap;
    word-break: break-word;
    padding: 10px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(0,0,0,0.22);
}

/* Make timeline items feel clickable */
.tl-item {
    cursor: pointer;
}

    .tl-item:hover {
        outline: 1px solid rgba(255,255,255,0.14);
    }

    .tl-item.is-selected {
        outline: 2px solid rgba(255,255,255,0.25);
    }

/* ===== TimeWeave Header Upgrade (topbar) ===== */
.topbar.tw-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(140, 180, 255, 0.12);
    background: linear-gradient(180deg, rgba(6, 10, 20, 0.86), rgba(6, 10, 20, 0.72) );
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.tw-brand {
    display: flex;
    align-items: center;
    min-width: 260px;
}

.tw-brandimg {
    height: 84px;
    width: auto;
    display: block;
    border-radius: 14px;
    background: transparent; /* keeps alpha clean */
    object-fit: contain;
}

.tw-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex: 1;
    min-width: 220px;
}

.tw-tagline {
    color: rgba(200, 230, 255, 0.65);
    font-size: 12.5px;
    letter-spacing: 0.35px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tw-stats {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.tw-pill {
    font-size: 12px;
    color: rgba(230, 245, 255, 0.92);
    background: rgba(140, 180, 255, 0.12);
    border: 1px solid rgba(140, 180, 255, 0.18);
    padding: 5px 10px;
    border-radius: 999px;
    line-height: 1;
    white-space: nowrap;
}

.tw-pill--mode {
    color: rgba(195, 255, 235, 0.95);
    border-color: rgba(120, 255, 210, 0.20);
    background: rgba(120, 255, 210, 0.10);
}

.tw-dot {
    color: rgba(180, 210, 255, 0.35);
    user-select: none;
}

.tw-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tw-iconbtn {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    border: 1px solid rgba(140, 180, 255, 0.16);
    background: rgba(140, 180, 255, 0.08);
    color: rgba(230, 245, 255, 0.88);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform .08s ease, background .12s ease, border-color .12s ease;
}

    .tw-iconbtn:hover {
        background: rgba(140, 180, 255, 0.14);
        border-color: rgba(140, 180, 255, 0.24);
        transform: translateY(-1px);
    }

    .tw-iconbtn:active {
        transform: translateY(0px);
    }

@media (max-width: 820px) {
    .tw-brandimg {
        height: 70px;
    }

    .tw-tagline {
        display: none;
    }
}

/* =========================
   Histogram "full-bleed" breakout (wider than .content)
   ========================= */

/* Make the histogram card use viewport width, but keep nice gutters */
.card.histogram-card {
    width: min(var(--histogram-max), calc(100vw - var(--content-gutter)));
    margin-left: calc(50% - 50vw + (var(--content-gutter) / 2));
    margin-right: calc(50% - 50vw + (var(--content-gutter) / 2));
}

/* On small screens, don't do any breakout */
@media (max-width: 900px) {
    .card.histogram-card {
        width: auto;
        margin-left: 0;
        margin-right: 0;
    }
}
