* { box-sizing: border-box; }

:root {
    --folium-sidebar: 230px;
    --folium-properties: 310px;
    --folium-toolbar-height: 126px;
    --folium-canvas-bg: #eef1f4;
}

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--folium-canvas-bg);
    color: #212529;
}

body { overflow: hidden; }
button, input, textarea { font: inherit; }

#app {
    display: grid;
    grid-template-columns: var(--folium-sidebar) minmax(0, 1fr) var(--folium-properties);
    min-height: 100vh;
    height: 100vh;
}

#templatesPanel,
#propertiesPanel {
    min-width: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 30;
}

.panel-heading {
    padding: 18px 16px 14px;
    z-index: 2;
}

.panel-title {
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .09em;
    text-transform: uppercase;
}

.panel-subtitle {
    font-size: .78rem;
    color: #6c757d;
}

#templateList {
    display: grid;
    gap: 14px;
}

.template-button {
    width: 100%;
    padding: 0;
    overflow: hidden;
    border: 2px solid transparent;
    border-radius: 12px;
    background: #fff;
    text-align: left;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.template-button:hover {
    transform: translateY(-1px);
    border-color: #adb5bd;
    box-shadow: 0 5px 15px rgba(0,0,0,.1);
}

.template-button.active {
    border-color: #212529;
    box-shadow: 0 0 0 2px rgba(33,37,41,.08), 0 5px 15px rgba(0,0,0,.1);
}

.template-preview-wrap {
    margin: 10px 10px 0;
    aspect-ratio: 8.5 / 11;
    overflow: hidden;
    background: #fff;
    border: 1px solid #dee2e6;
    position: relative;
}

.template-preview {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.template-preview > svg {
    width: 100% !important;
    height: 100% !important;
    max-width: 100%;
    max-height: 100%;
    display: block;
    pointer-events: none !important;
}

.template-preview-loading {
    color: #adb5bd;
}

.template-preview-error {
    padding: 12px;
    color: #6c757d;
    text-align: center;
    font-size: .72rem;
}

.template-name {
    min-width: 0;
    font-size: .9rem;
    font-weight: 700;
}

.selected-check {
    color: #212529;
    opacity: 0;
}

.template-button.active .selected-check { opacity: 1; }

#workspace {
    min-width: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

#toolbar {
    position: relative;
    z-index: 20;
    flex: 0 0 auto;
}

.toolbar-main {
    min-height: 68px;
    padding: 11px 16px;
    display: flex;
    align-items: center;
    gap: 9px;
}

.app-brand {
    white-space: nowrap;
    line-height: 1.05;
}

.app-brand strong {
    display: block;
    font-size: 1.05rem;
}

.app-brand span {
    color: #6c757d;
    font-size: .75rem;
}

.zoom-readout {
    min-width: 58px;
    font-size: .84rem;
}

#instructionBar {
    border: 0;
    border-top: 1px solid rgba(13,110,253,.16);
    border-radius: 0;
    padding: 9px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 56px;
}

.instruction-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(13,110,253,.12);
    display: grid;
    place-items: center;
    flex: 0 0 34px;
}

.instruction-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

#statusTitle {
    font-size: .82rem;
}

#status {
    color: #495057;
    font-size: .8rem;
    margin-top: 2px;
}

#canvasArea {
    flex: 1 1 auto;
    min-height: 0;
    padding: 30px;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background-image:
        linear-gradient(45deg, rgba(0,0,0,.018) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(0,0,0,.018) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(0,0,0,.018) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(0,0,0,.018) 75%);
    background-size: 22px 22px;
    background-position: 0 0, 0 11px, 11px -11px, -11px 0;
}

#page {
    background: white;
    box-shadow: 0 8px 30px rgba(0,0,0,.18);
    line-height: 0;
    transform-origin: top center;
}

#svgCanvas, #svgCanvas > svg { display: block; }

#svgCanvas > svg {
    width: min(612px, calc(100vw - var(--folium-sidebar) - var(--folium-properties) - 80px));
    height: auto;
    max-width: none;
}

#svgCanvas .folium-editable { cursor: pointer; }
#svgCanvas .folium-editable:hover { filter: brightness(.96); }
#svgCanvas .folium-selected {
    outline: 3px dashed #0d6efd;
    outline-offset: 3px;
}

.property-state {
    font-size: .9rem;
    line-height: 1.5;
    color: #495057;
}

.empty-state-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: #f1f3f5;
    display: grid;
    place-items: center;
    font-size: 1.4rem;
    margin-bottom: 14px;
    color: #495057;
}

.selection-type {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border-radius: 999px;
    background: #e9ecef;
    color: #343a40;
    font-size: .78rem;
    font-weight: 700;
    padding: 5px 9px;
}

code {
    font-family: Menlo, Consolas, monospace;
    font-size: .78em;
}

#mobileTemplatesBackdrop { display: none; }

@media (max-width: 1199.98px) {
    :root { --folium-properties: 285px; }

    #app { grid-template-columns: minmax(0, 1fr) var(--folium-properties); }

    #templatesPanel {
        position: fixed;
        left: 0;
        top: 0;
        width: 250px;
        transform: translateX(-102%);
        transition: transform .2s ease;
        box-shadow: 8px 0 24px rgba(0,0,0,.16);
    }

    body.folium-templates-open #templatesPanel { transform: translateX(0); }
    body.folium-templates-open #mobileTemplatesBackdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 25;
        background: rgba(0,0,0,.28);
    }

    #svgCanvas > svg {
        width: min(612px, calc(100vw - var(--folium-properties) - 80px));
    }
}

@media (max-width: 767.98px) {
    body { overflow: auto; }
    #app {
        display: block;
        min-height: 100vh;
        height: auto;
    }

    #workspace { height: auto; min-height: 100vh; }

    #propertiesPanel {
        height: auto;
        border-left: 0 !important;
        border-top: 1px solid #dee2e6;
    }

    .toolbar-main {
        flex-wrap: wrap;
        min-height: 60px;
    }

    #printButton span { display: none; }

    #canvasArea {
        min-height: 65vh;
        padding: 18px;
    }

    #svgCanvas > svg {
        width: calc(100vw - 36px);
        max-width: 612px;
    }
}

/* --- Existing v9.0 print behavior retained verbatim in spirit -------- */
@page { size: Letter portrait; margin: 0; }

@media print {
    :root {
        --folium-print-top-margin: 0.33in;
        --folium-print-height: 10.67in;
        --folium-print-width: 8.245in;
    }

    html, body {
        width: 8.5in !important;
        height: 11in !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        overflow: hidden !important;
    }

    .no-print, #templatesPanel, #propertiesPanel, #toolbar { display: none !important; }

    #app, #workspace, #canvasArea, #page, #svgCanvas {
        display: block !important;
        min-width: 0 !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        box-shadow: none !important;
        background: #fff !important;
        overflow: visible !important;
        transform: none !important;
    }

    #app, #workspace, #canvasArea { width: 8.5in !important; height: 11in !important; }

    #page, #svgCanvas {
        width: var(--folium-print-width) !important;
        height: var(--folium-print-height) !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }

    #page {
        padding-top: var(--folium-print-top-margin) !important;
        height: 11in !important;
    }

    #svgCanvas > svg {
        display: block !important;
        width: var(--folium-print-width) !important;
        height: var(--folium-print-height) !important;
        max-width: none !important;
        max-height: none !important;
        margin: 0 !important;
        padding: 0 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    #svgCanvas .folium-selected { outline: none !important; }
}

#foliumPrintFrame {
    position: fixed !important;
    width: 1px !important;
    height: 1px !important;
    right: 0 !important;
    bottom: 0 !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

#foliumPrintRaster { display: none; }
#foliumPrintRaster img { display: block; }

@media print {
    body.folium-raster-print > *:not(#foliumPrintRaster) { display: none !important; }

    body.folium-raster-print #foliumPrintRaster {
        display: block !important;
        position: fixed !important;
        inset: 0 !important;
        width: 8.5in !important;
        height: 11in !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        z-index: 2147483647 !important;
    }

    body.folium-raster-print #foliumPrintRaster img {
        display: block !important;
        width: 8.5in !important;
        height: 11in !important;
        object-fit: fill !important;
        margin: 0 !important;
        padding: 0 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* --- v9.3 multi-page flyer session ----------------------------------- */
.edited-badge {
    font-size: .62rem;
    letter-spacing: .02em;
}

#printSetButton .badge {
    min-width: 1.55rem;
}

#foliumPrintSet {
    display: none;
}

@media print {
    body.folium-set-print,
    body.folium-set-print html {
        height: auto !important;
        overflow: visible !important;
    }

    body.folium-set-print > *:not(#foliumPrintSet) {
        display: none !important;
    }

    body.folium-set-print #foliumPrintSet {
        display: block !important;
        position: static !important;
        width: 8.5in !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
    }

    body.folium-set-print .folium-print-set-page {
        display: block !important;
        position: relative !important;
        width: 8.5in !important;
        height: 11in !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
        background: #fff !important;
        break-after: page;
        page-break-after: always;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body.folium-set-print .folium-print-set-page:last-child {
        break-after: auto;
        page-break-after: auto;
    }

    body.folium-set-print .folium-print-set-raster img {
        display: block !important;
        width: 8.5in !important;
        height: 11in !important;
        object-fit: fill !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Capability fallback for clean SVGs that do not rasterize in WebKit. */
    body.folium-set-print .folium-print-set-native {
        padding-top: .33in !important;
        text-align: center !important;
    }

    body.folium-set-print .folium-print-set-native > svg {
        display: block !important;
        width: 8.245in !important;
        height: 10.67in !important;
        max-width: none !important;
        max-height: none !important;
        margin: 0 auto !important;
        padding: 0 !important;
    }
}

/* Folium 9.4 MLS lookup */
.folium-mls-lookup { width: min(310px, 28vw); min-width: 190px; }
.folium-mls-lookup .form-control { min-width: 80px; }
@media (max-width: 767.98px) {
    .folium-mls-lookup { width: 150px; min-width: 130px; }
    .folium-mls-lookup .btn span { display: none !important; }
}
