/*********************/
/*** WORKFLOW RUN  ***/
/*********************/

/* Full-height grid that owns the AppBar-adjusted viewport.
   3 rows: header (auto) · status bar (auto) · instruction area (1fr).
   position: relative anchors the MudOverlay error flash. */
.wf-run-layout {
    height: calc(100dvh - var(--zk-appbar-height) - 0.75rem);
    display: grid;
    grid-template-rows: auto auto 1fr;
    overflow: hidden;
    position: relative;
}

/* Instruction area fills remaining grid height */
.wf-instruction-area {
    min-height: 0;
    overflow: hidden;
    padding-top: clamp(8px, 1.2vh, 16px);
    padding-bottom: clamp(4px, 0.5vh, 8px);
}

/* 2×2 card grid (TwoByTwo) */
.wf-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    height: 100%;
    gap: clamp(4px, 0.6vh, 10px);
}

/* Single-column override (TwoByOne, OneByOne) */
.wf-cards--one-col {
    grid-template-columns: 1fr;
}

/* Single-row override (OneByOne) */
.wf-cards--one-row {
    grid-template-rows: 1fr;
}

/* Individual instruction card — text on top (auto), image fills rest (1fr) */
.wf-card {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
    border: 10px solid black;
    border-radius: 4px;
    padding: clamp(14px, 2vh, 28px);
    background: var(--mud-palette-surface, white);
    cursor: pointer;
    box-sizing: border-box;
    min-height: 0;
}

/* Flash animations override the default black border */
.wf-card.flash-green-border,
.wf-card.flash-red-border {
    border-color: transparent;
}

/* Text region: description + optional tool status/torque */
.wf-card-text {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: clamp(2px, 0.4vh, 6px);
    padding-bottom: clamp(4px, 0.5vh, 8px);
    min-height: 0;
}

/* Left-aligned variant (TwoByOne/OneByOne) */
.wf-card-text--left {
    align-items: flex-start;
    text-align: left;
}

/* Primary description text — MudText Typo.h5 provides font family; clamp scales down only on very small screens */
.wf-card-description {
    font-size: clamp(1rem, 3vh, 2rem) !important;
    white-space: normal;
    word-break: break-word;
    line-height: 1.3 !important;
    margin: 0 !important;
}

/* Tool status / torque row — same size as description */
.wf-card-meta {
    display: flex;
    gap: clamp(8px, 1.5vw, 24px);
    flex-wrap: wrap;
    justify-content: center;
}

.wf-card-meta .mud-typography {
    font-size: clamp(1rem, 3vh, 2rem) !important;
}

.wf-card-text--left .wf-card-meta {
    justify-content: flex-start;
}

/* Image region: fills available card height */
.wf-card-image {
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(4px, 0.5vh, 8px);
}

.wf-card-image img {
    min-height: 0;
    min-width: 0;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    flex: 1 1 0;
}

/* Horizontal layout: text left, image right (TwoByOne/OneByOne) */
.wf-card--horizontal {
    grid-template-rows: 1fr;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.wf-card--horizontal .wf-card-text {
    align-items: flex-start;
    text-align: left;
    justify-content: center;
    padding: clamp(6px, 0.8vh, 12px) clamp(24px, 3.5vw, 56px) clamp(6px, 0.8vh, 12px) clamp(24px, 3.5vw, 56px);
    border-right: 1px solid rgba(0, 0, 0, 0.08);
    min-width: 0;
}

.wf-card--horizontal .wf-card-image {
    min-width: 0;
    padding-left: clamp(4px, 0.5vw, 8px);
}

/***********************************/
/*** ADVANCED FASTENING VISUALIZER ***/
/***********************************/

/* --af-footer-text/--af-chip-size scale down with viewport height (not just width) so the whole
   footer shrinks on short/laptop screens instead of staying pinned to its largest-screen size and
   crowding out the canvas above it. The text floor is raised so short viewports don't shrink it
   as aggressively. */
.af-footer {
    --af-footer-text-size: clamp(0.78rem, 1.8vh, 0.93rem);
    --af-chip-size: clamp(1.6rem, 4.1vh, calc(var(--zk-icon-lg) * 1.3));
    --af-chip-gap: clamp(0.25rem, 0.7vh, var(--zk-space-2));
    flex: 0 0 auto;
    width: 100%;
    border-top: 1px solid var(--mud-palette-lines-default, #e0e0e0);
    display: flex;
    flex-wrap: wrap;
    min-width: 0;
    overflow: hidden;
    box-sizing: border-box;
}

.af-footer-col {
    min-width: 0;
    box-sizing: border-box;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: clamp(0.2rem, 0.7vh, var(--zk-space-2));
    padding: clamp(0.45rem, 1.35vh, var(--zk-space-3));
}

.af-footer-col + .af-footer-col {
    border-left: 1px solid var(--mud-palette-lines-default, #e0e0e0);
}

/* Fastening-status chip summary — leftmost column. */
.af-col-chips {
    flex: 2 2 220px;
}

/* Workflow/station/step/tool details — formerly a full-height sidebar next to the canvas, now its
   own footer column so the canvas gets full width. */
.af-col-details {
    flex: 4 4 320px;
}

/* Two fixed columns: identity (workflow/station/step/fastener ID) on the left, live tool state
   (active tools/torque/status) on the right. minmax(0, 1fr) means neither column can ever force
   the grid wider than its container, regardless of resolution. */
.af-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(0.15rem, 0.5vh, var(--zk-space-1)) clamp(0.6rem, 1.6vw, var(--zk-space-4));
    align-content: start;
}

.af-detail-col {
    display: flex;
    flex-direction: column;
    gap: clamp(0.15rem, 0.5vh, var(--zk-space-1));
    min-width: 0;
}

/* Other footer columns truncate values with an ellipsis since they only have one line to work
   with — but nothing here should be hidden, so let long values wrap instead. */
.af-col-details .af-kv-value {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    word-break: break-word;
}

/* Excluded from the footer row's height calculation via `contain: size` so its own table content
   (which can run to many rows) never dictates the footer's height. It then gets stretched
   (align-items: stretch on .af-footer) to match whichever of the other columns is taller,
   and .af-table-wrap fills that space, scrolling internally past it. */
.af-col-status {
    flex: 4 4 320px;
    contain: size;
    padding-bottom: clamp(0.2rem, 0.6vh, calc(var(--zk-space-3) / 2));
}

/* Shared footer typography, centralized so sizes/weights stay consistent across the footer */
.af-label-heading {
    font-size: var(--af-footer-text-size);
    font-weight: 700;
    white-space: nowrap;
}

.af-text {
    font-size: var(--af-footer-text-size);
}

.af-text-bold {
    font-size: var(--af-footer-text-size);
    font-weight: 700;
    white-space: nowrap;
}

.af-kv-row {
    display: flex;
    align-items: baseline;
    gap: clamp(0.25rem, 0.7vh, var(--zk-space-2));
    min-width: 0;
    flex-wrap: wrap;
}

.af-kv-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1 1 0;
}

.af-push-right {
    margin-left: auto;
}

/* Body row: 3D canvas, sitting above the full-width footer. */
.af-body-row {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    display: flex;
    overflow: hidden;
}

.af-canvas {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

/* Instruction chips: sized off --af-chip-size (see .af-footer), which shrinks with viewport height
   so the whole chip block gets smaller on short/laptop screens instead of crowding the canvas.
   auto-fill (not a fixed count) lets the column shrink freely — chips wrap onto more rows instead
   of forcing the column wider, so this never causes horizontal overflow/scrolling. */
.af-chip-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, var(--af-chip-size));
    gap: var(--af-chip-gap);
    justify-content: start;
    min-width: 0;
}

.af-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    min-width: var(--af-chip-size);
    height: var(--af-chip-size);
    padding: 0 var(--zk-space-1);
    border-radius: 50%;
    flex-shrink: 0;
    cursor: default;
    user-select: none;
}

/* Calm brightness pulse — breathes between a lighter and darker amber, never scales/moves the chip.
   Mirrors the 3D zone marker's HSL-lightness pulse (AdvancedFasteningVisualizer.js, animate()). */
@keyframes af-chip-pulse-active {
    0%, 100% { background-color: #ffd54f; }
    50%      { background-color: #f57f17; }
}

.af-chip-pulse-active {
    animation: af-chip-pulse-active 1.1s ease-in-out infinite;
}

.af-chip-number {
    font-size: clamp(0.78rem, 1.6vh, 0.9rem);
    font-weight: 700;
    line-height: 1;
}

/* Fastening status table: fills whatever height .af-col-status is stretched to (see contain: size
   above), and scrolls internally (vertically only) once its rows exceed that height. */
.af-table-wrap {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

/* table-layout: fixed keeps the table locked to the wrapper's width regardless of cell content,
   so it can never force horizontal overflow/scrolling — long values ellipsize within their cell
   instead (full value still available via the title attribute on the ID cell). */
.af-table {
    border-collapse: collapse;
    table-layout: fixed;
    width: 100%;
    font-size: var(--af-footer-text-size);
}

.af-table th {
    text-align: left;
    padding: clamp(0.08rem, 0.3vh, 0.125rem) clamp(0.3rem, 1.1vw, var(--zk-space-2));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    position: sticky;
    top: 0;
    background: var(--mud-palette-surface);
    font-weight: 700;
    font-size: inherit;
}

.af-table td {
    padding: clamp(0.08rem, 0.3vh, 0.125rem) clamp(0.3rem, 1.1vw, var(--zk-space-2));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 400;
}

/*** DYNAMIC FASTENING VISUALIZER ***/
/***********************************/

/* Results/debug column header. The debug toggle is a MudIconButton, whose default padding is
   taller than the footer's text line - left alone it sets the row height itself and pushes the
   table down, so it's stripped back to sit inside the heading's own line height. */
.df-status-header {
    display: flex;
    align-items: center;
    gap: var(--zk-space-1);
    flex-wrap: nowrap;
    min-width: 0;
}

.df-status-header .mud-icon-button {
    padding: 0;
    margin-left: auto;
    min-width: 0;
    height: auto;
}

.df-status-header .mud-icon-button .mud-icon-root {
    font-size: 1rem;
    width: 1rem;
    height: 1rem;
}

.df-canvas-wrap {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
}

/* Sequencer debug dump. Matches the rest of the footer's text size rather than being its own
   smaller size, and drops the paragraph margin a MudText would bring. */
.df-debug-text {
    font-size: var(--af-footer-text-size);
    white-space: pre-line;
    margin: 0;
}
