/* ===== FEATURE TABLE DOCK =====
   Bottom-docked, tabbed attribute table. Positioned against the viewport, the
   same convention #layer-switcher uses (.content-container has no `position`,
   so absolute resolves to the initial containing block).
   z-index 1002: above #layer-switcher (1000) and .floating-control (1001),
   below the modal/backdrop layer (9998+). */

#feature-dock {
    position: absolute;
    /* Starts at the layer switcher's right edge. Derived from the same custom
       properties style.css sizes the panel with, so dragging the panel's resize
       handle moves this edge too; it used to be the literal 370px. */
    left: calc(var(--sidebar-width, 70px) + var(--layer-switcher-width, 300px));
    right: 0;
    bottom: 0;
    z-index: 1002;
    height: 300px;
    background: #fff;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Work Sans', sans-serif;
    transition: left 0.2s ease;
}

/* Layer switcher hidden -> dock extends to the sidebar edge */
#feature-dock.switcher-hidden {
    left: var(--sidebar-width, 70px);
}

/* While the panel's edge is being dragged, the dock must track it frame for frame.
   The `transition: left` above exists for the switcher's show/hide toggle, which is
   a single jump; during a drag it makes the dock ease toward each new position and
   trail the pointer by a fifth of a second. body.layer-resizing is set for exactly
   the duration of the drag (see style.css and the handler in script.js). */
body.layer-resizing #feature-dock {
    transition: none;
}

#feature-dock.collapsed {
    height: 40px !important;
}

/* ----- Resize handle ----- */
.fd-resize {
    height: 6px;
    flex-shrink: 0;
    cursor: ns-resize;
    background: #f0f0f0;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fd-resize:hover,
.fd-resize.resizing {
    background: #B5D6F4;
}

.fd-resize-grip {
    width: 36px;
    height: 3px;
    border-radius: 2px;
    background: #bbb;
}

.fd-resize:hover .fd-resize-grip {
    background: #0E69B5;
}

/* Prevents text selection while dragging the resize handle */
body.fd-resizing {
    user-select: none;
    cursor: ns-resize;
}

/* ----- Tab strip ----- */
.fd-tabs {
    display: flex;
    align-items: stretch;
    background: #F0F0F0;
    border-bottom: 1px solid #ccc;
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.fd-tab {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 9px 14px;
    border: none;
    background: transparent;
    color: #818181;
    cursor: pointer;
    font-family: 'Work Sans', sans-serif;
    font-size: 13px;
    font-weight: 500;
    border-top: 3px solid transparent;
    white-space: nowrap;
    flex-shrink: 0;
}

.fd-tab i {
    font-size: 12px;
}

.fd-tab.active {
    background: #fff;
    color: #333;
    border-top-color: #0E69B5;
}

.fd-tab-count {
    background: #e0e0e0;
    color: #666;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 600;
}

.fd-tab.active .fd-tab-count {
    background: #B5D6F4;
    color: #0E69B5;
}

.fd-tab-close {
    background: transparent;
    border: none;
    color: inherit;
    opacity: 0.6;
    cursor: pointer;
    font-size: 11px;
    padding: 2px 3px;
    border-radius: 3px;
    display: inline-flex;
    align-items: center;
}

.fd-tab-close:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.08);
}

.fd-tabs-spacer {
    flex: 1;
    min-width: 12px;
}

.fd-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 8px;
    flex-shrink: 0;
}

.fd-icon-btn {
    background: transparent;
    border: none;
    color: #818181;
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fd-icon-btn:hover {
    background: #e0e0e0;
    color: #333;
}

/* ----- Filter chips ----- */
.fd-filters {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 14px;
    background: #f8f8f8;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

.fd-filters-icon {
    color: #818181;
    font-size: 12px;
    margin-right: 2px;
}

.fd-filters-empty {
    font-size: 12px;
    color: #999;
}

.fd-chip-wrap {
    position: relative;
}

.fd-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px 4px 10px;
    background: #E4F0FA;
    border: 1px solid #B5D6F4;
    border-radius: 14px;
    font-size: 12px;
    color: #0E69B5;
    cursor: pointer;
}

.fd-chip:hover {
    background: #d6e8f7;
}

.fd-chip.editing {
    background: #0E69B5;
    color: #fff;
    border-color: #0E69B5;
}

.fd-chip-remove {
    border: none;
    background: rgba(14, 105, 181, 0.12);
    color: inherit;
    cursor: pointer;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    font-size: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
}

.fd-chip.editing .fd-chip-remove {
    background: rgba(255, 255, 255, 0.25);
}

.fd-chip-add {
    border: 1px dashed #B5D6F4;
    background: transparent;
    color: #0E69B5;
    cursor: pointer;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 14px;
    font-weight: 600;
    font-family: 'Work Sans', sans-serif;
}

.fd-chip-add:hover {
    background: #E4F0FA;
}

/* Disabled once every attribute carries a condition, or at the shared cap. The
   :hover rule above would otherwise still light the button up. */
.fd-chip-add:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.fd-chip-add:disabled:hover {
    background: transparent;
}

.fd-filters-clear {
    margin-left: 4px;
    border: none;
    background: transparent;
    color: #999;
    cursor: pointer;
    font-size: 12px;
    text-decoration: underline;
    font-family: 'Work Sans', sans-serif;
}

.fd-filters-clear:hover {
    color: #666;
}

/* ----- Inline chip editor ----- */
.fd-chip-editor {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 40;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 320px;
}

.fd-chip-editor-row {
    display: flex;
    gap: 5px;
}

.fd-chip-editor select {
    font-size: 12px;
    padding: 5px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    color: #333;
    min-width: 0;
    font-family: 'Work Sans', sans-serif;
}

.fd-chip-editor .fd-editor-field {
    flex: 2;
}

.fd-chip-editor .fd-editor-operator {
    flex: 1;
    min-width: 60px;
}

.fd-chip-editor .fd-editor-value {
    flex: 2;
    min-width: 0;
    display: flex;
}

/* Multi-value checkbox dropdown inside the chip editor — match the 12px selects */
.fd-chip-editor .filter-value-trigger {
    font-size: 12px;
    padding: 5px 6px;
    border-radius: 4px;
    font-family: 'Work Sans', sans-serif;
}

.fd-chip-editor .filter-value-panel {
    z-index: 50;
}

.fd-chip-editor .filter-value-option {
    font-size: 12px;
    font-family: 'Work Sans', sans-serif;
}

/* Typeahead layout inside the chip editor — match the 12px selects. font-family
   needs no override: .filter-value-input inherits and #feature-dock sets Work Sans. */
.fd-chip-editor .filter-value-box {
    font-size: 12px;
    padding: 3px 4px;
    border-radius: 4px;
}

.fd-chip-editor .filter-value-input {
    font-size: 12px;
}

.fd-chip-editor .filter-value-chip {
    font-size: 11px;
}

/* Also covers the pre-existing "no values" line, which was stuck at 11px here. */
.fd-chip-editor .filter-value-empty {
    font-size: 12px;
}

.fd-chip-editor-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.fd-editor-apply,
.fd-editor-delete {
    font-size: 12px;
    padding: 5px 12px;
    border-radius: 4px;
    border: 1px solid #ccc;
    cursor: pointer;
    background: #fff;
    color: #333;
    font-family: 'Work Sans', sans-serif;
}

.fd-editor-apply {
    background: #0E69B5;
    color: #fff;
    border-color: #0E69B5;
}

.fd-editor-delete {
    color: #c0392b;
}

/* ----- Toolbar (count + export) ----- */
.fd-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    padding: 6px 14px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

.fd-count {
    font-size: 12px;
    color: #666;
}

.fd-export {
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #ccc;
    background: #fff;
    color: #333;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 600;
    font-family: 'Work Sans', sans-serif;
}

.fd-export:hover {
    background: #f0f0f0;
}

.fd-export:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== SELECTION TRAY =====
   Lists every selected feature, whichever page it came from. A flex sibling of
   .fd-body, not a child: .fd-body is the only scroll container and owns the
   sticky thead at top:0, so a nested tray would either scroll away or fight the
   header for the same offset. Rendered only when something is selected. */
.fd-selection-panel {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #F5FAFE;
    border-bottom: 2px solid #0E69B5;
}

.fd-selection-head {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 32px;
    padding: 0 14px;
    background: #E4F0FA;
    flex-shrink: 0;
}

.fd-selection-toggle {
    display: flex;
    align-items: center;
    gap: 7px;
    border: none;
    background: transparent;
    color: #0E69B5;
    cursor: pointer;
    font-family: 'Work Sans', sans-serif;
    font-size: 12px;
    font-weight: 600;
    padding: 0;
    white-space: nowrap;
}

.fd-selection-toggle i {
    font-size: 10px;
    width: 10px;
}

/* The count is information, not decoration, so it clears 4.5:1 like any other
   text. Brand #0E69B5 on #B5D6F4 measures 3.75:1 and fails; #0A4E88 on the same
   fill measures 5.65:1. Same reasoning at the cap: #B35C00 on #FDE7CC is 3.90:1,
   #8A4700 is 5.86:1. */
.fd-selection-count {
    background: #B5D6F4;
    color: #0A4E88;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 600;
}

/* At MAX_SELECTION the pill changes hue AND carries a title, never colour alone. */
.fd-selection-count.at-limit {
    background: #FDE7CC;
    color: #8A4700;
}

.fd-selection-spacer {
    flex: 1;
    min-width: 8px;
}

/* Outlined rather than filled: it is the tray's primary action, but must not
   out-shout the neutral layer-scoped exports sitting just above it. */
.fd-selection-export {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #fff;
    border: 1px solid #0E69B5;
    color: #0E69B5;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Work Sans', sans-serif;
    white-space: nowrap;
}

.fd-selection-export:hover {
    background: #E4F0FA;
}

.fd-selection-icon-btn {
    background: transparent;
    border: none;
    color: #0E69B5;
    cursor: pointer;
    width: 26px;
    height: 26px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.fd-selection-icon-btn:hover {
    background: #B5D6F4;
}

.fd-selection-rows {
    overflow: auto;
    min-height: 0;
}

/* ----- Tray resize handle ----- */
.fd-selection-grip {
    height: 6px;
    flex-shrink: 0;
    cursor: ns-resize;
    background: #E4F0FA;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fd-selection-grip:hover,
.fd-selection-grip.resizing {
    background: #B5D6F4;
}

.fd-selection-grip-bar {
    width: 36px;
    height: 3px;
    border-radius: 2px;
    background: #7FB3E0;
}

/* Rows whose attributes have not arrived yet. Distinct from .fd-skel-bar: this
   one sits on the selected-row fill, so it needs a blue-tinted ramp. */
.fd-sel-skel-bar {
    height: 12px;
    width: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, #cfe3f5 25%, #e8f2fb 37%, #cfe3f5 63%);
    background-size: 400% 100%;
    animation: fd-sel-skel 1.3s ease infinite;
}

@keyframes fd-sel-skel {
    0%   { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* One pulse when a map click reveals an off-page feature in the tray. */
@keyframes fd-flash {
    0%   { background: #fff; }
    35%  { background: #7FB3E0; }
    100% { background: #B5D6F4; }
}

.fd-table tbody tr.fd-row-flash td {
    animation: fd-flash 600ms ease-out 1;
}

/* Footer suffix naming the rows the tray lifted out of this page. */
.fd-footer-lifted {
    color: #0E69B5;
}

/* ----- Per-layer highlight colour ----- */
.fd-highlight {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #818181;
    cursor: pointer;
}

.fd-highlight-input {
    width: 26px;
    height: 20px;
    padding: 0;
    border: 1px solid #ccc;
    border-radius: 3px;
    background: none;
    cursor: pointer;
}

/* Browsers wrap the swatch in padded chrome; strip it so the control reads as
   a plain colour chip rather than a button. */
.fd-highlight-input::-webkit-color-swatch-wrapper { padding: 0; }
.fd-highlight-input::-webkit-color-swatch { border: none; border-radius: 2px; }
.fd-highlight-input::-moz-color-swatch { border: none; border-radius: 2px; }

.fd-highlight-input:focus-visible {
    outline: 2px solid #0E69B5;
    outline-offset: 1px;
}

/* ----- Spatial export menu ----- */
.fd-export-wrap {
    position: relative;
    display: inline-flex;
}

/* Fixed, not absolute: #feature-dock is overflow:hidden, so an absolutely
   positioned menu gets clipped by the dock's top edge (and by its bottom edge
   if opened downward on a short dock). Coordinates are set by positionExportMenu(). */
.fd-export-menu {
    position: fixed;
    top: -9999px;
    left: -9999px;
    z-index: 1100;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    padding: 4px;
    display: flex;
    flex-direction: column;
    min-width: 150px;
}

/* Names the scope the formats below will act on, so "CSV" in the tray's menu is
   not mistaken for the layer-wide CSV button sitting just above it. */
.fd-export-menu-title {
    font-size: 11px;
    color: #818181;
    padding: 6px 12px 7px;
    border-bottom: 1px solid #eee;
    margin-bottom: 4px;
    white-space: nowrap;
}

.fd-export-menu-item {
    border: none;
    background: transparent;
    color: #333;
    cursor: pointer;
    font-size: 13px;
    font-family: 'Work Sans', sans-serif;
    text-align: left;
    padding: 8px 12px;
    border-radius: 4px;
    white-space: nowrap;
}

.fd-export-menu-item:hover {
    background: #E4F0FA;
    color: #0E69B5;
}

/* ----- Table ----- */
/* min-height is load-bearing, not cosmetic. The selection tray is a flex sibling,
   so without a floor here it squeezes the table to zero at the 300px default dock
   and the dock renders as a tray with a pager glued underneath. 96px keeps the
   sticky header plus about two rows. Kept in sync with MIN_TABLE_HEIGHT in
   feature-table.js, which sizes the tray against it. */
.fd-body {
    flex: 1;
    min-height: 96px;
    overflow: auto;
    position: relative;
    display: flex;
    flex-direction: column;
}

.fd-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.fd-table thead th {
    position: sticky;
    top: 0;
    background: #f2f2f2;
    text-align: left;
    padding: 8px 10px;
    border-bottom: 2px solid #ddd;
    color: #555;
    font-weight: 600;
    white-space: nowrap;
    z-index: 2;
}

/* Two pinned leading columns: checkbox (left 0) then zoom (left 34px). */
.fd-table th.fd-col-check,
.fd-table td.fd-col-check {
    position: sticky;
    left: 0;
    width: 34px;
    padding: 4px 6px;
    text-align: center;
}

.fd-table th.fd-col-zoom,
.fd-table td.fd-col-zoom {
    position: sticky;
    left: 34px;
    width: 34px;
    padding: 4px 6px;
}

.fd-table thead th.fd-col-check,
.fd-table thead th.fd-col-zoom {
    background: #f2f2f2;
    z-index: 3;
}

.fd-table tbody td.fd-col-check,
.fd-table tbody td.fd-col-zoom {
    background: #fff;
    z-index: 1;
}

.fd-table tbody tr:nth-child(even) td.fd-col-check,
.fd-table tbody tr:nth-child(even) td.fd-col-zoom {
    background: #fafafa;
}

/* The default 13px box left ~88% of its 46px cell as dead space that fell through
   to the row handler. The row now toggles too, so a near miss is harmless, but a
   13px target is still below the 24px WCAG 2.2 minimum on its own. */
.fd-table td.fd-col-check input[type="checkbox"],
.fd-table th.fd-col-check input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.fd-table td {
    padding: 7px 10px;
    border-bottom: 1px solid #eee;
    color: #333;
    white-space: nowrap;
}

.fd-table tbody tr {
    cursor: pointer;
}

.fd-table tbody tr:nth-child(even) {
    background: #fafafa;
}

.fd-table tbody tr:hover {
    background: #f7f9fb;
}

.fd-table tbody tr.selected {
    background: #B5D6F4;
}

.fd-table tbody tr.selected:hover {
    background: #a8cdf0;
}

.fd-table tbody tr.selected td.fd-col-check {
    background: #B5D6F4;
    box-shadow: inset 3px 0 0 #0E69B5;
}

.fd-table tbody tr.selected td.fd-col-zoom {
    background: #B5D6F4;
}

.fd-zoom-btn {
    border: none;
    background: transparent;
    color: #818181;
    cursor: pointer;
    width: 22px;
    height: 22px;
    border-radius: 4px;
}

.fd-zoom-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    color: #0E69B5;
}

.fd-table tbody tr.selected .fd-zoom-btn {
    color: #0E69B5;
}

/* Link-valued attributes (APP_CONFIG.LINK_FIELDS). Underlined only on hover, so a
   column of them does not out-shout the data cells beside it. */
.fd-table td a {
    color: #0E69B5;
    text-decoration: none;
}

.fd-table td a:hover,
.fd-table td a:focus-visible {
    text-decoration: underline;
}

/* ----- Pager ----- */
.fd-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 7px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    font-size: 12px;
    color: #555;
}

.fd-pager-btn {
    border: none;
    background: transparent;
    color: #0E69B5;
    cursor: pointer;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    font-size: 12px;
}

.fd-pager-btn:hover:not(:disabled) {
    background: #E4F0FA;
}

.fd-pager-btn:disabled {
    color: #ccc;
    cursor: not-allowed;
}

/* ----- State messages ----- */
.fd-message {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #888;
    font-size: 13px;
    padding: 20px;
    text-align: center;
}

.fd-message i {
    font-size: 26px;
    opacity: 0.4;
}

.fd-message button {
    border: 1px solid #0E69B5;
    background: #fff;
    color: #0E69B5;
    cursor: pointer;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    font-family: 'Work Sans', sans-serif;
}

.fd-message button:hover {
    background: #E4F0FA;
}

/* ----- Loading skeleton ----- */
.fd-skel-bar {
    height: 12px;
    border-radius: 3px;
    background: linear-gradient(90deg, #eee 25%, #f6f6f6 37%, #eee 63%);
    background-size: 400% 100%;
    animation: fd-skel 1.3s ease infinite;
}

@keyframes fd-skel {
    0%   { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

@media (prefers-reduced-motion: reduce) {
    .fd-skel-bar { animation: none; }
    .fd-sel-skel-bar { animation: none; }
    /* The reveal still lands the row in view via scrollIntoView; only the pulse goes. */
    .fd-table tbody tr.fd-row-flash td { animation: none; }
    #feature-dock { transition: none; }
}

/* ----- Layer-row table button (lives in the layer switcher) ----- */
.table-layer-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    min-width: 28px;
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 6px;
    border-radius: 3px;
    flex-shrink: 0;
    color: #818181;
}

.table-layer-btn.active {
    color: #0E69B5;
}

/* Focus visibility, matching the app's existing convention */
#feature-dock button:focus-visible,
#feature-dock select:focus-visible,
#feature-dock tr:focus-visible,
.table-layer-btn:focus-visible {
    outline: 2px solid #0E69B5;
    outline-offset: 1px;
}

.fd-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
