/* Advanced view: a full-viewport drawing surface under the shared header.
   All colors lean on the tokens rebarCalc.css defines. */

.advancedBody {
    overflow: hidden;
}

#advancedMain {
    flex: 1;
    min-height: 0;
    display: flex;
}

#drawArea {
    position: relative;
    flex: 1;
    min-height: 0;
    background: var(--card-bg);
}

#drawSvg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    /* Pointer events drive everything; stop the browser from panning/zooming
       the page with the same gestures. */
    touch-action: none;
    cursor: crosshair;
    user-select: none;
    -webkit-user-select: none;
}

/* Floating tool clusters positioned by script (CSSOM only, per CSP). */
#selectionTools,
#drawTools {
    position: absolute;
    display: flex;
    gap: 6px;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
    padding: 6px;
    z-index: 5;
}

#drawTools {
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
}

#selectionTools button,
#drawTools button {
    font: inherit;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 5px 10px;
    cursor: pointer;
}

#selectionTools button:hover,
#drawTools button:hover {
    border-color: var(--border-strong);
}

#selectionTools label {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 5px;
}

#selectionTools input[type="number"] {
    width: 58px;
    font: inherit;
    font-size: 13px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 4px 6px;
}

/* The per-slab spec panel: docked over the canvas while a slab is selected.
   Its DOM is static (advanced.html); script only fills values, so fields
   keep focus while the canvas re-renders underneath. */
#slabPanel {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 248px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--card-bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
    padding: 10px;
    z-index: 6;
}

.panelHead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

#slabName {
    width: 64px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 4px 6px;
}

.panelRotation {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 5px;
}

.panelGrid {
    display: grid;
    grid-template-columns: auto 1fr 1fr;
    gap: 6px;
    align-items: center;
}

.panelGrid .colHead {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: center;
}

.panelGrid .colWidth { color: #185fa5; }
.panelGrid .colHeight { color: #e07b00; }

.panelGrid .rowLabel {
    font-size: 12px;
    color: var(--text-secondary);
}

#slabPanel input[type="number"],
#slabPanel select {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    font: inherit;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 4px 6px;
}

/* Narrow screens: the panel becomes a bottom sheet so the canvas stays
   usable above it. */
@media (max-width: 640px) {
    #slabPanel {
        top: auto;
        left: 8px;
        right: 8px;
        bottom: 8px;
        width: auto;
        max-height: 46%;
        overflow-y: auto;
    }
}

/* Project-level tools: the cut sheet toggle and export/import cluster. */
#projectTools {
    position: absolute;
    left: 12px;
    top: 12px;
    z-index: 5;
    display: flex;
    gap: 6px;
}

#projectTools button {
    font: inherit;
    font-size: 13px;
    color: var(--text-primary);
    background: var(--card-bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
    padding: 6px 12px;
    cursor: pointer;
}

#cutSheetDrawer {
    position: absolute;
    left: 12px;
    top: 12px;
    bottom: 12px;
    width: 264px;
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
    z-index: 7;
}

.drawerHead {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

.drawerTitle {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    margin-right: auto;
}

.drawerRound {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 5px;
}

.drawerRound input {
    width: 52px;
    font: inherit;
    font-size: 13px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 3px 6px;
}

#cutSheetClose {
    font: inherit;
    font-size: 16px;
    line-height: 1;
    color: var(--text-secondary);
    background: none;
    border: none;
    padding: 2px 6px;
    cursor: pointer;
}

#printSheet {
    font: inherit;
    font-size: 12px;
    color: var(--text-primary);
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 3px 8px;
    cursor: pointer;
}

/* The printed sheet's header line; screen never shows it. */
#printHead {
    display: none;
}

#cutSheetBody {
    overflow-y: auto;
    padding: 10px;
    font-size: 13px;
    color: var(--text-primary);
}

#cutSheetBody .sheetSectionTitle {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin: 10px 0 4px;
}

#cutSheetBody .sheetSectionTitle:first-child {
    margin-top: 0;
}

#cutSheetBody .orderRow {
    padding: 3px 0;
    line-height: 1.45;
}

#cutSheetBody .orderRow .orderBar {
    font-weight: 600;
}

#cutSheetBody .orderRow .orderDetail {
    color: var(--text-secondary);
}

#cutSheetBody .sheetEntry {
    font-weight: 600;
    margin: 6px 0 2px;
}

#cutSheetBody table {
    border-collapse: collapse;
    width: 100%;
}

#cutSheetBody td {
    padding: 2px 0;
    border-bottom: 1px solid var(--border);
}

#cutSheetBody tr:last-child td {
    border-bottom: none;
}

#cutSheetBody .qty {
    text-align: right;
    padding-right: 8px;
    color: var(--text-secondary);
    white-space: nowrap;
    width: 1%;
}

#cutSheetBody .empty {
    color: var(--text-muted);
}

@media (max-width: 640px) {
    #cutSheetDrawer {
        right: 12px;
        width: auto;
        bottom: auto;
        max-height: 70%;
    }
}

/* Print: the page becomes the cut sheet. Everything else disappears, the
   drawer sheds its chrome and flows at full width, and section titles stay
   attached to their tables across page breaks. */
@media print {
    #appHeader,
    #appFooter,
    #drawSvg,
    #slabPanel,
    #selectionTools,
    #drawTools,
    #projectTools,
    #canvasHint,
    .drawerHead {
        display: none !important;
    }

    body,
    .advancedBody,
    #app,
    #advancedMain,
    #drawArea {
        display: block !important;
        overflow: visible !important;
        height: auto !important;
        background: #ffffff !important;
    }

    #cutSheetDrawer {
        display: block !important;
        position: static;
        width: auto;
        border: none;
        box-shadow: none;
        border-radius: 0;
    }

    #printHead {
        display: block;
        font-size: 13px;
        color: #444444;
        border-bottom: 1px solid #999999;
        padding: 0 0 6px;
        margin-bottom: 8px;
    }

    #cutSheetBody {
        overflow: visible;
        padding: 0;
    }

    #cutSheetBody .sheetSectionTitle,
    #cutSheetBody .sheetEntry {
        break-after: avoid;
    }

    #cutSheetBody .orderRow {
        break-inside: avoid;
    }
}

#canvasHint {
    position: absolute;
    left: 50%;
    top: 42%;
    transform: translate(-50%, -50%);
    color: var(--text-muted);
    font-size: 15px;
    pointer-events: none;
}

/* Hide the header legend when narrow; the switcher matters more here. */
@media (max-width: 640px) {
    .advancedBody .legend {
        display: none;
    }
}
