
:root {
    font-family: Inter, system-ui, sans-serif;
    color: #25333a;
    --blue: #234e68;
    --blue-dark: #173749;
    --border: #d4dfe5;
    --s: 1;
    --m: calc(7mm * var(--s));
    --fh: calc(34mm * var(--s));
}

* {
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
}

button, input, select, textarea {
    font: inherit;
}

button {
    cursor: pointer;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    color: var(--blue-dark);
    font-size: 12px;
    font-weight: 650;
    touch-action: manipulation;
}

button:hover {
    background: #eaf1f5;
}

button.primary {
    color: white;
    background: var(--blue);
    border-color: var(--blue);
}

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

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 1px;
}

input[type="text"], input[type="number"], input[type="date"], select, textarea {
    width: 100%;
    min-width: 0;
    padding: 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    color: #24343d;
    font-size: 12px;
}

textarea {
    resize: vertical;
    min-height: 65px;
}

input[type="checkbox"] {
    accent-color: var(--blue);
}

label {
    display: block;
    margin-bottom: 5px;
    font-size: 11px;
    color: #60717c;
}

.field {
    margin-bottom: 12px;
}

.row {
    display: flex;
    align-items: end;
    gap: 8px;
}

.row > * {
    flex: 1;
    min-width: 0;
}

#map {
    position: fixed;
    inset: 0;
    background: #e9edf0;
    border: 1px solid #263b47;
    touch-action: none;
}

#printArea {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    outline: 2px dashed #c05b36;
    box-shadow: 0 0 0 100vmax rgba(20, 43, 58, .28);
}

.panel {
    position: fixed;
    z-index: 20;
    top: 14px;
    bottom: 58px;
    left: 14px;
    width: 310px;
    max-width: calc(100vw - 28px);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: rgba(255, 255, 255, .97);
    border: 1px solid #d7e0e5;
    border-radius: 12px;
    box-shadow: 0 8px 32px #142b3a24;
    padding: 18px;
    transition: transform .2s ease, opacity .2s ease;
}

.sidebar-toggle {
    position: fixed;
    z-index: 30;
    top: 20px;
    left: 274px;
    width: 30px;
    height: 30px;
    padding: 0;
    font-size: 16px;
    background: transparent;
    border: 0;
}

body.sidebar-collapsed .panel {
    transform: translateX(calc(-100% - 20px));
    opacity: 0;
    pointer-events: none;
}

body.sidebar-collapsed .sidebar-toggle {
    left: calc(18px + env(safe-area-inset-left, 0px));
    top: calc(18px + env(safe-area-inset-top, 0px));
    width: 38px;
    height: 38px;
    font-size: 20px;
    background: white;
    border: 1px solid var(--border);
    box-shadow: 0 2px 10px #142b3a25;
}

.brand {
    margin-bottom: 14px;
    padding-right: 30px;
}

.brand h1 {
    font-size: 20px;
    margin: 0;
    letter-spacing: -.7px;
    color: var(--blue-dark);
}

.section {
    padding: 15px 0;
    border-top: 1px solid #e5ebef;
}

.section.first {
    padding-top: 0;
    border-top: 0;
}

.check {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 11px 0 0;
    font-size: 12px;
    color: #334954;
}

.check input {
    margin: 0;
}

.full {
    width: 100%;
}

.status {
    font-size: 11px;
    line-height: 1.5;
    color: #75858e;
    overflow-wrap: anywhere;
    margin-top: 8px;
}

.status.warning {
    color: #9a3412;
}

.location-results {
    display: grid;
    gap: 6px;
    margin-top: 8px;
}

.location-results button {
    text-align: left;
    line-height: 1.4;
    font-weight: 500;
}

.location-results button small {
    display: block;
    color: #71838d;
    font-size: 10px;
    margin-top: 3px;
}

[hidden] {
    display: none !important;
}

.tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    margin-bottom: 14px;
    background: #eef3f6;
    border-radius: 8px;
}

.tabs button {
    flex: 1 1 0;
    min-width: 0;
    white-space: nowrap;
    padding: 8px 4px;
    border: 0;
    background: transparent;
    color: #60717c;
}

.ol-attribution, .ol-attribution * {
    display: none !important;
}

.tabs button:hover {
    background: #e1eaef;
}

.tabs button[aria-selected="true"] {
    background: white;
    color: var(--blue-dark);
    box-shadow: 0 1px 3px #142b3a24;
}

.declination-row {
    display: flex;
    align-items: end;
    gap: 8px;
}

.declination-row .field {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.declination-row .field:has(#magDate) {
    flex: 1 1 auto;
    min-width: 0;
}

.declination-row .field:has(#declination) {
    flex: 0 1 105px;
    max-width: 105px;
}

.declination-row button {
    flex: 0 0 42px;
    width: 42px;
    height: 36px;
    padding: 0;
    font-size: 20px;
    line-height: 1;
}

.location-search-row {
    display: flex;
    align-items: end;
    gap: 8px;
}

.location-search-row .field {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.location-search-row button {
    flex: 0 0 42px;
    width: 42px;
    height: 36px;
    padding: 0;
    font-size: 17px;
    line-height: 1;
}

.ol-zoom {
    position: fixed !important;
    top: auto !important;
    right: calc(18px + env(safe-area-inset-right, 0px)) !important;
    bottom: calc(18px + env(safe-area-inset-bottom, 0px)) !important;
    left: auto !important;
}

.ol-control button {
    color: #234e68;
    background: rgba(255, 255, 255, .95);
}

.ol-zoom button:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.locate-button {
    position: fixed;
    z-index: 10;
    right: calc(18px + env(safe-area-inset-right, 0px));
    bottom: calc(90px + env(safe-area-inset-bottom, 0px));
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    color: #234e68;
    background: rgba(255, 255, 255, .95);
    box-shadow: 0 1px 4px #142b3a40;
}

.locate-button.following {
    color: #fff;
    background: #1a73e8;
}

.compass {
    position: fixed;
    z-index: 10;
    top: calc(18px + env(safe-area-inset-top, 0px));
    right: calc(18px + env(safe-area-inset-right, 0px));
    width: 94px;
    height: 94px;
    padding: 4.5px;
    display: grid;
    place-items: center;
    pointer-events: none;
    background: rgba(255, 255, 255, .88);
    border: 1px solid #111;
    border-radius: 50%;
}

.compass svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.compass text {
    font-family: Georgia, serif;
    fill: #111;
    font-size: 9px;
    font-weight: 800;
}

.print-border, .print-page {
    display: none;
}

@media (max-width: 600px) {
    .panel {
        top: calc(8px + env(safe-area-inset-top, 0px));
        bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        left: calc(8px + env(safe-area-inset-left, 0px));
        right: calc(8px + env(safe-area-inset-right, 0px));
        width: auto;
        max-width: none;
        padding: 16px;
    }

    body:not(.sidebar-collapsed) .sidebar-toggle {
        left: auto;
        right: calc(18px + env(safe-area-inset-right, 0px));
        top: calc(16px + env(safe-area-inset-top, 0px));
        width: 38px;
        height: 38px;
        font-size: 22px;
    }

    input[type="text"], input[type="number"], input[type="date"], select, textarea {
        font-size: 16px;
        padding: 10px;
    }

    button {
        font-size: 13px;
    }

    .tabs button {
        padding: 10px 4px;
    }

    .compass {
        width: 72px;
        height: 72px;
        padding: 3.5px;
        top: calc(14px + env(safe-area-inset-top, 0px));
        right: calc(14px + env(safe-area-inset-right, 0px));
    }

    .declination-row .field:has(#declination) {
        flex-basis: 100px;
        max-width: 100px;
    }

    .declination-row button, .location-search-row button {
        height: 42px;
    }
}

/* ---------------------------- print layout ---------------------------- */

@media print {
    html, body {
        margin: 0;
        padding: 0;
        overflow: hidden !important;
        background: white;
    }

    .panel, .sidebar-toggle, .locate-button, .ol-zoom, .ol-rotate, .ol-attribution, .ol-scale-bar, .ol-scale-line, #printArea {
        display: none !important;
    }

    * {
        print-color-adjust: exact !important;
        -webkit-print-color-adjust: exact !important;
    }
}

body.printing {
    position: relative;
    width: var(--pw);
    height: calc(var(--ph) - .5mm);
    overflow: hidden;
    background: #fff;
}

body.printing .panel,
body.printing .sidebar-toggle,
body.printing .locate-button,
body.printing .ol-zoom,
body.printing .ol-rotate,
body.printing .ol-attribution,
body.printing .ol-scale-bar,
body.printing .ol-scale-line,
body.printing #printArea {
    display: none !important;
}

body.printing #map {
    position: absolute;
    inset: auto;
    left: var(--m);
    top: var(--m);
    width: calc(var(--pw) - 2 * var(--m));
    height: calc(var(--ph) - 2 * var(--m) - var(--fh));
    border: calc(.5mm * var(--s)) solid #111;
    background: #fff;
}

body.printing .print-border {
    display: block;
    position: absolute;
    pointer-events: none;
    left: calc(var(--m) - 1.6mm * var(--s));
    top: calc(var(--m) - 1.6mm * var(--s));
    width: calc(var(--pw) - 2 * var(--m) + 3.2mm * var(--s));
    height: calc(var(--ph) - 2 * var(--m) + 3.2mm * var(--s));
    border: calc(.25mm * var(--s)) solid #111;
}

body.printing .compass {
    display: grid;
    position: absolute;
    top: calc(var(--m) + 3mm * var(--s));
    right: calc(var(--m) + 3mm * var(--s));
    width: calc(21mm * var(--s));
    height: calc(21mm * var(--s));
    padding: calc(1mm * var(--s));
    background: rgba(255, 255, 255, .88);
    border: calc(.2mm * var(--s)) solid #111;
    border-radius: 50%;
    z-index: 10000;
}

body.printing .print-page {
    display: grid;
    position: absolute;
    left: var(--m);
    top: calc(var(--ph) - var(--m) - var(--fh));
    width: calc(var(--pw) - 2 * var(--m));
    height: var(--fh);
    grid-template-columns: minmax(42mm, .85fr) minmax(0, 3.2fr) auto minmax(31mm, .85fr) auto;
    align-items: stretch;
    column-gap: calc(2.5mm * var(--s));
    padding: calc(2.5mm * var(--s)) calc(3mm * var(--s));
    border: calc(.5mm * var(--s)) solid #111;
    border-top: 0;
    background: #fff;
    color: #111;
    font-size: calc(7pt * var(--s));
    line-height: 1.2;
    overflow: hidden;
}

.pp-main, .pp-scale, .pp-decl, .pp-dtable, .pp-qr {
    min-width: 0;
}

.pp-main {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-width: 0;
}

.pp-main > strong {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    overflow-wrap: anywhere;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: calc(15pt * var(--s));
    font-weight: 700;
    line-height: 1.05;
}

/* Metadata remains one ordered column directly beneath the title. */
.pp-info {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: calc(.65mm * var(--s));
    margin-top: calc(1.5mm * var(--s));
    min-width: 0;
    font-size: calc(6pt * var(--s));
}

.pp-info > div {
    display: flex;
    align-items: baseline;
    min-width: 0;
    white-space: nowrap;
}

.pp-info small {
    flex: 0 0 calc(9mm * var(--s));
    margin-right: calc(.5mm * var(--s));
    color: #666;
    font-size: calc(5pt * var(--s));
    text-transform: uppercase;
    letter-spacing: .025em;
}

.pp-info strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: calc(6pt * var(--s));
}

.pp-scale {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
}

.pp-ratio {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: calc(13pt * var(--s));
    font-weight: 700;
    line-height: 1.1;
}

.pp-scale > small {
    margin: calc(.4mm * var(--s)) 0 calc(1mm * var(--s));
    color: #555;
    font-size: calc(6pt * var(--s));
}

#scaleBars {
    display: flex;
    flex-direction: column;
    gap: calc(.6mm * var(--s));
    width: 100%;
    min-width: 0;
}

.sb {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.sb-bar {
    display: flex;
    box-sizing: content-box;
    height: calc(1.8mm * var(--s));
    border: calc(.2mm * var(--s)) solid #111;
    overflow: hidden;
}

.sb-bar > div {
    flex: none;
    height: 100%;
    border-right: calc(.12mm * var(--s)) solid #111;
}

.sb-labels {
    position: relative;
    height: calc(2.6mm * var(--s));
}

.sb-labels span {
    position: absolute;
    top: calc(.25mm * var(--s));
    transform: translateX(-50%);
    white-space: nowrap;
    font-size: calc(5.2pt * var(--s));
}

.sb-labels span[data-edge="start"] {
    transform: none;
}

.sb-labels span[data-edge="end"] {
    transform: translateX(-100%);
}

.pp-contours {
    margin-top: calc(.8mm * var(--s));
    color: #333;
    font-size: calc(6pt * var(--s));
    white-space: nowrap;
}

.pp-decl {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: calc(17mm * var(--s));
}

.pp-decl svg {
    width: calc(14mm * var(--s));
    height: calc(14mm * var(--s));
    overflow: visible;
}

.pp-decl small {
    color: #666;
    font-size: calc(5pt * var(--s));
    text-transform: uppercase;
    letter-spacing: .03em;
}

.pp-decl strong {
    font-size: calc(6pt * var(--s));
    white-space: nowrap;
}

.pp-dtable {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: calc(25mm * var(--s));
    min-width: 0;
    font-size: calc(5.2pt * var(--s));
}

.pp-dtable > small {
    margin-bottom: calc(.6mm * var(--s));
    color: #666;
    font-size: calc(4.8pt * var(--s));
    text-transform: uppercase;
    letter-spacing: .025em;
}

.pp-dtable table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.pp-dtable td {
    padding: calc(.15mm * var(--s)) 0;
    white-space: nowrap;
}

.pp-dtable td:last-child {
    text-align: right;
    font-weight: 600;
}

.pp-dtable tr:first-child td {
    border-bottom: calc(.15mm * var(--s)) solid #999;
}

.pp-rate {
    margin-top: calc(.5mm * var(--s));
    white-space: nowrap;
    font-size: calc(4.5pt * var(--s));
    color: #333;
}

/* Give the QR its own breathing room after the forecast table. */
.pp-qr {
    display: flex;
    align-items: center;
    justify-content: center;
    width: calc(21mm * var(--s));
    margin-left: calc(3mm * var(--s));
}

.pp-qr img {
    display: block;
    width: calc(20mm * var(--s));
    height: calc(20mm * var(--s));
    object-fit: contain;
}

/* Portrait keeps the footer groups aligned while using the slimmer footer. */
body.printing.print-portrait .print-page {
    grid-template-columns: minmax(38mm, .9fr) minmax(0, 2.5fr) auto minmax(28mm, .8fr) auto;
    column-gap: calc(1.5mm * var(--s));
}

body.printing.print-portrait .pp-main {
    justify-content: center;
}

body.printing.print-portrait .pp-info {
    margin-top: calc(1.5mm * var(--s));
}

#printArea[hidden] {
    display: none !important;
}

.panel {
    display: flex;
    flex-direction: column;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand img {
    width: auto;
    height: 46px;
    object-fit: contain;
}

.panel-footer {
    margin-top: auto;
    padding-top: 12px;
    text-align: center;
}

.panel-footer a {
    color: inherit;
    opacity: .45;
    font-size: 12px;
    text-decoration: none;
    transition: opacity .15s;
}

.panel-footer a:hover {
    opacity: .85;
}
