/* ═══════════════════════════════════════════════════════════════════
   base.css — shared structure, typography, forms and buttons.

   Every deployment loads this file plus ONE brand file from
   static/themes/*.css. Brand files only set CSS custom properties
   (colours, fonts, shadows) for light and dark mode; they never
   restyle elements. Anything visual that needs to differ per brand
   must therefore be expressed as a token that this file consumes.
   ═══════════════════════════════════════════════════════════════════ */

:root {
    /* Layout tokens shared by every brand (brand files may override) */
    --column-width: 42rem;
    --column-margin-top: 4rem;
    --border-radius: 8px;
    --border-radius-sm: 6px;
    --border-radius-lg: 12px;

    /* App shell */
    --sidebar-width: 232px;
    --sidebar-width-collapsed: 64px;
    --topbar-height: 56px;

    /* Sidebar / top bar defaults derive from the brand palette. A brand
       with a dark rail (BSC) overrides these in its theme file. */
    --sidebar-bg: var(--color-bg-0);
    --sidebar-border: var(--color-bg-2);
    --sidebar-text: var(--color-text);
    --sidebar-text-muted: var(--color-text-light);
    --sidebar-hover-bg: var(--color-bg-1);
    --sidebar-active-bg: color-mix(in srgb, var(--color-theme-1) 14%, transparent);
    --sidebar-active-text: var(--color-theme-1);
    --topbar-bg: color-mix(in srgb, var(--color-bg-0) 85%, transparent);
    --topbar-border: var(--color-bg-2);

    /* Focus ring falls back to the accent when a brand does not set one */
    --focus-ring: color-mix(in srgb, var(--color-theme-1) 45%, transparent);
    --pre-bg: var(--color-bg-1);
    --color-link: var(--color-theme-1);
    --color-link-hover: var(--color-theme-2);
}

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

body {
    min-height: 100vh;
    margin: 0;
    font-family: var(--font-body);
    color: var(--color-text);
    background-attachment: fixed;
    background-color: var(--bg-main);
    background-size: 100vw 100vh;
    background-image: linear-gradient(
        160deg,
        var(--bg-gradient-start, var(--bg-main)) 0%,
        var(--bg-main) 50%,
        var(--bg-gradient-end, var(--bg-main)) 100%
    );
}

/* ── Typography ─────────────────────────────────────────────────── */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-heading, var(--font-body));
}

h1,
h2,
p {
    font-weight: 400;
}

p {
    line-height: 1.6;
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    text-align: center;
    color: var(--header-text-color);
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--subheader-text-color);
}

h3,
h4 {
    font-weight: 600;
    color: var(--subheader-text-color);
}

blockquote,
.quote,
.highlight-text {
    font-family: var(--font-quote, var(--font-body));
    font-style: italic;
    color: var(--color-text);
}

a {
    color: var(--color-link);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--color-link-hover);
    text-decoration: underline;
}

pre {
    font-size: 16px;
    font-family: var(--font-mono);
    background-color: var(--pre-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    padding: 1em;
    overflow-x: auto;
    color: var(--color-text);
}

.text-column {
    display: flex;
    max-width: 60rem;
    flex: 0.6;
    flex-direction: column;
    justify-content: center;
    margin: 0 auto;
}

/* ── Form controls ──────────────────────────────────────────────── */
input,
button,
textarea,
select {
    font-size: inherit;
    font-family: inherit;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="search"],
textarea,
select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--input-border);
    border-radius: var(--border-radius-sm);
    background-color: var(--input-bg);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: 1rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
input[type="search"]:focus,
textarea:focus,
select:focus {
    border-color: var(--input-border-focus);
    outline: none;
    box-shadow: 0 0 0 3px var(--focus-ring);
}

input[type="text"]:disabled,
input[type="email"]:disabled,
input[type="password"]:disabled,
input[type="number"]:disabled,
input[type="date"]:disabled,
input[type="time"]:disabled,
input[type="search"]:disabled,
textarea:disabled,
select:disabled {
    background-color: var(--color-bg-1);
    cursor: not-allowed;
    opacity: 0.6;
}

textarea {
    min-height: 100px;
    resize: vertical;
}

/* Radio buttons */
.radio-button,
input[type="radio"] {
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--radio-button-inactive);
    border-radius: 50%;
    position: relative;
    cursor: pointer;
    margin-right: 0.5rem;
    transition: border-color 0.2s ease;
    flex-shrink: 0;
}

.radio-button:checked,
input[type="radio"]:checked {
    border-color: var(--radio-button-active);
}

.radio-button:checked::after,
input[type="radio"]:checked::after {
    content: '';
    width: 10px;
    height: 10px;
    background-color: var(--radio-button-active);
    border-radius: 50%;
    position: absolute;
    top: 3px;
    left: 3px;
}

/* Checkboxes */
input[type="checkbox"] {
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--radio-button-inactive);
    border-radius: var(--border-radius-sm);
    position: relative;
    cursor: pointer;
    margin-right: 0.5rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

input[type="checkbox"]:checked {
    background-color: var(--radio-button-active);
    border-color: var(--radio-button-active);
}

input[type="checkbox"]:checked::after {
    content: '\2713';
    color: var(--button-text-color-common);
    font-size: 14px;
    font-weight: bold;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.radio-button:focus-visible,
input[type="radio"]:focus-visible,
input[type="checkbox"]:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

/* ── Buttons ────────────────────────────────────────────────────────
   The bare <button> element is deliberately NOT styled beyond font and
   cursor. Visual button styles are opt-in through the .btn classes, so
   components that draw their own controls (tabs, icon buttons, pills)
   no longer have to undo a global look with box-shadow:none etc.
   ─────────────────────────────────────────────────────────────────── */
button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
}

button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

button:focus:not(:focus-visible) {
    outline: none;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--border-radius-sm);
    font-family: var(--font-heading, var(--font-body));
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: 0.01em;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition:
        background-color 0.2s ease,
        border-color 0.2s ease,
        color 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.15s ease;
}

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

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn-primary {
    background-color: var(--button-bg);
    color: var(--button-text-color-common);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--button-bg-hover);
    color: var(--button-text-color-common);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

.btn-primary:disabled {
    background-color: var(--button-bg-disabled);
}

.btn-secondary {
    background-color: var(--button-secondary-bg, var(--color-bg-0));
    color: var(--button-secondary-text, var(--color-text));
    border-color: var(--button-secondary-border, var(--button-border));
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--button-secondary-bg-hover, var(--color-bg-1));
    color: var(--button-secondary-text, var(--color-text));
    border-color: var(--button-border-hover);
}

.btn-ghost {
    background-color: transparent;
    color: var(--color-text-light);
}

.btn-ghost:hover:not(:disabled) {
    background-color: var(--color-bg-1);
    color: var(--color-text);
}

.btn-danger {
    background-color: var(--color-error);
    color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
    filter: brightness(0.92);
    color: #ffffff;
}

.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 0.7rem 1.4rem;
    font-size: 1rem;
}

.btn-icon {
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border-radius: 999px;
}

.btn-block {
    width: 100%;
}

/* ── Utility classes ────────────────────────────────────────────── */
.header {
    font-family: var(--font-heading, var(--font-body));
    color: var(--header-text-color);
}

.subheader {
    font-family: var(--font-heading, var(--font-body));
    color: var(--subheader-text-color);
}

.legend-text {
    fill: var(--color-text);
    font-size: 12px;
    font-family: var(--font-body);
}

.hint,
.callout,
.callout-bar {
    background-color: var(--callout-bg, var(--color-bg-1));
    color: var(--callout-text, var(--color-text));
    border-left: 4px solid var(--color-theme-1);
    border-radius: var(--border-radius-sm);
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
}

.visually-hidden {
    border: 0;
    clip: rect(0 0 0 0);
    height: auto;
    margin: 0;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    white-space: nowrap;
}

/* ── Responsive ─────────────────────────────────────────────────── */
@media (min-width: 720px) {
    h1 {
        font-size: 2.4rem;
    }
}

@media (max-width: 768px) {
    h1 {
        font-size: 1.6rem;
    }

    h2 {
        font-size: 1.2rem;
    }

    /* 44px tap targets */
    .btn,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    input[type="search"],
    select {
        min-height: 44px;
    }

    pre {
        font-size: 14px;
        padding: 0.75em;
    }

    .text-column {
        max-width: 100%;
        padding: 0 0.5rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}
