/* Shared application design system: tokens, page chrome, forms, buttons, and utility states. */
:root {
    --ease-in-cubic: cubic-bezier(0.55, 0.055, 0.675, 0.19);
    --gap-sm: clamp(0.5rem, 1.2vw, 1rem);
    --gap-md: clamp(0.75rem, 2vw, 1.5rem);
    --gap-lg: clamp(1rem, 3vw, 2.25rem);
    --radius-sm: 6px;
    --radius-md: 10px;
    --header-h: 64px;
    --content-max: 760px;
    --fg: #111;
    --muted: #6b7280;
    --border: #d1d5db;
    --bg: #ffffff;
    --card-bg: #ffffff;
    --chip-bg: #f9fafb;
    --grid-line: rgba(0, 0, 0, 0.05);
    --header-bg: #000;
    --header-fg: #fff;
    --danger: #dc2626;
    --focus-ring: var(--fg);
    --surface: var(--card-bg);
    --text: var(--fg);
    --border-radius: var(--radius-md);
}

[data-theme="dark"] {
    --fg: #f5f5f5;
    --muted: #a3a3a3;
    --border: #404040;
    --bg: #0a0a0a;
    --card-bg: #1a1a1a;
    --chip-bg: #262626;
    --grid-line: rgba(255, 255, 255, 0.05);
    --header-bg: #171717;
    --header-fg: #f5f5f5;
    --danger: #f87171;
}

[data-palette="natural"] {
    --fg: #171914;
    --muted: #687064;
    --border: #d8ddd4;
    --bg: #f6f7f3;
    --card-bg: #ffffff;
    --chip-bg: #eef0e8;
    --grid-line: rgba(85, 107, 47, .06);
    --header-bg: #2d3a22;
    --header-fg: #f6f7f3;
}

[data-palette="natural"][data-theme="dark"] {
    --fg: #e9eee0;
    --muted: #9aa68c;
    --border: #384029;
    --bg: #11140d;
    --card-bg: #1a2114;
    --chip-bg: #232c1c;
    --grid-line: rgba(160, 205, 120, .06);
    --header-bg: #0b0e07;
    --header-fg: #e9eee0;
}

[data-palette="blue"] {
    --fg: #0f1830;
    --muted: #5b6b86;
    --border: #d3dbea;
    --bg: #f5f7fc;
    --card-bg: #ffffff;
    --chip-bg: #eef2fb;
    --grid-line: rgba(37, 99, 235, .06);
    --header-bg: #14213d;
    --header-fg: #f5f7fc;
}

[data-palette="blue"][data-theme="dark"] {
    --fg: #e6ecf8;
    --muted: #93a3c4;
    --border: #283449;
    --bg: #0a0f1a;
    --card-bg: #121826;
    --chip-bg: #1a2336;
    --grid-line: rgba(96, 165, 250, .07);
    --header-bg: #070b14;
    --header-fg: #e6ecf8;
}

@font-face {
    font-family: "Space Grotesk";
    font-weight: 400 900;
    font-style: normal;
    src: url("/assets/fonts/Space_Grotesk/SpaceGrotesk-VariableFont_wght.ttf") format("truetype-variations");
}

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

* {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-family: "Space Grotesk", "Inter", system-ui, -apple-system, sans-serif;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    padding: 0;
    scroll-behavior: smooth;
}

html {
    scroll-padding-top: var(--header-h);
}

body {
    color: var(--fg);
    background-color: var(--bg);
    background-image:
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 8px 8px;
    overflow-x: hidden;
    transition: background-color .2s ease, color .2s ease;
}

a {
    color: inherit;
    text-decoration: none;
}

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

img {
    display: block;
    height: auto;
}

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

button {
    cursor: pointer;
}

input[hidden],
[hidden] {
    display: none !important;
}

:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

body > header {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 100;
    min-width: 100%;
    max-width: 100vw;
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap-sm);
    padding: 0 clamp(0.75rem, 3vw, 2rem);
    color: var(--header-fg);
    background-color: var(--header-bg);
}

body > header .header-left,
body > header .header-right {
    display: flex;
    align-items: center;
    gap: .6rem;
}

body > header .header-right {
    flex-shrink: 0;
}

.brand {
    color: var(--header-fg);
    font-weight: 700;
}

body > header > nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    min-width: 0;
}

body > header > nav > a {
    border-radius: var(--radius-sm);
    padding: .4rem .7rem;
    color: rgb(185, 185, 185);
    font-size: .9rem;
    transition: color .15s ease, background-color .15s ease;
}

body > header > nav > a:hover {
    color: #fff;
    background: rgba(255, 255, 255, .08);
}

.topbar {
    position: sticky;
    z-index: 50;
    height: 56px;
}

.topbar .brand {
    font-size: .95rem;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    flex-shrink: 0;
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 999px;
    padding: .25rem .55rem .25rem .3rem;
    color: var(--header-fg);
    background: rgba(255, 255, 255, .08);
    font-size: .8rem;
    transition: background .15s ease;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, .16);
}

.theme-toggle .knob {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: #111;
    background: #fff;
    font-size: .85rem;
    transition: transform .3s var(--ease-in-cubic);
}

.theme-toggle .knob svg {
    width: 14px;
    height: 14px;
}

.theme-toggle .theme-sun {
    display: none;
}

[data-theme="dark"] .theme-toggle .theme-sun {
    display: block;
}

[data-theme="dark"] .theme-toggle .theme-moon {
    display: none;
}

[data-theme="dark"] .theme-toggle .knob {
    color: #fff;
    background: #111;
    transform: rotate(180deg);
}

.logout-btn {
    border: 2px solid #000;
    border-radius: var(--radius-sm);
    padding: .4rem .8rem;
    color: #000;
    background: #fff;
    font-size: .85rem;
    font-weight: 600;
}

#nav-toggle,
.nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#nav-toggle:empty {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: var(--radius-sm);
    color: #111;
    background-color: #fff;
    background-image: none;
}

#nav-toggle:empty::before {
    content: "";
    width: 22px;
    height: 22px;
    display: block;
    background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24'%3E%3Cpath stroke='white' stroke-width='2' stroke-linecap='round' d='M4 7h16M4 12h16M4 17h16'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24'%3E%3Cpath stroke='white' stroke-width='2' stroke-linecap='round' d='M4 7h16M4 12h16M4 17h16'/%3E%3C/svg%3E") center / contain no-repeat;
}

body > main:not(.app-shell):not(.survey-main):not(.contact-page):not(.billing-wrap):not(.consent-builder-shell):not(.participants-shell) {
    max-width: var(--content-max);
    margin: 0 auto;
    padding: calc(var(--header-h) + clamp(1.5rem, 5vw, 3rem)) clamp(1rem, 4vw, 2rem) clamp(2rem, 6vw, 4rem);
}

.auth-shell,
body.compact-login main {
    max-width: var(--content-max);
    min-height: calc(100svh - var(--header-h));
    display: grid;
    align-content: start;
}

body.compact-login main {
    width: min(690px, 100%);
}

.auth-shell.is-wide {
    max-width: 640px;
}

.project-shell {
    max-width: 580px;
}

.page-header {
    display: flex;
    flex-direction: column;
    gap: .4rem;
    margin-bottom: var(--gap-lg);
}

.page-header h1 {
    margin: 0;
    font-size: clamp(1.6rem, 4vw, 2.2rem);
}

.page-header p {
    margin: 0;
    color: var(--muted);
}

.muted,
.hint {
    color: var(--muted);
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-bottom: var(--gap-md);
    border-bottom: 1px solid var(--border);
}

.tab {
    margin-bottom: -1px;
    border: 0;
    border-bottom: 2px solid transparent;
    padding: .6rem .9rem;
    color: var(--muted);
    background: transparent;
    font-size: .95rem;
    font-weight: 600;
}

.tab.is-active {
    color: var(--fg);
    border-bottom-color: var(--fg);
}

.pane {
    display: none;
}

.pane.is-active {
    display: block;
}

form.upload-form,
form.forgot-form,
form.newpassword-form,
#consent-form,
.form-card {
    display: grid;
    gap: var(--gap-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: clamp(1rem, 3vw, 1.75rem);
    background: var(--card-bg);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .04);
}

.field {
    display: flex;
    flex-direction: column;
    gap: .35rem;
}

.field label,
.field-label {
    margin-bottom: .2rem;
    font-size: .85rem;
    font-weight: 600;
}

.field .hint {
    font-size: .75rem;
}

.field input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]),
.field select,
.field textarea,
#consent-form input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]),
#consent-form select,
#consent-form textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .6rem .7rem;
    color: var(--fg);
    background: var(--card-bg);
    font-size: .95rem;
}

.field textarea,
#consent-form textarea {
    min-height: 90px;
    resize: vertical;
}

.field input[type="file"],
#consent-form input[type="file"] {
    padding: .4rem 0;
    color: var(--fg);
    font-size: .9rem;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
#consent-form input:focus,
#consent-form textarea:focus,
#consent-form select:focus {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

.field [aria-invalid="true"] {
    border-color: var(--danger);
}

.field-error {
    min-height: fit-content;
    margin: 0;
    color: var(--danger);
    font-size: .78rem;
    line-height: 1.3;
}

.row-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--gap-md);
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: .4rem;
}

.checkbox-grid label {
    display: flex;
    align-items: center;
    gap: .4rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .45rem .6rem;
    background: var(--chip-bg);
    cursor: pointer;
    font-size: .85rem;
    font-weight: 500;
}

.checkbox-grid input,
.choice input,
.q-consent input,
.checkbox-row input[type="checkbox"] {
    accent-color: var(--fg);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: .5rem;
}

.btn,
.button {
    min-width: 120px;
    min-height: 44px;
    border: 2px solid var(--fg);
    border-radius: var(--radius-sm);
    padding: .55rem 1rem;
    color: var(--fg);
    background: var(--card-bg);
    font-size: .95rem;
    font-weight: 600;
    transition: transform .15s ease, filter .15s ease, background-color .15s ease, color .15s ease;
}

a.btn,
a.button,
button.btn,
button.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    text-align: center;
}

select.button {
    display: inline-block;
    min-width: 0;
}

.btn:hover,
.button:hover {
    filter: invert(1);
    transform: scale(1.03);
}

.btn.primary,
.button.is-active {
    color: var(--bg);
    background: var(--fg);
}

[data-theme="dark"] .btn.primary,
[data-theme="dark"] .button.is-active {
    color: #111;
    background: #f5f5f5;
}

.btn[disabled],
.button[disabled],
.actions .btn[disabled] {
    opacity: .68;
    cursor: wait;
    transform: none;
}

.feedback,
.modal-feedback {
    min-height: 1.2rem;
    margin-bottom: var(--gap-md);
    border-radius: var(--radius-sm);
    padding: .7rem .85rem;
    color: var(--muted);
    font-size: .9rem;
}

.feedback {
    display: none;
}

.feedback.is-visible {
    display: block;
}

.feedback.success {
    border: 1px solid #6ee7b7;
    color: #065f46;
    background: #ecfdf5;
}

.feedback.error {
    border: 1px solid #fca5a5;
    color: #991b1b;
    background: #fef2f2;
}

[data-theme="dark"] .feedback.success {
    color: #a7f3d0;
    border-color: #065f46;
    background: #052e22;
}

[data-theme="dark"] .feedback.error {
    color: #fecaca;
    border-color: #7f1d1d;
    background: #3b0d0d;
}

.contact-hp {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.palette-toggle {
    border: 1px solid rgba(255, 255, 255, .2);
    background: rgba(255, 255, 255, .08);
}

.palette-toggle.is-active {
    border-color: rgba(255, 255, 255, .58);
    background: rgba(255, 255, 255, .18);
}

@media (max-width: 600px) {
    body > header {
        height: auto;
        min-height: var(--header-h);
    }

    .brand {
        font-size: .9rem;
    }

    .row-2 {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
    }
}
