/*
 * Shared STORM UI: colour tokens and reusable components (forms, buttons).
 * Loaded on the front end and in the block editor. Colours and button
 * settings come from the Customizer; page-specific rules live in
 * assets/css/<page>.css.
 */

/* Fonts: chosen in Customizer → Typography (self-hosted, see storm-fonts.css). */

/* Colour tokens */

:root {
    --storm-ui-primary: var(--theme-palette-color-1);
    --storm-ui-primary-hover: var(--theme-palette-color-2);
    --storm-ui-text: var(--theme-text-color);
    --storm-ui-background: var(--theme-palette-color-8);
    --storm-ui-surface: var(--theme-palette-color-8);
    --storm-ui-surface-muted: var(--theme-palette-color-7);

    --storm-ui-border: var(--theme-palette-color-6);
    --storm-ui-border-hover: #b7c5d2;
    /* White surfaces on the light grey page (content and work pages):
       a faint edge instead of a full line. */
    --storm-ui-border-faint: color-mix(in srgb, var(--storm-ui-border) 70%, transparent);

    --storm-ui-radius: 9px;
    --storm-ui-shadow:
            2px 3px 14px rgba(15, 23, 42, 0.05);

    --storm-ui-danger: #b42318;

    /* Interreg NEXT MED accents: only where colour carries a meaning
       (categories, statuses, charts). Fills only — not text on white. */
    --storm-accent-teal: #00b7a5;
    --storm-accent-coral: #ec5152;
    --storm-accent-blue: #006fbc;

    /* Text versions of the accents (contrast ≥ 4.5:1 on white). */
    --storm-text-green: #4e7a00;
    --storm-text-teal: #007a6e;
    --storm-text-coral: #c8323a;
}

/* Form structure */

.storm-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.storm-form [hidden] {
    display: none !important;
}

.storm-form-field {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;

    margin: 0;
}

.storm-form-label {
    color: var(--storm-ui-text);
    font-size: 1rem;
    font-weight: 600;
}


/* Standard controls */

.storm-form-control {
    box-sizing: border-box;

    width: 100%;
    min-height: 48px;
    padding: 0.75rem 0.9rem;

    border: 1px solid var(--storm-ui-border);
    border-radius: var(--storm-ui-radius);

    background: var(--storm-ui-background);
    color: var(--storm-ui-text);

    font: inherit;
}

textarea.storm-form-control {
    min-height: 120px;
    resize: vertical;
}

/* Short texts with a character limit (e.g. a 300-character summary): can
   grow a little, not without end. */
textarea.storm-form-control--short {
    min-height: 6.5em;
    max-height: 14em;
}

.storm-form-control:hover {
    border-color: var(--storm-ui-border-hover);
}

.storm-form-control:focus-visible {
    border-color: var(--storm-ui-primary);

    outline: 2px solid var(--storm-ui-primary);
    outline-offset: 2px;
}


/* Form messages (saved / error) */

.storm-notice {
    padding: 0.75rem 1rem;

    border: 1px solid var(--storm-ui-border);
    border-left: 4px solid var(--storm-ui-primary);
    border-radius: var(--storm-ui-radius);

    background: var(--storm-ui-surface-muted);
}

.storm-notice p {
    margin: 0;
}

.storm-notice--success {
    border-left-color: var(--storm-text-green);
}

.storm-notice--error {
    border-left-color: var(--storm-ui-danger);
    color: var(--storm-ui-danger);
}

/* File inputs */

.storm-file-input {
    box-sizing: border-box;

    width: 100%;
    padding: 0.35rem;

    border: 1px solid var(--storm-ui-border);
    border-radius: var(--storm-ui-radius);

    background: var(--storm-ui-background);
    color: var(--storm-ui-text);

    font: inherit;
}

.storm-file-input::file-selector-button {
    margin-right: 0.75rem;
    padding: 0.55rem 0.8rem;

    border: 0;
    border-radius: var(--theme-button-border-radius, 3px);

    background: var(--storm-ui-surface-muted);
    color: var(--storm-ui-primary);

    font: inherit;
    font-weight: 500;

    cursor: pointer;
}

.storm-file-input::file-selector-button:hover {
    background: var(--storm-ui-border);
}

.storm-file-input:focus-visible {
    outline: 2px solid var(--storm-ui-primary);
    outline-offset: 2px;
}


/* Submission forms (resource form; later initiative proposals): sections as
   cards, fields side by side where there is room, hints, errors, required
   marks, a drop zone for files and the list of selected files. */

.storm-notice ul {
    margin: 0.5rem 0 0 1.25rem;
}

.storm-form-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;

    padding: clamp(1.25rem, 4vw, 2rem);

    border: 1px solid var(--storm-ui-border-faint);
    border-radius: var(--storm-ui-radius);

    background: var(--storm-ui-surface);
}

.storm-form-section__header {
    padding-bottom: 0.25rem;
}

.storm-form-section__header > * {
    margin: 0;
}

.storm-form-section__header h2 {
    font-size: 1.25rem;
}

.storm-form-section__header p {
    margin-top: 0.35rem;
    color: var(--theme-palette-color-4);
    font-size: 0.9rem;
}

.storm-form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
    gap: 1.5rem;
}

/* A group of fields shown or hidden together (e.g. the venue of an event). */
.storm-form-fieldset {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.storm-form-fieldset[hidden] {
    display: none;
}

.storm-form-fieldset > legend {
    margin-bottom: 0.75rem;
    padding: 0;
}

.storm-form-field__top {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
}

.storm-form-hint,
.storm-form-counter {
    color: var(--theme-palette-color-4);
    font-size: 0.875rem;
}

.storm-form-required,
.storm-form-error {
    color: var(--storm-ui-danger);
}

.storm-form-error {
    font-size: 0.9rem;
    font-weight: 500;
}

.storm-form-control[aria-invalid="true"] {
    border-color: var(--storm-ui-danger);
}

.storm-form-check {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
}

.storm-form-check input {
    flex: 0 0 auto;
    width: 1.15rem;
    height: 1.15rem;
    margin: 0.2rem 0 0;
}

.storm-form .wp-editor-container {
    overflow: hidden;

    border: 1px solid var(--storm-ui-border);
    border-radius: var(--storm-ui-radius);
}

.storm-dropzone {
    position: relative;

    display: grid;
    place-items: center;

    min-height: 7rem;
    padding: 2rem 1rem;

    border: 2px dashed var(--storm-ui-border);
    border-radius: var(--storm-ui-radius);

    background: var(--storm-ui-surface-muted);
    text-align: center;
}

.storm-dropzone:hover,
.storm-dropzone.is-dragover {
    border-color: var(--storm-ui-primary);
}

.storm-dropzone:focus-within {
    outline: 2px solid var(--storm-ui-primary);
    outline-offset: 2px;
}

/* The real file field covers the zone: click and drop work without script. */
.storm-dropzone__input {
    position: absolute;
    inset: 0;

    width: 100%;
    height: 100%;

    opacity: 0;
    cursor: pointer;
}

.storm-dropzone__browse {
    color: var(--storm-ui-primary);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.storm-file-list {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
}

.storm-file-list__title {
    margin: 0;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.storm-file-list ul {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;

    width: 100%;
    margin: 0;
    padding: 0;

    list-style: none;
}

.storm-file-list__item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.75rem;

    padding: 0.6rem 0.9rem;

    border: 1px solid var(--storm-ui-border);
    border-radius: var(--storm-ui-radius);

    background: var(--storm-ui-surface);
}

.storm-file-list__name {
    flex: 1 1 12rem;
    font-weight: 500;
    overflow-wrap: anywhere;
}

.storm-file-list__meta {
    color: var(--theme-palette-color-4);
    font-size: 0.85rem;
}

.storm-file-list__item .storm-button--text-danger {
    min-width: 2rem;
    min-height: 2rem;
    font-size: 1.25rem;
}

.storm-file-list__error {
    margin: 0;
    color: var(--storm-ui-danger);
}

.storm-submission {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.storm-submission__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin: 0;
}

.storm-submission__submit {
    display: flex;
    justify-content: flex-end;
    margin: 0;
}

/* Location picker (initiative proposals): a map above the coordinate
   fields; shown only with the script, the fields work without it. */
.storm-location-picker {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Same height as the Atlas map (STORM Atlas block). */
.storm-location-picker__map {
    position: relative;
    z-index: 0; /* keeps Leaflet's panes below the sticky header */

    height: clamp(360px, 70vh, 640px);

    border: 1px solid var(--storm-ui-border);
    border-radius: var(--storm-ui-radius);

    background: var(--storm-ui-surface-muted);
}

@media (max-width: 689.98px) {
    .storm-location-picker__map {
        height: clamp(320px, 60vh, 460px);
    }
}

.storm-location-picker__map:focus-visible {
    outline: 2px solid var(--storm-ui-primary);
    outline-offset: 2px;
}

.storm-location-picker__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

/* A drop shape whose tip marks the point (the icon anchor in the script). */
.storm-location-picker__pin {
    display: block;
    box-sizing: border-box;
    width: 22px;
    height: 22px;

    border: 3px solid var(--storm-ui-surface);
    border-radius: 50% 50% 50% 0;

    background: var(--storm-ui-primary);
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.4);

    transform: rotate(-45deg);
}


/* Stand-alone links ("Learn more →"; Home: "Start with the basics →", hero
   shortcuts): no underline until hover. Links inside running text keep the
   site-wide underline (Customizer → General → Content Elements → Links Type). */

.storm-link a,
.storm-home-link a,
.storm-home-shortcuts a {
    font-weight: 500;
    text-decoration: none;
}

.storm-link a:hover,
.storm-link a:focus-visible,
.storm-home-link a:hover,
.storm-home-link a:focus-visible,
.storm-home-shortcuts a:hover,
.storm-home-shortcuts a:focus-visible {
    text-decoration: underline;
    text-underline-offset: 3px;
}


/* Clickable cards ("Browse by" tiles): a Group with the class
   "storm-card-link"; its link covers the whole card on the front end (not in
   the editor, so the card's blocks stay selectable). Background, border,
   radius and padding are block settings. Hover: an outline over the border
   in the button colour and a faint shadow. */

.storm-card-link {
    position: relative;
    transition: box-shadow 0.25s ease;
}

.storm-card-link a {
    text-decoration: none;
}

:where(body:not(.editor-styles-wrapper)) .storm-card-link a::after {
    content: "";
    position: absolute;
    inset: 0;
}

.storm-card-link:hover {
    outline: 1px solid var(--theme-button-background-initial-color, var(--theme-palette-color-1));
    outline-offset: -1px;
    box-shadow: 0 6px 18px -10px color-mix(in srgb, var(--theme-palette-color-1) 18%, transparent);
}

.storm-card-link:hover a {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.storm-card-link a:focus-visible {
    outline: none;
}

/* Keyboard focus only (see Home toolkit) */
.storm-card-link:has(a:focus-visible) {
    outline: 2px solid var(--theme-palette-color-1);
    outline-offset: 2px;
}


/* Academy levels (Home, Knowledge & Learning): a core List with the class
   "storm-levels". Numbered circles, the first level highlighted; later levels
   are marked "coming soon" in the text. A level may have a bold title and a
   description on the next line (Shift + Enter). */

.storm-levels {
    margin: 1.25rem 0 1.5rem;
    padding: 0;
    list-style: none;
    counter-reset: storm-level;
}

.storm-levels li {
    position: relative;
    min-height: 1.75rem;
    margin-block: 0.6rem;
    padding-left: 2.5rem;
    font-size: 0.95rem;
    counter-increment: storm-level;
}

.storm-levels li:has(strong) {
    margin-block: 1.5rem;
}

.storm-levels strong {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 1.1rem;
    font-weight: 600;
}

/* Centred on the first line */
.storm-levels li::before {
    content: counter(storm-level);
    position: absolute;
    top: calc((1lh - 1.75rem) / 2);
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 1.75rem;
    height: 1.75rem;
    border: 1px solid var(--theme-palette-color-6);
    border-radius: 50%;
    color: var(--theme-palette-color-5);
    font-size: 0.8rem;
    font-weight: 400;
}

.storm-levels li:first-child::before {
    border-color: var(--theme-palette-color-1);
    color: var(--theme-palette-color-1);
    font-weight: 600;
}


/* Classification badges (Atlas cards, initiative page, Knowledge Centre,
   resource page). Neutral: secondary terms (language, technology, country). */

.storm-badge {
    display: inline-flex;
    align-items: center;

    padding: 0.2rem 0.55rem;

    border-radius: 4px;

    background: color-mix(in srgb, var(--storm-type-accent, var(--theme-palette-color-1)) 10%, var(--theme-palette-color-8));
    color: var(--storm-type-ink, var(--theme-palette-color-1));

    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.3;
}

/* Resource types: one accent per group of types (class storm-type--<slug>,
   set by storm-core on the type badge and the type filter). Fieldwork teal,
   reports blue, learning green, data coral; other or new types navy. */

.storm-type--case-history {
    --storm-type-accent: var(--storm-accent-teal);
    --storm-type-ink: var(--storm-text-teal);
}

.storm-type--technical-report,
.storm-type--publication {
    --storm-type-accent: var(--storm-accent-blue);
    --storm-type-ink: var(--storm-accent-blue);
}

.storm-type--training-material,
.storm-type--guide,
.storm-type--video {
    --storm-type-accent: var(--theme-palette-color-3);
    --storm-type-ink: var(--storm-text-green);
}

.storm-type--dataset {
    --storm-type-accent: var(--storm-accent-coral);
    --storm-type-ink: var(--storm-text-coral);
}

.storm-badge--neutral {
    border: 1px solid var(--theme-palette-color-6);
    background: var(--theme-palette-color-7);
    color: var(--theme-palette-color-4);
    font-weight: 500;
}


/* Operational status: the name with a coloured dot. The same colours mark
   the Atlas map markers (one place for the status colours). Unknown or new
   statuses get the default colour; the text always names the status. */

.storm-status {
    --storm-status-colour: var(--theme-palette-color-4);
}

.storm-status--planned {
    --storm-status-colour: var(--theme-palette-color-1);
}

.storm-status--under-construction {
    --storm-status-colour: var(--storm-text-teal);
}

.storm-status--operational {
    --storm-status-colour: var(--storm-text-green);
}

.storm-status--decommissioned {
    --storm-status-colour: var(--theme-palette-color-5);
}

.storm-status:not(.storm-atlas-marker) {
    display: inline-flex;
    align-items: center;
    gap: 0.45em;
}

.storm-status:not(.storm-atlas-marker)::before {
    content: "";
    flex: 0 0 auto;
    width: 0.65em;
    height: 0.65em;
    border-radius: 50%;
    background: var(--storm-status-colour);
}


/* Key facts (initiative page): label above value, only filled facts. */

.storm-facts {
    margin: 0;
}

.storm-facts > div {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--theme-palette-color-6);
}

.storm-facts > div:first-child {
    padding-top: 0;
}

.storm-facts > div:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.storm-facts dt {
    margin-bottom: 0.2rem;
    color: var(--theme-palette-color-5);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.storm-facts dd {
    margin: 0;
    overflow-wrap: anywhere;
}


/* Shared buttons: shape and colours follow Customizer → Buttons */

.storm-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;

    width: fit-content;
    min-height: 42px;
    padding: 0.6rem 1rem;

    border: 1px solid transparent;
    border-radius: var(--theme-button-border-radius, 3px);

    font: inherit;
    font-weight: var(--theme-button-font-weight, 500);
    line-height: 1.2;

    cursor: pointer;
    text-decoration: none;
}

.storm-button--primary {
    background: var(--theme-button-background-initial-color, var(--storm-ui-primary));
    color: var(--theme-button-text-initial-color, #fff);
}

.storm-button--primary:hover {
    background: var(--theme-button-background-hover-color, var(--storm-ui-primary-hover));
    color: var(--theme-button-text-hover-color, #fff);
}

/* Unavailable but focusable (aria-disabled, e.g. until consent is given). */
.storm-button[aria-disabled="true"] {
    opacity: 0.6;
    cursor: not-allowed;
}

.storm-button--primary[aria-disabled="true"]:hover {
    background: var(--theme-button-background-initial-color, var(--storm-ui-primary));
}

.storm-button--secondary {
    border-color: var(--storm-ui-border);

    background: var(--storm-ui-surface-muted);
    color: var(--storm-ui-primary);
}

.storm-button--secondary:hover {
    background: var(--storm-ui-border);
}

/* Confirms a permanent deletion */
.storm-button--danger {
    background: var(--storm-ui-danger);
    color: #fff;
}

.storm-button--danger:hover {
    background: color-mix(in srgb, var(--storm-ui-danger) 85%, #000);
    color: #fff;
}

.storm-button--text-danger {
    min-height: auto;
    padding: 0;

    background: transparent;
    color: var(--storm-ui-danger);
}

.storm-button:focus-visible {
    outline: 2px solid var(--storm-ui-primary);
    outline-offset: 2px;
}


/* Group style "Contribute panel" (registered in functions.php; the class
   keeps its first name, is-style-storm-green, because content refers to it):
   invitations to contribute (Knowledge Centre). A white surface like the
   cards on the grey page; the colour comes from a teal icon and a dark teal
   button. Low specificity, so colours, border and radius set on the blocks
   win. */

:where(.wp-block-group.is-style-storm-green) {
    border: 1px solid var(--storm-ui-border-faint);
    border-radius: var(--storm-ui-radius);
    background-color: var(--storm-ui-surface);

    --theme-button-background-initial-color: var(--storm-text-teal);
    --theme-button-background-hover-color: color-mix(in srgb, var(--storm-text-teal) 80%, #000);

    transition: box-shadow 0.2s ease;
}

:where(.wp-block-group.is-style-storm-green .wp-block-icon svg) {
    border-radius: 50%;
    background-color: color-mix(in srgb, var(--storm-accent-teal) 12%, var(--storm-ui-surface));
    color: var(--storm-text-teal);
}

/* Hover (or keyboard focus inside): the shared soft shadow, and the
   button's arrow moves towards the action. */
:where(.wp-block-group.is-style-storm-green):is(:hover, :focus-within) {
    box-shadow: var(--storm-ui-shadow);
}

:where(.wp-block-group.is-style-storm-green) .wp-block-button__link::after {
    content: "→" / "";
    margin-left: 0.5em;
    transition: transform 0.2s ease;
}


/* Quick links to a resource type (Button blocks with the class
   storm-type--<slug>, Advanced → Additional CSS class): on hover the shared
   soft shadow (their white background is a block setting, so it can't
   change on hover). */

.wp-block-button[class*="storm-type--"] > .wp-block-button__link {
    transition: box-shadow 0.2s ease;
}

.wp-block-button[class*="storm-type--"] > .wp-block-button__link:is(:hover, :focus-visible) {
    box-shadow: var(--storm-ui-shadow);
}

/* Movement only for visitors who haven't asked for reduced motion. */
@media (prefers-reduced-motion: no-preference) {
    :where(.wp-block-group.is-style-storm-green):is(:hover, :focus-within) .wp-block-button__link::after {
        transform: translateX(3px);
    }
}


/* Resource templates (patterns/: Case History, General resource): sections
   are groups with the class storm-section, separated by space; a section
   left empty is not output at all. */

:where(.storm-section + .storm-section) {
    margin-top: var(--wp--preset--spacing--70, 3rem);
}

:where(.storm-section, .storm-section__part) > :first-child {
    margin-top: 0;
}

:where(.storm-section, .storm-section__part) > :last-child {
    margin-bottom: 0;
}

/* Group styles "Panel", "Panel · positive", "Panel · challenge" (registered
   in functions.php): a white surface with a faint edge; the two variants
   add a coloured top line (green: what worked well, coral: challenges).
   Low specificity, so colours, padding and borders set on the block win. */

:where(.wp-block-group.is-style-storm-panel, .wp-block-group.is-style-storm-panel-positive, .wp-block-group.is-style-storm-panel-challenge) {
    padding: var(--wp--preset--spacing--60, 2.25rem);
    border: 1px solid var(--storm-ui-border-faint);
    border-radius: 8px;
    background-color: var(--storm-ui-surface);
}

:where(.wp-block-group.is-style-storm-panel-positive) {
    border-top: 4px solid var(--theme-palette-color-3);
}

:where(.wp-block-group.is-style-storm-panel-challenge) {
    border-top: 4px solid var(--storm-accent-coral);
}

/* Paragraph style "Key result": the main figure of a Results panel. One
   class of specificity to beat the theme's paragraph typography; colour and
   size chosen on the block still win (WordPress marks them !important). */
p.is-style-storm-key-result {
    color: var(--theme-palette-color-1);
    font-size: var(--wp--preset--font-size--large, 1.35rem);
    font-weight: 600;
    line-height: 1.3;
}
