@font-face {
    font-family: "RO Sans";
    src: url("https://www.emaddc.com/communities/common/themes/mett%20responsive/includes/fonts/ro%20sans.woff") format("woff");
    font-display: swap;
}

/* Colours taken from the emaddc.com theme */
:root {
    --primary: #154373;
    --primary-hover: #2C5F96;
    --accent: #01689B;
    --accent-soft: #e6f0f6;
    --ink: #1d2733;
    --muted: #5b6878;
    --line: #d6dee7;
    --bg: #f4f6f9;
    --card: #ffffff;
    --radius: 8px;
    --focus: 0 0 0 3px rgba(1, 104, 155, .35);
    --control-h: 34px;
}

* {
    box-sizing: border-box;
}

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

body {
    display: flex;
    flex-direction: column;
    font-family: "RO Sans", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.4;
    color: var(--ink);
    background: var(--bg);
    -webkit-text-size-adjust: 100%;
}

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

:focus-visible {
    outline: none;
    box-shadow: var(--focus);
}

[hidden] {
    display: none !important;
}

/* ---------- Toolbar ---------- */

.toolbar {
    padding: 10px 20px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
}

.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px 16px;
}

.control {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.control-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
}

.segmented {
    display: inline-flex;
    padding: 2px;
    gap: 2px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.segmented button {
    height: calc(var(--control-h) - 6px);
    padding: 0 11px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color .15s, color .15s;
}

.segmented button:hover {
    background: var(--accent-soft);
    color: var(--primary);
}

/* No font-weight change, so selecting a button never changes its width */
.segmented button.active {
    background: var(--primary);
    color: #fff;
}

/* Feature branch: "dev-em-" followed directly by the story number */
.branch {
    display: flex;
    gap: 4px;
    margin: 0;
}

.branch-field {
    display: flex;
    align-items: center;
    width: 130px;
    height: var(--control-h);
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    font-size: 14px;
    cursor: text;
}

.branch-field:focus-within {
    border-color: var(--accent);
    box-shadow: var(--focus);
}

.branch-prefix {
    color: var(--muted);
    white-space: nowrap;
    user-select: none;
}

.branch-field input {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    font-size: inherit;
}

.branch-field input:focus-visible {
    box-shadow: none;
}

.branch-field input::placeholder {
    color: #b3bcc7;
}

/* Period: fixed width so switching between daily/weekly/monthly doesn't move anything */
.period {
    display: flex;
    align-items: center;
    gap: 4px;
}

.period input,
.period select {
    height: var(--control-h);
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    font-size: 14px;
}

.period-field {
    display: flex;
    gap: 4px;
    width: 250px;
}

.period-field input,
.period-field select {
    flex: 1;
    min-width: 0;
}

/* The script sets data-type (day / week / month) on the body; show only that type's period field */
body:not([data-type="day"]) #date-input,
body:not([data-type="week"]) #week-select,
body:not([data-type="month"]) #month-select {
    display: none;
}

/* iOS Safari centres the date value otherwise */
.period-field input[type="date"]::-webkit-date-and-time-value {
    text-align: left;
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: var(--control-h);
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--primary);
    font-size: 14px;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s, border-color .15s;
}

.btn:hover:not(:disabled) {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.btn:disabled,
.btn.disabled {
    color: #a7b1bd;
    cursor: default;
    pointer-events: none;
}

.btn.icon {
    width: 30px;
    padding: 0;
    font-size: 18px;
}

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

.btn.primary:hover:not(:disabled) {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn.primary:disabled {
    background: var(--card);
    border-color: var(--line);
    color: #a7b1bd;
}

/* Last on desktop */
.open-link {
    order: 1;
}

/* Environment buttons show the full name, and the short id (prd / acc) on phones */
.env-id {
    display: none;
}

/* The credit and the section dropdown are grouped for the phone layout. On larger screens the
   group is transparent (the credit is a regular item of the controls row) and the dropdown, a
   compact replacement for the contents links, is hidden. */
.credit-row {
    display: contents;
}

.section-select {
    display: none;
    flex: 1;
    min-width: 0;
    height: var(--control-h);
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
}

/* Met Office credit: the logo with the funding statement below it, at the right end of the controls */
.credit {
    order: 2;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
    margin-left: auto;
    text-align: right;
}

/* Always exactly two lines of about equal length, one per span */
.credit p {
    margin: 0;
    font-size: 10.5px;
    line-height: 1.3;
    color: var(--muted);
}

.credit span {
    display: block;
    white-space: nowrap;
}

.credit a {
    color: var(--accent);
}

/* The PNG has wide transparent margins; this box shows only the logo itself, which is the
   1036 × 141 px area starting at (139, 136) of the 1317 × 413 px image */
.logo {
    --logo-h: 30px;
    flex: none;
    width: calc(var(--logo-h) * 1036 / 141);
    height: var(--logo-h);
    overflow: hidden;
}

.logo img {
    display: block;
    height: calc(var(--logo-h) * 413 / 141);
    margin: calc(var(--logo-h) * -136 / 141) 0 0 calc(var(--logo-h) * -139 / 141);
}

/* Narrower than this the credit no longer fits next to the controls and gets its own row,
   with the statement next to the logo */
@media (max-width: 1199px) {
    .credit {
        flex: 1 0 100%;
        flex-direction: row;
        align-items: center;
        gap: 12px;
        margin-left: 0;
        text-align: left;
    }
}

/* ---------- Contents ---------- */

.layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.toc {
    padding: 6px 20px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
}

/* Two rows of six; inline-grid + 1fr makes every column as wide as the widest link */
.toc-links {
    display: inline-grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 2px 4px;
}

.toc-links button {
    padding: 3px 8px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--accent);
    font-size: 13px;
    text-align: center;
    white-space: nowrap;
    cursor: pointer;
}

.toc-links button:hover:not(:disabled),
.toc-links button:focus-visible {
    background: var(--primary);
    color: #fff;
}

.toc-links button:active:not(:disabled) {
    background: var(--primary-hover);
}

/* Timeliness while viewing a monthly report, which has no such section */
.toc-links button:disabled {
    color: #a7b1bd;
    cursor: default;
}

@media (max-width: 840px) {
    .toc-links {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ---------- Report ---------- */

.viewer {
    flex: 1;
    min-width: 0;
    min-height: 600px;
    background: var(--card);
}

.viewer iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
}

.empty {
    padding: 48px 20px;
    text-align: center;
    color: var(--muted);
}

.empty strong {
    display: block;
    margin-bottom: 4px;
    font-size: 17px;
    color: var(--ink);
}

/* ---------- Mobile ---------- */

@media (max-width: 600px) {
    :root {
        --control-h: 36px;
    }

    .toolbar {
        padding: 8px 12px;
    }

    /* Compact: no labels, Open button or contents links. Environment and report type share the
       first row, the period gets the second, and the credit and section dropdown the last one.
       The dev page's feature branch field needs a row of its own. */
    .control-label,
    .open-link,
    .toc {
        display: none;
    }

    .controls {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        gap: 8px;
    }

    .control-env:has(.branch),
    .control-env:has(.branch) ~ .control-type,
    .control-period,
    .credit-row {
        grid-column: 1 / -1;
    }

    .env-name {
        display: none;
    }

    .env-id {
        display: inline;
    }

    /* The gap is 24px where possible, but never leaves the dropdown narrower than the 144px its
       placeholder needs next to the 180px credit (percentages are of the row width) */
    .credit-row {
        display: flex;
        align-items: center;
        gap: clamp(8px, calc(100% - 180px - 144px), 24px);
    }

    .section-select {
        display: block;
        padding: 0 6px;
    }

    /* Logo above the statement, which stays on its two lines (178px at most at 8px). The logo is
       as wide as the statement, and sized by width here, so the crop uses percentages of it. */
    .credit {
        order: 1;
        flex: none;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        width: 180px;
        text-align: center;
    }

    .logo {
        flex: none;
        width: 100%;
        height: auto;
        aspect-ratio: 1036 / 141;
    }

    .logo img {
        width: calc(100% * 1317 / 1036);
        height: auto;
        /* Percentage margins are relative to the width, also for the top margin */
        margin: calc(-100% * 136 / 1036) 0 0 calc(-100% * 139 / 1036);
    }

    .credit p {
        font-size: 8px;
    }

    .control,
    .period,
    .period-field,
    .branch,
    .branch-field {
        min-width: 0;
    }

    .segmented {
        display: flex;
    }

    .segmented button {
        flex: 1;
        padding: 0 10px;
    }

    .branch-field,
    .period-field {
        flex: 1;
        width: auto;
    }

    .branch .btn {
        min-width: 64px;
    }

    .btn.icon {
        flex: none;
    }

    .btn.icon {
        width: 36px;
    }

    /* 16px stops iOS from zooming in when a field is tapped */
    .branch-field,
    .period input,
    .period select,
    .section-select {
        font-size: 16px;
    }

    .segmented button,
    .btn {
        font-size: 15px;
    }
}

/* Too narrow for the credit next to the section dropdown: the credit gets its own row between the
   period and the dropdown, with the statement on two lines. The environment and report type
   buttons also get less padding to fit on one row. */
@media (max-width: 359px) {
    .segmented button {
        padding: 0 6px;
    }

    .credit-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .credit {
        order: 0;
        width: auto;
    }

    .logo {
        width: 220px;
    }

    .credit p {
        font-size: 11px;
    }
}
