/* Production floor overlay (Work stations grid).
   An aerial view: concrete slab with a faint 1 m grid, each production line a bay outlined in yellow floor tape,
   stations as machine footprints carrying a stencilled post plate. Lines without a line ref sit in a hazard-striped bay.
   Chrome around the floor is quiet shadcn: neutral surface, hairline borders, sentence-case labels.
   Everything is sized from the viewport (grid fr + container query units) so the floor never scrolls. */

.fp-dialog {
    --fp-fg: var(--mud-palette-text-primary);
    --fp-muted: var(--mud-palette-text-secondary);
    --fp-border: var(--mud-palette-lines-default);
    --fp-surface: var(--mud-palette-surface);
    --fp-concrete: color-mix(in srgb, var(--mud-palette-background-gray) 85%, var(--mud-palette-text-secondary) 15%);
    --fp-concrete-grid: color-mix(in srgb, var(--mud-palette-text-primary) 7%, transparent);
    --fp-bay: color-mix(in srgb, var(--mud-palette-surface) 55%, var(--mud-palette-background-gray) 45%);
    --fp-tape: #E8B004;          /* floor-marking yellow: the one accent, used only for line boundaries */
    --fp-hazard: #1F2328;
    --fp-stencil: 'Barlow Semi Condensed', 'Roboto Condensed', 'Arial Narrow', sans-serif;
    --fp-radius: 12px;

    position: fixed; inset: 16px; z-index: 1400;
    display: flex; flex-direction: column;
    background: var(--fp-surface); color: var(--fp-fg);
    border: 1px solid var(--fp-border); border-radius: var(--fp-radius);
    box-shadow: 0 24px 64px -16px rgba(15, 23, 42, .35);
    overflow: hidden; outline: none;
    animation: fp-open .18s ease-out;
}
.fp-backdrop {
    position: fixed; inset: 0; z-index: 1399;
    background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px);
}
@keyframes fp-open { from { opacity: 0; transform: scale(.985); } to { opacity: 1; transform: none; } }

/* ── Header ── */
.fp-header {
    display: flex; align-items: center; gap: 12px; flex: none;
    padding: 12px 16px; border-bottom: 1px solid var(--fp-border);
}
.fp-header-text { flex: 1 1 auto; min-width: 0; }
.fp-title { margin: 0; font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; }
.fp-summary {
    margin: 1px 0 0; font-size: .8125rem; color: var(--fp-muted); line-height: 1.4;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fp-search {
    display: inline-flex; align-items: center; gap: 6px; height: 34px; width: min(240px, 40vw);
    padding: 0 10px; border: 1px solid var(--fp-border); border-radius: 6px; color: var(--fp-muted);
    background: var(--fp-surface);
}
.fp-search:focus-within { outline: 2px solid var(--fp-fg); outline-offset: 1px; }
.fp-search input {
    flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
    font: inherit; font-size: .875rem; color: var(--fp-fg);
}
.fp-close {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 34px; height: 34px; border-radius: 6px; border: 1px solid transparent;
    background: transparent; color: var(--fp-muted); cursor: pointer;
}
.fp-close:hover { background: var(--mud-palette-background-gray); color: var(--fp-fg); }
.fp-close:focus-visible { outline: 2px solid var(--fp-fg); outline-offset: 1px; }

/* ── Floor slab ── */
.fp-floor {
    flex: 1 1 auto; min-height: 0;
    display: grid; gap: 14px; padding: 14px;
    grid-template-columns: repeat(var(--fp-floor-cols, 1), minmax(0, 1fr));
    grid-template-rows: repeat(var(--fp-floor-rows, 1), minmax(0, 1fr));
    background-color: var(--fp-concrete);
    background-image:
        linear-gradient(var(--fp-concrete-grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--fp-concrete-grid) 1px, transparent 1px);
    background-size: 28px 28px;
    background-position: -1px -1px;
}
.fp-floor-empty { display: flex; align-items: center; justify-content: center; }
.fp-floor-empty p {
    max-width: 44ch; margin: 0; text-align: center; font-size: .875rem; color: var(--fp-muted);
    background: var(--fp-surface); padding: 12px 16px; border-radius: 8px; border: 1px solid var(--fp-border);
}

/* ── Bay (one production line) ── */
.fp-bay {
    display: flex; flex-direction: column; min-height: 0; min-width: 0;
    background: var(--fp-bay);
    border: 3px solid var(--fp-tape); border-radius: 3px;
    padding: 6px 10px 10px;
}
.fp-bay-unassigned {
    border: 3px solid transparent;
    background:
        linear-gradient(var(--fp-bay), var(--fp-bay)) padding-box,
        repeating-linear-gradient(-45deg, var(--fp-tape) 0 10px, var(--fp-hazard) 10px 20px) border-box;
}
.fp-bay-head {
    display: flex; align-items: baseline; gap: 8px; flex: none; min-width: 0;
    margin-bottom: 6px;
}
.fp-bay-name {
    font-family: var(--fp-stencil); font-weight: 700; font-size: clamp(.875rem, 1.6vh, 1.0625rem);
    letter-spacing: .02em; line-height: 1.2; color: var(--fp-fg); text-decoration: none;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
a.fp-bay-name:hover { text-decoration: underline; text-underline-offset: 3px; }
a.fp-bay-name:focus-visible { outline: 2px solid var(--fp-fg); outline-offset: 2px; border-radius: 2px; }
.fp-tag {
    flex: none; font-size: .6875rem; font-weight: 500; line-height: 1;
    padding: 3px 6px; border-radius: 4px; border: 1px solid var(--fp-border);
    color: var(--fp-muted); background: var(--fp-surface);
}
.fp-bay-count { flex: none; margin-left: auto; font-size: .75rem; color: var(--fp-muted); white-space: nowrap; }

/* Stations sit on the bay floor in post order; the dashed aisle behind them shows the direction of flow. */
.fp-bay-floor {
    position: relative; flex: 1 1 auto; min-height: 0;
    display: grid; gap: clamp(4px, .8vw, 10px);
    grid-template-columns: repeat(var(--fp-cols, 1), minmax(0, 1fr));
    grid-template-rows: repeat(var(--fp-rows, 1), minmax(0, 1fr));
    container-type: size;
}
.fp-flow {
    position: absolute; left: 0; right: 10px; top: 50%; height: 0; pointer-events: none;
    border-top: 2px dashed color-mix(in srgb, var(--fp-fg) 22%, transparent);
}
.fp-flow::after {
    content: ""; position: absolute; right: -10px; top: -7px;
    border-left: 10px solid color-mix(in srgb, var(--fp-fg) 30%, transparent);
    border-top: 6px solid transparent; border-bottom: 6px solid transparent;
}

/* ── Station footprint ── */
.fp-station {
    --fp-cell: min(calc(100cqw / var(--fp-cols, 1)), calc(100cqh / var(--fp-rows, 1) * 1.6));
    position: relative; z-index: 1;
    display: flex; flex-direction: column; justify-content: flex-start; gap: .25em;
    min-width: 0; min-height: 0; overflow: hidden;
    padding: .55em .6em;
    font-size: clamp(9px, calc(var(--fp-cell) * .085), 14px);
    background: var(--fp-surface); color: var(--fp-fg); text-decoration: none;
    border: 1px solid color-mix(in srgb, var(--fp-fg) 22%, transparent); border-radius: 4px;
    box-shadow: 0 1px 0 color-mix(in srgb, var(--fp-fg) 12%, transparent);
    transition: border-color .12s, opacity .12s;
}
.fp-station:hover { border-color: var(--fp-fg); }
.fp-station:focus-visible { outline: 2px solid var(--fp-fg); outline-offset: 2px; }
.fp-post {
    align-self: flex-start; flex: none;
    font-family: var(--fp-stencil); font-weight: 700; font-size: 1.15em; line-height: 1;
    padding: .2em .4em; border-radius: 2px; min-width: 1.6em; text-align: center;
    background: var(--fp-fg); color: var(--fp-surface);
}
.fp-station-name {
    font-weight: 500; font-size: 1em; line-height: 1.25;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
    overflow-wrap: anywhere;
}
.fp-station-role {
    font-size: .875em; line-height: 1.25; color: var(--fp-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fp-dim { opacity: .25; }

/* Short cells: drop the role first, then let the name take one line. */
@container (max-height: 70px) {
    .fp-station-role { display: none; }
    .fp-station-name { -webkit-line-clamp: 1; }
}

@media (max-width: 640px) {
    .fp-dialog { inset: 0; border-radius: 0; border: 0; }
    .fp-floor { gap: 10px; padding: 10px; grid-template-columns: minmax(0, 1fr);
                grid-template-rows: repeat(var(--fp-bays, 1), minmax(0, 1fr)); }
    .fp-summary { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .fp-dialog { animation: none; }
    .fp-station { transition: none; }
}

/* ── Station references panel: opens over the floor when a station is clicked ── */
button.fp-station { font-family: inherit; text-align: left; cursor: pointer; }
.fp-panel-scrim {
    position: absolute; inset: 0; z-index: 5;
    background: rgba(15, 23, 42, .35);
}
.fp-panel {
    position: absolute; z-index: 6; top: 50%; left: 50%; transform: translate(-50%, -50%);
    display: flex; flex-direction: column;
    width: min(920px, calc(100% - 32px)); max-height: calc(100% - 48px);
    background: var(--fp-surface); color: var(--fp-fg);
    border: 1px solid var(--fp-border); border-radius: var(--fp-radius);
    box-shadow: 0 24px 64px -16px rgba(15, 23, 42, .45);
    overflow: hidden;
    animation: fp-open .14s ease-out;
}
.fp-panel-head {
    display: flex; align-items: center; gap: 12px; flex: none;
    padding: 12px 16px; border-bottom: 1px solid var(--fp-border);
}
.fp-panel-head .fp-post { font-size: 1.1rem; }
.fp-panel-link {
    flex: none; padding: 6px 10px; border: 1px solid var(--fp-border); border-radius: 6px;
    color: var(--fp-fg); font-size: .8125rem; font-weight: 500; text-decoration: none;
}
.fp-panel-link:hover { background: var(--mud-palette-background-gray); }
.fp-panel-body {
    flex: 1 1 auto; min-height: 0; overflow-y: auto;
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 24px;
    padding: 12px 16px 16px;
}
@media (max-width: 720px) { .fp-panel-body { grid-template-columns: minmax(0, 1fr); gap: 16px; } }
.fp-panel-body > .mud-progress-linear, .fp-panel-body > .fp-panel-empty { grid-column: 1 / -1; }
.fp-panel-empty { margin: 8px 0; color: var(--fp-muted); font-size: .8125rem; }
.fp-ref-col { min-width: 0; }
.fp-ref-title {
    position: sticky; top: -12px; z-index: 1;
    padding: 6px 0; background: var(--fp-surface);
    font-size: .8125rem; font-weight: 600; border-bottom: 1px solid var(--fp-border);
}
.fp-ref-count { margin-left: 4px; color: var(--fp-muted); font-weight: 500; }
.fp-ref-row {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 0; border-bottom: 1px solid var(--fp-border); font-size: .8125rem;
}
.fp-ref-row:last-child { border-bottom: 0; }
.fp-ref-row.is-obsolete { opacity: .55; }
.fp-ref-main { flex: 1 1 auto; min-width: 0; }
.fp-ref-name {
    display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--fp-fg); font-weight: 500; text-decoration: none;
}
a.fp-ref-name { color: var(--mud-palette-primary); }
a.fp-ref-name:hover { text-decoration: underline; }
.fp-ref-sub {
    display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--fp-muted); font-size: .72rem;
}
.fp-ref-plans {
    flex: none; padding: 1px 7px; border: 1px solid var(--fp-border); border-radius: 6px;
    color: var(--fp-muted); font-size: .72rem; font-weight: 600; cursor: help;
    font-variant-numeric: tabular-nums;
}
