/*
 * Base layer shared by the public site and the admin panel: reset, element
 * defaults, utilities, skip link, theme toggle, buttons, pager, empty state,
 * focus and Windows high-contrast (forced colours) rules.
 *
 * Load order in both layouts: tokens.css → base.css → site.css | admin.css.
 * Components defined here are NOT redefined in site.css / admin.css; those
 * files only add page-specific pieces (modifiers, layout around them).
 * Colours, sizes and timings come from tokens.css.
 */

/* ==========================================================================
   Reset / element defaults
   ========================================================================== */

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

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

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
    overflow-wrap: break-word;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Chinese anywhere on the page (an article, a language name in a menu…):
   use the CJK-first stack from tokens.css (:lang(zh) redefines --font-sans). */
[lang|="zh"] {
    font-family: var(--font-sans);
}

[hidden] {
    display: none !important;
}

img,
svg,
video {
    max-width: 100%;
}

img {
    height: auto;
}

h1,
h2,
h3 {
    text-wrap: balance;
}

a {
    color: var(--color-primary);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.18em;
    transition: color var(--duration-fast) var(--ease-standard);
}

a:hover {
    color: var(--color-primary-hover);
}

::selection {
    background: var(--color-selection);
}

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

/* <main tabindex="-1"> receives focus from the skip link; no ring on a region. */
main[tabindex="-1"]:focus {
    outline: none;
}

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

/* ==========================================================================
   Utilities
   ========================================================================== */

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.skip-link {
    position: absolute;
    top: var(--space-2);
    inset-inline-start: var(--space-2);
    z-index: var(--z-skip-link);
    padding: var(--space-3) var(--space-4);
    border: 1px solid transparent; /* visible in forced colours */
    border-radius: var(--radius-md);
    background: var(--color-primary);
    color: var(--color-primary-contrast);
    font-weight: var(--font-weight-semibold);
    text-decoration: none;
    transform: translateY(calc(-100% - var(--space-4)));
}

.skip-link:focus,
.skip-link:focus-visible {
    transform: none;
    color: var(--color-primary-contrast);
}

/* ==========================================================================
   Theme toggle (templates/shared/theme-toggle.php)
   ========================================================================== */

.theme-toggle {
    display: inline-grid;
    place-items: center;
    width: var(--tap-target);
    height: var(--tap-target);
    padding: 0;
    border: 1px solid transparent; /* visible in forced colours */
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--color-text);
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--ease-standard);
}

.theme-toggle:hover {
    background: var(--color-hover);
}

.theme-toggle__icon {
    display: none;
}

.theme-toggle:not([data-mode]) .theme-toggle__icon--system,
.theme-toggle[data-mode="system"] .theme-toggle__icon--system,
.theme-toggle[data-mode="light"] .theme-toggle__icon--light,
.theme-toggle[data-mode="dark"] .theme-toggle__icon--dark {
    display: block;
}

/* ==========================================================================
   Buttons — one family for site and admin.
   .button            neutral (admin default)
   .button--primary   brand   .button--danger   destructive
   .button--ghost     no border   .button--small   compact   .button--large  site CTA
   .button--block     full width
   ========================================================================== */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--control-height);
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    line-height: var(--line-height-tight);
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition:
        background-color var(--duration-fast) var(--ease-standard),
        border-color var(--duration-fast) var(--ease-standard),
        color var(--duration-fast) var(--ease-standard);
}

.button:hover {
    background: var(--color-hover);
    color: var(--color-text);
}

.button:active {
    background: var(--color-active);
}

.button:disabled,
.button[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.55;
}

.button--primary {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: var(--color-primary-contrast);
}

.button--primary:hover,
.button--primary:active {
    border-color: var(--color-primary-hover);
    background: var(--color-primary-hover);
    color: var(--color-primary-contrast);
}

.button--danger {
    border-color: var(--color-danger);
    background: var(--color-danger);
    color: var(--color-danger-contrast);
}

.button--danger:hover,
.button--danger:active {
    border-color: var(--color-danger-hover);
    background: var(--color-danger-hover);
    color: var(--color-danger-contrast);
}

.button--ghost {
    border-color: transparent;
    background: transparent;
}

.button--ghost:hover {
    background: var(--color-hover);
}

.button--small {
    min-height: 2rem;
    padding: var(--space-1) var(--space-3);
    font-size: var(--font-size-sm);
}

.button--large {
    min-height: var(--tap-target);
    padding: var(--space-2) var(--space-5);
    font-size: var(--font-size-base);
}

.button--block {
    display: flex;
    width: 100%;
}

/* A file input inside a <label class="button">: show its focus. */
.button:has(input[type="file"]:focus-visible) {
    outline: var(--focus-width) solid var(--color-focus-ring);
    outline-offset: var(--focus-offset);
}

/* Touch: every button is a full-size target. */
@media (pointer: coarse) {
    .button,
    .button--small {
        min-height: var(--tap-target);
    }
}

/* ==========================================================================
   Pager (layout only; site.css styles the links, admin uses .button)
   ========================================================================== */

.pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    margin-top: var(--space-8);
}

.pager__info {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

/* ==========================================================================
   Empty state
   ========================================================================== */

.empty-state {
    margin: 0;
    padding: var(--space-12) var(--space-6);
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    color: var(--color-text-muted);
    text-align: center;
}

.empty-state p {
    margin: 0;
}

/* ==========================================================================
   Windows high contrast / forced colours: backgrounds and box-shadows are
   dropped, colours replaced by system colours. Restore the cues that relied
   on them.
   ========================================================================== */

@media (forced-colors: active) {
    :focus-visible {
        outline-color: Highlight;
    }

    .theme-toggle__icon {
        color: ButtonText;
    }

    .button:disabled,
    .button[aria-disabled="true"] {
        border-color: GrayText;
        color: GrayText;
        opacity: 1;
    }
}
