/*
 * Base Element Styles (H Layer)
 *
 * Default styles for bare HTML elements — the "H" in HUG CSS.
 * Every element should look clean and professional without any classes.
 * Load order: reset.css → tokens.css → base.css
 */

/* ===================================================================
 * Body defaults
 * =================================================================== */

body {
    font-family: var(--font-body);
    font-size: var(--step-0);
    color: var(--color-text);
    background-color: var(--color-background);
    line-height: var(--leading-normal);
}

main {
    padding-block-start: var(--space-s);
    padding-block-end: var(--space-xl);
}

/* ===================================================================
 * Global focus ring
 * =================================================================== */

:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
}

/* ===================================================================
 * Headings
 * =================================================================== */

h1,
h2,
h3,
h4,
h5,
h6 {
    line-height: var(--leading-tight);
    margin-block-start: var(--space-m-l);
}

h1,
h2 {
    font-weight: var(--weight-bold);
}

h3,
h4,
h5,
h6 {
    font-weight: var(--weight-semibold);
}

h1 {
    font-size: var(--step-5);
}
h2 {
    font-size: var(--step-4);
}
h3 {
    font-size: var(--step-3);
}
h4 {
    font-size: var(--step-2);
}
h5 {
    font-size: var(--step-1);
}
h6 {
    font-size: var(--step-0);
}

/* ===================================================================
 * Prose elements
 * =================================================================== */

p,
ul,
ol,
pre,
blockquote,
figure,
table,
dl,
details,
fieldset,
hr {
    margin-block-start: var(--space-xs-s);
}

ul,
ol {
    padding-inline-start: var(--space-m-l);
}

small {
    font-size: var(--step--1);
    color: var(--color-text-muted);
}

mark {
    background-color: var(--color-primary-fill-muted);
    border-radius: var(--radius-sm);
    padding-inline: 0.25em;
    padding-block: 0.125em;
}

strong,
b {
    font-weight: var(--weight-bold);
}

/* ===================================================================
 * Links
 * =================================================================== */

a {
    color: var(--color-primary-fill-vivid);
    text-decoration-color: var(--color-primary-border-muted);
    text-underline-offset: 0.15em;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-primary-border-accent);
    text-decoration-color: currentColor;
}

/* ===================================================================
 * Code elements
 * =================================================================== */

code {
    font-family: var(--font-mono);
    font-size: var(--step--1);
    background-color: var(--color-primary-fill-muted);
    border-radius: var(--radius-sm);
    padding-inline: 0.375em;
    padding-block: 0.125em;
}

pre {
    background-color: var(--color-primary-fill-accent);
    border: 1px solid var(--color-primary-border-muted);
    border-radius: var(--radius-md);
    padding: var(--space-s);
    overflow-x: auto;
}

pre code {
    background-color: transparent;
    border-radius: 0;
    padding: 0;
    font-size: inherit;
}

kbd {
    font-family: var(--font-mono);
    font-size: var(--step--1);
    background-color: var(--color-neutral-fill-vivid);
    color: var(--color-neutral-on-vivid);
    border-radius: var(--radius-sm);
    padding-inline: 0.5em;
    padding-block: 0.125em;
    box-shadow: var(--shadow-sm);
}

/* ===================================================================
 * Blockquote
 * =================================================================== */

blockquote {
    border-inline-start: var(--space-3xs) solid var(--color-primary-border-muted);
    padding-inline-start: var(--space-s);
    color: var(--color-text-muted);
    font-style: italic;
}

/* ===================================================================
 * Tables
 * =================================================================== */

table {
    width: 100%;
    text-align: start;
}

th {
    font-size: var(--step--1);
    font-weight: var(--weight-semibold);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--space-2xs) var(--space-xs);
    border-block-end: 2px solid var(--color-neutral-border-accent);
}

td {
    padding: var(--space-2xs) var(--space-xs);
    border-block-end: 1px solid var(--color-neutral-border-muted);
    vertical-align: middle;
}

tbody tr:hover {
    background-color: var(--color-neutral-fill-muted);
}

table[data-variant="striped"] tbody tr:nth-child(even) {
    background-color: var(--color-neutral-fill-muted);
}

table[data-variant="striped"] tbody tr:hover {
    background-color: var(--color-neutral-fill-accent);
}

caption {
    caption-side: bottom;
    font-size: var(--step--1);
    color: var(--color-text-muted);
    padding-block-start: var(--space-2xs);
}

/* ===================================================================
 * Forms — Labels
 * =================================================================== */

label {
    display: block;
    font-size: var(--step--1);
    font-weight: var(--weight-medium);
}

label + input,
label + select,
label + textarea {
    margin-block-start: var(--space-3xs);
}

/* ===================================================================
 * Forms — Text inputs, select, textarea
 * =================================================================== */

input:where(
        [type="text"],
        [type="email"],
        [type="password"],
        [type="url"],
        [type="tel"],
        [type="number"],
        [type="search"],
        [type="date"],
        [type="datetime-local"],
        [type="month"],
        [type="week"],
        [type="time"]
    ),
select,
textarea {
    display: block;
    width: 100%;
    padding: var(--space-2xs) var(--space-xs);
    border: 1px solid var(--color-neutral-border-accent);
    border-radius: var(--radius-md);
    background-color: var(--color-background);
    font: inherit;
    color: inherit;
    transition: border-color var(--transition-fast);
}

input:where(
        [type="text"],
        [type="email"],
        [type="password"],
        [type="url"],
        [type="tel"],
        [type="number"],
        [type="search"],
        [type="date"],
        [type="datetime-local"],
        [type="month"],
        [type="week"],
        [type="time"]
    ):focus-visible,
select:focus-visible,
textarea:focus-visible {
    border-color: var(--focus-ring-color);
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: 0;
}

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

/* ===================================================================
 * Forms — Select (custom chevron)
 * =================================================================== */

select {
    appearance: none;
    /* Chevron — hardcoded SVG data URI (custom properties don't work inside data URIs) */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%23666' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-xs) center;
    padding-inline-end: var(--space-l);
}

/* ===================================================================
 * Forms — Fieldset & legend
 * =================================================================== */

fieldset {
    border: none;
    padding: 0;
}

fieldset > * + * {
    margin-block-start: var(--space-s);
}

legend {
    font-size: var(--step--1);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    padding-block-end: var(--space-2xs);
    border-block-end: var(--border-thin) solid var(--color-border-muted);
    margin-block-end: var(--space-xs);
    width: 100%;
}

/* ===================================================================
 * Forms — Checkboxes & radios
 * =================================================================== */

input[type="checkbox"],
input[type="radio"] {
    appearance: none;
    width: 1.25em;
    height: 1.25em;
    border: 2px solid var(--color-neutral-border-accent);
    background-color: var(--color-background);
    vertical-align: middle;
    cursor: pointer;
    flex-shrink: 0;
}

input[type="checkbox"] {
    border-radius: var(--radius-sm);
}

input[type="radio"] {
    border-radius: var(--radius-full);
}

input[type="checkbox"]:checked,
input[type="radio"]:checked {
    background-color: var(--color-primary-fill-vivid);
    border-color: var(--color-primary-fill-vivid);
}

input[type="checkbox"]:checked {
    /* Checkmark — hardcoded SVG data URI (custom properties don't work inside data URIs) */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='10' fill='none'%3E%3Cpath d='M1 5.5l3.5 3.5L11 1' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
}

input[type="radio"]:checked {
    /* Dot via inset box-shadow — no data URI needed */
    background-image: none;
    box-shadow: inset 0 0 0 3px var(--color-background);
}

input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
    outline: var(--focus-ring-width) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
}

/* ===================================================================
 * Forms — File input
 * =================================================================== */

input[type="file"]::file-selector-button {
    font: inherit;
    font-size: var(--step--1);
    font-weight: var(--weight-medium);
    padding: var(--space-3xs) var(--space-xs);
    border: 1px solid var(--color-neutral-border-accent);
    border-radius: var(--radius-md);
    background-color: var(--color-background);
    color: var(--color-text);
    cursor: pointer;
    margin-inline-end: var(--space-xs);
    transition: background-color var(--transition-fast);
}

input[type="file"]::file-selector-button:hover {
    background-color: var(--color-neutral-fill-muted);
}

/* ===================================================================
 * Forms — Validation
 * =================================================================== */

input:user-invalid,
select:user-invalid,
textarea:user-invalid {
    border-color: var(--color-danger-fill-vivid);
    background-color: var(--color-danger-fill-muted);
}

/* ===================================================================
 * Forms — Disabled
 * =================================================================== */

input:disabled,
select:disabled,
textarea:disabled {
    background-color: var(--color-neutral-fill-muted);
    color: var(--color-text-muted);
    cursor: not-allowed;
}

/* ===================================================================
 * Buttons
 *
 * Good-looking default for bare <button> elements. For the polished
 * component with variants, use the .btn block (blocks/btn.css).
 * =================================================================== */

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3xs);
    padding: var(--space-2xs) var(--space-s);
    font: inherit;
    font-size: var(--step--1);
    font-weight: var(--weight-medium);
    line-height: var(--leading-tight);
    border: 1px solid var(--color-neutral-border-accent);
    border-radius: var(--radius-md);
    background-color: var(--color-background);
    color: var(--color-text);
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

button:hover {
    background-color: var(--color-neutral-fill-muted);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* ===================================================================
 * Horizontal rule
 * =================================================================== */

hr {
    border: 0;
    border-block-start: 1px solid var(--color-neutral-border-muted);
    margin-block: var(--space-m-l);
}

/* ===================================================================
 * Details & summary
 * =================================================================== */

details {
    border: 1px solid var(--color-neutral-border-muted);
    border-radius: var(--radius-md);
    padding: var(--space-xs) var(--space-s);
}

summary {
    font-weight: var(--weight-semibold);
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: var(--space-3xs);
}

/* Remove default marker across browsers */
summary::-webkit-details-marker {
    display: none;
}

summary::marker {
    content: "";
}

/* Custom chevron */
summary::before {
    content: "";
    display: inline-block;
    width: 0.75em;
    height: 0.75em;
    flex-shrink: 0;
    /* Chevron — hardcoded SVG data URI (custom properties don't work inside data URIs) */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none'%3E%3Cpath d='M4 2l4 4-4 4' stroke='%23666' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    transition: transform var(--transition-fast);
}

details[open] > summary::before {
    transform: rotate(90deg);
}

details > *:not(summary) {
    margin-block-start: var(--space-xs);
}

/* ===================================================================
 * Dialog
 * =================================================================== */

dialog {
    margin: auto;
    border: 1px solid var(--color-neutral-border-muted);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-m-l);
    max-width: min(90vw, 40rem);
}

dialog::backdrop {
    background-color: var(--color-overlay);
}

/* ===================================================================
 * Scrollbars
 * =================================================================== */

/* Standards (Firefox, modern Chrome/Edge) */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--color-neutral-border-accent) transparent;
}

/* WebKit fallback */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: var(--color-neutral-border-accent);
    border-radius: var(--radius-full);
}

/* ===================================================================
 * View Transitions (cross-document, progressive enhancement)
 * =================================================================== */

@view-transition {
    navigation: auto;
}

/* ===================================================================
 * Reduced motion
 * =================================================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        /* biome-ignore lint/complexity/noImportantStyles: accessibility pattern — must override all transitions */
        transition-duration: 0.01ms !important;
    }
}
