/* Файл: frontend/static/css/pages/profile.css */

:root {
    --bg-base: #000000;
    --bg-elevated: #111214;
    --bg-card: rgba(255, 255, 255, 0.045);
    --bg-card-active: rgba(255, 255, 255, 0.08);
    --text-primary: #ffffff;
    --text-secondary: rgba(235, 235, 245, 0.62);
    --text-tertiary: rgba(235, 235, 245, 0.4);
    --border-color: rgba(255, 255, 255, 0.08);
    --accent: var(--tg-theme-button-color, #0a84ff);
    --accent-soft: rgba(10, 132, 255, 0.16);
    --success: #34c759;
    --danger: #ff453a;
    --radius-main: 20px;
    --radius-medium: 16px;
    --radius-small: 12px;

    /* Отступ от верхнего края с учётом «челки» и кнопок Telegram
       (камера / закрыть / меню) в полноэкранном режиме. */
    --safe-top: calc(
        var(--tg-safe-area-inset-top, 0px) +
        var(--tg-content-safe-area-inset-top, 0px)
    );
    --safe-bottom: calc(
        var(--tg-safe-area-inset-bottom, 0px) +
        var(--tg-content-safe-area-inset-bottom, 0px)
    );
}

html[data-theme="light"] {
    --bg-card: rgba(0, 0, 0, 0.035);
    --bg-card-active: rgba(0, 0, 0, 0.06);
    --text-tertiary: rgba(60, 60, 67, 0.45);
    --border-color: rgba(0, 0, 0, 0.07);
    --accent-soft: rgba(10, 132, 255, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html {
    min-height: 100%;
    background-color: var(--bg-base);
}

body {
    min-height: 100%;
    min-height: 100dvh;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', Roboto, Helvetica, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

button {
    font: inherit;
    color: inherit;
    appearance: none;
    -webkit-appearance: none;
}

/* ============================= LOADER ============================= */

.loader {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg-base);
}

.loader-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    text-align: center;
    color: var(--text-secondary);
}

.loader-text {
    font-size: 15px;
    line-height: 1.4;
    max-width: 260px;
}

.loader-retry {
    margin-top: 2px;
    padding: 10px 22px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.loader-retry:active { background: var(--bg-card-active); }

.spin {
    animation: spin 0.8s linear infinite;
}

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

/* ============================= LAYOUT ============================= */

.app-main {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 26px;
    padding: 0 16px calc(var(--safe-bottom) + 40px);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.app-main[hidden] { display: none; }

.app-main.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* ============================= HERO ============================= */

.profile-hero {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin: 0 -16px;
    padding: calc(var(--safe-top) + 28px) 20px 28px;
    border-bottom: 1px solid var(--border-color);
    border-radius: 0 0 28px 28px;
    background:
        radial-gradient(120% 90% at 50% 0%, var(--accent-soft) 0%, transparent 62%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.04) 0%, transparent 100%);
    overflow: hidden;
}

html[data-theme="light"] .profile-hero {
    background:
        radial-gradient(120% 90% at 50% 0%, var(--accent-soft) 0%, transparent 62%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.9) 0%, transparent 100%);
}

.profile-identity {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    max-width: 100%;
}

.profile-name {
    font-size: 24px;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: -0.02em;
    max-width: 100%;
    overflow-wrap: anywhere;
    text-align: center;
}

.profile-badges {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.profile-role {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-card);
    padding: 4px 11px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
}

.profile-role-admin {
    color: #ff9f0a;
    border-color: rgba(255, 159, 10, 0.35);
    background: rgba(255, 159, 10, 0.1);
}

/* ============================= AVATAR ============================= */

.avatar-wrapper {
    position: relative;
    width: 112px;
    height: 112px;
    padding: 0;
    border: 3px solid rgba(255, 255, 255, 0.09);
    border-radius: 50%;
    background-color: var(--bg-elevated);
    box-shadow: 0 18px 40px -20px rgba(0, 0, 0, 0.9);
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.18s cubic-bezier(0.25, 0.8, 0.25, 1);
}

html[data-theme="light"] .avatar-wrapper {
    border-color: rgba(0, 0, 0, 0.06);
    box-shadow: 0 18px 40px -24px rgba(0, 0, 0, 0.35);
}

.avatar-wrapper:active { transform: scale(0.96); }

.avatar-wrapper img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-wrapper img[hidden] { display: none; }

.avatar-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
}

.avatar-fallback[hidden] { display: none; }

.avatar-edit-badge {
    position: absolute;
    right: -3px;
    bottom: -3px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 3px solid var(--bg-base);
    background: var(--accent);
    color: #ffffff;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.avatar-wrapper.is-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.45);
}

.avatar-wrapper.is-loading::before {
    content: '';
    position: absolute;
    z-index: 2;
    top: 50%;
    left: 50%;
    width: 22px;
    height: 22px;
    margin: -11px 0 0 -11px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ============================= SECTIONS ============================= */

.profile-section {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.section-header {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 0 4px;
}

.section-title {
    font-size: 18px;
    font-weight: 700;
}

.section-subtitle {
    font-size: 13px;
    color: var(--text-tertiary);
    line-height: 1.35;
}

.card-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.profile-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 14px 16px;
    border-radius: var(--radius-medium);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    text-align: left;
}

.profile-card-button {
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}

.profile-card-button:active {
    background: var(--bg-card-active);
    transform: scale(0.985);
}

#copy-id-btn {
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}

#copy-id-btn:active {
    background: var(--bg-card-active);
    transform: scale(0.985);
}

.profile-card-icon {
    width: 42px;
    height: 42px;
    border-radius: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-soft);
    color: var(--accent);
    flex-shrink: 0;
}

.profile-card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.profile-card-label {
    font-size: 15px;
    font-weight: 600;
}

.profile-card-value {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-card-value-mono {
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 12px;
    letter-spacing: 0.04em;
}

.profile-card-value-sub {
    font-size: 13px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-card-action {
    display: flex;
    align-items: center;
    color: var(--text-tertiary);
    flex-shrink: 0;
    transition: color 0.2s ease;
}

.copy-indicator.is-copied {
    color: var(--success);
}

.profile-hint {
    text-align: center;
    font-size: 13px;
    color: var(--text-tertiary);
    padding: 0 12px;
}

/* ============================= SHEETS ============================= */

.sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0 8px;
    background: rgba(0, 0, 0, 0.55);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}

html[data-theme="light"] .sheet-overlay {
    background: rgba(0, 0, 0, 0.3);
}

.sheet-overlay.is-open {
    opacity: 1;
    pointer-events: auto;
}

.sheet-panel {
    width: min(460px, 100%);
    margin-bottom: calc(var(--safe-bottom) + 8px);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    background: var(--bg-elevated);
    box-shadow: 0 -24px 60px rgba(0, 0, 0, 0.45);
    overflow: hidden;
    transform: translateY(28px);
    transition: transform 0.28s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.sheet-overlay.is-open .sheet-panel {
    transform: translateY(0);
}

.sheet-handle {
    width: 38px;
    height: 4px;
    margin: 8px auto 2px;
    border-radius: 999px;
    background: var(--border-color);
}

.sheet-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
}

.sheet-header-center {
    justify-content: center;
    padding: 12px 16px 6px;
}

.sheet-title {
    flex: 1;
    text-align: center;
    font-size: 15px;
    font-weight: 700;
}

.sheet-header-center .sheet-title { flex: none; }

.sheet-close,
.sheet-save {
    border: none;
    background: transparent;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px;
    border-radius: 10px;
}

.sheet-close {
    display: flex;
    align-items: center;
    color: var(--text-secondary);
}

.sheet-close:active,
.sheet-save:active { background: var(--bg-card); }

.sheet-save {
    color: var(--accent);
    padding: 6px 4px;
}

.sheet-save[disabled] {
    opacity: 0.5;
    cursor: default;
}

.sheet-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px 16px 18px;
}

.field {
    position: relative;
}

.field-input {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-small);
    background: var(--bg-base);
    color: var(--text-primary);
    font-size: 16px;
    padding: 14px 64px 14px 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

.field-input::placeholder { color: var(--text-tertiary); }

.field-input:focus {
    border-color: var(--accent);
}

.field-counter {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 13px;
    color: var(--text-tertiary);
    pointer-events: none;
}

.field-hint {
    font-size: 12px;
    line-height: 1.4;
    color: var(--text-tertiary);
    padding: 0 2px;
}

/* Меню выбора источника аватара */

.sheet-actions {
    gap: 0;
    padding: 0 8px 4px;
}

.sheet-option {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 8px;
    border: none;
    background: transparent;
    text-align: left;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 12px;
}

.sheet-option:active { background: var(--bg-card); }

.sheet-option-icon {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: var(--accent-soft);
    color: var(--accent);
    flex-shrink: 0;
}

.sheet-option-text { flex: 1; }

.sheet-url[hidden] { display: none; }

.sheet-submit {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: 12px;
    background: var(--accent);
    color: #ffffff;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}

.sheet-submit:active { opacity: 0.85; }

.sheet-cancel {
    display: block;
    width: calc(100% - 16px);
    margin: 0 8px 8px;
    padding: 14px;
    border: none;
    border-radius: 14px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.sheet-cancel:active { background: var(--bg-card-active); }

/* ============================= TOAST ============================= */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--safe-bottom) + 24px);
    z-index: 1300;
    max-width: calc(100% - 32px);
    padding: 12px 18px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: rgba(28, 28, 30, 0.96);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.35;
    text-align: center;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
    opacity: 0;
    transform: translate(-50%, 12px);
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease;
}

html[data-theme="light"] .toast {
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.15);
}

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

.toast.is-error {
    color: #ff8a80;
    border-color: rgba(255, 69, 58, 0.35);
}

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

/* ============================================================
   АДАПТАЦИЯ ПОД ПК (только десктоп, мобильная версия не тронута)
   ============================================================ */
@media (min-width: 961px) {
    html, body {
        --road-shell: min(1240px, calc(100vw - 32px));
        --road-rail: 252px;
        --road-gutter: max(16px, calc((100vw - 1240px) / 2));
    }

    .app-main {
        width: min(760px, calc(100vw - 48px));
        margin: 0 auto;
    }

    .profile-card {
        transition: background 0.2s ease;
    }

    .profile-card:hover { background: var(--bg-card-active); }
}
