/* The theme centers page content in a fixed-max-width Bootstrap .container
   (1140px, regardless of viewport). These two classes are added by JS to only
   the specific ancestor elements of THIS page's own root — never globally, since
   .container is also used by the header/footer/nav which must keep their normal
   layout — to let the build tool actually use the full viewport width. */
.kb-unlocked-container {
    max-width: none !important;
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* This stylesheet is only ever linked from the köksbyggare page's own template,
   so this rule can't leak onto any other page. The <footer id="footer"> element
   itself sits outside the {block name="footer"} that rita.tpl empties out, so
   it still renders (just with no content) unless collapsed here too — needed to
   avoid it leaving behind an empty strip / border / margin at the bottom. */
#footer.js-footer {
    display: none !important;
}

.kb-unlocked-content {
    padding-left: 16px !important;
    padding-right: 16px !important;
}

@media (max-width: 1300px) {
    .kb-unlocked-content {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }
}

.koksbyggare-app {
    display: flex;
    gap: 16px;
    /* Set by JS (updateViewportSizing) from the real measured viewport height
       minus however much space the theme's header actually takes up — not a
       fixed vh guess tuned for one screen. Falls back to 80vh before JS runs. */
    height: var(--kb-available-height, 80vh);
    min-height: 420px;
    font-size: 14px;
}

@media (max-width: 1300px) {
    .koksbyggare-app { gap: 8px; }
}

.kb-sidebar {
    /* Scales with viewport width between a usable floor and a ceiling past which
       extra screen space should go to the drawing area instead, per-request. */
    width: clamp(220px, 18vw, 320px);
    flex: 0 0 clamp(220px, 18vw, 320px);
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 12px;
    background: #fafafa;
    height: 100%;
    overflow-y: auto;
    box-sizing: border-box;
    transition: flex-basis 0.15s ease, width 0.15s ease;
}

@media (max-width: 1300px) {
    .kb-sidebar {
        width: clamp(190px, 22vw, 260px);
        flex-basis: clamp(190px, 22vw, 260px);
        padding: 8px;
    }
}

.koksbyggare-app.kb-sidebar-collapsed .kb-sidebar {
    width: 32px;
    flex: 0 0 32px;
    padding: 8px 4px;
    overflow: hidden;
}

.koksbyggare-app.kb-sidebar-collapsed .kb-sidebar > *:not(.kb-sidebar-collapse-btn) {
    display: none;
}

.kb-sidebar-collapse-btn {
    display: block;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    padding: 4px 0;
    margin-bottom: 8px;
    border: 1px solid #ccc;
    border-radius: 3px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    color: #2c3e50;
    user-select: none;
}

.kb-sidebar-collapse-btn:hover { background: #eee; }

.kb-sidebar h3 {
    font-size: 15px;
    margin: 0 0 8px;
    border-bottom: 1px solid #ddd;
    padding-bottom: 6px;
}

.kb-sidebar .kb-section {
    margin-bottom: 20px;
}

.kb-search {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 8px;
    margin-bottom: 8px;
    border: 1px solid #ccc;
    border-radius: 3px;
}

.kb-product-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    border: 1px solid #e0e0e0;
    border-radius: 3px;
    margin-bottom: 4px;
    cursor: grab;
    background: #fff;
    font-size: 12px;
}

.kb-product-item:hover {
    border-color: #2c3e50;
}

.kb-product-item img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    flex: 0 0 32px;
}

.kb-product-item .kb-pname {
    flex: 1;
    line-height: 1.3;
}

.kb-product-item .kb-pdims {
    color: #888;
    font-size: 11px;
}

.kb-btn {
    display: inline-block;
    padding: 6px 10px;
    margin: 2px 4px 2px 0;
    border: 1px solid #2c3e50;
    background: #2c3e50;
    color: #fff;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    text-align: center;
}

.kb-btn:hover { background: #1a252f; }

.kb-btn.kb-btn-secondary {
    background: #fff;
    color: #2c3e50;
}

.kb-btn.kb-btn-secondary.active {
    background: #2c3e50;
    color: #fff;
}

.kb-util-btn {
    width: 100%;
    box-sizing: border-box;
    text-align: left;
}

.kb-canvas-wrap {
    /* Always takes whatever width is left after the sidebar (and, if the module
       ever grows one, a right info panel) — the drawing area is the one part of
       this layout that should get all the extra space on a wide screen. */
    flex: 1 1 auto;
    min-width: 0; /* allow the flex item to actually shrink below the SVG's intrinsic size */
    display: flex;
    flex-direction: column;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    position: relative;
    overflow: hidden;
}

.kb-toolbar {
    flex: 0 0 auto;
    padding: 8px 12px;
    border-bottom: 1px solid #ddd;
    background: #f5f7f9;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.kb-toolbar .kb-spacer { flex: 1; }

svg.kb-svg {
    display: block;
    width: 100%;
    /* Fills whatever vertical space is left in the column after the toolbar,
       within the app's own JS-measured height — not a fixed vh/px guess. */
    flex: 1 1 auto;
    min-height: 0;
    background: #fcfcfc;
    cursor: grab;
}

/* ===== Right panel: placed products, prices, totals, leasing ===== */
.kb-right-panel {
    display: none;
    width: clamp(260px, 20vw, 360px);
    flex: 0 0 clamp(260px, 20vw, 360px);
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fafafa;
    padding: 12px;
    position: relative;
    overflow: hidden; /* the list scrolls internally; totals stay put at the bottom */
}

.koksbyggare-app.kb-products-open .kb-right-panel {
    display: flex;
}

@media (max-width: 1300px) {
    .koksbyggare-app.kb-products-open .kb-right-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: min(360px, 90vw);
        flex: none;
        z-index: 1000;
        border-radius: 0;
        box-shadow: -2px 0 12px rgba(0, 0, 0, 0.25);
    }
}

.kb-right-panel h3 {
    font-size: 15px;
    margin: 0 0 8px;
    border-bottom: 1px solid #ddd;
    padding-bottom: 6px;
    flex: 0 0 auto;
}

.kb-right-panel-close {
    display: none;
    position: absolute;
    top: 8px;
    right: 10px;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    color: #777;
}

@media (max-width: 1300px) {
    .kb-right-panel-close { display: block; }
}

.kb-placed-list {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
}

.kb-placed-row {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 8px;
    border: 1px solid #e0e0e0;
    border-radius: 3px;
    margin-bottom: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 12px;
}

.kb-placed-row:hover {
    border-color: #2c3e50;
}

.kb-placed-row.kb-row-selected {
    border-color: #cc8400;
    background: #fff8ea;
    box-shadow: 0 0 0 1px #cc8400 inset;
}

.kb-placed-main {
    flex: 1;
    min-width: 0;
}

.kb-placed-name {
    font-weight: 600;
    line-height: 1.3;
    word-break: break-word;
}

.kb-placed-meta {
    color: #888;
    font-size: 11px;
    margin-top: 2px;
}

.kb-placed-price {
    margin-top: 4px;
    font-size: 12px;
}

.kb-price-missing {
    color: #c0392b;
}

.kb-placed-delete {
    flex: 0 0 auto;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    opacity: 0.6;
}

.kb-placed-delete:hover {
    opacity: 1;
    background: #f6c6c2;
}

.kb-placed-totals {
    flex: 0 0 auto;
    border-top: 1px solid #ddd;
    padding-top: 8px;
    margin-top: 4px;
    font-size: 13px;
}

.kb-totals-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
}

.kb-totals-row-strong {
    font-weight: 700;
    font-size: 15px;
    border-top: 1px solid #ddd;
    margin-top: 4px;
    padding-top: 6px;
}

.kb-leasing-box {
    margin-top: 10px;
    padding: 8px 10px;
    background: #eef5ff;
    border: 1px solid #b8d4f5;
    border-radius: 4px;
    font-size: 12px;
}

.kb-leasing-line { margin-bottom: 4px; }

.kb-leasing-box a {
    display: inline-block;
    margin-top: 2px;
    color: #2c3e50;
}

.kb-overlay {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.kb-3d-mount {
    display: none; /* toggled to block by set3DViewActive() in koksbyggare.js */
    /* Same flex slot as svg.kb-svg (canvasWrap is a flex column) rather than an
       absolute overlay — an absolute inset:0 box would sit on top of the toolbar
       row too and swallow clicks meant for the 2D/3D buttons themselves. */
    flex: 1 1 auto;
    min-height: 0;
    cursor: grab;
    /* Establishes a positioning context of its own so the cutaway control panel
       (position:absolute) anchors to this element, not to the further-up
       .kb-canvas-wrap (which would place it up over the toolbar row instead). */
    position: relative;
}

.kb-3d-mount:active {
    cursor: grabbing;
}

.kb-3d-mount canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.kb-3d-cutaway-controls {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-width: calc(100% - 20px);
    z-index: 5;
    cursor: default;
}

.kb-3d-cutaway-controls .kb-btn {
    margin: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* 2D stays mounted (not display:none) so its own drag/edit interactions keep
   working normally when the user is on 2D — only the 3D view toggles. */
.koksbyggare-app.kb-view-3d .kb-svg,
.koksbyggare-app.kb-view-3d .kb-overlay,
.koksbyggare-app.kb-view-3d .kb-advisory {
    display: none;
}

.kb-opening-rect {
    fill: #fcfcfc;
    stroke: #999;
    stroke-width: 2;
    cursor: move;
}

.kb-opening-rect.selected {
    stroke: #cc8400;
    stroke-width: 3;
}

.kb-door-swing {
    fill: none;
    stroke: #2c3e50;
    stroke-width: 8;
    pointer-events: none;
}

.kb-window-line {
    stroke: #3498db;
    stroke-width: 10;
    pointer-events: none;
}

.kb-opening-panel {
    position: absolute;
    transform: translate(-50%, -50%);
    background: #fff;
    border: 1px solid #2c3e50;
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 12px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    pointer-events: auto;
    min-width: 190px;
    z-index: 3;
}

.kb-opening-panel-title {
    font-weight: 700;
    margin-bottom: 6px;
}

.kb-opening-panel-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
}

.kb-opening-panel-row label {
    color: #555;
}

.kb-opening-panel-row input {
    width: 70px;
    box-sizing: border-box;
}

.kb-opening-panel-delete {
    margin-top: 4px;
    text-align: center;
    color: #c0392b;
    cursor: pointer;
    font-size: 11px;
}

.kb-opening-panel-delete:hover {
    text-decoration: underline;
}

.kb-wall-length-input {
    position: absolute;
    width: 64px;
    transform: translate(-50%, -50%);
    background: #fff;
    border: 1px solid #2c3e50;
    border-radius: 3px;
    font-size: 12px;
    padding: 2px 4px;
    text-align: center;
    pointer-events: auto;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.kb-wall-rect {
    fill: #e4e4e4;
    stroke: #555;
    stroke-width: 1;
    cursor: pointer;
}

.kb-wall-rect.selected {
    fill: #cfe0f0;
    stroke: #2c3e50;
    stroke-width: 2;
}

.kb-wall-joint {
    fill: #e4e4e4;
    stroke: #555;
    stroke-width: 1;
}

.kb-node-handle {
    fill: #2c3e50;
    stroke: #fff;
    stroke-width: 1.5;
    cursor: move;
}

.kb-node-handle.merge-target {
    fill: #27ae60;
    r: 90;
}

.kb-item-rect {
    fill: #d6e4f0;
    stroke: #2c3e50;
    stroke-width: 1;
    cursor: move;
}

.kb-item-rect.selected {
    fill: #ffe9b3;
    stroke: #cc8400;
    stroke-width: 2;
}

.kb-item-rect.invalid {
    fill: #f6c6c2;
    stroke: #c0392b;
    stroke-width: 2;
}

.kb-item-label-line {
    fill: #1a1a1a;
    pointer-events: none;
    text-anchor: middle;
    paint-order: stroke;
    stroke-linejoin: round;
    font-family: inherit;
}

.kb-item-label-line.bold {
    font-weight: 600;
}

.kb-item-front-marker {
    fill: #2c3e50;
    stroke: #fff;
    stroke-width: 6;
    pointer-events: none;
    opacity: 0.9;
}

.kb-rotate-stem {
    stroke: #cc8400;
    stroke-width: 6;
    pointer-events: none;
}

.kb-rotate-handle {
    fill: #fff;
    stroke: #cc8400;
    stroke-width: 8;
    cursor: grab;
}

.kb-rotate-handle:hover {
    fill: #fff8ea;
}

.kb-rotate-readout {
    fill: #cc8400;
    font-weight: 700;
    paint-order: stroke;
    stroke-linejoin: round;
    pointer-events: none;
    text-anchor: middle;
}

.kb-wall-label-leader {
    stroke: #aaa;
    stroke-width: 8;
    stroke-dasharray: 30 24;
    pointer-events: none;
}

.kb-util-marker {
    cursor: move;
}

.kb-util-el { fill: #e74c3c; }
.kb-util-vatten { fill: #3498db; }
.kb-util-avlopp { fill: #7f5b3f; }
.kb-util-utsug { fill: #8e44ad; }

.kb-util-label {
    font-size: 9px;
    fill: #333;
    pointer-events: none;
}

.kb-advisory {
    position: absolute;
    bottom: 10px;
    left: 10px;
    right: 10px;
    background: #fff8e1;
    border: 1px solid #e0a800;
    border-radius: 4px;
    padding: 8px 12px;
    font-size: 12px;
    max-height: 140px;
    overflow-y: auto;
}

.kb-advisory strong { color: #7a5c00; }

.kb-hint {
    font-size: 11px;
    color: #777;
    margin-top: 4px;
}

/* ===== Send-drawing modal ===== */
.kb-modal-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.kb-modal {
    background: #fff;
    border-radius: 6px;
    padding: 20px 24px 24px;
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.kb-modal h3 {
    margin: 0 0 4px;
}

.kb-modal p.kb-modal-intro {
    font-size: 13px;
    color: #555;
    margin: 0 0 16px;
}

.kb-modal label {
    display: block;
    font-size: 12px;
    font-weight: bold;
    margin: 12px 0 4px;
}

.kb-modal input[type="text"],
.kb-modal input[type="email"],
.kb-modal input[type="tel"],
.kb-modal textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 3px;
    font-size: 14px;
    font-family: inherit;
}

.kb-modal textarea { min-height: 70px; resize: vertical; }

.kb-modal-actions {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.kb-modal-error {
    color: #c0392b;
    font-size: 12px;
    margin-top: 10px;
    display: none;
}

.kb-modal-success {
    text-align: center;
    padding: 12px 0;
}

.kb-modal-success h3 { color: #27ae60; }

.kb-loaded-banner {
    background: #eaf3ff;
    border: 1px solid #3498db;
    border-radius: 4px;
    padding: 8px 12px;
    font-size: 12px;
    margin: 0 0 8px;
}
