/* =============================================================================
    CUSTOM PROPERTIES
    Two-tier token system:
        1. Primitives  – raw palette & scale values (--_prefix)
        2. Semantic    – role-based aliases consumed by components
========================================================================== */

:root {

    /* -------------------------------------------------------------------------
    1. PRIMITIVES
    --------------------------------------------------------------------- */

    /* — Color palette: Neutral / Gray — */
    --_white: #fff;
    --_gray-50: #f9fafb;
    --_gray-100: #f3f4f6;
    --_gray-200: #e5e7eb;
    --_gray-300: #d1d5db;
    --_gray-400: #9ca3af;
    --_gray-500: #6b7280;
    --_gray-600: #4b5563;
    --_gray-700: #374151;
    --_gray-800: #1f2937;
    --_gray-900: #111827;

    /* — Color palette: Dark surfaces — */
    --_dark-100: #555;
    --_dark-200: #444;
    --_dark-300: rgb(55, 55, 55);
    --_dark-400: #303030;
    --_dark-500: #382e42;
    --_dark-600: #222;

    /* — Color palette: Blue / Primary — */
    --_blue-50: #eff6ff;
    --_blue-100: #dbeafe;
    --_blue-400: #4887fc;
    --_blue-500: #3b82f6;
    --_blue-600: #2563eb;
    --_blue-700: #1d4ed8;
    --_blue-ring: rgba(59, 130, 246, 0.15);

    /* — Color palette: Green / Success — */
    --_green-50: #ecfdf5;
    --_green-300: #6ee7b7;
    --_green-600: #059669;
    --_green-700: #047857;
    --_green-800: #065f46;

    /* — Color palette: Red / Error — */
    --_red-50: #fef2f2;
    --_red-300: #fca5a5;
    --_red-600: #dc2626;
    --_red-800: #991b1b;

    /* — Color palette: Accent — */
    --_purple-300: #d3a8fc;

    /* — Typography scale — */
    --_font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
        Ubuntu, Cantarell, sans-serif;
    --_font-mono: 'SF Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo,
        monospace;

    --_text-xs: 0.75rem;
    /* 12px */
    --_text-sm: 0.8125rem;
    /* 13px */
    --_text-base: 0.875rem;
    /* 14px */
    --_text-md: 1rem;
    /* 16px */
    --_text-lg: 1.125rem;
    /* 18px */
    --_text-xl: 1.25rem;
    /* 20px */
    --_text-2xl: 1.5rem;
    /* 24px */

    --_leading-tight: 1.5;
    --_leading-normal: 1.6;

    --_font-medium: 500;
    --_font-semibold: 600;
    --_font-bold: 700;

    /* — Spacing scale — */
    --_space-1: 0.1em;
    --_space-2: 0.25rem;
    /* 4px  */
    --_space-3: 0.375rem;
    /* 6px  */
    --_space-4: 0.5rem;
    /* 8px  */
    --_space-5: 0.75rem;
    /* 12px */
    --_space-6: 1rem;
    /* 16px */
    --_space-7: 1.25rem;
    /* 20px */
    --_space-8: 1.5rem;
    /* 24px */
    --_space-9: 2rem;
    /* 32px */

    /* — Radii — */
    --_radius-xs: 0.2rem;
    --_radius-sm: 0.25rem;
    --_radius-md: 0.375rem;
    --_radius-lg: 0.5rem;

    /* — Shadows — */
    --_shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --_shadow-md: 0 1px 3px rgba(0, 0, 0, 0.08);

    /* — Motion — */
    --_duration-fast: 0.15s;
    --_duration-normal: 0.25s;

    /* — Borders — */
    --_border-width: 1px;

    /* — Layout — */
    --_max-w-container: 56rem;
    --_max-w-login: 24rem;


    /* -------------------------------------------------------------------------
    2. SEMANTIC TOKENS
    --------------------------------------------------------------------- */

    /* — Page — */
    --page-bg-start: var(--_dark-400);
    --page-bg-end: var(--_dark-500);
    --page-padding: 20px;

    /* — Surfaces — */
    --surface-primary: var(--_dark-300);
    --surface-card: var(--_dark-200);
    --surface-code: var(--_dark-100);
    --surface-code-inline: var(--_dark-600);
    --surface-input: var(--_white);

    /* — Text — */
    --text-primary: var(--_gray-800);
    --text-heading: var(--_white);
    --text-secondary: #aaa;
    --text-muted: var(--_gray-400);
    --text-on-dark: #ccc;
    --text-on-dark-muted: #777;
    --text-footer: #cbd0d8;
    --text-accent: var(--_purple-300);

    /* — Interactive — */
    --link-color: var(--_blue-400);

    --btn-primary-bg: var(--_blue-600);
    --btn-primary-bg-hover: var(--_blue-700);
    --btn-success-bg: var(--_green-600);
    --btn-success-bg-hover: var(--_green-700);
    --btn-dark-bg: var(--_gray-800);
    --btn-dark-bg-hover: var(--_gray-900);
    --btn-text: var(--_white);

    /* — Form controls — */
    --input-border: var(--_gray-300);
    --input-focus-border: var(--_blue-500);
    --input-focus-ring: var(--_blue-ring);
    --input-file-bg: var(--_blue-50);
    --input-file-bg-hover: var(--_blue-100);
    --input-file-color: var(--_blue-700);

    /* — Alert — */
    --alert-success-bg: var(--_green-50);
    --alert-success-border: var(--_green-300);
    --alert-success-text: var(--_green-800);
    --alert-error-bg: var(--_red-50);
    --alert-error-border: var(--_red-300);
    --alert-error-text: var(--_red-800);

    /* — Danger / Logout — */
    --danger-color: var(--_red-600);
    --danger-color-hover: var(--_red-800);

    /* — Toggle / active selection — */
    --toggle-active-bg: var(--_blue-50);
    --toggle-active-border: var(--_blue-500);
    --toggle-active-text: var(--_blue-700);
}


/* =============================================================================
RESET & BASE
========================================================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--_font-sans);
    line-height: var(--_leading-normal);
    color: var(--text-primary);
    background: linear-gradient(135deg, var(--page-bg-start) 0%, var(--page-bg-end) 100%);
    min-height: 100vh;
    padding: var(--page-padding);
}

a {
    color: var(--link-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}


/* =============================================================================
LAYOUT
========================================================================== */

.container {
    max-width: var(--_max-w-container);
    margin: 0 auto;
    padding: var(--_space-6);
    background: var(--surface-primary);
    border-radius: var(--_radius-lg);
}

/* — Nav — */
.nav {
    background: transparent;
    box-shadow: var(--_shadow-md);
}

.nav .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: var(--_space-5);
    padding-bottom: var(--_space-5);
}

.nav-title {
    font-size: var(--_text-xl);
    font-weight: var(--_font-bold);
    color: var(--text-on-dark);
}

.nav-right {
    display: flex;
    align-items: center;
    gap: var(--_space-6);
}

.nav-user {
    font-size: var(--_text-base);
    color: var(--text-on-dark-muted);
}

.nav-logout {
    font-size: var(--_text-base);
    color: var(--danger-color);
}

.nav-logout:hover {
    color: var(--danger-color-hover);
}

.logo {
    color: var(--_gray-900);
    display: inline-block;
    background-color: var(--_white);
    padding: 0.75rem 0.75rem 0 0.75rem;
    border-radius: var(--_radius-md);
    margin: 0 0 var(--_space-6) 0;
}

/* — Main & Footer — */
main {
    padding: var(--_space-9) 0;
}

footer {
    padding: var(--_space-8) 0;
    text-align: center;
    font-size: var(--_text-base);
    color: var(--text-footer);
}


/* =============================================================================
CARDS
========================================================================== */

.card {
    background: var(--surface-card);
    border-radius: var(--_radius-lg);
    box-shadow: var(--_shadow-sm);
    padding: var(--_space-8);
}

.card+.card,
.card+.actions {
    margin-top: var(--_space-8);
}


/* =============================================================================
ALERTS
========================================================================== */

.alert {
    padding: var(--_space-5) var(--_space-6);
    border-radius: var(--_radius-md);
    margin-bottom: var(--_space-8);
    border: var(--_border-width) solid;
}

.alert-success {
    background: var(--alert-success-bg);
    border-color: var(--alert-success-border);
    color: var(--alert-success-text);
}

.alert-error {
    background: var(--alert-error-bg);
    border-color: var(--alert-error-border);
    color: var(--alert-error-text);
}

.alert strong {
    display: block;
    margin-bottom: var(--_space-2);
}


/* =============================================================================
FORMS
========================================================================== */

label {
    display: block;
    font-size: var(--_text-base);
    font-weight: var(--_font-medium);
    color: var(--text-secondary);
    margin-bottom: var(--_space-2);
}

input[type="text"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: var(--_space-4) var(--_space-5);
    border: var(--_border-width) solid var(--input-border);
    border-radius: var(--_radius-md);
    font-size: var(--_text-base);
    font-family: inherit;
    color: var(--text-primary);
    background: var(--surface-input);
    transition: border-color var(--_duration-fast), box-shadow var(--_duration-fast);
}

input[type="text"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 3px var(--input-focus-ring);
}

textarea.mono {
    font-family: var(--_font-mono);
    font-size: var(--_text-sm);
}

input[type="file"] {
    width: 100%;
    font-size: var(--_text-base);
    color: var(--_gray-500);
    padding: var(--_space-3);
    border: var(--_border-width) solid var(--input-border);
    border-radius: var(--_radius-md);
}

input[type="file"]::file-selector-button {
    padding: var(--_space-2) var(--_space-6);
    margin-right: var(--_space-5);
    border: none;
    border-radius: var(--_radius-sm);
    background: var(--input-file-bg);
    color: var(--input-file-color);
    font-size: var(--_text-base);
    cursor: pointer;
}

input[type="file"]::file-selector-button:hover {
    background: var(--input-file-bg-hover);
}

.hint {
    font-size: var(--_text-xs);
    color: var(--text-muted);
    margin-top: var(--_space-2);
}


/* =============================================================================
GRID
========================================================================== */

.grid-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--_space-6);
}

@media (min-width: 640px) {
    .grid-2 {
        grid-template-columns: 1fr 1fr;
    }
}

.col-span-2 {
    grid-column: 1 / -1;
}


/* =============================================================================
BUTTONS
========================================================================== */

.btn {
    display: inline-block;
    padding: var(--_space-4) var(--_space-7);
    border: none;
    border-radius: var(--_radius-md);
    font-size: var(--_text-base);
    font-weight: var(--_font-medium);
    cursor: pointer;
    text-align: center;
    transition: background var(--_duration-fast);
    line-height: var(--_leading-tight);
}

.btn-primary {
    background: linear-gradient(135deg, var(--page-bg-end) 0%, var(--page-bg-start) 100%);
    color: var(--btn-text);
    font-size: var(--_text-lg);
    font-weight: var(--_font-bold);
    padding: var(--_space-5) var(--_space-8);
    border-radius: var(--_radius-lg);
    width: 100%;
    transition: transform var(--_duration-normal);
}

.btn-primary:hover {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    text-decoration: none;
}

.btn-success {
    background: var(--btn-success-bg);
    color: var(--btn-text);
    padding: var(--_space-4) var(--_space-6);
}

.btn-success:hover {
    background: var(--btn-success-bg-hover);
    text-decoration: none;
}

.btn-dark {
    background: var(--btn-dark-bg);
    color: var(--btn-text);
    width: 100%;
    font-weight: var(--_font-bold);
}

.btn-dark:hover {
    background: var(--btn-dark-bg-hover);
    text-decoration: none;
}

.btn-full {
    width: 100%;
}

.actions {
    display: flex;
    justify-content: flex-end;
    margin-top: var(--_space-8);
}


/* =============================================================================
TOGGLE (file / text)
========================================================================== */

.toggle-group {
    display: flex;
    gap: var(--_space-5);
    margin-bottom: var(--_space-6);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: var(--_space-4);
    padding: var(--_space-4) var(--_space-6);
    border: var(--_border-width) solid var(--input-border);
    border-radius: var(--_radius-md);
    cursor: pointer;
    font-size: var(--_text-base);
    color: var(--_gray-300);
    user-select: none;
    transition: background var(--_duration-fast), border-color var(--_duration-fast);
}

.toggle-label:hover {
    background: var(--_gray-50);
    color: var(--_gray-700);
}

.toggle-label svg {
    width: var(--_space-6);
    height: var(--_space-6);
    color: var(--_gray-500);
}

.hidden-radio {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

/* CSS-only show/hide */
#input-text-area {
    display: none;
}

#input-file-area {
    display: block;
}

#mode-text:checked~.form-body #input-text-area {
    display: block;
}

#mode-text:checked~.form-body #input-file-area {
    display: none;
}

#mode-file:checked~.form-body #input-text-area {
    display: none;
}

#mode-file:checked~.form-body #input-file-area {
    display: block;
}

/* Active toggle highlight */
#mode-file:checked~.form-body .toggle-label[for="mode-file"],
#mode-text:checked~.form-body .toggle-label[for="mode-text"] {
    background: var(--toggle-active-bg);
    border-color: var(--toggle-active-border);
    color: var(--toggle-active-text);
}


/* =============================================================================
DETAILS / SUMMARY
========================================================================== */

details summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: var(--_space-4);
}

details summary::-webkit-details-marker {
    display: none;
}

details summary::before {
    content: '▸';
    font-size: var(--_text-2xl);
    transition: transform var(--_duration-normal) ease-in;
    color: var(--text-heading);
}

details[open] summary::before {
    transform: rotate(90deg);
}

.section-title {
    font-size: var(--_text-lg);
    font-weight: var(--_font-semibold);
    color: var(--text-heading);
}

.section-subtitle {
    font-size: var(--_text-base);
    font-weight: 400;
    color: var(--text-muted);
}

details .inner {
    margin-top: var(--_space-6);
}


/* =============================================================================
DIVIDER
========================================================================== */

.divider {
    position: relative;
    margin: var(--_space-8) 0;
    text-align: center;
}

.divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    border-top: var(--_border-width) solid var(--input-border);
}

.divider span {
    position: relative;
    background: var(--_white);
    padding: 0 var(--_space-5);
    font-size: var(--_text-base);
    color: var(--text-muted);
}


/* =============================================================================
API DOCS
========================================================================== */

.api-section+.api-section {
    margin-top: var(--_space-6);
}

.api-section h3 {
    font-weight: var(--_font-semibold);
    color: var(--text-accent);
    font-size: var(--_text-base);
}

.api-code {
    display: block;
    background: var(--_gray-50);
    padding: var(--_space-4) var(--_space-5);
    border-radius: var(--_radius-sm);
    margin-top: var(--_space-2);
    font-family: monospace;
    font-size: var(--_text-sm);
}

.api-list {
    color: var(--text-on-dark);
    list-style: disc;
    padding-left: var(--_space-7);
    margin-top: var(--_space-2);
    font-size: var(--_text-base);
}

.api-list li+li {
    margin-top: var(--_space-2);
}

.api-list code {
    font-size: var(--_text-sm);
    background: var(--surface-code-inline);
    padding: var(--_space-1) 0.3em;
    border-radius: var(--_radius-xs);
}

pre.example {
    background: var(--surface-code);
    color: var(--text-on-dark);
    padding: var(--_space-5);
    border-radius: var(--_radius-md);
    overflow-x: auto;
    font-size: var(--_text-sm);
    line-height: var(--_leading-tight);
    margin-top: var(--_space-2);
    white-space: pre-wrap;
}


/* =============================================================================
LOGIN
========================================================================== */

.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    width: 100%;
    max-width: var(--_max-w-login);
}

.login-card>h2 {
    color: var(--text-on-dark-muted)
}

.login-card>.logo {
    display: block;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
}

.login-card>.logo svg {
    height: 7rem;
}

.login-card .btn-primary {
    margin-top: var(--_space-6);
}

.login-title {
    font-size: var(--_text-2xl);
    font-weight: var(--_font-bold);
    color: var(--text-primary);
    text-align: center;
    margin-bottom: var(--_space-8);
}

.form-group {
    margin-bottom: var(--_space-6);
}