/* small project-specific tweaks on top of Pico */

/* Modal alert/confirm/prompt (see app.js _uiModal) — replaces native dialogs. */
.ui-modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.45);
    display: flex; align-items: center; justify-content: center; z-index: 2000;
}
.ui-modal-box {
    background: var(--pico-background-color, #fff); border-radius: 6px;
    padding: 1.25rem 1.5rem; max-width: 420px; width: calc(100% - 2rem);
    box-shadow: 0 6px 24px rgba(0,0,0,0.3);
}
.ui-modal-message { white-space: pre-wrap; margin: 0 0 1rem; }
.ui-modal-input { width: 100%; margin-bottom: 1rem; }
.ui-modal-buttons { display: flex; justify-content: flex-end; gap: 0.5rem; }
.ui-modal-buttons button { margin: 0; }

/* ----- CSS Tabs (radio-button pattern, no JS required) -----
   Usage:
     <div class="tabs">
       <input type="radio" name="tab" id="tab-a" checked>
       <input type="radio" name="tab" id="tab-b">
       <nav class="tab-nav">
         <label for="tab-a">Tab A</label>
         <label for="tab-b">Tab B</label>
       </nav>
       <article class="tab-panel" id="panel-a">…</article>
       <article class="tab-panel" id="panel-b">…</article>
     </div>
   The Nth radio controls the Nth panel via CSS :checked sibling selectors.
*/
.tabs > input[type="radio"] { display: none; }
.tabs .tab-nav { display: flex; gap: 0; border-bottom: 1px solid #d0d8e4; flex-wrap: wrap;  justify-content: flex-start;}
.tabs .tab-nav label {
    padding: 0.5rem 1.25rem;
    cursor: pointer;
    border: 1px solid transparent;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-size: 0.9rem;
    color: #555;
    user-select: none;
    text-align: left;
}
.tabs .tab-nav label:hover { color: #2c4f7c; }
.tabs .tab-panel { display: none; margin: 0; padding: 1rem; border: 1px solid #d0d8e4; background: none; }

/* Activate the matching panel + highlight its label when a radio is :checked.
   ID-based (not nth-of-type), so the visual tab order is the LABEL order only —
   the radio inputs and panel blocks can sit in any document order. */
#tab-overview:checked   ~ #panel-overview,
#tab-monitoring:checked ~ #panel-monitoring,
#tab-events:checked     ~ #panel-events,
#tab-map:checked        ~ #panel-map,
#tab-terminal:checked   ~ #panel-terminal,
#tab-actions:checked    ~ #panel-actions,
#tab-history:checked    ~ #panel-history { display: block; }

#tab-overview:checked   ~ .tab-nav label[for="tab-overview"],
#tab-monitoring:checked ~ .tab-nav label[for="tab-monitoring"],
#tab-events:checked     ~ .tab-nav label[for="tab-events"],
#tab-map:checked        ~ .tab-nav label[for="tab-map"],
#tab-terminal:checked   ~ .tab-nav label[for="tab-terminal"],
#tab-actions:checked    ~ .tab-nav label[for="tab-actions"],
#tab-history:checked    ~ .tab-nav label[for="tab-history"] {
    color: #2c4f7c;
    border-color: #d0d8e4 #d0d8e4 #fff;
    background: #fff;
    font-weight: 600;
}

/* Slightly denser than Pico's defaults - admin UI, not marketing copy. */
html { font-size: 14px; }
/* 92 vw on most screens; hard cap at 2400 px so lines don't get unreadably
   wide on very large displays. Grows naturally with screen width. */
main.container { max-width: min(92vw, 2400px); }

.badge {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.8em;
    line-height: 1.4;
    font-weight: 600;
}
.badge.online   { background: #d1f5d1; color: #1e6f1e; }
.badge.offline  { background: #f5d1d1; color: #6f1e1e; }
.badge.disabled { background: #e0e0e0; color: #444;   }
.badge.unknown  { background: #f1ecd1; color: #6a5b1e; }
.badge.warn     { background: #fbe4cf; color: #8a4b12; }
.badge-link     { text-decoration: none; }
.badge-link .badge { cursor: pointer; }

/* Ethernet port boxes (device detail overview) */
.port-row { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.port-box {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.9rem; height: 1.9rem; border-radius: 4px;
    font-size: 0.8rem; font-weight: 700; color: #fff;
}
.port-up   { background: #e8821e; }   /* link up @ 10/100 Mbit (orange) */
.port-gbit { background: #1e8e3e; }   /* link up @ 1 Gbit      (green)  */
.port-down { background: #b8b8b8; }   /* no link               (grey)   */

/* Resource usage bars (device detail overview) */
.res-table th { font-weight: 500; width: 11rem; }
.res-table td { vertical-align: middle; }
.res-bar {
    display: inline-block; width: 100%; min-width: 8rem; height: 0.7rem;
    background: #e6e6e6; border-radius: 4px; overflow: hidden; vertical-align: middle;
}
.res-fill { display: block; height: 100%; background: #2d7ff9; border-radius: 4px; }
.res-fill.res-hot { background: #c0392b; }
.res-val { white-space: nowrap; padding-left: 0.6rem; font-variant-numeric: tabular-nums; }
.badge.tag      { background: #e7eef7; color: #2c4f7c; margin-right: 0.15rem; }

/* SIM slot status dots in the device list. */
.sim-icon { font-size: 1.1em; margin-right: 0.2em; cursor: default; }
.sim-connected    { color: #1e6f1e; }
.sim-disconnected { color: #b35900; }
.sim-unknown      { color: #bbb; }

.error {
    color: #6f1e1e;
    background: #f9e0e0;
    border: 1px solid #f5c0c0;
    padding: 0.5rem 0.75rem;
    border-radius: 0.25rem;
    margin: 0.5rem 0;
}

.flash {
    background: #eef5ff;
    border: 1px solid #cfe0ff;
    padding: 0.5rem 0.75rem;
    border-radius: 0.25rem;
}

code.wrap {
    word-break: break-all;
    white-space: normal;
}

.inline-form { display: inline-block; margin: 0 0.4rem 0 0; }

table th { white-space: nowrap; text-align: left; }
/* Row-header column in the 3-column device overview table. */
table.dense tbody th { background: #f9fafb; font-weight: 600; }

/* Horizontal scroll wrapper for wide tables (devices list). */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scroll-x table.dense th,
.scroll-x table.dense td {
    padding: 0.35rem 0.5rem;
    font-size: 0.9rem;
    white-space: nowrap;
}

/* Column chooser dropdown. */
.col-chooser-wrap { position: relative; }
#col-chooser-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 200;
    background: #fff;
    border: 1px solid #d0d8e4;
    border-radius: 0.4rem;
    padding: 0.4rem 0.5rem 0.5rem;
    min-width: 13rem;
    box-shadow: 0 4px 14px rgba(0,0,0,.13);
}
#col-list { list-style: none; margin: 0; padding: 0; }
#col-list li {
    display: flex; align-items: center; gap: 0.35rem;
    padding: 0.18rem 0.25rem; border-radius: 0.25rem;
    font-size: 0.88em; user-select: none;
}
#col-list li:hover { background: #f3f6fa; }
#col-list li.col-drag-over { background: #dce8f8; }
#col-list li.col-dragging { opacity: 0.4; }
.col-drag-handle { cursor: grab; color: #ccc; font-size: 1.05em; line-height: 1; }
#col-list label { display: flex; align-items: center; gap: 0.3rem; cursor: pointer; flex: 1; }
#col-list label input[type="checkbox"] { margin: 0; }
.col-chooser-footer { text-align: right; padding-top: 0.35rem; border-top: 1px solid #eee; margin-top: 0.3rem; }

/* Sub-navigation (within devices/trackers pages). */
.subnav {
    display: flex; gap: 1rem; margin-bottom: 1rem;
    justify-content: flex-start;
    font-size: 0.9em; border-bottom: 1px solid #d0d8e4; padding-bottom: 0.4rem;
}
.subnav a { color: #555; text-decoration: none; }
.subnav a:hover, .subnav a.active { color: #2c4f7c; font-weight: 600; }

/* Toolbar above the list. Two halves: left actions, right controls. */
.toolbar {
    display: flex; gap: 0.4rem; flex-wrap: wrap;
    align-items: center; margin-bottom: 0.75rem;
}
.toolbar-left  { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; flex: 1 1 auto; }
.toolbar-right { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; margin-left: auto; }
.toolbar form { margin: 0; padding: 0; display: inline-flex; }

/* Uniform button sizing across all toolbars. */
.toolbar button, .toolbar a[role="button"],
.toolbar form > button {
    margin: 0;
    padding: 0.35rem 0.75rem;
    font-size: 0.88rem;
    line-height: 1.3;
    box-sizing: border-box;
    white-space: nowrap;
}

/* Toggle switch (show-all, auto-refresh). */
.toggle-wrap {
    display: inline-flex; align-items: center; gap: 0.4rem;
    font-size: 0.88rem; white-space: nowrap; cursor: pointer;
}
.toggle-switch {
    position: relative; display: inline-block;
    width: 2.4rem; height: 1.4rem; flex-shrink: 0;
}
.toggle-switch input[type="checkbox"] {
    opacity: 0; width: 0; height: 0; position: absolute;
}
.toggle-track {
    position: absolute; inset: 0;
    background: #bbb; border-radius: 0.7rem;
    transition: background 0.2s;
}
.toggle-track::before {
    content: ''; position: absolute;
    width: 1rem; height: 1rem;
    left: 0.2rem; top: 0.2rem;
    background: #fff; border-radius: 50%;
    transition: transform 0.18s;
    box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.toggle-switch input:checked + .toggle-track { background: #2c4f7c; }
.toggle-switch input:checked + .toggle-track::before { transform: translateX(1rem); }
.toggle-switch input:focus-visible + .toggle-track { outline: 2px solid #5a8fd4; outline-offset: 2px; }

/* Actions dropdown panel. */
.actions-wrap { position: relative; }
#actions-panel {
    position: absolute; top: calc(100% + 4px); left: 0;
    z-index: 200; background: #fff;
    border: 1px solid #d0d8e4; border-radius: 0.4rem;
    padding: 0.3rem 0; min-width: 16rem;
    box-shadow: 0 4px 14px rgba(0,0,0,.13);
}
.actions-group-label {
    padding: 0.25rem 0.75rem; font-size: 0.75em;
    text-transform: uppercase; letter-spacing: 0.04em;
    color: #888; user-select: none;
}
.actions-divider { border: none; border-top: 1px solid #eee; margin: 0.25rem 0; }
.actions-item {
    display: block; width: 100%;
    padding: 0.35rem 0.75rem; font-size: 0.88rem;
    text-align: left; background: none; border: none;
    cursor: pointer; color: #333;
    border-radius: 0; margin: 0;
}
.actions-item:hover:not(:disabled) { background: #f3f6fa; }
.actions-item:disabled { color: #bbb; cursor: default; }

/* Compact action buttons inside table cells. */
button.small, .button.small { padding: 0.15rem 0.5rem; font-size: 0.85em; }

/* Action result modal overlay. */
.action-modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.35);
    z-index: 500; display: flex; align-items: center; justify-content: center;
}
.action-modal {
    background: #fff; border-radius: 0.5rem; padding: 1.25rem 1.5rem;
    min-width: 22rem; max-width: 90vw; max-height: 80vh;
    overflow-y: auto; box-shadow: 0 8px 30px rgba(0,0,0,.18);
}
.action-modal h3 { margin-top: 0; font-size: 1rem; }
.action-result-list { list-style: none; padding: 0; margin: 0.5rem 0; font-size: 0.88rem; }
.action-result-list li { padding: 0.2rem 0; display: flex; gap: 0.5rem; }
.action-result-list .r-ok      { color: #1e6f1e; }
.action-result-list .r-err     { color: #6f1e1e; }
.action-result-list .r-queued  { color: #888; }

.group-edit-link { margin-left: 0.35em; text-decoration: none; }

/* Task group picker popup (for Execute task action). */
#task-picker-modal select { width: 100%; margin-bottom: 0.5rem; }

/* Sortable headers. */
table.sortable thead tr:first-child th[data-sort] {
    cursor: pointer;
    user-select: none;
    position: relative;
}
table.sortable thead tr:first-child th[data-sort]:hover { background: #f0f4f8; }
table.sortable thead tr:first-child th[data-sort]::after {
    content: '\2195'; /* up-down arrow when unsorted */
    opacity: 0.3;
    margin-left: 0.3em;
    font-size: 0.85em;
}
table.sortable thead tr:first-child th[data-sort].sort-asc::after  { content: '\25B2'; opacity: 1; }
table.sortable thead tr:first-child th[data-sort].sort-desc::after { content: '\25BC'; opacity: 1; }
/* Secondary / tertiary sort indicators (dimmer). */
table.sortable thead tr:first-child th[data-sort].sort-2::after { opacity: 0.55; font-size: 0.75em; }
table.sortable thead tr:first-child th[data-sort].sort-3::after { opacity: 0.35; font-size: 0.65em; }

/* Filter row dropdown selects. */
table.sortable thead tr.filter-row select[data-filter] {
    width: 100%; min-width: 5rem; height: 2rem;
    padding: 0.1rem 0.3rem; font-size: 0.8rem;
    border-radius: 8px; border: 1px solid #ccc;
    margin: 0; box-shadow: none; background: #fff;
}

/* Filter row sits directly under the sortable headers. */
table.sortable thead tr.filter-row th { padding: 0.2rem 0.3rem; background: #f9fafb; }
table.sortable thead tr.filter-row input[data-filter] {
    width: 100%;
    min-width: 4rem;
    height: 2rem;
    padding: 0.15rem 0.5rem;
    font-size: 0.8rem;
    border-radius: 8px;
    border: 1px solid #ccc;
    margin: 0;
    line-height: 1.2;
    box-shadow: none;
    background: #fff;
}
/* Hide the type="search" clear button (X) - it adds inconsistent width. */
table.sortable thead tr.filter-row input[data-filter]::-webkit-search-cancel-button {
    -webkit-appearance: none;
}

/* Warning icon shown inline in the VPN Status cell (and elsewhere). */
.warn-icon {
    color: #b35900;
    font-size: 1em;
    cursor: default;
    margin-left: 0.25em;
    vertical-align: middle;
}
/* Orange dot in the VPN Status cell: a task is queued waiting for this device. */
.pending-task-dot {
    display: inline-block;
    width: 0.55em;
    height: 0.55em;
    border-radius: 50%;
    background: #e08a00;
    margin-left: 0.35em;
    vertical-align: middle;
    cursor: default;
}
/* Pico 2 renders [data-tooltip] as a floating ::after pseudo-element.
   Force it above the cell so it doesn't clip under the table border. */
[data-tooltip] { position: relative; }

/* Plain warning text block in the detail page. */
.warn-text {
    color: #b35900;
    display: inline-block;
    font-weight: 500;
}

/* Parameter-set execute: row colouring by current-vs-desired. */
tr.row-match    > td { background: #e7f7df; }
tr.row-mismatch > td { background: #fbe1de; }
tr.row-error    > td { background: #ececec; color: #555; }
tr.row-stale    > td { background: #f5e6e0; color: #7a3a25; }
tr.row-pending  > td { background: #fff8e1; }
tr.row-queued   > td { background: #fff8e1; }
tr.row-skipped  > td { background: #eef5ff; }

/* Command description shown below the catalogue picker. */
.cmd-description { color: #555; font-size: 0.85em; min-height: 1.2em; margin: 0.1rem 0 0.4rem; }
.cmd-description:empty { display: none; }

/* Auto-refresh label sits inline in the toolbar. */
.auto-refresh-label { display: inline-flex; align-items: center; gap: 0.35rem; margin: 0; font-size: 0.9em; white-space: nowrap; }
.auto-refresh-label input[type="checkbox"] { margin: 0; }

/* Rendered Codec 12 data preview under the tracker-detail command form. */
.rendered-data {
    font-family: monospace;
    font-size: 0.9em;
    background: #f5f5f7;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    min-height: 1.5rem;
}
.rendered-data:empty::before { content: '—'; color: #999; }

/* Multi-line response panel. */
#cmd-response pre { white-space: pre-wrap; word-break: break-word; }

/* Monitoring tab charts. */
.chart-wrap { position: relative; max-height: 300px; margin-bottom: 0.5rem; }

/* Leaflet zoom control: Pico's global anchor/line-height rules push the +/-
   glyph to the bottom-right instead of Leaflet's expected centered glyph. */
.leaflet-control-zoom-in, .leaflet-control-zoom-out {
    display: flex !important;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
    line-height: normal !important;
}

.leaflet-marker-icon {
    border: none;
    background-color: transparent;
}

/* Collapsible sections in device detail (VPN, boot log, etc.). */
details.section-details > summary {
    font-weight: 600;
    cursor: pointer;
    padding: 0.3rem 0.4rem;
    border-radius: 0.25rem;
    user-select: none;
    color: #2c4f7c;
    list-style: none;
}
details.section-details > summary::-webkit-details-marker { display: none; }
details.section-details > summary::before { content: '▶ '; font-size: 0.75em; }
details.section-details[open] > summary::before { content: '▼ '; }
details.section-details > summary:hover { background: #f3f6fa; }
details.section-details.boot-log > summary { color: #555; font-weight: 500; }
