:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --border: #dbe4f0;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --shadow: 0 18px 48px rgba(15, 23, 42, .10);
    --radius: 18px;
    --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, .16), transparent 34rem),
        linear-gradient(180deg, #ffffff 0%, var(--bg) 100%);
}

.app-header {
    padding: 30px clamp(16px, 4vw, 48px) 18px;
}

.app-header > div,
.app-layout {
    max-width: 1440px;
    margin: 0 auto;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 850;
    letter-spacing: .13em;
    text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
    font-size: clamp(30px, 5vw, 56px);
    line-height: 1.02;
    margin-bottom: 12px;
}

h2 {
    font-size: clamp(21px, 2.6vw, 30px);
    margin-bottom: 8px;
}

h3 {
    margin-bottom: 8px;
}

.app-header p:not(.eyebrow) {
    color: var(--muted);
    font-size: 17px;
    max-width: 760px;
}

.app-layout {
    display: grid;
    grid-template-columns: minmax(320px, 460px) minmax(0, 1fr);
    gap: 20px;
    padding: 0 clamp(16px, 4vw, 48px) 48px;
    align-items: start;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.input-card,
.output-card {
    padding: 20px;
}

.input-card {
    position: sticky;
    top: 16px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 16px;
}

fieldset {
    border: 1px solid var(--border);
    background: var(--surface-soft);
    border-radius: 15px;
    padding: 16px;
    margin: 0 0 14px;
}

legend {
    font-weight: 850;
    padding: 0 8px;
}

.grid {
    display: grid;
    gap: 12px;
}

.grid.two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
    display: grid;
    gap: 6px;
    font-weight: 750;
    font-size: 14px;
}

input,
select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
    background: #fff;
    color: var(--text);
}

.with-unit {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
}

.with-unit input {
    border-radius: 10px 0 0 10px;
}

.with-unit span {
    border: 1px solid var(--border);
    border-left: 0;
    border-radius: 0 10px 10px 0;
    background: #eef2f7;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    color: var(--muted);
    font-size: 13px;
    min-width: 52px;
}

.roll-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.roll-options label,
.check-line {
    display: flex;
    align-items: center;
    gap: 9px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
}

.roll-options input,
.check-line input {
    width: auto;
}

.check-line {
    margin-top: 12px;
}

.hint {
    color: var(--muted);
    font-size: 13px;
    margin: 10px 0 0;
}

.button-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.button {
    border: 0;
    border-radius: 999px;
    padding: 11px 16px;
    min-height: 42px;
    font: inherit;
    font-weight: 850;
    cursor: pointer;
}

.button.primary {
    background: var(--primary);
    color: #fff;
}

.button.primary:hover {
    background: var(--primary-dark);
}

.button.secondary {
    background: #e2e8f0;
    color: var(--text);
}

.empty-state {
    min-height: 500px;
    display: grid;
    place-content: center;
    text-align: center;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    color: var(--muted);
    padding: 24px;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.metric {
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
}

.metric span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 850;
    letter-spacing: .08em;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.metric strong {
    display: block;
    font-size: 21px;
}

.metric small {
    color: var(--muted);
}

.notice {
    padding: 13px 14px;
    border-radius: 14px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    margin-bottom: 16px;
    color: #1e3a8a;
}

.notice.warning {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}

.diagram-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    overflow: hidden;
    background: #fff;
}

.roll-svg {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
}

.roll-bg {
    fill: #eef4ff;
    stroke: #93c5fd;
    stroke-width: 2;
}

.cut-rect {
    fill: #dbeafe;
    stroke: #2563eb;
    stroke-width: 2;
}

.cut-rect.stair_run_strip,
.cut-rect.stair_winder_piece {
    fill: #dcfce7;
    stroke: #16a34a;
}

.cut-rect.area_main.hallway {
    fill: #fef3c7;
    stroke: #d97706;
}

.cut-rect.area_main.landing {
    fill: #fae8ff;
    stroke: #a855f7;
}

.svg-title {
    font: 800 14px var(--font);
    fill: #0f172a;
}

.svg-small {
    font: 12px var(--font);
    fill: #475569;
}

.table-wrap {
    border: 1px solid var(--border);
    border-radius: 14px;
    margin-top: 16px;
    overflow: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th,
td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

th {
    background: #f8fafc;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .08em;
}

tr:last-child td {
    border-bottom: 0;
}

.notes {
    margin-top: 16px;
    color: var(--muted);
    font-size: 13px;
}

.notes ul {
    margin: 8px 0 0;
    padding-left: 20px;
}

@media (max-width: 1120px) {
    .app-layout {
        grid-template-columns: 1fr;
    }

    .input-card {
        position: static;
    }
}

@media (max-width: 720px) {
    .grid.two,
    .roll-options,
    .metrics {
        grid-template-columns: 1fr;
    }

    .section-header {
        display: block;
    }

    .section-header .button {
        margin-top: 8px;
    }

    input {
        font-size: 16px;
    }

    .button {
        width: 100%;
    }
}

@media print {
    body {
        background: #fff;
    }

    .app-header,
    .input-card,
    .button-row {
        display: none !important;
    }

    .app-layout {
        display: block;
        padding: 0;
        max-width: none;
    }

    .output-card {
        box-shadow: none;
        border: 0;
    }

    .diagram-wrap {
        overflow: visible;
    }
}


.l-shape-controls {
    margin-top: 12px;
    border-top: 1px dashed var(--border);
    padding-top: 12px;
}

.inline-check {
    align-self: end;
    min-height: 42px;
}

select {
    appearance: auto;
}

.cut-poly {
    fill: #dbeafe;
    stroke: #2563eb;
    stroke-width: 2;
}

.cut-poly.area_l_shape {
    fill: #e0f2fe;
    stroke: #0284c7;
}

.cut-poly.hallway,
.cut-poly.hall {
    fill: #fef3c7;
    stroke: #d97706;
}

.cut-poly.landing {
    fill: #fae8ff;
    stroke: #a855f7;
}


.label-box {
    fill: rgba(255, 255, 255, .94);
    stroke: #cbd5e1;
    stroke-width: 1.25;
}

.label-line {
    stroke: #64748b;
    stroke-width: 1.2;
    stroke-dasharray: 4 4;
}

.label-title {
    font: 800 13px var(--font);
    fill: #0f172a;
}

.label-size {
    font: 12px var(--font);
    fill: #475569;
}

@media (max-width: 720px) {
    .diagram-wrap {
        padding: 8px;
    }

    .label-title {
        font-size: 12px;
    }

    .label-size {
        font-size: 11px;
    }
}


.center-label-title {
    font: 800 13px var(--font);
    fill: #0f172a;
    text-anchor: middle;
    dominant-baseline: middle;
    paint-order: stroke;
    stroke: rgba(255, 255, 255, .88);
    stroke-width: 4px;
    stroke-linejoin: round;
}

.center-label-size {
    font: 12px var(--font);
    fill: #475569;
    text-anchor: middle;
    dominant-baseline: middle;
    paint-order: stroke;
    stroke: rgba(255, 255, 255, .88);
    stroke-width: 4px;
    stroke-linejoin: round;
}

@media (max-width: 720px) {
    .center-label-title {
        font-size: 12px;
    }

    .center-label-size {
        font-size: 11px;
    }
}
