/* ===========================================================================
   Diia design language — tokens and base components
   ===========================================================================

   This file is the design system. It knows nothing about vessels, maps or
   geofences: it defines what a button, a field, a card and a table look like,
   and site.css assembles screens out of them.

   Two rules keep the split honest:

     1. Nothing here is positioned. No `position: fixed`, no viewport units, no
        grid template that names an application region. A component has to be
        usable inside the map's side panel and on a full-width page alike, and
        the moment it carries its own placement it stops being reusable.
     2. Nothing here is JavaScript. Every component is styled by a class the
        server already renders or by a CSS state (`:hover`, `:focus-visible`,
        `:disabled`, `:checked`). A component that needed a script would need a
        script inside the map island too, and there is exactly one island here
        (ADR-0001, docs/htmx-conventions.md).

   Colours, radii and type follow the Diia design language (ADR-0004): a white
   ground, near-black type, one blue accent, black primary actions, and generous
   rounding. Everything is expressed as a custom property — restyling the
   application to another brand is meant to be an edit of the block below and
   nothing else.
   ------------------------------------------------------------------------- */

:root {
    /* --- Brand ---------------------------------------------------------- */
    --c-black: #000000;
    --c-white: #ffffff;

    /* The accent. Links, focus rings, selected states and the map's own
       highlights all come from this one value. */
    --c-accent: #2b77e7;
    --c-accent-strong: #1b5fc4;
    /* Tinted surface for a selected row or an informational panel. Light enough
       that near-black type on it still clears AA. */
    --c-accent-soft: #e7effd;

    /* --- Neutrals ------------------------------------------------------- */
    --c-fg: #1a1a1a;
    --c-muted: #63666a;
    --c-border: #e2e6ea;
    --c-border-strong: #c9cfd5;
    --c-surface: #f4f6f8;
    --c-bg: #ffffff;

    /* --- Status --------------------------------------------------------- */
    /* Each has a fill used for a badge and a foreground used for its text. The
       two are separate because the badge's text sits on the fill, and a single
       value cannot do both at the contrast this interface needs. */
    --c-success: #12894f;
    --c-success-soft: #e4f6ec;
    --c-warning: #8a5a00;
    --c-warning-soft: #fdf1d8;
    --c-error: #c5283d;
    --c-error-soft: #fbe9eb;

    /* --- Type ----------------------------------------------------------- */
    /* e-Ukraine is the Diia typeface. Its files are licensed and are not in the
       repository, so the stack degrades to the platform grotesque; dropping the
       family name would mean an installed copy is never picked up. */
    --font-sans: "e-Ukraine", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-head: "e-Ukraine Head", var(--font-sans);
    /* Device identifiers are 15-digit IMEIs read against a label on a box. */
    --font-mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", monospace;

    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-md: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.375rem;
    --text-2xl: 1.75rem;

    /* --- Space ---------------------------------------------------------- */
    --sp-1: 0.25rem;
    --sp-2: 0.5rem;
    --sp-3: 0.75rem;
    --sp-4: 1rem;
    --sp-5: 1.5rem;
    --sp-6: 2rem;
    --sp-7: 3rem;

    /* --- Shape ---------------------------------------------------------- */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-pill: 999px;

    /* --- Elevation ------------------------------------------------------ */
    /* Two levels only. A third invites a hierarchy nobody can keep straight,
       and everything in this interface is either on the page or over the map. */
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.10);
    --shadow-lg: 0 4px 6px rgba(16, 24, 40, 0.04), 0 12px 28px rgba(16, 24, 40, 0.14);

    --focus-ring: 0 0 0 3px rgba(43, 119, 231, 0.35);

    --transition: 0.15s ease;
}

/* ---------------------------------------------------------------------------
   Base
   --------------------------------------------------------------------------- */

*,
*::before,
*::after { box-sizing: border-box; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font-sans);
    font-size: var(--text-md);
    line-height: 1.5;
    color: var(--c-fg);
    background: var(--c-bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    font-family: var(--font-head);
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.25;
    margin: 0;
}

h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

a { color: var(--c-accent); text-decoration: none; }
a:hover { color: var(--c-accent-strong); text-decoration: underline; }

code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    padding: 0.1em 0.35em;
    border-radius: 4px;
    background: var(--c-surface);
}

/* One focus treatment for the whole interface. Keyboard-only (`:focus-visible`)
   so a mouse click on a button does not leave a ring behind it. */
:focus-visible {
    outline: 2px solid var(--c-accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Available to screen readers, invisible on screen. Used for labels whose text
   would be redundant next to an icon that already carries it. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.text-muted { color: var(--c-muted); }
.text-sm { font-size: var(--text-sm); }
/* Figures that update in place must not shift the text around them. */
.tabular { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------------
   Button

   Four intents, and the choice between them is about consequence rather than
   prominence: `--primary` commits (black, the Diia primary), `--accent` is the
   same commitment where black would read as an application chrome control,
   `--secondary` is reversible, `--ghost` is navigation. `--danger` destroys.
   --------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 0.625rem 1.25rem;
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    background: transparent;
    font: inherit;
    font-weight: 600;
    line-height: 1.2;
    color: var(--c-fg);
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.btn:hover { text-decoration: none; }

.btn:disabled,
.btn[aria-disabled="true"] {
    cursor: default;
    opacity: 0.45;
    pointer-events: none;
}

.btn--primary { background: var(--c-black); color: var(--c-white); }
.btn--primary:hover { background: #2c2c2c; color: var(--c-white); }

.btn--accent { background: var(--c-accent); color: var(--c-white); }
.btn--accent:hover { background: var(--c-accent-strong); color: var(--c-white); }

.btn--secondary { background: var(--c-white); border-color: var(--c-border-strong); color: var(--c-fg); }
.btn--secondary:hover { border-color: var(--c-black); background: var(--c-surface); }

.btn--ghost { background: transparent; color: var(--c-fg); }
.btn--ghost:hover { background: var(--c-surface); }

.btn--danger { background: var(--c-error); color: var(--c-white); }
.btn--danger:hover { background: #a41f31; color: var(--c-white); }

.btn--sm { padding: 0.375rem 0.875rem; font-size: var(--text-sm); }
.btn--lg { padding: 0.875rem 1.75rem; font-size: var(--text-base); }
.btn--block { display: flex; width: 100%; }

/* Square button for a single glyph — a close cross, a pager arrow. Sized from
   the font so it stays square whatever the surrounding type is. */
.btn--icon {
    padding: 0;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius-pill);
}

/* A POST that has to look like a link. Sign-out is the case: a GET that ends a
   session is triggerable by any image tag pointed at it. */
.link-button {
    border: none;
    background: none;
    padding: 0;
    font: inherit;
    color: var(--c-accent);
    cursor: pointer;
}

.link-button:hover { color: var(--c-accent-strong); text-decoration: underline; }

/* ---------------------------------------------------------------------------
   Fields
   --------------------------------------------------------------------------- */

.field { display: block; margin-bottom: var(--sp-4); }

.field__label {
    display: block;
    margin-bottom: var(--sp-1);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--c-muted);
}

.input,
.select,
.textarea {
    display: block;
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius-sm);
    background: var(--c-white);
    font: inherit;
    color: var(--c-fg);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.input::placeholder,
.textarea::placeholder { color: var(--c-muted); }

.input:hover,
.select:hover,
.textarea:hover { border-color: var(--c-border-strong); }

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--c-accent);
    box-shadow: var(--focus-ring);
}

.input:disabled,
.select:disabled,
.textarea:disabled { background: var(--c-surface); color: var(--c-muted); cursor: default; }

.input.is-invalid { border-color: var(--c-error); }

.textarea { min-height: 6rem; resize: vertical; }

.select {
    /* Native chevron removed and redrawn, because the platform one differs
       enough between Windows and macOS to break the row's alignment. */
    appearance: none;
    padding-right: 2.25rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%2363666a' stroke-width='1.6' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.875rem center;
}

.field__hint { display: block; margin-top: var(--sp-1); font-size: var(--text-xs); color: var(--c-muted); }
.field__error,
.field-error { display: block; margin-top: var(--sp-1); font-size: var(--text-xs); color: var(--c-error); }
/* Empty validation spans are rendered unconditionally by the tag helper; an
   empty one must not reserve a line. */
.field__error:empty,
.field-error:empty { display: none; }

/* Search field. The magnifier is a background image rather than an element so
   the control stays a bare <input> that htmx and the browser both understand. */
.search {
    width: 100%;
    padding: 0.625rem 0.875rem 0.625rem 2.5rem;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius-pill);
    background-color: var(--c-white);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cg fill='none' stroke='%2363666a' stroke-width='1.6'%3E%3Ccircle cx='7' cy='7' r='4.6'/%3E%3Cpath d='M10.6 10.6 14 14' stroke-linecap='round'/%3E%3C/g%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 0.875rem center;
    font: inherit;
    color: var(--c-fg);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.search::placeholder { color: var(--c-muted); }
.search:focus { outline: none; border-color: var(--c-accent); box-shadow: var(--focus-ring); }
/* The browser's own clear cross duplicates a control the design does not have. */
.search::-webkit-search-cancel-button { cursor: pointer; }

/* Switch. A styled checkbox — the input stays a real checkbox so it posts, is
   focusable and reads as one to assistive technology. */
.switch { display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }

.switch__track {
    position: relative;
    flex: 0 0 auto;
    width: 2.75rem;
    height: 1.5rem;
    border-radius: var(--radius-pill);
    background: var(--c-border-strong);
    transition: background var(--transition);
}

.switch__track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 1.125rem;
    height: 1.125rem;
    border-radius: 50%;
    background: var(--c-white);
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition);
}

.switch input:checked + .switch__track { background: var(--c-accent); }
.switch input:checked + .switch__track::after { transform: translateX(1.25rem); }
.switch input:focus-visible + .switch__track { box-shadow: var(--focus-ring); }

/* ---------------------------------------------------------------------------
   Chip and badge

   A chip is pressable and filters something. A badge is read-only and states a
   condition. They look similar on purpose and are never interchangeable.
   --------------------------------------------------------------------------- */

.chip {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 0.3125rem 0.75rem;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius-pill);
    background: var(--c-white);
    font: inherit;
    font-size: var(--text-sm);
    color: var(--c-fg);
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.chip:hover { border-color: var(--c-black); }
.chip.is-active { background: var(--c-black); border-color: var(--c-black); color: var(--c-white); }
.chip__count { font-variant-numeric: tabular-nums; opacity: 0.7; }

/* Colour is never the only carrier: each badge is also its own word, because a
   colour-blind operator reads the same table. */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.1875rem 0.625rem;
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    font-size: var(--text-xs);
    font-weight: 500;
    white-space: nowrap;
}

.badge.is-reporting,
.badge--success { background: var(--c-success-soft); color: var(--c-success); border-color: rgba(18, 137, 79, 0.2); }
.badge.is-silent,
.badge--error { background: var(--c-error-soft); color: var(--c-error); border-color: rgba(197, 40, 61, 0.2); }
.badge--warning { background: var(--c-warning-soft); color: var(--c-warning); border-color: rgba(138, 90, 0, 0.2); }
.badge.is-nodata,
.badge--neutral { background: var(--c-surface); color: var(--c-muted); border-color: var(--c-border); }
.badge--info { background: var(--c-accent-soft); color: var(--c-accent-strong); border-color: rgba(43, 119, 231, 0.2); }

/* Status dot for a badge that leads with one. Inherits the badge's colour, so a
   new badge variant needs no dot rule of its own. */
.badge__dot {
    width: 0.4375rem;
    height: 0.4375rem;
    border-radius: 50%;
    background: currentColor;
    flex: 0 0 auto;
}

/* ---------------------------------------------------------------------------
   Card
   --------------------------------------------------------------------------- */

.card {
    background: var(--c-white);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    padding: var(--sp-5);
}

.card--flat { border: none; background: var(--c-surface); }
.card--raised { border: none; box-shadow: var(--shadow-sm); }
.card--tight { padding: var(--sp-4); }

.card__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--sp-3);
    margin-bottom: var(--sp-4);
}

.card__title { font-size: var(--text-lg); }

/* Prose inside a card. The browser's own paragraph margin is symmetrical and in
   `em`, which leaves the first line pushed away from the card's top padding by a
   different amount at every type size. */
.card p { margin: 0 0 var(--sp-3); }
.card > :last-child,
.card__body > :last-child { margin-bottom: 0; }

/* Label above a group of figures. Small, upper-case and spaced — the Diia
   section marker. */
.eyebrow {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--c-muted);
}

/* A single figure with its caption. Rows of these are the standard summary. */
.stat-tile {
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius-md);
    background: var(--c-surface);
}

.stat-tile__value {
    display: block;
    font-family: var(--font-head);
    font-size: var(--text-xl);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.stat-tile__label { display: block; margin-top: 0.125rem; font-size: var(--text-xs); color: var(--c-muted); }
.stat-tile--success .stat-tile__value { color: var(--c-success); }
.stat-tile--warning .stat-tile__value { color: var(--c-warning); }
.stat-tile--error .stat-tile__value { color: var(--c-error); }

.tile-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); gap: var(--sp-2); }

/* ---------------------------------------------------------------------------
   Table
   --------------------------------------------------------------------------- */

.data-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }

.data-table th,
.data-table td {
    padding: 0.625rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--c-border);
}

.data-table th {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--c-muted);
    border-bottom-color: var(--c-border-strong);
    white-space: nowrap;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--c-surface); }
.data-table .cell-id { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--c-muted); }
.data-table .muted { color: var(--c-muted); }
.data-table .empty { color: var(--c-muted); text-align: center; padding: var(--sp-6) var(--sp-4); }
.data-table .empty:hover { background: none; }

/* Colour chip beside a name, tying a row to the outline it names on the map. */
.zone-swatch {
    display: inline-block;
    width: 0.625rem;
    height: 0.625rem;
    margin-right: var(--sp-2);
    border-radius: 3px;
    vertical-align: baseline;
}

/* ---------------------------------------------------------------------------
   Segmented control

   Rendered inside the fragment it switches, so its pressed state comes from the
   server's response rather than from a click handler.
   --------------------------------------------------------------------------- */

.segmented { display: inline-flex; padding: 3px; border-radius: var(--radius-pill); background: var(--c-surface); }

.segmented > .toggle,
.toggle {
    border: none;
    background: transparent;
    border-radius: var(--radius-pill);
    padding: 0.375rem 0.875rem;
    font: inherit;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--c-muted);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.toggle:hover:not(.is-active) { color: var(--c-fg); }
.toggle.is-active { background: var(--c-white); color: var(--c-fg); box-shadow: var(--shadow-sm); }

/* ---------------------------------------------------------------------------
   Alert
   --------------------------------------------------------------------------- */

.alert {
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius-md);
    border-left: 3px solid transparent;
    font-size: var(--text-sm);
}

.alert-error,
.alert--error { background: var(--c-error-soft); color: var(--c-error); border-left-color: var(--c-error); }
.alert--warning { background: var(--c-warning-soft); color: var(--c-warning); border-left-color: var(--c-warning); }
.alert--success { background: var(--c-success-soft); color: var(--c-success); border-left-color: var(--c-success); }
.alert--info { background: var(--c-accent-soft); color: var(--c-accent-strong); border-left-color: var(--c-accent); }

/* The shared error fragment is returned bare by FromResult, without the .alert
   base class in some call sites — give .alert-error the padding on its own. */
.alert-error:not(.alert) { padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-md); font-size: var(--text-sm); }

/* ---------------------------------------------------------------------------
   Pager, empty state, skeleton
   --------------------------------------------------------------------------- */

.pager { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-1) 0; }

.pager button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius-pill);
    background: var(--c-white);
    font: inherit;
    line-height: 1;
    color: var(--c-fg);
    cursor: pointer;
    transition: border-color var(--transition), color var(--transition);
}

.pager button:hover:not(:disabled) { border-color: var(--c-black); }
.pager button:disabled { color: var(--c-border-strong); border-color: var(--c-border); cursor: default; }
.pager-status { color: var(--c-muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }

.empty-state { padding: var(--sp-6) var(--sp-4); text-align: center; color: var(--c-muted); }
.empty-state__title { font-family: var(--font-head); font-weight: 600; color: var(--c-fg); margin-bottom: var(--sp-1); }
.empty-state__text { font-size: var(--text-sm); }

/* Placeholder for content that has been requested and has not arrived. Used
   where a spinner would be the wrong shape — a list, a figure. */
.skeleton {
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--c-surface) 25%, #eaeef2 37%, var(--c-surface) 63%);
    background-size: 400% 100%;
    animation: skeleton-shimmer 1.4s ease infinite;
}

@keyframes skeleton-shimmer {
    from { background-position: 100% 50%; }
    to { background-position: 0 50%; }
}

/* Motion here is decorative and repeats indefinitely, which is exactly what a
   vestibular sensitivity setting is asking about. */
@media (prefers-reduced-motion: reduce) {
    .skeleton { animation: none; }
    * { transition-duration: 0.01ms !important; }
}

/* ---------------------------------------------------------------------------
   Avatar
   --------------------------------------------------------------------------- */

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--c-accent-soft);
    color: var(--c-accent-strong);
    font-size: var(--text-xs);
    font-weight: 600;
    flex: 0 0 auto;
    text-transform: uppercase;
}
