/*
 * Layout additions for the dashboard, loaded after the page's own <style> block:
 *   - sticky status-group headers and table headers
 *   - Custom View filling the page on desktop
 *   - Excel-style filter menus, filter chip bar and card-field editor (excel-filter.js)
 *   - card view for tables on phones and tablets
 *   - small-screen fixes for forms, docs and dialogs
 * layout.js measures the sticky offsets and labels card cells.
 */

/* ---------------------------------------------------------------------------------------
 *  Sticky headers
 *
 *  A status group's header ("Not Started (37)") sticks under the top nav while you scroll
 *  through that group, then hands over to the next group's header. On desktop the column
 *  header sticks beneath it. layout.js sets --nav-h and, per table, --sticky-top
 *  (nav + group header).
 * ------------------------------------------------------------------------------------- */
.group-header { position: sticky; top: var(--nav-h, 60px); z-index: 30; }

/* The old filter row (text boxes and fixed lists) is replaced by Excel-style column menus */
table.xf-table thead tr.filter-row { display: none !important; }

.master-table:not(#table-custom) thead { position: sticky; top: var(--sticky-top, 112px); z-index: 20; }

/* A Workbench stack never needs to scroll sideways, and a sideways-scrolling box captures its
   sticky header (which then sits over the device list on phones) */
.stack-box.table-wrapper { overflow: visible !important; }

@media (min-width: 1101px) {
    /* An overflowing wrapper would capture the sticky header; these tables never need to
       scroll sideways at desktop widths (they're fixed-layout, 100% wide) */
    #masterList .table-wrapper, #software .table-wrapper, .stack-box.table-wrapper { overflow: visible !important; }

    /* Collapsed table borders stay behind when a header sticks, leaving a hairline gap
       that rows show through; separated borders move with their cells */
    .master-table { border-collapse: separate; border-spacing: 0; }

    /* Custom View fills the page like the other views, with a native sticky header (same
       as the other tables, so it can't lag or bounce). A sideways-scrolling box would stop
       the header sticking, so when the columns are wider than the page the table is
       clipped and scrolled sideways by layout.js through a scrollbar pinned to the bottom
       of the window (trackpad, shift+wheel and touch swipes work too) */
    #custom, #wrapper-custom { overflow: visible !important; }
    #scroll-custom { max-height: none !important; overflow-x: clip !important; overflow-y: visible !important; }
    #table-custom thead th { position: sticky !important; top: var(--sticky-top, 112px) !important; z-index: 20; }
    .custom-hscroll {
        position: sticky; bottom: var(--dock-h, 40px); z-index: 15;
        display: flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px;
        background: var(--bg-card); border-top: 2px solid var(--table-header-bg); border-radius: 0 0 8px 8px;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.15); user-select: none; touch-action: none;
    }
    .custom-hscroll[hidden] { display: none; }
    .chs-btn {
        flex: 0 0 24px; height: 18px; border: 1px solid var(--border-color, #ccc); border-radius: 4px;
        background: var(--bg-body, #f0f2f5); color: var(--text-main, #333); cursor: pointer;
        font-size: 9px; line-height: 1; padding: 0;
    }
    .chs-btn:hover:not(:disabled) { background: var(--table-header-bg); border-color: var(--table-header-bg); color: #fff; }
    .chs-btn:disabled { opacity: 0.35; cursor: default; }
    .chs-track {
        position: relative; flex: 1 1 auto; height: 10px; border-radius: 5px; cursor: pointer;
        background: rgba(127,127,127,0.2); box-shadow: inset 0 1px 2px rgba(0,0,0,0.2); outline: none;
    }
    .chs-track:focus-visible { box-shadow: 0 0 0 2px var(--table-header-bg); }
    .chs-thumb {
        position: absolute; top: -2px; left: 0; height: 14px; min-width: 40px; border-radius: 7px;
        background: var(--table-header-bg); cursor: grab; box-shadow: 0 1px 3px rgba(0,0,0,0.35);
        border: 1px solid rgba(255,255,255,0.18); box-sizing: border-box;
        display: flex; align-items: center; justify-content: center; transition: filter 0.15s;
    }
    .chs-thumb span { width: 10px; height: 6px; border-left: 2px solid rgba(255,255,255,0.7); border-right: 2px solid rgba(255,255,255,0.7); }
    .chs-thumb:hover, .custom-hscroll.dragging .chs-thumb { filter: brightness(1.3); }
    .custom-hscroll.dragging .chs-thumb { cursor: grabbing; }
    .chs-info { flex: 0 0 auto; min-width: 30px; text-align: right; font-size: 0.7em; color: var(--text-muted, #666); font-variant-numeric: tabular-nums; }
    [data-theme="dark"] .chs-track { background: rgba(255,255,255,0.12); }
    [data-theme="dark"] .chs-thumb { border-color: rgba(255,255,255,0.35); }

    /* Custom View header on one line like the other tables: drag grip, name, then the
       Excel-style button (sort + filter) and copy icon; remove (x) appears on hover */
    #table-custom .custom-th .col-grip-row {
        position: absolute; left: 0; top: 0; bottom: 0; width: 18px; height: auto;
        border: 0; background: transparent;
    }
    #table-custom .custom-th .col-grip { color: rgba(255,255,255,0.45); }
    #table-custom .custom-th:hover .col-grip { color: rgba(255,255,255,0.9); }
    #table-custom .custom-th .col-grip svg { width: 12px; height: 12px; }
    #table-custom .custom-th .th-icons {
        position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
        padding: 0; gap: 5px; overflow: visible;
    }
    #table-custom .custom-th .th-icons .col-filter-btn,
    #table-custom .custom-th .th-icons .sort-icon-inline { display: none !important; }
    #table-custom .custom-th .th-icons .col-remove { order: 0; }
    #table-custom .custom-th .th-icons .xf-btn { order: 1; margin: 0; }
    #table-custom .custom-th .th-icons .col-copy { order: 2; }
    #table-custom .custom-th .col-label-row { padding: 9px 66px 9px 20px; }
}

/* ---------------------------------------------------------------------------------------
 *  Bottom terminal dock: keep page content and dialogs clear of it.
 *  layout.js sets --dock-h to the dock's current height (bar only, or bar + terminal).
 * ------------------------------------------------------------------------------------- */
body { padding-bottom: var(--dock-h, 40px) !important; }

/* Dialogs sit above the dock (below the top nav), so it can't cover their bottom rows */
.modal-overlay { z-index: 1950 !important; }
#modal { z-index: 1960 !important; }
#syncModal { z-index: 1970 !important; }
#confirmModal, #promptModal { z-index: 1980 !important; }

/* Documentation fits the window on desktop: only the article list and the article scroll */
@media (min-width: 901px) {
    #docs > div { height: calc(100vh - var(--nav-h, 60px) - 50px - var(--dock-h, 40px)) !important; }
}

/* ---------------------------------------------------------------------------------------
 *  Card view for data tables (phones and tablets)
 *
 *  An 11-column table can't be read on a phone or an iPad in portrait, and sideways
 *  scrolling only ever shows a few columns. Below 1100px (where the nav also collapses)
 *  each row becomes a card: the device name as its title and every other column as a
 *  "label: value" line. layout.js copies the column names onto the cells. Cards flow one
 *  per row on phones and two or more on tablets. A sticky bar of column chips above the
 *  cards opens the same Excel-style filter menus as the desktop headers.
 * ------------------------------------------------------------------------------------- */
@media (max-width: 1100px) {
    .table-wrapper { overflow-x: visible !important; }

    table.master-table {
        display: block; width: 100% !important; min-width: 0 !important; max-width: none !important;
        table-layout: auto; font-size: 0.9em;
    }
    table.master-table colgroup { display: none; }
    table.master-table thead { display: block; }
    table.master-table thead tr.card-label-row,
    table.master-table thead tr.card-aux-row { display: none; }

    /* Column names live on the cards; the header is replaced by the filter chip bar */
    table.xf-table thead { display: none !important; }

    /* Custom View scrolls with the page like the other views */
    #custom, #wrapper-custom, #scroll-custom { overflow: visible !important; max-height: none !important; }
    /* Desktop column tools don't apply to cards ("Card fields" replaces them) */
    #custom button[onclick*="shrinkCustomColumns"], #custom [onclick*="toggleAddColMenu"] { display: none !important; }

    /* Rows -> cards */
    table.master-table tbody {
        display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr));
        gap: 10px; padding: 10px;
    }
    table.master-table tbody tr {
        display: block; position: relative;
        background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 8px;
        padding: 10px 12px; box-shadow: 0 2px 5px rgba(0,0,0,0.25);
    }
    /* Label in a fixed left gutter, value flows to its right (so a value made of several
       pieces - a name plus its copy icon, a list with links - stays one value) */
    table.master-table tbody td {
        display: block; position: relative; min-height: 1.3em;
        padding: 6px 0 6px 9.2em; border: 0; border-bottom: 1px solid var(--border-light);
        width: auto !important; max-width: none !important; height: auto !important;
        white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere;
    }
    table.master-table tbody td::before {
        content: attr(data-label); position: absolute; left: 0; top: 6px; width: 8.6em;
        font-size: 0.85em; font-weight: 600; color: var(--text-muted); line-height: 1.35;
    }
    table.master-table tbody td:last-child { border-bottom: 0; }

    /* First column (the device) is the card's title */
    table.master-table tbody td:first-child {
        display: block; font-size: 1.12em; font-weight: 700; padding: 0 34px 8px 0; min-height: 0;
    }
    table.master-table tbody td:first-child::before { content: none; }

    /* The per-row copy button has no column name: pin it to the card's corner */
    table.master-table tbody td[data-label=""]:not(:first-child) {
        position: absolute; top: 8px; right: 8px; display: block; padding: 0; border: 0;
    }
    table.master-table tbody td[data-label=""]::before { content: none; }

    /* "No devices" style rows span the full card */
    table.master-table tbody td[colspan] { display: block; text-align: center; border: 0; padding: 6px 0; }

}

@media (max-width: 420px) {
    table.master-table tbody td { padding-left: 7.8em; }
    table.master-table tbody td::before { width: 7.2em; }
}

@media (max-width: 900px) {
    .main { padding: 14px; }
    .main h1 { font-size: 1.55em; }

    /* Page headers with an action button (Workbench, All Devices) wrap instead of squeezing */
    .header-row { flex-wrap: wrap; gap: 10px; }

    /* Group headers: title on one line, copy buttons wrap underneath */
    .group-header { flex-wrap: wrap; gap: 8px; font-size: 1.05em; }
    .group-header > div { flex-wrap: wrap; }
    .copy-table-btn { padding: 5px 9px; font-size: 0.78em; }

    /* Tracked Devices: the two cards stack full width */
    .roster-box, .tags-box { min-width: 0 !important; max-width: none !important; flex-basis: 100% !important; }

    /* Documentation: article list above the article instead of beside it */
    #docs > div { height: auto !important; }
    #docs > div > div:last-child { flex-direction: column !important; }
    #docs > div > div:last-child > div:first-child {
        width: auto !important; min-width: 0 !important; max-height: 38vh;
    }
    #docs > div > div:last-child > div:last-child { min-height: 60vh; }
    #docContent img { max-width: 100%; height: auto; }
    #docToolbar { flex-wrap: wrap; gap: 8px; }

    /* Modals fill the screen width and scroll inside themselves */
    .modal-content {
        width: auto !important; max-width: none !important;
        margin: 70px 10px 10px !important;           /* clear the fixed 60px top nav */
        max-height: calc(100vh - 80px) !important;
        max-height: calc(100dvh - 80px) !important;
    }
    .modal-header { padding: 14px 14px 8px; }
    .modal-header h2 { font-size: 1.2em; word-break: break-all; }


    /* Device details: Advanced View's source / overview / destination columns stack,
       and the whole dialog scrolls instead of each column scrolling separately */
    #detailsModal .modal-content { height: auto !important; overflow-y: auto !important; display: block !important; }
    #detailsBody { display: block !important; padding: 10px !important; clear: both; }   /* clear the floated header buttons */
    #detailsBody > div[style*="display: flex"] { flex-direction: column !important; padding: 0 !important; gap: 12px !important; }
    #detailsBody [style*="overflow-y: auto"] { overflow: visible !important; flex: none !important; }
    #detailsBody > div[style*="display: flex"] > div { width: 100% !important; flex: none !important; }
    #detailsModal .modal-content td { white-space: normal; word-break: break-word; }

    /* Custom View toolbar buttons wrap */
    #custom button { flex-shrink: 0; }
    #custom > div { flex-wrap: wrap; }
}

@media (max-width: 600px) {
    /* iOS zooms into any focused input under 16px; keep fields at 16px on phones */
    input[type="text"], textarea, select { font-size: 16px !important; }

    .main h1 { font-size: 1.35em; }
    .group-header { font-size: 0.98em; padding: 8px 10px; }
    .modal-content { margin: 66px 6px 6px !important; max-height: calc(100dvh - 72px) !important; }
}

/* ---------------------------------------------------------------------------------------
 *  Excel-style filters (excel-filter.js)
 * ------------------------------------------------------------------------------------- */
/* Header dropdown button: takes the old sort icon's spot at the right of the header, next
   to the copy-column icon (sorting is in the menu, and the button shows the sort arrow) */
table.xf-table thead th > .sort-icon { display: none !important; }
table.xf-table thead th > .xf-btn { position: absolute; right: 22px; top: 50%; transform: translateY(-50%); margin: 0; }
table.xf-table thead th:has(> .xf-btn):not(.sortable-th) { position: relative; padding-right: 40px !important; }
.xf-btn {
    display: inline-flex; align-items: center; justify-content: center; vertical-align: middle;
    width: 17px; height: 17px; margin-left: 4px; padding: 0; cursor: pointer;
    border: 1px solid rgba(255,255,255,0.35); border-radius: 4px;
    background: rgba(255,255,255,0.08); color: inherit;
}
.xf-btn:hover { background: rgba(255,255,255,0.22); }
.xf-btn svg { width: 10px; height: 10px; }
.xf-btn.xf-on { background: #f1c40f; border-color: #f1c40f; color: #1f2937; }
.xf-btn.xf-sorted { background: rgba(255,255,255,0.28); border-color: rgba(255,255,255,0.6); }
.col-filter-btn.xf-on { color: #f1c40f !important; opacity: 1 !important; }

/* Dropdown menu (desktop) / bottom sheet (phones) */
.xf-menu {
    position: fixed; z-index: 2600; width: 290px; display: flex; flex-direction: column;
    padding: 6px 0; overflow: hidden; font-size: 14px; text-align: left;
    background: var(--bg-card); color: var(--text-main);
    border: 1px solid var(--border-color); border-radius: 8px; box-shadow: 0 12px 32px rgba(0,0,0,0.5);
}
.xf-head { display: none; }
.xf-item {
    display: flex; align-items: center; gap: 10px; padding: 7px 14px; cursor: pointer;
    background: none; border: 0; color: inherit; font: inherit; text-align: left;
}
.xf-item:hover:not(:disabled) { background: var(--hover-bg); }
.xf-item:disabled { opacity: 0.45; cursor: default; }
.xf-item svg { width: 14px; height: 14px; flex: none; }
.xf-item.xf-checked { color: #3498db; font-weight: 700; }
.xf-sep { height: 1px; margin: 4px 0; background: var(--border-light); }
.xf-search {
    margin: 6px 12px; padding: 7px 9px; font: inherit; color: var(--text-main);
    background: var(--input-bg); border: 1px solid var(--border-color); border-radius: 5px;
}
.xf-list {
    flex: 1 1 auto; min-height: 80px; max-height: 260px; overflow-y: auto;
    margin: 0 12px; padding: 4px 0; border: 1px solid var(--border-light); border-radius: 5px;
}
.xf-opt { display: flex; align-items: center; gap: 8px; padding: 4px 10px; cursor: pointer; white-space: nowrap; }
.xf-opt span { overflow: hidden; text-overflow: ellipsis; }
.xf-opt:hover { background: var(--hover-bg); }
.xf-opt[hidden] { display: none; }
.xf-all { font-weight: 600; border-bottom: 1px solid var(--border-light); }
.xf-empty { padding: 8px 10px; color: var(--text-muted); }
.xf-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 12px 6px; }
.xf-actions button {
    min-width: 76px; padding: 6px 12px; cursor: pointer; font: inherit;
    background: transparent; color: inherit; border: 1px solid var(--border-color); border-radius: 5px;
}
.xf-actions .xf-ok { background: #3498db; border-color: #3498db; color: #fff; font-weight: 600; }
.xf-actions .xf-ok:disabled { opacity: 0.5; cursor: default; }

.xf-backdrop { position: fixed; inset: 0; z-index: 2590; background: rgba(0,0,0,0.5); }
.xf-menu.xf-sheet {
    left: 0 !important; right: 0; bottom: 0; top: auto !important; margin: 0 auto;
    width: auto; max-width: 560px; max-height: 82vh !important; max-height: 82dvh !important;
    border-radius: 14px 14px 0 0; padding-bottom: calc(6px + env(safe-area-inset-bottom));
    font-size: 15px;
}
.xf-sheet .xf-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 16px 10px; margin-bottom: 4px; font-weight: 700; font-size: 1.05em;
    border-bottom: 1px solid var(--border-light);
}
.xf-x { background: none; border: 0; color: inherit; font-size: 1.7em; line-height: 1; cursor: pointer; padding: 0 4px; }
.xf-sheet .xf-item { padding: 11px 16px; }
.xf-sheet .xf-opt { padding: 9px 12px; }
.xf-sheet .xf-list { max-height: none; }
.xf-sheet input[type="checkbox"] { width: 18px; height: 18px; }
.xf-sheet .xf-actions button { flex: 1; padding: 11px; }

/* Filter chip bar (cards) */
.xf-bar { display: none; }
@media (max-width: 1100px) {
    .xf-bar {
        display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 10px; overflow: visible;   /* one short row: Filter & sort (+ Card fields / Clear) */
        position: sticky; top: var(--sticky-top, 112px); z-index: 25;
        background: linear-gradient(rgba(0,0,0,0.15), rgba(0,0,0,0.15)), var(--bg-card);
        border-bottom: 1px solid var(--border-color); box-shadow: 0 4px 8px rgba(0,0,0,0.25);
    }
    .xf-bar::-webkit-scrollbar { display: none; }
}
.xf-chip {
    display: inline-flex; align-items: center; gap: 5px; flex: none; padding: 6px 11px; cursor: pointer;
    font: inherit; font-size: 0.82em; white-space: nowrap;
    background: var(--bg-body); color: var(--text-main); border: 1px solid var(--border-color); border-radius: 999px;
}
.xf-chip svg { width: 10px; height: 10px; }
.xf-chip.xf-on { background: #f1c40f; border-color: #f1c40f; color: #1f2937; font-weight: 600; }
.xf-chip.xf-clear { color: #e74c3c; border-color: #e74c3c; }
.xf-chip.xf-fields { background: #3498db; border-color: #3498db; color: #fff; font-weight: 600; }

/* Custom View card-field editor */
.xf-hint { padding: 0 16px 8px; font-size: 0.85em; color: var(--text-muted); }
.xf-fields { flex: 0 0 auto; max-height: 34vh; overflow-y: auto; padding: 0 12px; }   /* never squeezed by the add list */
.xf-field { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--border-light); }
.xf-field-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xf-badge { font-size: 0.7em; padding: 2px 8px; border-radius: 999px; background: #3498db; color: #fff; }
.xf-mini {
    width: 36px; height: 36px; flex: none; cursor: pointer; font-size: 1.1em;
    background: transparent; color: inherit; border: 1px solid var(--border-color); border-radius: 6px;
}
.xf-mini:disabled { opacity: 0.3; cursor: default; }
.xf-mini { display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.xf-mini svg { width: 17px; height: 17px; }
.xf-mini:hover:not(:disabled) { border-color: #3498db; color: #3498db; }
.xf-mini.xf-mini-x:hover:not(:disabled) { border-color: #e74c3c; color: #e74c3c; }

/* Card fields: the same dialog frame as the device details */
.xf-fields-overlay .modal-content.xf-fields-sheet {
    width: 85%; max-width: 550px; margin: 80px auto 20px; max-height: calc(100vh - 100px); max-height: calc(100dvh - 100px);
    display: flex; flex-direction: column; overflow: hidden; font-size: 15px;
}
.xf-fields-sheet .modal-header { flex: none; }
.xf-fields-sheet .xf-fields-title { margin: 0; }
.xf-fields-sheet .xf-hint { padding: 12px 20px 8px; }
.xf-fields-sheet .xf-fields { padding: 0 20px; }
.xf-fields-sheet .xf-add { padding: 0 20px; }
.xf-fields-sheet .xf-actions { padding: 12px 20px 16px; }
.xf-fields-sheet .xf-actions button { flex: 1; padding: 11px; }
.xf-add { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; margin-top: 8px; }
.xf-fields-sheet .xf-list { flex: 1 1 auto; min-height: 110px; }
.xf-fields-sheet .xf-add .xf-search { flex: none; }
.xf-group { padding: 10px 10px 4px; font-size: 0.75em; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-muted); }
.xf-addfield { display: block; width: 100%; padding: 8px 10px; text-align: left; cursor: pointer; background: none; border: 0; color: #3498db; font: inherit; }
.xf-addfield:hover { background: var(--hover-bg); }
.xf-addfield[hidden] { display: none; }
.xf-clear-all { white-space: nowrap; color: #f1c40f !important; border-color: rgba(241,196,15,0.6) !important; }
.xf-clear-all svg { width: 14px; height: 14px; flex: none; }

/* Software menus: documented / undocumented quick picks, doc marker, "None" pinned first */
.xf-picks { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 6px; }
.xf-pick {
    flex: 1; padding: 5px 6px; cursor: pointer; font: inherit; font-size: 0.82em; white-space: nowrap;
    background: transparent; color: #3498db; border: 1px solid rgba(52,152,219,0.55); border-radius: 5px;
}
.xf-pick:hover:not(:disabled) { background: rgba(52,152,219,0.12); }
.xf-pick:disabled { opacity: 0.4; cursor: default; }
.xf-opt.xf-doc span::after {
    content: ''; display: inline-block; width: 9px; height: 11px; margin-left: 6px; vertical-align: -1px;
    border: 1.5px solid #3498db; border-radius: 1.5px; box-sizing: border-box;
    background: linear-gradient(#3498db, #3498db) 2px 3px / 3px 1.5px no-repeat,
                linear-gradient(#3498db, #3498db) 2px 6px / 3px 1.5px no-repeat;
}
.xf-opt.xf-none { font-style: italic; border-bottom: 1px dashed var(--border-light); }

/* Custom View column drag (layout.js): the column moves live as a ghost, a label follows */
#table-custom thead th.custom-th .col-label-row { cursor: grab; }
body.col-dragging, body.col-dragging * { cursor: grabbing !important; user-select: none !important; }
#table-custom .col-ghost {
    opacity: 0.55;
    background-image: repeating-linear-gradient(45deg, rgba(52,152,219,0.16) 0 6px, transparent 6px 12px) !important;
    box-shadow: inset 2px 0 0 #3498db, inset -2px 0 0 #3498db;
}
#table-custom thead th.col-ghost { opacity: 0.8; box-shadow: inset 2px 0 0 #3498db, inset -2px 0 0 #3498db, inset 0 2px 0 #3498db; }
.col-drag-float {
    position: fixed; z-index: 9999; pointer-events: none; white-space: nowrap;
    transform: translate(12px, -50%) rotate(-2deg);
    padding: 7px 12px; font-weight: 700; font-size: 13px; color: #fff;
    background: var(--table-header-bg); border: 1px solid #3498db; border-radius: 6px;
    box-shadow: 0 10px 24px rgba(0,0,0,0.45);
}

/* Filter menu: sections, free-space rule, any/only toggle */
.xf-section { padding: 2px 12px 6px; }
.xf-section-title { font-size: 0.75em; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-muted); padding: 4px 0; }
.xf-list-title { padding: 4px 12px; }
.xf-radio { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; }
.xf-thr { display: flex; align-items: center; gap: 8px; padding: 4px 0 0 24px; color: var(--text-muted); font-size: 0.9em; }
.xf-num {
    width: 64px; padding: 4px 6px; font: inherit; color: var(--text-main);
    background: var(--input-bg); border: 1px solid var(--border-color); border-radius: 4px;
}
.xf-seg { display: flex; margin: 0 12px 6px; border: 1px solid var(--border-color); border-radius: 6px; overflow: hidden; }
.xf-seg-btn {
    flex: 1; padding: 5px 6px; cursor: pointer; font: inherit; font-size: 0.85em; white-space: nowrap;
    background: transparent; color: var(--text-muted); border: 0;
}
.xf-seg-btn + .xf-seg-btn { border-left: 1px solid var(--border-color); }
.xf-seg-btn.on { background: #3498db; color: #fff; font-weight: 600; }
/* Only the value list shrinks when the menu is height-limited; controls keep their size */
.xf-menu > :not(.xf-list):not(.xf-add):not(.xf-fields) { flex-shrink: 0; }

/* ---------- Device info: reasons, presence, snapshot markers ---------- */
.di-waiting { color: var(--text-muted); font-style: italic; }
.di-missing { color: #c0392b; font-weight: 600; }
[data-theme="dark"] .di-missing { color: #f1948a; }
.di-online { color: #27ae60; }
.di-offline { color: #d68910; }
.di-offline-long { color: #c0392b; }
[data-theme="dark"] .di-offline-long { color: #f1948a; }
.di-sub { color: var(--text-muted); font-size: 0.85em; }
.di-inline-clock { width: 11px; height: 11px; vertical-align: -1px; }
.snap-mark { display: inline-flex; vertical-align: -2px; margin-left: 3px; color: var(--text-muted); opacity: 0.8; cursor: help; }
.snap-mark svg { width: 12px; height: 12px; }

/* ---------- Data Synchronization: per-type timing ---------- */
.sync-breakdown:empty { display: none; }
.sync-breakdown { margin-top: 14px; font-size: 0.85em; }
.sync-bd-title { font-weight: 700; margin-bottom: 6px; color: var(--text-main); }
.sync-bd-title span { font-weight: 400; color: var(--text-muted); margin-left: 4px; }
table.sync-bd { width: 100%; border-collapse: collapse; }
table.sync-bd th, table.sync-bd td { text-align: right; padding: 4px 6px; border-bottom: 1px solid var(--border-color); white-space: nowrap; }
table.sync-bd th:first-child, table.sync-bd td:first-child { text-align: left; white-space: normal; }
table.sync-bd th { color: var(--text-muted); font-weight: 600; }
table.sync-bd tbody tr { cursor: help; }
.sync-bd-phases { margin-top: 6px; color: var(--text-muted); line-height: 1.4; }
#syncModal .modal-content { max-width: 460px !important; }

/* Desktop nav between the hamburger breakpoint and wide screens: tighten so the links,
   DEMO pill, theme toggle and sync status all fit on one line */
@media (min-width: 1101px) and (max-width: 1600px) {
    .top-nav .nav-btn { padding: 8px 7px; font-size: 0.9em; }
    .top-nav h2 { margin-right: 8px; font-size: 1.25em; }
    .status-btn { padding: 8px 10px; }
}
@media (min-width: 1101px) and (max-width: 1450px) {
    .st-pre { display: none; }
    .status-btn::before { content: 'Updated '; color: rgba(255,255,255,0.65); }
}
@media (min-width: 1101px) and (max-width: 1250px) {
    .status-btn::before { content: none; }
    .top-nav .nav-btn { padding: 8px 5px; font-size: 0.86em; }
    .nav-logo { margin-right: 6px; }
}
@media (min-width: 1101px) and (max-width: 1180px) {
    .nav-logo { display: none; }
    .top-nav .nav-btn { padding: 8px 4px; }
}

/* Logo + name: the Home link (Overview) */
a.nav-brand { text-decoration: none; color: inherit; cursor: pointer; border-radius: 6px; }
a.nav-brand:hover h2 { color: #d6eaf8; }
a.nav-brand:focus-visible { outline: 2px solid #3498db; outline-offset: 3px; }

/* Device details title: name on the left, Simple / Advanced View toggle on the right, one line */
/* The dialog is wide enough for name + toggle on one line; on a phone that can't fit both,
   the toggle moves under the name rather than cutting the name off */
#detailsTitle { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding-right: 10px; min-width: 0; }
#detailsTitle .dt-name { flex: 0 1 auto; min-width: 0; white-space: nowrap; }
#detailsTitle .dt-name .copy-row-btn { vertical-align: middle; }
#detailsTitle .dt-toggle { flex: 0 0 auto; }
#detailsTitle .dt-toggle {
    margin-left: auto; cursor: pointer; padding: 6px 12px; border-radius: 4px; background: #34495e; color: #fff;
    border: none; font-size: 0.55em; font-weight: bold; white-space: nowrap; transition: background 0.2s;
}
#detailsTitle .dt-toggle:hover { background: #3498db; }
@media (max-width: 700px) { #detailsTitle { font-size: 1.15em; gap: 8px; } }

/* Excel filter: three list modes */
.xf-seg3 .xf-seg-btn { font-size: 0.78em; padding-left: 4px; padding-right: 4px; }

/* Phones / tablets: the "Filter & sort" button and its column list */
.xf-chip.xf-filterbtn { font-weight: 600; padding: 7px 13px; }
.xf-chip.xf-filterbtn svg:first-child { width: 12px; height: 12px; }
.xf-picker .xf-pick-list { overflow-y: auto; min-height: 0; flex: 1 1 auto; padding: 0 8px 8px; }
.xf-pick-col {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 13px 10px; text-align: left; cursor: pointer;
    background: none; border: 0; border-bottom: 1px solid var(--border-light); color: var(--text-main); font: inherit;
}
.xf-pick-col:hover, .xf-pick-col:focus-visible { background: var(--hover-bg); }
.xf-pick-name { flex: 1 1 auto; min-width: 0; font-weight: 600; }
.xf-pick-state { flex: none; font-size: 0.8em; color: var(--text-muted); }
.xf-pick-col.xf-on .xf-pick-state { color: #b7950b; font-weight: 600; }
[data-theme="dark"] .xf-pick-col.xf-on .xf-pick-state { color: #f1c40f; }
.xf-pick-chev { width: 14px; height: 14px; flex: none; color: var(--text-muted); }

/* Card fields: the dialog keeps a fixed height and the two halves share it evenly */
.xf-fields-overlay .modal-content.xf-fields-sheet { height: calc(100vh - 100px); height: calc(100dvh - 100px); }
@media (max-width: 1100px) { .xf-fields-overlay .modal-content.xf-fields-sheet { height: calc(100vh - 80px) !important; height: calc(100dvh - 80px) !important; } }
@media (max-width: 600px) { .xf-fields-overlay .modal-content.xf-fields-sheet { height: calc(100dvh - 72px) !important; } }
.xf-fields-sheet .xf-fields { flex: 1 1 0; min-height: 120px; max-height: none; }
.xf-fields-sheet .xf-add { flex: 1 1 0; min-height: 150px; margin-top: 10px; }
.xf-fields-sheet .xf-add .xf-list { flex: 1 1 auto; min-height: 0; max-height: none; overflow-y: auto; }

/* Details title: when the toggle has to wrap under the name it sits on the left */
#detailsTitle.dt-wrapped .dt-toggle { margin-left: 0; }

/* Card fields: the search box and the add list are as wide as the field rows above them */
.xf-fields-sheet .xf-add .xf-search { margin: 0 0 8px; width: 100%; box-sizing: border-box; }
.xf-fields-sheet .xf-add .xf-list { margin: 0; width: 100%; box-sizing: border-box; }

/* Phones / tablets: the filter bar's own Clear button is enough */
@media (max-width: 1100px) {
    .xf-clear-all { display: none !important; }
}

/* Documentation on phones / tablets: nothing scrolls sideways. Long paths, links and code
   wrap; tables fit the width; the toolbar is title, last edited, then the buttons */
@media (max-width: 1100px) {
    #docContent { overflow-x: hidden; overflow-wrap: anywhere; word-break: break-word; }
    #docContent pre, #docContent pre code { white-space: pre-wrap !important; word-break: break-all; overflow-x: hidden !important; }
    #docContent table { display: table !important; table-layout: fixed; width: 100%; overflow: visible !important; }
    #docContent th, #docContent td { overflow-wrap: anywhere; word-break: break-word; white-space: normal !important; }
    #docContent img { max-width: 100% !important; height: auto !important; }
    #docContent a, #docContent code { overflow-wrap: anywhere; word-break: break-all; }
    #docs, #docs > div, #docs > div > div:last-child > div:last-child { max-width: 100%; overflow-x: hidden; box-sizing: border-box; }
    #docToolbar { flex-wrap: wrap !important; align-items: center; gap: 8px !important; }
    #docToolbar #docHeaderInfo { flex: 1 1 100% !important; min-width: 0; }
    #docToolbar #docDisplayTitle { overflow-wrap: anywhere; }
    #docToolbar > button, #docToolbar > select { flex: 0 0 auto; margin: 0 !important; }
}

/* Phones / tablets: floating Jump button and its sheet */
.jump-btn {
    position: fixed; right: 14px; bottom: calc(var(--dock-h, 40px) + 14px); z-index: 1800;
    display: inline-flex; align-items: center; gap: 6px; padding: 10px 15px 10px 12px;
    background: var(--table-header-bg); color: #fff; border: 1px solid rgba(255,255,255,0.25); border-radius: 999px;
    font: inherit; font-weight: 700; font-size: 0.9em; cursor: pointer; box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}
.jump-btn[hidden] { display: none; }
.jump-btn svg { width: 26px; height: 18px; }
.jump-ends { gap: 8px; }
.jump-end { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; }
.jump-end svg { width: 17px; height: 17px; flex: none; }
.jump-sheet .jump-search { margin: 8px 12px; font-size: 16px; }
.jump-results, .jump-sections { overflow-y: auto; padding: 0 8px; }
.jump-results { max-height: 38vh; }
.jump-sections { max-height: 30vh; }
.jump-item {
    display: flex; align-items: baseline; justify-content: space-between; gap: 10px; width: 100%;
    padding: 12px 10px; background: none; border: 0; border-bottom: 1px solid var(--border-light);
    color: var(--text-main); font: inherit; text-align: left; cursor: pointer;
}
.jump-item:hover, .jump-item:focus-visible { background: var(--hover-bg); }
.jump-item span { font-size: 0.8em; color: var(--text-muted); text-align: right; }
.jump-sec { font-weight: 600; }
.jump-empty { padding: 12px 10px; color: var(--text-muted); font-size: 0.9em; }
@keyframes jump-flash { 0%, 60% { box-shadow: 0 0 0 3px #3498db, 0 0 18px rgba(52,152,219,0.8); } 100% { box-shadow: none; } }
tr.jump-flash { animation: jump-flash 2.2s ease-out; }
