/* ===========================================
   Range picker (partials/_range_picker.html, js/range_picker.js)

   Quick tabs + "More ▾" (preset-tabs), and a panel with Customize (From–To fields,
   "Last N hours / days") beside the searchable quick ranges. The panel is
   fixed-positioned under the More button by the JS (so card overflow never clips it);
   on phones it is a bottom sheet over a scrim.
   =========================================== */

.range-picker {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}
.range-tabs { flex-shrink: 0; }
.range-more { display: inline-flex; align-items: center; gap: 0.25rem; }
.range-more svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2; }
.range-picker.open .range-more { background: var(--card); color: var(--text-primary); box-shadow: var(--shadow-sm); }

.range-panel {
    position: fixed;
    z-index: 1003;
    width: 580px;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    padding: 0;
    gap: 0;
}
/* .popover sets display: flex, which beats the [hidden] default. */
.range-panel[hidden] { display: none; }
.range-sheet-head { display: none; }

.range-body { display: grid; grid-template-columns: minmax(0, 1fr) 232px; min-height: 0; }

.range-quick {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
    padding: 0.7rem 0.6rem 0.4rem;
    border-left: 1px solid var(--border-light);
}
.range-search { display: flex; flex-shrink: 0; width: 100%; margin: 0; }
/* A fixed height, so filtering never resizes the panel; the fade hints at the rows below. */
.range-presets {
    display: flex;
    flex-direction: column;
    gap: 1px;
    height: 192px;
    padding-bottom: 18px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    -webkit-mask-image: linear-gradient(to bottom, var(--c-fg) calc(100% - 28px), transparent);
    mask-image: linear-gradient(to bottom, var(--c-fg) calc(100% - 28px), transparent);
}
.range-preset {
    display: flex;
    flex-shrink: 0;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    padding: 0.35rem 0.6rem;
    border: none;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.8rem;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
}
.range-preset:hover { background: var(--surface-hover); color: var(--text-primary); transform: none; }
.range-preset.active { background: var(--sel-bg); box-shadow: inset 0 0 0 1px var(--hairline); color: var(--text-primary); font-weight: 600; }
/* display: flex above beats the [hidden] default. */
.range-preset[hidden] { display: none; }
.range-key { font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-faint); }
.range-sep { flex-shrink: 0; height: 1px; margin: 4px 6px; background: var(--border-light); }
.range-empty { margin: 0; padding: 0.35rem 0.6rem; font-size: 0.8rem; color: var(--text-muted); }

.range-custom { display: flex; flex-direction: column; gap: 0.6rem; padding: 0.85rem; }
.range-sub {
    margin: 0;
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-faint);
}
.range-lastn { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: var(--text-secondary); }
.range-picker input {
    width: auto;
    height: 30px;
    margin: 0;
    padding: 0 0.5rem;
    font-size: 0.8rem;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text-primary);
}
/* The global .input draws the search box: its field stays bare. */
.range-picker .input > input { height: auto; padding: 0; border: none; background: transparent; }
.range-lastn input { width: 4.5rem; }
.range-lastn .preset-btn.active { background: var(--c-secondary-ghost); color: var(--text-primary); }
.range-fields {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) 7rem;
    gap: 0.4rem 0.5rem;
    align-items: center;
    font-size: 0.74rem;
    color: var(--text-muted);
}
.range-fields input { min-width: 0; width: 100%; }
.range-custom.invalid .range-fields input { border-color: var(--c-danger); }
.range-note { margin: 0; font-size: 0.7rem; color: var(--text-faint); }
.range-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-top: auto;
    padding-top: 0.6rem;
    border-top: 1px solid var(--border-light);
}
.range-span { font-size: 0.74rem; color: var(--text-muted); }
.range-actions div { display: flex; gap: 0.4rem; }

.range-scrim { display: none; }

@media (max-width: 768px) {
    /* The tabs wrap under the page title: they start at its left edge, not the far right. */
    .page-head-actions:has(.range-picker) { margin-left: 0; }

    /* Phones: a bottom sheet over a scrim, big touch targets, 16px inputs (no iOS zoom). */
    .range-scrim:not([hidden]) {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1002;
        background: var(--overlay-bg);
    }
    .range-panel {
        inset: auto 0 0 0 !important;
        width: auto;
        max-height: 88vh;
        border-radius: var(--r-xl) var(--r-xl) 0 0;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .range-sheet-head { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem 0; }
    .range-sheet-head b { align-self: flex-start; font-size: 15px; }
    .range-grab { width: 40px; height: 4px; border-radius: 2px; background: var(--border); }
    /* Chips first, Customize under them; the search has no room to earn here. */
    .range-body { display: flex; flex-direction: column; }
    .range-quick { order: -1; padding: 0; border-left: none; }
    .range-search { display: none; }
    .range-presets {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
        height: auto;
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--border-light);
        overflow: visible;
        -webkit-mask-image: none;
        mask-image: none;
    }
    .range-preset {
        justify-content: center;
        padding: 0.45rem 0.2rem;
        border: 1px solid var(--border-light);
        border-radius: var(--r-md);
        font-size: 0.74rem;
        white-space: normal;
        text-align: center;
    }
    .range-preset.active { border-color: var(--c-secondary); }
    .range-key, .range-sep { display: none; }
    .range-custom { gap: 0.55rem; padding: 0.75rem 1rem 1rem; }
    .range-picker input { height: 40px; font-size: 16px; }
    .range-lastn input { width: 5rem; }
    /* The time's picker icon goes, or it clips the value at phone width. */
    .range-fields { grid-template-columns: auto minmax(0, 1fr) minmax(0, 6.5rem); }
    .range-picker input[type="time"]::-webkit-calendar-picker-indicator { display: none; }
}
