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

/* Visually hidden but exposed to assistive tech — used for persistent live regions. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

/* Light theme — default */
:root {
    --bg: #f4f6fb;
    --bg-surface: #ffffff;
    --bg-menu: #ffffff;
    --border: #e4e8f2;
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #475569;
    --header-bg: rgba(244, 246, 251, 0.85);
    --card-shadow: 0 1px 3px rgba(15, 23, 42, 0.07), 0 1px 2px rgba(15, 23, 42, 0.04);
    --menu-shadow: 0 8px 32px rgba(15, 23, 42, 0.12), 0 2px 8px rgba(15, 23, 42, 0.08);
    --accent: #8a3d0c;
    --accent-on: #ffffff;
    --accent-end: #ea580c;
    --accent-glow: rgba(245, 158, 11, 0.15);
    --icon-shadow: 0 2px 8px rgba(245, 158, 11, 0.25);
    --danger: #a8200e;
    --danger-fill: #a8200e;
    --danger-on: #ffffff;
    --spinner-track: #e4e8f2;
}

/* Auto dark — system preference, only when no explicit override */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #090b12;
        --bg-surface: #0d1019;
        --bg-menu: #111521;
        --border: #161d2e;
        --text-primary: #e2e8f0;
        --text-secondary: #c8d0e8;
        --text-muted: #9aa6c2;
        --header-bg: rgba(9, 11, 18, 0.80);
        --card-shadow: none;
        --menu-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
        --accent: #f59e0b;
        --accent-on: #0d1019;
        --accent-end: #ea580c;
        --accent-glow: rgba(245, 158, 11, 0.12);
        --icon-shadow: 0 0 12px rgba(245, 158, 11, 0.35);
        --danger: #fca5a5;
        --danger-fill: #a8200e;
        --danger-on: #ffffff;
        --spinner-track: #161d2e;
    }
}

/* Explicit dark */
[data-theme="dark"] {
    --bg: #090b12;
    --bg-surface: #0d1019;
    --bg-menu: #111521;
    --border: #161d2e;
    --text-primary: #e2e8f0;
    --text-secondary: #c8d0e8;
    --text-muted: #9aa6c2;
    --header-bg: rgba(9, 11, 18, 0.80);
    --card-shadow: none;
    --menu-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
    --accent: #f59e0b;
    --accent-on: #0d1019;
    --accent-end: #ea580c;
    --accent-glow: rgba(245, 158, 11, 0.12);
    --icon-shadow: 0 0 12px rgba(245, 158, 11, 0.35);
    --danger: #fca5a5;
    --danger-fill: #a8200e;
    --danger-on: #ffffff;
    --spinner-track: #161d2e;
}

/* Explicit light */
[data-theme="light"] {
    --bg: #f4f6fb;
    --bg-surface: #ffffff;
    --bg-menu: #ffffff;
    --border: #e4e8f2;
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #475569;
    --header-bg: rgba(244, 246, 251, 0.85);
    --card-shadow: 0 1px 3px rgba(15, 23, 42, 0.07), 0 1px 2px rgba(15, 23, 42, 0.04);
    --menu-shadow: 0 8px 32px rgba(15, 23, 42, 0.12), 0 2px 8px rgba(15, 23, 42, 0.08);
    --accent: #8a3d0c;
    --accent-on: #ffffff;
    --accent-end: #ea580c;
    --accent-glow: rgba(245, 158, 11, 0.15);
    --icon-shadow: 0 2px 8px rgba(245, 158, 11, 0.25);
    --danger: #a8200e;
    --danger-fill: #a8200e;
    --danger-on: #ffffff;
    --spinner-track: #e4e8f2;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Formular-Basis — gilt appweit. Seiten definieren diese Klassen nicht erneut,
   sondern nur echte Abweichungen (Scoped CSS gewinnt durch höhere Spezifität). */
.form-field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.form-row {
    display: flex;
    gap: 0.75rem;
}

.form-row > .form-field {
    flex: 1;
}

.form-label {
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.form-input,
.form-textarea {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 0.875rem;
    font-size: 1rem;
    font-family: inherit;
    color: var(--text-primary);
    width: 100%;
    -webkit-appearance: none;
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input:disabled,
.form-textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.form-textarea {
    resize: none;
    line-height: 1.5;
}

.form-actions {
    display: flex;
    gap: 0.625rem;
    padding-top: 0.5rem;
}

.field-error {
    font-size: 0.8125rem;
    color: var(--danger);
}

/* 3.5rem = 56px Touch-Ziel → ADR-007 */
.btn-save,
.btn-cancel {
    flex: 1;
    width: 100%;
    min-height: 3.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border-radius: 10px;
    border: none;
    font-size: 0.9375rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.btn-save {
    background: var(--accent);
    color: var(--accent-on);
}

.btn-cancel {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-save:disabled,
.btn-cancel:disabled {
    opacity: 0.5;
    cursor: default;
}

.blazor-error-boundary {
    background: #2d0a0a;
    padding: 1rem;
    color: #fca5a5;
    border-radius: 10px;
    border: 1px solid #7f1d1d;
    margin: 1rem;
}

.blazor-error-boundary::after {
    content: "Ein Fehler ist aufgetreten."
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid #22c55e;
}

.invalid {
    outline: 1px solid var(--danger);
}

.validation-message {
    color: var(--danger);
}

.text-danger {
    color: var(--danger);
}

:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

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