body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    overflow: hidden;
    background: #4a4a4a;
}

/* Form controls don't inherit the page font by default — make them match
   (e.g. the calibration dialog's inputs / selects / buttons). */
input, button, select, textarea {
    font-family: inherit;
}

.full-screen {
    width: 100vw;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

#pdf-canvas {
    position: absolute;
    top: 0;
    left: 0;
}

/* Fabric.js creates .canvas-container wrapper automatically */
#pdf-container .canvas-container {
    position: absolute !important;
    top: 0;
    left: 0;
}

/* ── Toolbar ──
   Mirrors `.tooltray` in static/css/ifc.css (frag.html) and the
   `.appmap-measure-tooltray` it derives from, so the PDF viewer's bottom
   toolbar matches the IFC viewer and the floating-map measure tray. */
.tooltray {
    position: fixed;
    left: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px;
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.06);
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.10), 0 1px 2px rgba(15, 23, 42, 0.06);
}

.tooltray__btn {
    box-sizing: border-box;
    width: 34px;
    height: 34px;
    padding: 6px;
    margin: 0;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: #334155;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 120ms ease, transform 80ms ease;
}

.tooltray__btn img {
    width: 20px;
    height: 20px;
    display: block;
    pointer-events: none;
    /* SVG sources are filled white — invert to black for visibility on the
       white tray background. Pressed state un-inverts back to white on blue. */
    filter: invert(1);
    transition: filter 120ms ease;
}

/* Inline <svg> icons drive their stroke/fill from `currentColor`;
   `.tooltray__btn` sets that to the dark text colour so they read on the
   white tray, and `.pressed` flips it to white over the blue bg. */
.tooltray__btn svg {
    width: 20px;
    height: 20px;
    display: block;
    pointer-events: none;
    transition: color 120ms ease;
}

.tooltray__btn:hover {
    background: #f1f5f9;
}

.tooltray__btn:active {
    transform: translateY(1px);
}

.tooltray__btn.pressed {
    background: #3b82f6;
    color: #ffffff;
}

.tooltray__btn.pressed img {
    filter: none;
}

.tooltray__btn.saved {
    border-color: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, .4);
}

.tooltray__separator {
    width: 1px;
    height: 20px;
    background: rgba(0, 0, 0, 0.1);
    margin: 0 4px;
}

/* "Clear all" button — render del.svg through a red CSS mask so it stays red
   on the white tray (mirrors frag.html #btn-reset and appmap's
   .appmap-measure-clear). */
#btn-clear img {
    display: none;
}

#btn-clear::before {
    content: '';
    width: 20px;
    height: 20px;
    background-color: #dc2626;
    -webkit-mask: url(/static/svg/del.svg) center / contain no-repeat;
            mask: url(/static/svg/del.svg) center / contain no-repeat;
    transition: background-color 120ms ease;
}

#btn-clear:hover::before {
    background-color: #b91c1c;
}

/* Download dropdown menu */
.download-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.download-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.06);
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.10), 0 1px 2px rgba(15, 23, 42, 0.06);
    padding: 4px;
    display: flex;
    flex-direction: column;
    min-width: 200px;
    z-index: 1001;
}

.download-menu[hidden] {
    display: none;
}

.download-menu a {
    display: block;
    padding: 8px 12px;
    color: #334155;
    text-decoration: none;
    font-size: 13px;
    border-radius: 6px;
    white-space: nowrap;
    cursor: pointer;
}

.download-menu a:hover {
    background: #f1f5f9;
}

/* Color picker inside toolbar */
.color-btn {
    position: relative;
    overflow: hidden;
}

.color-btn input[type="color"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

/* ── Page navigation ──
   Mirrors the bottom `.tooltray` so the top panel reads as the same control:
   white surface, soft border, rounded corners and the same button treatment. */
#page-nav {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px;
    background: #ffffff;
    border: 1px solid rgba(15, 23, 42, 0.06);
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.10), 0 1px 2px rgba(15, 23, 42, 0.06);
    font-size: 13px;
    color: #334155;
}

#page-nav button {
    box-sizing: border-box;
    width: 34px;
    height: 34px;
    padding: 6px;
    margin: 0;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: #334155;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: background 120ms ease, transform 80ms ease;
}

#page-nav button:hover {
    background: #f1f5f9;
}

#page-nav button:active {
    transform: translateY(1px);
}

/* Icon buttons (rotate) in the top panel — drive stroke from currentColor and
   keep a consistent 20px glyph, matching the bottom tray. */
#page-nav button svg {
    width: 20px;
    height: 20px;
    display: block;
    pointer-events: none;
}

#page-info {
    min-width: 44px;
    padding: 0 4px;
    text-align: center;
    color: #334155;
}

.nav-separator {
    width: 1px;
    height: 20px;
    background: rgba(0, 0, 0, 0.1);
    margin: 0 4px;
}

#zoom-info {
    min-width: 40px;
    padding: 0 4px;
    text-align: center;
    font-size: 12px;
    color: #334155;
}

/* ── File selector ──
   Styled to match the white `.tooltray` panels: soft border, rounded corners,
   the same shadow and a custom chevron (native arrow hidden via appearance). */
#file-selector {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: 12px;
    z-index: 1000;
}

#file-selector select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    max-width: 240px;
    padding: 8px 34px 8px 12px;
    border: 1px solid rgba(15, 23, 42, 0.06);
    border-radius: 8px;
    background-color: #ffffff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23334155' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.10), 0 1px 2px rgba(15, 23, 42, 0.06);
    font-size: 13px;
    color: #334155;
    cursor: pointer;
    outline: none;
    text-overflow: ellipsis;
    transition: background-color 120ms ease;
}

#file-selector select:hover {
    background-color: #f8fafc;
}

/* Keep the dropdown's option list readable even when the closed control hides
   its own text on mobile (`color: transparent` in the media query below). */
#file-selector select option {
    color: #334155;
}

/* ── Calibration dialog ── */
#calibration-dialog {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 3000;
    align-items: center;
    justify-content: center;
}

.calib-inner {
    background: #fff;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
    min-width: 300px;
    max-width: 400px;
}

.calib-inner h3 {
    margin: 0 0 12px;
    font-size: 18px;
}

.calib-inner p {
    margin: 0 0 16px;
    font-size: 14px;
    color: #555;
}

.calib-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.calib-scale-row {
    align-items: center;
    flex-wrap: wrap;
}

.calib-scale-row input {
    min-width: 60px;
}

.calib-eq {
    font-size: 18px;
    font-weight: bold;
    color: #555;
    padding: 0 4px;
}

.calib-btn-alt {
    display: block;
    width: 100%;
    margin: 12px 0 16px;
    padding: 10px 14px;
    border: 1px solid #c7c9d1;
    border-radius: 4px;
    background: #f3f4f6;
    color: #333;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
}

.calib-btn-alt:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
}

.calib-row input {
    flex: 1;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 16px;
}

.calib-row select {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
}

.calib-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.calib-btn-ok, .calib-btn-cancel {
    padding: 8px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.calib-btn-ok {
    background: #6366f1;
    color: #fff;
}

.calib-btn-ok:hover {
    background: #4f46e5;
}

.calib-btn-cancel {
    background: #e5e7eb;
    color: #333;
}

.calib-btn-cancel:hover {
    background: #d1d5db;
}

/* ── "Place on map" (georeference) dialog — reuses the .calib-* look ── */
#georef-dialog {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 3000;
    align-items: center;
    justify-content: center;
}

#georef-hint {
    display: none;
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    max-width: min(90vw, 480px);
    padding: 10px 16px;
    border-radius: 8px;
    background: rgba(17, 24, 39, 0.9);
    color: #fff;
    font-size: 14px;
    text-align: center;
    z-index: 2500;
    pointer-events: none;
}

.georef-scale-line {
    font-size: 14px;
}

.georef-xy-row,
.georef-rot-row,
.georef-level-row {
    align-items: center;
    flex-wrap: wrap;
}

.georef-xy-row label,
.georef-rot-row label,
.georef-level-row label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    flex: 1;
    min-width: 0;
}

.georef-xy-row input,
.georef-rot-row input {
    width: 100%;
    min-width: 80px;
}

.georef-rot-row input {
    max-width: 120px;
}

.georef-level-row select {
    flex: 1;
    min-width: 0;
}

.georef-unit {
    font-size: 14px;
    color: #555;
}

.georef-note {
    font-size: 12px !important;
    color: #777 !important;
    margin-top: -8px !important;
}

.georef-error {
    color: #b91c1c;
    font-size: 13px;
}

.georef-error[hidden] {
    display: none;
}

.georef-link {
    display: inline-block;
    text-decoration: none;
    line-height: normal;
}

/* While the server renders and places the page the OK button keeps its size and
   swaps the label for a spinner (`spin` keyframes come from spinner.css, which
   pdf.html loads too). Cancel stays clickable - confirm() handles a mid-flight abort. */
#georef-ok {
    position: relative;
}

.georef-busy #georef-ok {
    pointer-events: none;
}

.georef-busy .georef-ok-label {
    visibility: hidden;
}

.georef-ok-spinner {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    box-sizing: border-box;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.georef-busy .georef-ok-spinner {
    display: block;
}

/* ── Responsive ── */
@media (max-width: 700px) {
    .tooltray {
        gap: 3px;
        padding: 4px;
        bottom: 8px;
        flex-wrap: wrap;
        max-width: 95vw;
        justify-content: center;
    }

    .tooltray__btn {
        width: 28px;
        height: 28px;
    }

    #page-nav button {
        width: 28px;
        height: 28px;
    }

    /* Collapse the file dropdown to a compact hamburger button so it no longer
       overlaps the centred page-nav. The native <select> still drives the file
       list — only its closed-state appearance changes: label hidden, a menu
       (three-line) icon centred, and the native picker opens on tap. */
    #file-selector select {
        width: 40px;
        max-width: 40px;
        height: 40px;
        padding: 0;
        color: transparent;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23334155' stroke-width='2' stroke-linecap='round'%3E%3Cline x1='3' y1='6' x2='21' y2='6'/%3E%3Cline x1='3' y1='12' x2='21' y2='12'/%3E%3Cline x1='3' y1='18' x2='21' y2='18'/%3E%3C/svg%3E");
        background-position: center;
        background-size: 20px;
    }
}
