/* NOTE: Inventory page layout + management dialogs — prefix: mw-im */

/* NOTE: Variation E layout — sidebar + center + bottom strip */

.mw-im-layout {
    display: grid;
    grid-template-columns: var(--mw-im-sidebar-width, 220px) 6px 1fr;
    grid-template-rows: 1fr 6px var(--mw-im-bottom-height, 180px);
    height: var(--mw-full-height);
}

/* NOTE: The sidebar/content divider line lives on the resizer's right edge (col 2/3 boundary), NOT on the
   sidebar, so it is flush with the content column — the grid + bottom-strip horizontal borders meet it with
   no gap across the 6px resizer track. */
.mw-im-sidebar {
    grid-column: 1;
    grid-row: 1 / 4;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.mw-im-sidebar-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.mw-im-sidebar-panel + .mw-im-sidebar-panel {
    border-top: 1px solid var(--mud-palette-lines-default);
}

.mw-im-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--mud-palette-text-secondary);
    border-bottom: 1px solid var(--mud-palette-lines-default);
    flex-shrink: 0;
}

.mw-im-sidebar-tree {
    flex: 1;
    overflow-y: auto;
    padding: 4px 2px;
}

.mw-im-center {
    grid-column: 3;
    grid-row: 1;
    overflow: hidden;
}

.mw-im-bottom {
    grid-column: 3;
    grid-row: 3;
    border-top: 1px solid var(--mud-palette-lines-default);
    display: grid;
    grid-template-columns: calc(50% + var(--mw-im-bottom-offset, 0px)) 6px 1fr;
    overflow: hidden;
}

.mw-im-bottom-panel {
    overflow-y: auto;
}

/* NOTE: Double-rule divider between the two bottom panels — a line on each side of the 6px resizer gap
   (left panel's right edge + right panel's left edge), so it reads as a defined groove. */
.mw-im-bottom > .mw-im-bottom-panel:first-child {
    border-right: 1px solid var(--mud-palette-lines-default);
}

.mw-im-bottom .mw-im-col-resizer + .mw-im-bottom-panel {
    border-left: 1px solid var(--mud-palette-lines-default);
}

/* NOTE: Draggable panel dividers (sidebar↔grid, bottom device-overview↔by-team). Pure Blazor pointer
   events; the 6px grabber fills its own grid track, transparent at rest, primary-tinted on hover/drag. */
.mw-im-col-resizer {
    cursor: col-resize;
    background: transparent;
    transition: background 0.15s;
    z-index: 5;
}

.mw-im-col-resizer:hover,
.mw-im-col-resizer.mw-im-resizing {
    background: var(--mud-palette-primary);
    opacity: 0.4;
}

.mw-im-sidebar-resizer {
    grid-column: 2;
    grid-row: 1 / 4;
    border-right: 1px solid var(--mud-palette-lines-default);
}

/* NOTE: Horizontal divider (grid ↔ bottom strip) — drag vertically to resize the bottom-strip height.
   Lives in its own 6px row track in column 3; the strip's border-top is the rest-state line. */
.mw-im-row-resizer {
    grid-column: 3;
    grid-row: 2;
    cursor: row-resize;
    background: transparent;
    transition: background 0.15s;
    z-index: 5;
}

.mw-im-row-resizer:hover,
.mw-im-row-resizer.mw-im-resizing {
    background: var(--mud-palette-primary);
    opacity: 0.4;
}

/* Full-screen surface that captures pointer moves during a resize drag so events aren't lost over the grid. */
.mw-im-resize-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    cursor: col-resize;
}

.mw-im-resize-overlay--row {
    cursor: row-resize;
}

.mw-im-bottom-header {
    padding: 5px 10px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--mud-palette-text-secondary);
    border-bottom: 1px solid var(--mud-palette-lines-default);
    position: sticky;
    top: 0;
    background: var(--mud-palette-surface);
    z-index: 1;
}

.mw-im-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 10px;
    font-size: 0.78rem;
}

.mw-im-borrowed-row {
    display: grid;
    grid-template-columns: 1fr 1fr 40px;
    padding: 3px 10px;
    font-size: 0.75rem;
    align-items: center;
}

.mw-im-borrowed-team {
    font-weight: 500;
}

.mw-im-borrowed-cat {
    color: var(--mud-palette-text-secondary);
}

/* NOTE: Every borrowed-by-team row is a rented count → share the amber "rented" colour used by
   MwAvailabilityCount, so the number language reads consistently across the page. */
.mw-im-borrowed-count {
    font-family: 'JetBrains Mono', monospace;
    text-align: right;
    font-size: 0.72rem;
    color: var(--mud-palette-warning);
}

/* NOTE: Sidebar filter tree nodes */

.mw-im-filter-node {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px 3px 4px;
    border-radius: 4px;
    font-size: 0.78rem;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.1s;
}

/* NOTE: Fixed-width, centred chevron slot so the tree-connector trunk always emanates from the same X. */
.mw-im-expand {
    width: 20px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.mw-im-filter-node:hover {
    background-color: var(--mud-palette-action-default-hover);
}

.mw-im-filter-node.active {
    background-color: var(--mud-palette-primary-lighten);
    color: var(--mud-palette-primary);
}

.mw-im-filter-node .mw-im-dot {
    width: 8px;
    height: 8px;
}

/* NOTE: Nested tree connectors — mirrors the MwDataGrid tree (`└` at the last child, `├` + a through-line
   for the rest, and a trunk from each open chevron down to its children). Pure CSS: `:last-child` picks the
   `└` vs `├`, `:not(:empty)` gates the trunk to expanded nodes. The guide line sits under the parent's
   chevron centre (node padding-left 4 + chevron half 10 = 14; children indent 16 → guide at -2 of the child). */
.mw-im-filter-children {
    padding-left: 16px;
    position: relative;
}

.mw-im-cat-node,
.mw-im-loc-node {
    position: relative;
}

/* Incoming vertical (row top → row centre) for every child row. */
.mw-im-filter-children > .mw-im-cat-node > .mw-im-filter-node::before,
.mw-im-filter-children > .mw-im-loc-node > .mw-im-filter-node::before {
    content: "";
    position: absolute;
    left: -2px;
    top: -1px;
    height: calc(50% + 1px);
    width: 1px;
    background: var(--mud-palette-lines-default);
    pointer-events: none;
}

/* Horizontal elbow (row centre → chevron left edge). */
.mw-im-filter-children > .mw-im-cat-node > .mw-im-filter-node::after,
.mw-im-filter-children > .mw-im-loc-node > .mw-im-filter-node::after {
    content: "";
    position: absolute;
    left: -2px;
    top: 50%;
    width: 6px;
    height: 1px;
    background: var(--mud-palette-lines-default);
    pointer-events: none;
}

/* Leaf rows (no chevron) extend the elbow past the placeholder to almost reach the colour dot. */
.mw-im-filter-children > .mw-im-cat-node > .mw-im-filter-node:not(.mw-im-has-children)::after,
.mw-im-filter-children > .mw-im-loc-node > .mw-im-filter-node:not(.mw-im-has-children)::after {
    width: 24px;
}

/* Non-last children keep the vertical running full height (`├` trunk + through-line past their subtree). */
.mw-im-filter-children > .mw-im-cat-node:not(:last-child)::before,
.mw-im-filter-children > .mw-im-loc-node:not(:last-child)::before {
    content: "";
    position: absolute;
    left: -2px;
    top: 12px;
    bottom: -1px;
    width: 1px;
    background: var(--mud-palette-lines-default);
    pointer-events: none;
}

/* Trunk from an open chevron down to its children's branch lines (only when the group is expanded). */
.mw-im-filter-children:not(:empty)::before {
    content: "";
    position: absolute;
    left: 14px;
    top: -14px;
    height: 14px;
    width: 1px;
    background: var(--mud-palette-lines-default);
    pointer-events: none;
}

.mw-im-filter-count {
    margin-left: auto;
    font-size: 0.68rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--mud-palette-text-secondary);
}

/* NOTE: Editable sidebar tree — rename input, hover Add/Color/Delete menu, drag drop-zones */
.mw-im-filter-node {
    position: relative;
}

.mw-im-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mw-im-filter-node .mw-im-node-actions {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    align-items: center;
    gap: 2px;
    background: var(--mud-palette-surface);
    padding: 0 2px;
    border-radius: 4px;
}

.mw-im-filter-node:hover .mw-im-node-actions {
    opacity: 1;
}

/* Empty child zones become droppable targets only while a tree drag is active */
.mw-im-tree-dragging .mw-im-filter-children:empty {
    min-height: 12px;
    outline: 1px dashed var(--mud-palette-primary);
    outline-offset: -3px;
    border-radius: 4px;
}

/* NOTE: Filter chip bar */

.mw-im-filter-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: var(--mud-palette-surface);
    border-bottom: 1px solid var(--mud-palette-lines-default);
    flex-wrap: wrap;
    min-height: 30px;
}

.mw-im-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    background: var(--mud-palette-primary-lighten);
    color: var(--mud-palette-primary);
    cursor: pointer;
    transition: background-color 0.1s;
}

.mw-im-filter-chip:hover {
    background: var(--mud-palette-primary-hover);
}

/* NOTE: Management dialogs */

.mw-im-tree-zone {
    min-height: 40px;
    padding: 4px 0;
}

.mw-im-node {
    margin-left: 0;
}

.mw-im-node-content {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 4px;
}

.mw-im-drag-handle {
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
}

.mw-im-node-content:hover {
    background-color: var(--mud-palette-action-default-hover);
}

.mw-im-node-selected {
    background-color: var(--mud-palette-primary-lighten) !important;
}

.mw-im-child-zone {
    margin-left: 24px;
    min-height: 8px;
    border-left: 1px dashed var(--mud-palette-lines-default);
    padding-left: 8px;
}

.mw-im-color-dot {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.mw-im-color-dot::-webkit-color-swatch-wrapper {
    padding: 0;
}

.mw-im-color-dot::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
}

.mw-im-color-dot::-moz-color-swatch {
    border: none;
    border-radius: 50%;
}

.mw-im-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.mw-im-name {
    flex: 1;
    min-width: 0;
}

.mw-im-name-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: 1px solid var(--mud-palette-primary);
    border-radius: 4px;
    color: inherit;
    font: inherit;
    padding: 2px 6px;
    outline: none;
    user-select: text;
    cursor: text;
}

.mw-im-count {
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
    margin-left: auto;
    flex-shrink: 0;
}

.mw-im-node-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.12s;
    flex-shrink: 0;
}

.mw-im-node-content:hover .mw-im-node-actions {
    opacity: 1;
}
