/* Stealth Browse - History tab */

.web-content.hist-embed {
    --accent: #5a0dd6;
    --accent-2: #4900c2;
    --accent-soft: rgba(73, 0, 194, 0.22);
    --accent-text: #c4b5fd;
    --bg: #0b0c10;
    --panel: #121218;
    --panel-elevated: #18181f;
    --surface: rgba(255, 255, 255, 0.04);
    --surface-hover: rgba(255, 255, 255, 0.07);
    --border: rgba(255, 255, 255, 0.1);
    --text: #f2f4f8;
    --text-dim: #a8b0c0;
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #f87171;
    --stealth-cut: 12px 2px 2px 2px;
    --stealth-cut-sm: 8px 2px 2px 2px;
    --stealth-cut-lg: 14px 4px 4px 4px;
    --stealth-cut-panel: 22px 4px 4px 4px;
    --shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
    --transition: 0.15s ease;
}

.web-content.hist-embed *,
.web-content.hist-embed *::before,
.web-content.hist-embed *::after {
    box-sizing: border-box;
}

.web-content.hist-embed {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.web-content.hist-embed,
.web-content.hist-embed,
.web-content.hist-embed {
    background: var(--bg) !important;
    color: var(--text) !important;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Open Sans', sans-serif;
    -webkit-font-smoothing: subpixel-antialiased;
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
}

[data-theme="dark"] {
    --bg: #0a0a0f;
    --panel: #121218;
    --panel-elevated: #18181f;
    --surface: rgba(255, 255, 255, 0.04);
    --surface-hover: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.12);
    --text: #ffffff;
    --text-dim: #a1a1aa;
    --accent: #5a0dd6;
    --accent-2: #4900c2;
    --accent-text: #c4b5fd;
    --accent-soft: rgba(73, 0, 194, 0.22);
}

[data-theme="light"] {
    --bg: #d4cec4;
    --panel: #f0ebe3;
    --panel-elevated: #f7f3ec;
    --surface: rgba(255, 255, 255, 0.72);
    --surface-hover: rgba(255, 255, 255, 0.9);
    --border: rgba(55, 48, 40, 0.16);
    --text: #1c1916;
    --text-dim: #5c574f;
    --accent: #5a0dd6;
    --accent-2: #4900c2;
    --accent-text: #5a0dd6;
    --accent-soft: rgba(90, 13, 214, 0.12);
}

[data-theme="stealth"] {
    --bg: #0e0a16;
    --panel: #140f1c;
    --panel-elevated: #1a1426;
    --surface: rgba(124, 58, 237, 0.08);
    --surface-hover: rgba(124, 58, 237, 0.16);
    --border: rgba(168, 85, 247, 0.22);
    --text: #eae2ff;
    --text-dim: #c7b6f7;
    --accent: #5a0dd6;
    --accent-2: #4900c2;
    --accent-text: #c4b5fd;
    --accent-soft: rgba(90, 13, 214, 0.22);
}

[data-theme="stealth-glass"] {
    --bg: #010103;
    --panel: #0c0c12;
    --panel-elevated: #12121a;
    --surface: rgba(255, 255, 255, 0.06);
    --surface-hover: rgba(255, 255, 255, 0.1);
    --border: rgba(255, 255, 255, 0.14);
    --text: #f2f4f8;
    --text-dim: #c7cdd8;
    --accent: #5a0dd6;
    --accent-2: #4900c2;
    --accent-text: #c4b5fd;
    --accent-soft: rgba(73, 0, 194, 0.22);
}

[data-theme="stealth-float"] {
    --bg: #0b0c10;
    --panel: #10121a;
    --panel-elevated: #161922;
    --surface: rgba(16, 18, 26, 0.92);
    --surface-hover: rgba(28, 32, 44, 0.95);
    --border: rgba(255, 255, 255, 0.12);
    --text: #f2f4f8;
    --text-dim: #a8b0c0;
    --accent: #5a0dd6;
    --accent-2: #4900c2;
    --accent-text: #c4b5fd;
    --accent-soft: rgba(73, 0, 194, 0.22);
}

#hist-boot[hidden],
#hist-app[hidden] {
    display: none !important;
}

.hist-app {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: 100%;
    height: 100%;
    min-height: 0;
    color: var(--text);
}

.hist-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 16px clamp(14px, 3vw, 32px) 14px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}

.hist-brand {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.hist-back-btn {
    flex-shrink: 0;
    padding: 8px 12px;
}

.hist-brand-text {
    min-width: 0;
}

.hist-title {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.hist-subtitle {
    margin: 2px 0 0;
    color: var(--text-dim);
    font-size: 13px;
}

.hist-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.hist-search {
    position: relative;
    min-width: 220px;
    width: min(420px, 42vw);
}

.hist-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
    font-size: 13px;
    pointer-events: none;
}

.hist-search input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--stealth-cut);
    color: var(--text);
    font: inherit;
    font-size: 13.5px;
    padding: 10px 12px 10px 34px;
    outline: none;
}

.hist-search input::placeholder {
    color: var(--text-dim);
}

.hist-search input:focus {
    border-color: var(--accent);
    background: var(--surface-hover);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.hist-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--stealth-cut-sm);
    padding: 7px 10px;
}

.hist-retention {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 10px 5px 11px;
    border: 1px solid var(--border);
    border-radius: var(--stealth-cut);
    background: var(--surface);
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.hist-retention:hover {
    border-color: color-mix(in srgb, var(--accent) 45%, transparent);
    background: var(--surface-hover);
}

.hist-retention i {
    font-size: 11px;
    opacity: 0.8;
}

.hist-retention select {
    appearance: none;
    border: none;
    border-radius: var(--stealth-cut-sm);
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    padding: 3px 4px;
    outline: none;
    cursor: pointer;
}

.hist-retention select:focus-visible {
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.hist-retention select option {
    color: var(--text);
    background: var(--panel);
}

.hist-retention-days {
    width: 62px;
    border: 1px solid var(--border);
    border-radius: var(--stealth-cut-sm);
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    padding: 3px 6px;
    outline: none;
}

.hist-retention-days:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.hist-retention-unit {
    color: var(--text-dim);
    font-weight: 500;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid var(--border);
    border-radius: var(--stealth-cut);
    padding: 7px 12px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.3;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    color: var(--text);
    background: var(--surface);
    white-space: nowrap;
}

.btn i {
    font-size: 11px;
}

.btn:disabled {
    opacity: 0.55;
    cursor: default;
}

.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    font-weight: 500;
}

.btn-ghost:hover:not(:disabled) {
    color: var(--accent-text);
    border-color: color-mix(in srgb, var(--accent) 55%, transparent);
    background: var(--accent-soft);
}

.btn-danger {
    color: #fff;
    background: color-mix(in srgb, var(--danger, #f87171) 22%, var(--surface));
    border-color: color-mix(in srgb, var(--danger, #f87171) 45%, var(--border));
}

.btn-danger:hover:not(:disabled) {
    background: color-mix(in srgb, var(--danger, #f87171) 38%, var(--surface));
}

.hist-body {
    position: relative;
    display: grid;
    --hist-rail-w: 210px;
    grid-template-columns: var(--hist-rail-w) minmax(0, 1fr);
    min-height: 0;
    height: 100%;
}

.hist-timeline-pane,
.hist-list-pane {
    min-height: 0;
    overflow: auto;
}

.hist-timeline-pane {
    position: relative;
    border-right: 1px solid var(--border);
    background: var(--panel);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 0;
    overflow: hidden;
    overscroll-behavior: contain;
    scrollbar-width: none;
}

.hist-timeline-pane::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.hist-timeline-pane.is-scrubbing {
    cursor: ns-resize;
    user-select: none;
}

.hist-timeline-pane:hover .hist-wrap,
.hist-timeline-pane.is-scrubbing .hist-wrap {
    --sel: 1;
}

.hist-timeline-empty {
    color: var(--text-dim);
    font-size: 13px;
    padding: 24px 8px;
    margin: auto;
    align-self: center;
}

.hist-list-pane {
    background: var(--bg);
}

.hist-list {
    position: relative;
    min-height: 100%;
}

.hist-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 280px;
    color: var(--text-dim);
    text-align: center;
    padding: 40px 20px;
}

.hist-empty i {
    font-size: 28px;
    color: var(--accent-text);
    margin-bottom: 6px;
}

.hist-empty-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.hist-group {
    position: absolute;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    padding: 10px 22px 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.hist-item {
    position: absolute;
    left: 12px;
    right: 12px;
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr) auto auto auto;
    align-items: center;
    gap: 10px;
    height: 56px;
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: var(--stealth-cut);
    cursor: pointer;
}

.hist-item:hover {
    background: var(--surface-hover);
    border-color: var(--border);
}

.hist-favicon,
.hist-favicon-fallback {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    object-fit: contain;
}

.hist-favicon-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    background: var(--surface);
    font-size: 11px;
}

.hist-item-info {
    min-width: 0;
}

.hist-item-title {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hist-item-url {
    font-size: 12px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hist-item-time {
    font-size: 12px;
    color: var(--text-dim);
    white-space: nowrap;
}

.hist-item-dwell {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-width: 62px;
    justify-content: flex-end;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--accent-text);
    white-space: nowrap;
}

.hist-item-dwell i {
    font-size: 10px;
    opacity: 0.75;
}

.hist-item-dwell.is-empty {
    color: var(--text-dim);
    opacity: 0.45;
    font-weight: 500;
}

.hist-item-delete {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--stealth-cut-sm);
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    opacity: 0;
}

.hist-item:hover .hist-item-delete {
    opacity: 1;
}

.hist-item-delete:hover {
    background: color-mix(in srgb, var(--danger, #f87171) 18%, transparent);
    color: var(--danger, #f87171);
}

/* ===== Timeline ruler (converted range slider) ===== */
.hist-wrap,
.hist-wrap datalist {
    display: grid;
}

.hist-wrap {
    --u: 1rem;
    --g: 0.75rem;
    --ruler-m: 6;
    --thumb-d: 3.5rem;
    --thumb-r: 1.75rem;
    --thumb-f: 0.42;
    --thumb-p: 0.5rem;
    --input-t: 1.25rem;
    --input-r: 0.625rem;
    --input-d: -1.125rem;
    --track-t: 0.1875rem;
    --track-x: 1.375rem;
    --track-i: 2.5rem;
    --track-o: 2.6875rem;
    --track-r: 4.4375rem;
    --track-y: 3.2065rem;
    --track-s: 1.5045rem;
    --track-d: 1.702rem;
    --rail-inset-top: 1.75rem;
    --rail-inset-bottom: 2.25rem;
    --rail-shift: 0px;
    --line-pad: 100vh;
    --sel: 0;
    --rng: max(1, calc(var(--max) - var(--min)));
    --prg: calc((var(--val) - var(--min)) / var(--rng));
    --prc: calc(var(--prg) * 100%);
    --pos: calc(var(--val) * var(--u));
    grid-gap: var(--g);
    grid-template-columns: 5rem var(--track-t) var(--input-t);
    justify-content: center;
    color: var(--accent-2);
    font: 1em 'Segoe UI', ubuntu, verdana, arial, sans-serif;
    position: absolute;
    top: calc(var(--rail-inset-top) + var(--rail-shift));
    left: 0;
    right: 0;
    width: max-content;
    margin: 0 auto;
    padding: 0 10px;
    transform: none;
    transition: color 0.35s ease;
    overflow: visible;
    touch-action: none;
}

.hist-timeline-pane.is-scrubbing .hist-wrap {
    transition: color 0.35s ease;
}

@supports (color: color-mix(in lch, red 1%, tan)) {
    .hist-wrap {
        color: color-mix(in lch, var(--accent) var(--prc), var(--accent-2));
    }
}

.hist-wrap::before,
.hist-wrap::after {
    --pos-x: calc(100% + var(--track-x));
    --pos-y: calc(var(--pos) + var(--track-r) + var(--line-pad));
    position: absolute;
    right: calc(10px + var(--input-t) + var(--g));
    top: calc(-1 * var(--track-r) - var(--line-pad));
    z-index: 1;
    width: calc(var(--track-r) - var(--input-r) - var(--g));
    height: calc(100% + 2 * var(--track-r) + 2 * var(--line-pad));
    transform: scaley(-1);
    pointer-events: none;
    content: '';
}

.hist-wrap::before {
    --sl: transparent calc(100% + -0.5px), red calc(100% + 0.5px);
    background:
        radial-gradient(
            circle var(--track-r) at var(--pos-x) var(--pos-y),
            currentcolor calc(var(--track-i) - var(--track-t)),
            transparent
        );
    mask:
        radial-gradient(circle var(--track-i) at var(--pos-x) var(--pos-y), var(--sl)) subtract,
        radial-gradient(circle var(--track-o) at 0 0, var(--sl))
            100% calc(var(--pos-y) + -1 * var(--track-y)) /
            var(--track-o) var(--track-s) no-repeat add,
        radial-gradient(circle var(--track-o) at 0 100%, var(--sl))
            100% calc(var(--pos-y) + var(--track-d)) /
            var(--track-o) var(--track-s) no-repeat;
}

.hist-wrap::after {
    --sl:
        transparent calc(var(--track-i) + -0.5px),
        red calc(var(--track-i) + 0.5px) calc(100% + -0.5px),
        transparent calc(100% + 0.5px);
    background:
        linear-gradient(
            currentcolor calc(var(--pos-y) + var(--thumb-d)),
            transparent calc(var(--pos-y) + 2 * var(--thumb-d))
        )
        color-mix(in srgb, var(--text) 48%, transparent);
    mask:
        linear-gradient(
            red calc(var(--pos-y) + -1 * var(--track-y) + 0.5px),
            transparent 0 calc(var(--pos-y) + var(--track-y) + -0.5px),
            red 0
        )
        100% / var(--track-t) 100%,
        radial-gradient(circle var(--track-o) at var(--pos-x), var(--sl))
            100% calc(var(--pos-y) + -1 * var(--track-d) + -0.5px) /
            100% calc(2 * var(--track-d) + 1px),
        radial-gradient(circle var(--track-o) at 0 0, var(--sl))
            100% calc(var(--pos-y) + -1 * var(--track-y)) /
            var(--track-o) var(--track-s),
        radial-gradient(circle var(--track-o) at 0 100%, var(--sl))
            100% calc(var(--pos-y) + var(--track-d)) /
            var(--track-o) var(--track-s);
    mask-repeat: no-repeat;
}

.hist-knob-layer {
    --pos-x: calc(100% + var(--track-x));
    --pos-y: calc(var(--pos) + var(--track-r) + var(--line-pad));
    position: absolute;
    right: calc(10px + var(--input-t) + var(--g));
    top: calc(-1 * var(--track-r) - var(--line-pad));
    z-index: 3;
    width: calc(var(--track-r) - var(--input-r) - var(--g));
    height: calc(100% + 2 * var(--track-r) + 2 * var(--line-pad));
    transform: scaley(-1);
    pointer-events: none;
}

.hist-knob {
    --shl: 0 0 0 calc((1 - 0.375 * var(--sel)) * 0.6rem)
        color-mix(in srgb, var(--accent) calc(var(--sel) * 45%), transparent);
    position: absolute;
    left: var(--pos-x);
    top: var(--pos-y);
    box-sizing: border-box;
    border: none;
    padding: var(--thumb-p);
    width: var(--thumb-d);
    height: var(--thumb-d);
    border-radius: 50%;
    transform: translate(-50%, -50%) scaleY(-1);
    box-shadow:
        inset 0 0 1px 1px color-mix(in srgb, var(--text) 8%, transparent),
        inset var(--shl),
        inset 0 0 0 calc(0.5 * var(--thumb-f) * (var(--thumb-d) + -2 * var(--thumb-p)) + var(--thumb-p)) var(--panel),
        0.2rem -0.2rem 0.2rem color-mix(in srgb, var(--text) 10%, transparent),
        -0.2rem 0.2rem 0.6rem rgba(0, 0, 0, 0.45),
        var(--shl),
        0.6rem -0.6rem 0.6rem color-mix(in srgb, var(--text) 8%, transparent),
        -0.6rem 0.6rem 1rem rgba(0, 0, 0, 0.5);
    background:
        repeating-conic-gradient(
            from 60deg,
            transparent 0%,
            currentColor 1deg 59deg,
            transparent 60deg 50%
        )
        0 / calc(var(--thumb-f) * 100%) 100% space content-box
        var(--panel);
    transition: box-shadow 0.35s;
}

.hist-wrap [type='range'],
.hist-wrap [type='range']::-webkit-slider-runnable-track,
.hist-wrap [type='range']::-webkit-slider-thumb {
    -webkit-appearance: none;
}

.hist-wrap [type='range'] {
    --sel: 0;
    grid-area: 1 / 3;
    place-self: center;
    appearance: none;
    width: calc(var(--max) * var(--u) + var(--thumb-d));
    height: var(--input-t);
    transform: rotate(-90deg);
    background: transparent;
    font: inherit;
    cursor: pointer;
    z-index: 2;
    pointer-events: none;
}

.hist-wrap [type='range']:focus {
    outline: none;
}

.hist-wrap [type='range']:hover,
.hist-wrap [type='range']:focus {
    --sel: 1;
}

/* Vendor pseudo-elements must stay in separate rules: an engine drops the whole
   rule when any selector in the list is unknown to it. */
.hist-wrap [type='range']::-webkit-slider-runnable-track {
    height: 100%;
}

.hist-wrap [type='range']::-moz-range-track {
    height: 100%;
}

.hist-wrap [type='range']::-webkit-slider-thumb {
    appearance: none;
    border: none;
    width: var(--thumb-d);
    height: var(--thumb-d);
    background: transparent;
    box-shadow: none;
    opacity: 0;
    margin-top: var(--input-d);
}

.hist-wrap [type='range']::-moz-range-thumb {
    appearance: none;
    border: none;
    width: var(--thumb-d);
    height: var(--thumb-d);
    background: transparent;
    box-shadow: none;
    opacity: 0;
}

.hist-wrap datalist {
    grid-area: 1 / 1;
    width: 100%;
    min-width: 5rem;
    grid-template-rows: repeat(calc(var(--max) + 1), var(--u));
    margin: calc(-0.5 * var(--u)) 0;
}

.hist-wrap option {
    display: block;
    --abs: max(var(--val) - var(--idx), var(--idx) - var(--val));
    --rel: calc(var(--abs) / var(--ruler-m));
    --sel: max(0, 1 - var(--rel) * var(--rel));
    --off: 0px;
    grid-row: calc(var(--max) + 1 - var(--idx));
    align-self: center;
    padding-right: 0.75em;
    min-width: 5rem;
    overflow: visible;
    white-space: nowrap;
    transform: none;
    background:
        linear-gradient(hsl(0, 0%, var(--lum, 32%)) 0 0)
        100% / 0.5em 2px no-repeat;
    color: color-mix(in srgb, var(--text) calc((1 - 0.0625 * var(--abs)) * 100%), transparent);
    font-size: 0.8rem;
    font-weight: 650;
    text-align: right;
    transition: transform 0.2s ease-out, color 0.2s ease-out;
    pointer-events: auto;
    cursor: pointer;
}

@supports (top: calc(sin(5deg) * 1px)) {
    .hist-wrap option {
        --sel: max(0, 1 - var(--rel));
        --off: 0px;
    }
}

.hist-wrap option[label] {
    --lum: 68%;
}

.hist-wrap option[data-major] {
    --lum: 92%;
    font-weight: 750;
}

[data-theme="light"] .hist-wrap option {
    --lum: 42%;
}

[data-theme="light"] .hist-wrap option[label] {
    --lum: 26%;
}

[data-theme="light"] .hist-wrap option[data-major] {
    --lum: 14%;
}

@media (max-width: 860px) {
    .hist-body {
        --hist-rail-w: 196px;
    }

    .hist-wrap {
        --g: 0.55rem;
        --thumb-d: 2.75rem;
        --thumb-r: 1.375rem;
        --input-d: -0.75rem;
        --track-x: 1.175rem;
        --track-i: 1.925rem;
        --track-o: 2.1125rem;
        --track-r: 3.4875rem;
        --track-y: 2.5015rem;
        --track-s: 1.1355rem;
        --track-d: 1.366rem;
    }
}
