:root {
    --color-root-bg:       hsla(207, 56%, 96%, 1);
    --color-white:         hsla(0, 0%, 100%, 1);
    --color-text-primary:  hsla(204, 17%, 14%, 1);
    --color-text-hint:     hsla(203, 19%, 31%, 0.65);
    --color-text-extra:    hsla(203, 19%, 31%, 0.65);
    --color-text-disabled: hsla(205, 24%, 75%, 1);

    --color-border:        hsla(208, 57%, 89%, 1);
    --color-border-focus:  hsla(203, 87%, 57%, 1);

    --color-primary:         hsla(203, 87%, 57%, 1);
    --color-primary-hover:   hsla(203, 78%, 54%, 1);
    --color-primary-clicked: hsla(203, 81%, 48%, 1);
    --color-button-default-bg: hsla(203, 87%, 57%, 0.1);
    --color-button-active-bg: hsla(203, 87%, 57%, 1);
    --color-text-secondary: hsla(0, 0%, 100%, 1);

    --color-secondary-bg:    hsla(203, 87%, 57%, 0.10);
    --color-secondary-hover: hsla(203, 86%, 56%, 0.15);

    --color-error:   hsla(347, 50%, 49%, 1);
    --color-success: hsla(147, 47%, 53%, 1);

    --radius-card:  16px;
    --radius-input: 10px;
    --radius-btn:   999px;

    --form-gap: clamp(22px, 3vh, 30px);
    --field-gap: clamp(8px, 1.2vh, 12px);
}

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

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Open Sans', 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.5;
    color: var(--color-text-primary);
    background-color: var(--color-root-bg);
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */

.page {
    height: 100dvh;
    min-height: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 2.5dvh 16px 0;
}

.card {
    background: var(--color-white);
    border-radius: var(--radius-card);
    padding: clamp(14px, 2.2vh, 26px) clamp(16px, 2.6vw, 36px);
    width: 100%;
    max-width: 600px;
    max-height: 95dvh;
    box-shadow: 0 2px 20px rgba(32, 96, 140, 0.07);
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.card__title {
    font-size: clamp(18px, 2.6vh, 22px);
    font-weight: 600;
    color: var(--color-text-primary);
    margin-bottom: clamp(10px, 1.8vh, 18px);
    line-height: 1.2;
    flex-shrink: 0;
}

/* ─── Form ───────────────────────────────────────────────────────────────── */

.form {
    display: flex;
    flex-direction: column;
    gap: var(--form-gap);
    flex: 1;
    min-height: 0;
}

.form__field {
    display: flex;
    flex-direction: column;
    gap: var(--field-gap);
}

.form__label {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-primary);
    line-height: 1.4;
}

.form__label--with-tip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: relative;
}

.form__required {
    color: var(--color-error);
    margin-left: 2px;
}

.form__hint {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.form__hint p {
    font-size: 12px;
    color: var(--color-text-hint);
    line-height: 1.5;
}

.form__tip {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    color: var(--color-text-hint);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    cursor: help;
    position: relative;
    outline: none;
}

.form__tip:focus-visible {
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 2px hsla(203, 87%, 57%, 0.14);
}

.form__tip-popup {
    position: absolute;
    left: 50%;
    top: calc(100% + 8px);
    transform: translateX(-50%);
    background: hsla(250, 9%, 27%, 1);
    color: hsla(0, 0%, 100%, 1);
    padding: 8px 10px;
    border-radius: 8px;
    min-width: 300px;
    max-width: 360px;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.4;
    z-index: 20;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease;
    pointer-events: none;
}

.form__tip:hover .form__tip-popup,
.form__tip:focus-visible .form__tip-popup {
    opacity: 1;
    visibility: visible;
}

/* ─── Inputs ─────────────────────────────────────────────────────────────── */

.form__input {
    width: 100%;
    height: clamp(38px, 4.6vh, 44px);
    padding: 8px 12px;
    font-family: inherit;
    font-size: 14px;
    color: var(--color-text-primary);
    background: var(--color-white);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-input);
    outline: none;
    transition: border-color 0.2s;
    appearance: none;
}

.form__input:focus {
    border-color: var(--color-border-focus);
}

.form__input::placeholder {
    color: var(--color-text-disabled);
}

.form__input--error {
    border-color: var(--color-error);
}

.form__textarea {
    height: clamp(58px, 8.5vh, 92px);
    min-height: 0;
    resize: none;
}

/* ─── Switch (Giga/Qwen style) ───────────────────────────────────────────── */

.form__switch {
    position: relative;
    display: inline-block;
}

.form__switch input[type="radio"] {
    position: absolute;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    pointer-events: none !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    display: none !important;
}

.form__switch-track {
    position: relative;
    display: flex;
    height: 36px;
    border-radius: 999px;
    background: var(--color-button-default-bg);
    overflow: hidden;
    cursor: pointer;
    min-width: 210px;
    padding: 2px;
}

.form__switch-thumb {
    position: absolute;
    top: 2px;
    bottom: 2px;
    left: 2px;
    width: calc(50% - 2px);
    background: var(--color-button-active-bg);
    border-radius: 999px;
    transition: transform 0.2s ease-in-out;
    pointer-events: none;
}

.form__switch-option {
    flex: 1;
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-extra);
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
    white-space: nowrap;
    padding: 0 12px;
}

.form__switch input:first-of-type:checked ~ .form__switch-track .form__switch-option:first-of-type,
.form__switch input:last-of-type:checked ~ .form__switch-track .form__switch-option:last-of-type {
    color: var(--color-text-secondary);
}

.form__switch input:last-of-type:checked ~ .form__switch-track .form__switch-thumb {
    transform: translateX(calc(100% + 2px));
}

.form__switch-track--error {
    box-shadow: 0 0 0 2px var(--color-error);
}

/* ─── Date range ─────────────────────────────────────────────────────────── */

.form__date-group {
    display: flex;
    gap: 16px;
}

.form__date-item {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.form__date-label {
    font-size: 14px;
    color: var(--color-text-hint);
    white-space: nowrap;
}

.form__date {
    flex: 1;
    min-width: 0;
}

/* ─── File input ─────────────────────────────────────────────────────────── */

.form__file {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    height: clamp(38px, 4.6vh, 44px);
    padding: 8px 12px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-input);
    cursor: pointer;
    transition: border-color 0.2s;
    overflow: hidden;
}

.form__file-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.form__file:hover {
    border-color: var(--color-border-focus);
}

.form__file-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.form__file-text {
    font-size: 14px;
    color: var(--color-text-disabled);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s;
}

.form__file-text--selected {
    color: var(--color-text-primary);
}

/* ─── Error & success ────────────────────────────────────────────────────── */

.form__error {
    font-size: 12px;
    color: var(--color-error);
    display: block;
    line-height: 1.2;
}

.form__error:empty {
    display: none;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-btn);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    outline: none;
}

.btn--primary {
    width: 100%;
    height: clamp(38px, 4.8vh, 44px);
    min-height: 38px;
    padding: 0 24px;
    background: var(--color-primary);
    color: #fff;
    line-height: 1;
    flex-shrink: 0;
}

.btn--primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.btn--primary:active:not(:disabled) {
    background: var(--color-primary-clicked);
}

.btn--primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn--secondary {
    height: 36px;
    padding: 0 20px;
    background: var(--color-secondary-bg);
    color: var(--color-primary);
}

.btn--secondary:hover {
    background: var(--color-secondary-hover);
}

/* ─── Popup ──────────────────────────────────────────────────────────────── */

.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}

.popup-overlay[hidden] {
    display: none;
}

.popup {
    background: var(--color-white);
    border-radius: var(--radius-card);
    padding: 28px 32px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.popup__message {
    font-size: 14px;
    color: var(--color-text-primary);
    line-height: 1.6;
}

.popup__close {
    align-self: flex-end;
}

/* ─── Toast ──────────────────────────────────────────────────────────────── */

.toast {
    position: fixed;
    top: 18px;
    left: 50%;
    transform: translate(-50%, -12px);
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 120;
    pointer-events: none;
    min-width: min(700px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    padding: 16px 22px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
    font-size: 16px;
    line-height: 1.4;
    font-weight: 600;
    text-align: center;
}

.toast--success {
    background: hsla(147, 47%, 53%, 1);
    border: 1.5px solid var(--color-success);
    color: hsla(0, 0%, 100%, 1);
}

.toast--visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */

@media (max-height: 900px) {
    .page {
        --form-gap: 24px;
        --field-gap: 9px;
        padding-top: 2.5dvh;
        padding-bottom: 0;
    }

    .card {
        padding: 16px 22px;
    }

    .form__input,
    .form__file,
    .btn--primary {
        height: 40px;
    }

    .form__textarea {
        min-height: 82px;
    }

    .form__switch-track {
        height: 34px;
    }
}

@media (max-height: 760px) {
    .page {
        --form-gap: 20px;
        --field-gap: 8px;
        padding: 2.5dvh 12px;
        gap: 20px;
    }

    .card {
        padding: 12px 16px;
    }

    .form__label {
        font-size: 13px;
    }

    .form__input,
    .form__file,
    .btn--primary {
        height: 36px;
        min-height: 36px;
        font-size: 13px;
    }

    .form__textarea {
        height: 58px;
    }

    .form__switch-track {
        height: 32px;
        min-width: 190px;
    }

    .form__switch-option {
        font-size: 13px;
    }

    .form__error {
        font-size: 11px;
    }
}

@media (max-height: 680px) and (min-width: 1000px) {
    .card {
        max-width: 780px;
    }

    .form {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: var(--form-gap) 16px;
    }

    .form__field:nth-child(3),
    .btn--primary {
        grid-column: 1 / -1;
    }

    .form__textarea {
        height: 48px;
    }
}

@media (max-width: 480px) {
    .page {
        --form-gap: 18px;
        --field-gap: 7px;
        padding: 2.5dvh 10px 0;
    }

    .card {
        max-height: 95dvh;
        padding: 10px 12px;
    }

    .form__label,
    .form__switch-option,
    .form__file-text,
    .form__input {
        font-size: 12px;
    }

    .form__input,
    .form__file,
    .btn--primary {
        height: 32px;
        min-height: 32px;
    }

    .form__textarea {
        height: 44px;
    }

    .form__switch-track {
        height: 30px;
        min-width: 0;
        width: 100%;
    }

    .form__switch {
        display: block;
        width: 100%;
    }

    .form__date-group {
        flex-direction: column;
    }
}

@media (max-width: 480px) and (max-height: 620px) {
    .page {
        --form-gap: 14px;
        --field-gap: 6px;
        padding: 2.5dvh 8px 0;
    }

    .card {
        padding: 8px 10px;
    }

    .card__title {
        font-size: 16px;
        margin-bottom: 6px;
    }

    .form__label,
    .form__switch-option,
    .form__file-text,
    .form__input {
        font-size: 11px;
    }

    .form__input,
    .form__file,
    .btn--primary {
        height: 29px;
        min-height: 29px;
    }

    .form__textarea {
        height: 36px;
    }

    .form__switch-track {
        height: 28px;
    }
}
