/* ==========================================================================
   Стаффбаза — компоненты интерфейса
   ========================================================================== */

/* --- Кнопки --------------------------------------------------------------- */

.btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 18px;
    border-radius: var(--r-sm);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: -0.005em;
    white-space: nowrap;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    overflow: hidden;
    transition: transform var(--t-fast) var(--ease),
                background-color var(--t-fast) var(--ease),
                border-color var(--t-fast) var(--ease),
                box-shadow var(--t-fast) var(--ease),
                opacity var(--t-fast) var(--ease);
    -webkit-user-select: none;
    user-select: none;
}

.btn:hover:not(:disabled) {
    background: var(--surface-3);
    text-decoration: none;
}

.btn:active:not(:disabled) {
    transform: scale(0.975);
}

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

.btn--primary {
    background: var(--gradient);
    background-size: 160% 160%;
    color: var(--text-on-accent);
    border-color: transparent;
    box-shadow: 0 2px 10px rgba(79, 70, 229, 0.28);
}

.btn--primary:hover:not(:disabled) {
    background: var(--gradient);
    background-position: 100% 0;
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.36);
}

.btn--success {
    background: var(--success);
    color: #fff;
    border-color: transparent;
}

.btn--success:hover:not(:disabled) { background: var(--success); filter: brightness(1.08); }

.btn--danger {
    background: var(--danger-soft);
    color: var(--danger-soft-text);
    border-color: transparent;
}

.btn--danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

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

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

.btn--outline {
    background: transparent;
    border-color: var(--border-strong);
}

.btn--sm { min-height: 34px; padding: 0 12px; font-size: 0.82rem; border-radius: var(--r-xs); }
.btn--lg { min-height: 50px; padding: 0 24px; font-size: 0.98rem; border-radius: var(--r-md); }
.btn--block { width: 100%; }
.btn--icon { padding: 0; width: 42px; min-height: 42px; border-radius: var(--r-sm); }
.btn--icon.btn--sm { width: 34px; min-height: 34px; }

.btn__spinner {
    width: 15px;
    height: 15px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 640ms linear infinite;
}

.btn.is-loading { pointer-events: none; opacity: 0.75; }

/* Волна от нажатия */
.ripple {
    position: absolute;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.28;
    transform: scale(0);
    animation: ripple 520ms var(--ease-out) forwards;
    pointer-events: none;
}

@keyframes ripple {
    to { transform: scale(2.6); opacity: 0; }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Иконки --------------------------------------------------------------- */

.icon {
    width: 19px;
    height: 19px;
    flex: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.icon--sm { width: 15px; height: 15px; }
.icon--lg { width: 24px; height: 24px; }
.icon--xl { width: 34px; height: 34px; stroke-width: 1.5; }

/* --- Карточки ------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
}

.card--pad { padding: 18px; }
.card--tight { padding: 14px; }

.card--hover {
    transition: transform var(--t) var(--ease), box-shadow var(--t) var(--ease),
                border-color var(--t) var(--ease);
}

.card--hover:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border-strong);
}

.card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}

.card__body { padding: 18px; }
.card__foot { padding: 14px 18px; border-top: 1px solid var(--border); }

.panel {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 14px;
}

/* --- Бейджи и чипы -------------------------------------------------------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: var(--r-full);
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.badge--primary { background: var(--primary-soft); color: var(--primary-soft-text); }
.badge--success { background: var(--success-soft); color: var(--success-soft-text); }
.badge--warn    { background: var(--warn-soft);    color: var(--warn-soft-text); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger-soft-text); }
.badge--info    { background: var(--info-soft);    color: var(--info-soft-text); }

.badge__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}

.badge--pulse .badge__dot { animation: pulse-dot 1.8s var(--ease) infinite; }

@keyframes pulse-dot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.5); opacity: 0.5; }
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 13px;
    border-radius: var(--r-full);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 550;
    white-space: nowrap;
    transition: all var(--t-fast) var(--ease);
}

.chip:hover { border-color: var(--border-strong); color: var(--text); }

.chip.is-active {
    background: var(--primary-soft);
    border-color: transparent;
    color: var(--primary-soft-text);
    font-weight: 650;
}

.chip__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    border-radius: var(--r-full);
    background: var(--surface-3);
    font-size: 0.7rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.chip.is-active .chip__count { background: rgba(255, 255, 255, 0.45); }

.chip-scroller {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    margin: 0 -2px;
    padding-inline: 2px;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
}

.chip-scroller::-webkit-scrollbar { display: none; }
.chip-scroller > * { scroll-snap-align: start; }

/* --- Аватар --------------------------------------------------------------- */

.avatar {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: none;
    border-radius: 50%;
    background: var(--gradient);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    -webkit-user-select: none;
    user-select: none;
}

.avatar--sm { width: 32px; height: 32px; font-size: 0.72rem; }
.avatar--lg { width: 58px; height: 58px; font-size: 1.15rem; }
.avatar--xl { width: 76px; height: 76px; font-size: 1.5rem; }

/* --- Поля ввода ----------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 6px; }

.field__label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.field__label span { color: var(--danger); }

.field__hint { font-size: 0.76rem; color: var(--text-faint); }

.field__error {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.76rem;
    font-weight: 550;
    color: var(--danger);
    animation: shake 340ms var(--ease);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-4px); }
    75%      { transform: translateX(4px); }
}

.input,
.select,
.textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 13px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    font-size: 0.92rem;
    color: var(--text);
    transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease),
                background-color var(--t-fast) var(--ease);
    appearance: none;
}

.textarea { min-height: 92px; resize: vertical; line-height: 1.55; }

.input::placeholder,
.textarea::placeholder { color: var(--text-faint); }

.input:hover,
.select:hover,
.textarea:hover { border-color: var(--border-strong); }

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ring);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
    background: var(--surface-2);
    color: var(--text-faint);
    cursor: not-allowed;
}

.field.has-error .input,
.field.has-error .select,
.field.has-error .textarea {
    border-color: var(--danger);
}

.field.has-error .input:focus,
.field.has-error .textarea:focus {
    box-shadow: 0 0 0 3px var(--danger-soft);
}

.select {
    padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b94a8' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 17px;
    cursor: pointer;
}

/* Поле с иконкой слева */
.input-group { position: relative; display: flex; align-items: center; }

.input-group .icon {
    position: absolute;
    left: 13px;
    color: var(--text-faint);
    pointer-events: none;
}

.input-group .input { padding-left: 40px; }

.input-group__action {
    position: absolute;
    right: 6px;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: var(--r-xs);
    color: var(--text-faint);
    transition: color var(--t-fast), background-color var(--t-fast);
}

.input-group__action:hover { color: var(--text); background: var(--surface-2); }

/* Переключатель */
.switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.switch input { position: absolute; opacity: 0; pointer-events: none; }

.switch__track {
    width: 42px;
    height: 24px;
    flex: none;
    border-radius: var(--r-full);
    background: var(--surface-3);
    border: 1px solid var(--border);
    transition: background-color var(--t) var(--ease);
}

.switch__track::after {
    content: "";
    display: block;
    width: 18px;
    height: 18px;
    margin: 2px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--shadow-sm);
    transition: transform var(--t) var(--ease-spring);
}

.switch input:checked + .switch__track { background: var(--primary); border-color: transparent; }
.switch input:checked + .switch__track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 3px var(--ring); }

/* Чекбокс-плитка для выбора дат */
.tile-check {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-width: 62px;
    padding: 9px 10px;
    border-radius: var(--r-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all var(--t-fast) var(--ease);
    -webkit-user-select: none;
    user-select: none;
}

.tile-check input { position: absolute; opacity: 0; pointer-events: none; }
.tile-check:hover { border-color: var(--border-strong); }

.tile-check__day { font-size: 1.02rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-check__mon { font-size: 0.68rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }

.tile-check:has(input:checked) {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary-soft-text);
}

.tile-check:has(input:checked) .tile-check__mon { color: inherit; opacity: 0.75; }
.tile-check:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--ring); }

/* --- Оценки ---------------------------------------------------------------- */

.stars {
    display: inline-flex;
    gap: 1px;
    flex: none;
    line-height: 0;
}

.stars__item {
    fill: var(--border-strong);
    transition: fill var(--t-fast) var(--ease);
}

.stars__item.is-on { fill: #f59e0b; }

/* Выбор оценки: пять кнопок-звёзд, подсвечиваются до наведённой */
.star-pick { display: inline-flex; gap: 4px; }

.star-pick__btn {
    display: grid;
    place-items: center;
    padding: 3px;
    border-radius: var(--r-xs);
    line-height: 0;
    transition: transform var(--t-fast) var(--ease-spring);
}

.star-pick__btn svg { fill: var(--border-strong); transition: fill var(--t-fast); }
.star-pick__btn.is-on svg { fill: #f59e0b; }
.star-pick__btn:hover { transform: scale(1.15); }
.star-pick__btn:active { transform: scale(0.94); }

.rating-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
}

.rating-row + .rating-row { border-top: 1px solid var(--border); }

/* --- Прогресс мест -------------------------------------------------------- */

.meter {
    height: 6px;
    border-radius: var(--r-full);
    background: var(--surface-3);
    box-shadow: inset 0 0 0 1px var(--border);
    overflow: hidden;
}

.meter__fill {
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
    transform-origin: left;
    animation: meter-grow 620ms var(--ease-out) both;
}

.meter__fill--full    { background: var(--success); }
.meter__fill--warn    { background: var(--warn); }
.meter__fill--empty   { background: var(--border-strong); }

@keyframes meter-grow {
    from { transform: scaleX(0); }
}

/* --- Табы ----------------------------------------------------------------- */

.tabs {
    position: relative;
    display: flex;
    gap: 2px;
    padding: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
}

.tabs__btn {
    position: relative;
    z-index: 1;
    flex: 1 1 0;
    min-height: 36px;
    padding: 0 12px;
    border-radius: var(--r-xs);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: color var(--t) var(--ease);
    white-space: nowrap;
}

.tabs__btn.is-active { color: var(--text); }

.tabs__glider {
    position: absolute;
    top: 4px;
    bottom: 4px;
    border-radius: var(--r-xs);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: transform var(--t-slow) var(--ease-out), width var(--t-slow) var(--ease-out);
    pointer-events: none;
}

/* --- Пустое состояние ----------------------------------------------------- */

.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 52px 24px;
    text-align: center;
    animation: fade-up 420ms var(--ease-out) both;
}

.empty__art {
    display: grid;
    place-items: center;
    width: 76px;
    height: 76px;
    border-radius: var(--r-xl);
    background: var(--gradient-soft);
    color: var(--primary);
}

.empty__art .icon { width: 32px; height: 32px; }
.empty h3 { font-size: 1.05rem; }
.empty p { max-width: 380px; color: var(--text-muted); font-size: 0.9rem; }

/* --- Скелетоны ------------------------------------------------------------ */

.skeleton {
    position: relative;
    background: var(--surface-2);
    border-radius: var(--r-sm);
    overflow: hidden;
}

.skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.28), transparent);
    animation: shimmer 1.4s infinite;
}

:root[data-theme="dark"] .skeleton::after,
:root:not([data-theme="light"]) .skeleton::after {
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
}

@keyframes shimmer {
    from { transform: translateX(-100%); }
    to   { transform: translateX(100%); }
}

.skeleton-card {
    height: 132px;
    border-radius: var(--r-lg);
}

.skeleton-line { height: 12px; }
.skeleton-line--sm { height: 9px; }

/* --- Модалки и шторки ----------------------------------------------------- */

.overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(8, 11, 19, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fade-in var(--t) var(--ease) both;
}

.overlay.is-closing { animation: fade-out var(--t-fast) var(--ease) both; }

.modal {
    width: 100%;
    max-width: 480px;
    max-height: min(86dvh, 780px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    animation: modal-in var(--t-slow) var(--ease-spring) both;
}

.modal--wide { max-width: 660px; }

.overlay.is-closing .modal { animation: modal-out var(--t-fast) var(--ease) both; }

.modal__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 20px 20px 14px;
}

.modal__title { font-size: 1.1rem; }
.modal__sub { margin-top: 3px; font-size: 0.84rem; color: var(--text-muted); }
.modal__body { padding: 0 20px 4px; overflow-y: auto; flex: 1 1 auto; }

.modal__foot {
    display: flex;
    gap: 10px;
    padding: 16px 20px 20px;
}

.modal__foot .btn { flex: 1 1 0; }

@keyframes modal-in {
    from { opacity: 0; transform: translateY(18px) scale(0.965); }
}

@keyframes modal-out {
    to { opacity: 0; transform: translateY(8px) scale(0.98); }
}

/* На телефоне модалка превращается в нижнюю шторку */
@media (max-width: 640px) {
    .overlay {
        place-items: end center;
        padding: 0;
    }

    .modal {
        max-width: none;
        max-height: 92dvh;
        border-radius: var(--r-xl) var(--r-xl) 0 0;
        border-bottom: 0;
        animation: sheet-in var(--t-slow) var(--ease-out) both;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .overlay.is-closing .modal { animation: sheet-out var(--t-fast) var(--ease) both; }

    .modal::before {
        content: "";
        display: block;
        width: 38px;
        height: 4px;
        margin: 9px auto 0;
        border-radius: var(--r-full);
        background: var(--border-strong);
        flex: none;
    }
}

@keyframes sheet-in {
    from { transform: translateY(100%); }
}

@keyframes sheet-out {
    to { transform: translateY(100%); }
}

/* --- Тосты ---------------------------------------------------------------- */

.toasts {
    position: fixed;
    left: 50%;
    bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(440px, calc(100vw - 24px));
    transform: translateX(-50%);
    pointer-events: none;
}

@media (min-width: 900px) {
    .toasts { bottom: 22px; left: auto; right: 22px; transform: none; }
}

.toast {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 12px 14px;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    font-weight: 550;
    pointer-events: auto;
    animation: toast-in var(--t-slow) var(--ease-spring) both;
}

.toast.is-closing { animation: toast-out var(--t) var(--ease) both; }

.toast__icon {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    flex: none;
    border-radius: 50%;
}

.toast--success .toast__icon { background: var(--success-soft); color: var(--success-soft-text); }
.toast--error   .toast__icon { background: var(--danger-soft);  color: var(--danger-soft-text); }
.toast--info    .toast__icon { background: var(--info-soft);    color: var(--info-soft-text); }
.toast--success { border-left: 3px solid var(--success); }
.toast--error   { border-left: 3px solid var(--danger); }
.toast--info    { border-left: 3px solid var(--info); }

.toast__close { color: var(--text-faint); display: grid; place-items: center; }
.toast__close:hover { color: var(--text); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
}

@keyframes toast-out {
    to { opacity: 0; transform: translateY(-8px) scale(0.97); }
}

/* --- Общие анимации ------------------------------------------------------- */

@keyframes fade-in  { from { opacity: 0; } }
@keyframes fade-out { to   { opacity: 0; } }

@keyframes fade-up {
    from { opacity: 0; transform: translateY(10px); }
}

@keyframes fade-down {
    from { opacity: 0; transform: translateY(-8px); }
}

@keyframes scale-in {
    from { opacity: 0; transform: scale(0.94); }
}

/* Появление списков «лестницей»: index задаётся инлайн через --i */
.stagger > * {
    animation: fade-up 420ms var(--ease-out) both;
    animation-delay: calc(var(--i, 0) * 45ms);
}
