/*
 * CartoViewer foundation — tokens, type, and the primitives every page shares.
 *
 * The visual language comes from print production, because that is what these maps are: press
 * sheets. Hence the ink set below, the registration marks, the title blocks, and the colour bar.
 * Pure white is reserved for the map sheet itself and for the one chip that means "the sheet
 * exists"; everything else is ink and graphite, so the artefact is always the brightest thing
 * on screen. That is also why a review tool should be dark: a light surround shifts how a
 * reviewer judges colour on the sheet.
 */

/* ---- vendored faces -------------------------------------------------------------------- */

/* Archivo Narrow is the register of type printed on the sheets themselves — condensed
   grotesque, all caps, tight. It titles pages and nothing else. */
@font-face {
    font-family: 'Archivo Narrow';
    src: url('../lib/fonts/archivo-narrow-latin-700-normal.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Sans';
    src: url('../lib/fonts/ibm-plex-sans-latin-400-normal.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Sans';
    src: url('../lib/fonts/ibm-plex-sans-latin-500-normal.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Sans';
    src: url('../lib/fonts/ibm-plex-sans-latin-600-normal.woff2') format('woff2');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

/* Plex Mono carries every measured quantity: dimensions, tile counts, plate numbers, tokens,
   coordinates. If a number came off an instrument, it is set in mono. */
@font-face {
    font-family: 'IBM Plex Mono';
    src: url('../lib/fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Mono';
    src: url('../lib/fonts/ibm-plex-mono-latin-500-normal.woff2') format('woff2');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

/* ---- tokens ---------------------------------------------------------------------------- */

:root {
    /* The ink set. Each chromatic ink has exactly one job, the way a press plate does. */
    --ink: #0e1013;
    --ink-raise: #171a1f;
    --ink-sunk: #0a0b0e;
    --rule: #262b33;
    --rule-lit: #3a4250;
    --paper: #ffffff;

    --type: #e7eaee;
    --type-dim: #a3abb6;
    --type-faint: #7d8695;   /* ~5:1 on --ink; the marginalia is small, so it cannot go dimmer */

    --cyan: #00a6da;         /* interactive: links, focus, in progress */
    --magenta: #e5007e;      /* corrections: markups, failures, revocation */
    --yellow: #f5c400;       /* caution, and the colour bar */

    --display: 'Archivo Narrow', 'Arial Narrow', system-ui, sans-serif;
    --body: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;

    --shell: 1160px;
    --radius: 2px;           /* near-square: this is a technical document, not a card deck */
    --ease: cubic-bezier(0.2, 0.7, 0.3, 1);

    /* A registration mark, as a mask so it can take any ink. */
    --regmark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cg fill='none' stroke='%23000' stroke-width='1.25'%3E%3Ccircle cx='8' cy='8' r='4.25'/%3E%3Cpath d='M8 0v3.1M8 12.9V16M0 8h3.1M12.9 8H16'/%3E%3C/g%3E%3C/svg%3E");

    /* Corner brackets: fit the whole sheet in the frame. */
    --fitmark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='square' d='M1.5 5.5v-4h4M10.5 1.5h4v4M14.5 10.5v4h-4M5.5 14.5h-4v-4'/%3E%3C/svg%3E");
}

/* ---- reset ----------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

/*
 * An explicit `display` beats the user agent's [hidden] rule, so anything the JavaScript hides
 * by setting the attribute would stay on screen. This has now bitten twice — once on a label in
 * the composer, once on the composer itself — so the guard lives here, once, for everything.
 */
[hidden] { display: none !important; }

html {
    -webkit-text-size-adjust: 100%;
    background: var(--ink);
}

body {
    margin: 0;
    background: var(--ink);
    color: var(--type);
    font-family: var(--body);
    font-size: 14px;
    line-height: 1.55;
    font-feature-settings: 'kern' 1;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p, dl, dd, figure, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
img { display: block; max-width: 100%; }
svg { display: block; }

/*
 * Never clamp an SVG inside a Leaflet pane. A pane is an absolutely-positioned box with no width,
 * so `max-width: 100%` resolves to zero and a vector renderer silently disappears. Leaflet's own
 * stylesheet exempts the overlay pane, which is why annotations survived it — a custom pane, such
 * as the viewer's page matte, does not.
 */
.leaflet-container svg { max-width: none; }
button, input, select, textarea { font: inherit; color: inherit; }

a {
    color: var(--cyan);
    text-decoration: none;
    text-underline-offset: 3px;
}

a:hover { text-decoration: underline; }

:focus-visible {
    outline: 2px solid var(--cyan);
    outline-offset: 2px;
    border-radius: 1px;
}

::selection { background: rgba(0, 166, 218, 0.32); }

code, pre, .mono { font-family: var(--mono); }

/* ---- type roles ------------------------------------------------------------------------ */

.display {
    font-family: var(--display);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.01em;
    line-height: 1.02;
}

.display--xl { font-size: clamp(2rem, 4.4vw, 3.1rem); }
.display--l { font-size: clamp(1.6rem, 3vw, 2.2rem); }
.display--m { font-size: 1.35rem; }

/* Marginalia: the small letterspaced mono caps that label things on a drawing. */
.eyebrow {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--mono);
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--type-faint);
}

.eyebrow::before {
    content: '';
    flex: 0 0 auto;
    width: 11px;
    height: 11px;
    background: var(--cyan);
    -webkit-mask: var(--regmark) center / contain no-repeat;
    mask: var(--regmark) center / contain no-repeat;
}

.eyebrow--bare::before { display: none; }

.lede {
    max-width: 62ch;
    font-size: 0.9375rem;
    color: var(--type-dim);
}

.hint {
    font-size: 0.8125rem;
    color: var(--type-faint);
    line-height: 1.5;
}

.num {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}

/* ---- the colour bar ------------------------------------------------------------------- */

/*
 * The signature structural device: the strip of process-ink patches printed along the edge of a
 * press sheet so an operator can check ink density. Here it is the top edge of every page —
 * three short patches against a hairline, not a stripe across the whole width.
 */
.colourbar {
    display: flex;
    height: 2px;
    background: var(--rule);
}

.colourbar span {
    width: 30px;
    transform-origin: left center;
    animation: bar-wipe 420ms var(--ease) both;
}

.colourbar span:nth-child(1) { background: var(--cyan); animation-delay: 40ms; }
.colourbar span:nth-child(2) { background: var(--magenta); animation-delay: 110ms; }
.colourbar span:nth-child(3) { background: var(--yellow); animation-delay: 180ms; }

@keyframes bar-wipe {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
}

/* ---- the rail -------------------------------------------------------------------------- */

.rail {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(14, 16, 19, 0.92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--rule);
}

.rail__inner {
    max-width: var(--shell);
    margin: 0 auto;
    padding: 0 1.75rem;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 1.75rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    color: var(--type);
}

.brand:hover { text-decoration: none; }

.brand__mark {
    width: 17px;
    height: 17px;
    background: var(--type);
    -webkit-mask: var(--regmark) center / contain no-repeat;
    mask: var(--regmark) center / contain no-repeat;
    transition: background-color 180ms var(--ease);
}

.brand:hover .brand__mark { background: var(--cyan); }

.brand__name {
    font-family: var(--display);
    font-weight: 700;
    font-size: 1.0625rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.rail__nav {
    display: flex;
    gap: 1.25rem;
    font-size: 0.8125rem;
}

.rail__nav a {
    color: var(--type-dim);
    padding: 0.25rem 0;
    border-bottom: 1px solid transparent;
}

.rail__nav a:hover {
    color: var(--type);
    text-decoration: none;
    border-bottom-color: var(--rule-lit);
}

.rail__nav a[aria-current='page'] {
    color: var(--type);
    border-bottom-color: var(--cyan);
}

.rail__spacer { flex: 1 1 auto; }

.rail__user {
    font-family: var(--mono);
    font-size: 0.6875rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--type-faint);
}

/* ---- shell ----------------------------------------------------------------------------- */

.shell {
    max-width: var(--shell);
    margin: 0 auto;
    padding: 2.5rem 1.75rem 5rem;
}

.crumbs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    font-family: var(--mono);
    font-size: 0.6875rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.crumbs a { color: var(--type-faint); }
.crumbs a:hover { color: var(--cyan); }
.crumbs span { color: var(--rule-lit); }
.crumbs strong { color: var(--type-dim); font-weight: 400; }

/* ---- title block ----------------------------------------------------------------------- */

/*
 * The block of labelled cells in the corner of an engineering drawing or a map sheet: what this
 * is, who it is for, who made it, when. Same job here, same shape.
 */
.titleblock {
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--ink-raise);
}

.titleblock__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
    flex-wrap: wrap;
    padding: 1.5rem 1.75rem 1.375rem;
}

.titleblock__head h1 { margin-top: 0.5rem; }

.titleblock__ident {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
}

.titleblock__cells {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    border-top: 1px solid var(--rule);
}

.titleblock__cells > div {
    padding: 0.875rem 1.75rem 1rem;
    border-left: 1px solid var(--rule);
}

.titleblock__cells > div:first-child { border-left: 0; }

.titleblock__cells dt {
    font-family: var(--mono);
    font-size: 0.625rem;
    font-weight: 500;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--type-faint);
}

.titleblock__cells dd {
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: var(--type);
    overflow-wrap: anywhere;
}

/* ---- sections -------------------------------------------------------------------------- */

.section { margin-top: 3rem; }

.section__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--rule);
    margin-bottom: 1.25rem;
}

.section__head h2 {
    font-family: var(--display);
    font-weight: 700;
    font-size: 1.0625rem;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 2.5rem;
    align-items: start;
}

@media (max-width: 900px) {
    .split { grid-template-columns: minmax(0, 1fr); }
}

/* ---- docket ---------------------------------------------------------------------------- */

/* A job ticket: the panel you fill in to put work into the shop. */
.docket {
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: var(--ink-raise);
}

.docket > header {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--rule);
}

.docket__body {
    padding: 1.25rem;
    display: grid;
    gap: 1rem;
}

/* ---- fields ---------------------------------------------------------------------------- */

.field { display: grid; gap: 0.375rem; }

.field > label,
.field-label {
    font-family: var(--mono);
    font-size: 0.625rem;
    font-weight: 500;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--type-faint);
}

input[type='text'],
input[type='password'],
input[type='date'],
select,
textarea {
    width: 100%;
    padding: 0.5rem 0.625rem;
    background: var(--ink-sunk);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    color: var(--type);
    font-size: 0.875rem;
    transition: border-color 140ms var(--ease);
}

input::placeholder, textarea::placeholder { color: var(--type-faint); }

input:hover, select:hover, textarea:hover { border-color: var(--rule-lit); }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--cyan);
    box-shadow: inset 0 0 0 1px var(--cyan);
}


/*
 * A checkbox and its sentence, on one line. The label is a sentence rather than a field name, so
 * it stays in the body face — unlike .field > label, which titles an input.
 */
.check {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.75rem;
    line-height: 1.4;
    color: var(--type-dim);
    cursor: pointer;
}

.check input[type='checkbox'] {
    flex: 0 0 auto;
    width: 0.875rem;
    height: 0.875rem;
    margin: 0.0625rem 0 0;

    /* The one native control here: accent-color is what keeps it in the ink set. */
    accent-color: var(--cyan);
}

/*
 * The native file button keeps its light system chrome whatever ::file-selector-button says, so
 * the input is taken out of the layout and a real <label> stands in for it. Still a real input
 * and a real label, so the keyboard and screen readers see no difference.
 */
.filepick {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.filepick input:focus-visible + label {
    outline: 2px solid var(--cyan);
    outline-offset: 2px;
}

.filepick__name {
    min-width: 0;
    font-size: 0.8125rem;
    color: var(--type-faint);
    overflow-wrap: anywhere;
}

.filepick__name.is-chosen { color: var(--type-dim); }

select {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--type-faint) 50%),
                      linear-gradient(135deg, var(--type-faint) 50%, transparent 50%);
    background-position: right 1rem center, right 0.7rem center;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 2rem;
}

/* Date inputs render their own dark-on-dark glyph otherwise. */
input[type='date']::-webkit-calendar-picker-indicator { filter: invert(1) opacity(0.75); cursor: pointer; }

.field-error {
    font-size: 0.75rem;
    color: var(--magenta);
}

/* ---- buttons --------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    background: transparent;
    color: var(--type-dim);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 140ms var(--ease), border-color 140ms var(--ease), background-color 140ms var(--ease);
}

.btn:hover { color: var(--type); border-color: var(--rule-lit); text-decoration: none; }

.btn[disabled] { opacity: 0.45; cursor: default; }

.btn--primary {
    background: var(--cyan);
    border-color: var(--cyan);
    color: #04161d;
    font-weight: 600;
}

.btn--primary:hover { background: #1cb8e9; border-color: #1cb8e9; color: #04161d; }

.btn--danger { color: var(--magenta); border-color: rgba(229, 0, 126, 0.4); }
.btn--danger:hover { color: #fff; background: var(--magenta); border-color: var(--magenta); }

.btn--small { padding: 0.3125rem 0.625rem; font-size: 0.75rem; }

/* For an action that is always available but rarely the point — "Reply" on every note. */
.btn--quiet {
    border-color: transparent;
    background: transparent;
    color: var(--type-faint);
}

.btn--quiet:hover { border-color: var(--rule-lit); color: var(--type); }

.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ---- chips ----------------------------------------------------------------------------- */

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4375rem;
    padding: 0.1875rem 0.5rem;
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    font-family: var(--mono);
    font-size: 0.625rem;
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--type-dim);
    white-space: nowrap;
}

.chip::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
}

/* Ready is the only thing on the page allowed to be paper white: it means the sheet exists. */
.chip--ready { background: var(--paper); border-color: var(--paper); color: var(--ink); }

/*
 * On paper, a filled dot in near-black read as a bullet rather than a status. The mark that
 * belongs on a sheet is the registration mark — the same motif as the brand and every eyebrow,
 * where it is already cyan without being interactive. No new ink is spent: the chip's whiteness
 * is what says "ready", and the mark only has to stop looking like a typographic bullet.
 */
.chip--ready::before {
    width: 9px;
    height: 9px;
    border-radius: 0;
    background: var(--cyan);
    -webkit-mask: var(--regmark) center / contain no-repeat;
    mask: var(--regmark) center / contain no-repeat;
}
.chip--working { color: var(--cyan); border-color: rgba(0, 166, 218, 0.45); }
.chip--failed { color: var(--magenta); border-color: rgba(229, 0, 126, 0.45); }
.chip--idle { color: var(--type-faint); }

/*
 * Caution: temporary, and it clears itself. Not magenta — that ink means a correction or a
 * revocation, and a lockout is neither; it is a wait. Used for an account resting after too many
 * wrong passwords, with the remaining minutes set in mono beside it.
 */
.chip--caution { color: var(--yellow); border-color: rgba(245, 196, 0, 0.45); }

.chip--working::before { animation: chip-pulse 1.4s ease-in-out infinite; }

@keyframes chip-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.25; }
}

/* ---- notes ----------------------------------------------------------------------------- */

.note {
    display: flex;
    gap: 0.75rem;
    padding: 0.875rem 1.125rem;
    border: 1px solid var(--rule);
    border-left: 2px solid var(--cyan);
    border-radius: var(--radius);
    background: var(--ink-raise);
    font-size: 0.875rem;
    color: var(--type-dim);
}

.note--alert { border-left-color: var(--magenta); }

.note[hidden] { display: none; }

/* ---- empty ----------------------------------------------------------------------------- */

.empty {
    padding: 2.5rem 1.75rem;
    border: 1px dashed var(--rule);
    border-radius: var(--radius);
    text-align: center;
    color: var(--type-faint);
    font-size: 0.875rem;
}

.empty strong {
    display: block;
    margin-bottom: 0.25rem;
    font-family: var(--display);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--type-dim);
}

/* ---- dead end ---------------------------------------------------------------------------- */

/*
 * Expired, revoked, unknown, still processing, or a server error. A client following a link from
 * an email is quite likely to meet one of these, so it is a designed page and not an error dump —
 * and it lives here rather than in site.css because the viewer layout needs it too.
 */
.stop {
    max-width: 34rem;
    margin: 14vh auto;
    padding: 0 1.75rem;
    text-align: center;
}

.stop__mark {
    width: 32px;
    height: 32px;
    margin: 0 auto 1.75rem;
    background: var(--magenta);
    -webkit-mask: var(--regmark) center / contain no-repeat;
    mask: var(--regmark) center / contain no-repeat;
}

.stop code {
    display: inline-block;
    margin-top: 1.5rem;
    padding: 0.3125rem 0.625rem;
    background: var(--ink-raise);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    font-size: 0.75rem;
    color: var(--type-dim);
}

/* ---- utility --------------------------------------------------------------------------- */

.is-hidden { display: none !important; }
.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

/* ---- sign in ----------------------------------------------------------------------------- */

/* A single centred docket. Used by sign in, sign out and the forced password change. */
.signin {
    display: grid;
    place-items: center;
    min-height: 60vh;
    padding: 2rem 1rem;
}

.signin .docket {
    width: min(24rem, 100%);
}

/* ---- credentials ----------------------------------------------------------------------- */

/*
 * A one-time password is read aloud down a phone and copied by eye, so it is set in the face this
 * system reserves for typed quantities and given room to breathe. Caution yellow, never --paper:
 * white belongs to the map sheet, and spending it here would stop the artefact being the
 * brightest thing on screen.
 */
.credential {
    font-family: var(--mono);
    font-size: 1.0625rem;
    letter-spacing: 0.06em;
    margin: 0.25rem 0;
    color: var(--type-dim);
}

.credential--secret {
    font-size: 1.625rem;
    letter-spacing: 0.12em;
    color: var(--yellow);
}

/* The hand-off panel: shown once, immediately after an account is created or reset. */
.handoff {
    max-width: 32rem;
    margin-bottom: 2rem;
}

/* Sign out sits beside the signed-in name, so it is sized to match it rather than the nav. */
.rail__signout {
    font-family: var(--mono);
    font-size: 0.6875rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--type-faint);
    margin-left: 1rem;
}

.rail__signout:hover { color: var(--cyan); text-decoration: none; }

/*
 * Row actions on the user register. Four controls plus a typed confirmation do not fit a table
 * cell as separate block forms — left alone they stack, make every row several lines tall, and
 * spill under the docket beside them. Each form becomes an inline flex item so the whole set
 * reflows onto as few lines as the column allows.
 */
.register__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
}

.register__actions form {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin: 0;
}

/* Wide enough to read the name being typed, narrow enough not to dominate the row. */
.register__actions input[type='text'] {
    width: 8.5rem;
    padding: 0.25rem 0.5rem;
    font-family: var(--mono);
    font-size: 0.75rem;
}
