// Questo file fa parte di MyTown.
// MyTown è software libero: puoi ridistribuirlo e/o modificarlo secondo
// i termini della GNU Affero General Public License come pubblicata dalla
// Free Software Foundation, versione 3.
// Distribuito senza ALCUNA GARANZIA; vedi la GNU AGPL v3 per i dettagli.
// Copyright (C) Kondor Consulting & Services S.r.l.
// SPDX-License-Identifier: AGPL-3.0-or-later

// ─── COLORS ──────────────────────────────────────────────────
$primary: var(--app-brand);
$secondary: var(--app-brand-2);
$surface: #f6f8fc;
$card-bg: #ffffff;
$border: #e8edf4;
$text: #1a2332;
$text-sub: #64748b;

// ─── HERO ─────────────────────────────────────────────────────
.profile-content {
    --background: #{$surface};
}

.hero-wrapper {
    position: relative;
    overflow: hidden;
}

.hero-bg {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, $primary 0%, $secondary 100%);

    &::after {
        content: '';
        position: absolute;
        right: -60px;
        top: -60px;
        width: 220px;
        height: 220px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.06);
    }

    &::before {
        content: '';
        position: absolute;
        left: -40px;
        bottom: -70px;
        width: 180px;
        height: 180px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.04);
    }
}

.hero-body {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 36px 24px 28px;
    gap: 14px;
    animation: fadeSlideDown 0.4s ease both;
}

.avatar-ring {
    position: relative;
    width: 88px;
    height: 88px;
    border-radius: 50%;
    padding: 3px;
    background: rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.15);
}

.avatar-inner {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 1px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.avatar-badge-online {
    position: absolute;
    bottom: 5px;
    right: 5px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #22c55e;
    border: 2.5px solid white;
}

.avatar-inner--img {
    padding: 0;
    overflow: hidden;

    img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
    }
}

.avatar-edit-btn,
.avatar-remove-btn {
    position: absolute;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);

    ion-icon {
        font-size: 16px;
        color: #fff;
    }
}

.avatar-edit-btn {
    bottom: 0;
    right: 0;
    background: var(--app-brand, #0f75bb);

    &:disabled {
        opacity: 0.7;
    }
}

.avatar-remove-btn {
    top: 0;
    right: 0;
    background: #e24c4c;
}

.hero-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.hero-name {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.3px;
}

.hero-username {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.72);
    letter-spacing: 0.3px;
}

.hero-chips {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}

.hero-chip {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;

    ion-icon {
        font-size: 13px;
    }

    &.hero-chip--id {
        background: rgba(255, 255, 255, 0.1);
        font-weight: 400;
        opacity: 0.85;
    }
}

// ─── TABS BAR ────────────────────────────────────────────────
.tabs-bar {
    position: relative;
    display: flex;
    background: $card-bg;
    border-bottom: 2px solid $border;
    overflow: hidden;
}

.tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 12px 4px 10px;
    border: none;
    background: transparent;
    color: $text-sub;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s ease;
    position: relative;
    z-index: 1;

    ion-icon {
        font-size: 18px;
        transition: color 0.2s ease;
    }

    &.tab-active {
        color: $primary;
        font-weight: 700;

        ion-icon {
            color: $primary;
        }
    }
}

.tab-indicator {
    position: absolute;
    bottom: 0;
    height: 2.5px;
    width: 33.33%;
    background: $primary;
    border-radius: 2px 2px 0 0;
    transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    &.tab-indicator--profile  { left: 0%; }
    &.tab-indicator--roles    { left: 33.33%; }
    &.tab-indicator--settings { left: 66.66%; }
}

// ─── TAB PANELS ──────────────────────────────────────────────
.tab-panels {
    padding: 16px 16px 32px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tab-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.panel-enter {
    animation: panelFade 0.25s ease both;
}

// ─── SECTION CARD ────────────────────────────────────────────
.section-card {
    background: $card-bg;
    border-radius: 16px;
    border: 1px solid $border;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px 10px;
    border-bottom: 1px solid $border;

    h3 {
        margin: 0;
        font-size: 13px;
        font-weight: 700;
        color: $text-sub;
        text-transform: uppercase;
        letter-spacing: 0.6px;
    }

    .section-icon {
        font-size: 16px;
        color: $text-sub;
    }
}

// ─── INFO ROW ────────────────────────────────────────────────
.info-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-bottom: 1px solid $border;
    transition: background 0.15s ease;

    &:active {
        background: rgba(var(--app-brand-rgb), 0.04);
    }
}

.info-icon-wrap {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;

    ion-icon {
        font-size: 17px;
    }
}

.info-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.info-label {
    font-size: 11px;
    color: $text-sub;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.info-value {
    font-size: 15px;
    font-weight: 500;
    color: $text;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    &.mono {
        font-family: 'SF Mono', 'Fira Code', monospace;
        font-size: 14px;
        color: $primary;
    }
}

// ─── RUOLI ──────────────────────────────────────────────────
// Contatore nel section-header (coerente con stile Impostazioni)
.section-header .section-count {
    margin-left: auto;
    font-size: 12px;
    font-weight: 600;
    color: $text-sub;
    background: rgba(var(--app-brand-rgb), 0.08);
    border-radius: 999px;
    padding: 2px 10px;
    min-width: 24px;
    text-align: center;
}


// ─── SETTINGS TOGGLE ROW ─────────────────────────────────────
.toggle-row {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    gap: 12px;
}

.toggle-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.toggle-icon {
    font-size: 20px;
    color: $primary;
    flex-shrink: 0;
}

.toggle-label {
    font-size: 15px;
    font-weight: 500;
    color: $text;
}

.toggle-sub {
    font-size: 12px;
    color: $text-sub;
    margin-top: 2px;
}

// ─── EMPTY STATE ─────────────────────────────────────────────
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 40px 16px;
    color: $text-sub;
    text-align: center;

    ion-icon {
        font-size: 48px;
        opacity: 0.35;
    }

    p {
        margin: 0;
        font-size: 14px;
    }
}

// ─── SKELETON ────────────────────────────────────────────────
.skeleton-wrap {
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

@keyframes shimmer {
    0%   { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}

$shimmer: linear-gradient(90deg, #e8edf4 25%, #f6f8fc 50%, #e8edf4 75%);

.skeleton-avatar {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    background: $shimmer;
    background-size: 800px 100%;
    animation: shimmer 1.4s infinite;
}

.skeleton-line {
    height: 14px;
    width: 60%;
    border-radius: 7px;
    background: $shimmer;
    background-size: 800px 100%;
    animation: shimmer 1.4s infinite;

    &--lg {
        width: 80%;
        height: 18px;
    }
}

.skeleton-card {
    width: 100%;
    height: 120px;
    border-radius: 16px;
    background: $shimmer;
    background-size: 800px 100%;
    animation: shimmer 1.4s infinite;
}

// ─── NOTIFICATION PREFERENCES ────────────────────────────────

.pref-divider {
    height: 1px;
    background: $border;
    margin: 0 16px;
}

.toggle-row--disabled {
    opacity: 0.6;
}

.toggle-sub--warn {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #d97706;
    font-size: 11px;

    ion-icon { font-size: 12px; }
}

.pref-saving {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px 12px;
    font-size: 12px;
    color: $text-sub;
}

// ─── PUSH NOTIFICATION CONTROLS ─────────────────────────────

.push-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px;
    font-size: 13px;
    color: $text-sub;
}

.push-status-banner {
    display: flex;
    gap: 14px;
    padding: 16px;
    margin: 0;
    border-radius: 0;

    &--denied {
        background: #fff5f5;
        border-top: 1px solid #ffd5d5;
        border-bottom: 1px solid #ffd5d5;

        .push-status-icon ion-icon { color: #c62828; }
    }

    &--prompt {
        background: #fffbeb;
        border-top: 1px solid #fde68a;
        border-bottom: 1px solid #fde68a;

        .push-status-icon ion-icon { color: #d97706; }
    }
}

.push-status-icon {
    flex-shrink: 0;
    margin-top: 2px;

    ion-icon {
        font-size: 24px;
    }
}

.push-status-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.push-status-title {
    font-size: 14px;
    font-weight: 700;
    color: $text;
}

.push-status-desc {
    font-size: 12px;
    color: $text-sub;
    line-height: 1.5;
    margin-bottom: 8px;
}

.push-open-settings-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 10px;
    border: none;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.18s;
    background: #dc2626;
    color: #fff;
    align-self: flex-start;

    ion-icon { font-size: 15px; }

    &:active { opacity: 0.8; }

    &--primary {
        background: var(--app-brand);
    }
}

.push-status-granted {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    font-size: 12px;
    color: $text-sub;
    border-bottom: 1px solid $border;
}

.push-disabled-warning {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 16px;
    background: #fffbeb;
    border-top: 1px solid #fde68a;
    font-size: 12px;
    color: #92400e;

    ion-icon {
        font-size: 15px;
        flex-shrink: 0;
        margin-top: 1px;
        color: #d97706;
    }
}

.push-unavailable {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px;
    font-size: 13px;
    color: $text-sub;

    ion-icon { font-size: 18px; }
}

// ─── LOGOUT CARD ─────────────────────────────────────────────
.logout-card {
    background: $card-bg;
    border-radius: 16px;
    border: 1px solid #fecaca;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(220, 38, 38, 0.06);
    position: relative;
    margin: 4px 16px 32px;

    &::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 3px;
        background: linear-gradient(90deg, #dc2626 0%, #ef4444 100%);
    }
}

.logout-card-body {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 20px 16px 16px;
}

.logout-icon-wrap {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #fef2f2;
    border: 1px solid #fecaca;

    ion-icon {
        font-size: 22px;
        color: #dc2626;
    }
}

.logout-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.logout-title {
    font-size: 15px;
    font-weight: 700;
    color: $text;
    letter-spacing: -0.1px;
}

.logout-desc {
    font-size: 12px;
    color: $text-sub;
    line-height: 1.5;

    strong {
        color: $text;
        font-weight: 600;
    }
}

.logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: calc(100% - 32px);
    margin: 0 16px 16px;
    padding: 13px 16px;
    border: none;
    border-radius: 12px;
    background: #dc2626;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.2px;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.18s ease, box-shadow 0.18s ease;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.25);

    ion-icon {
        font-size: 17px;
    }

    &:active:not(:disabled) {
        transform: scale(0.98);
        background: #b91c1c;
        box-shadow: 0 2px 6px rgba(220, 38, 38, 0.3);
    }

    &:disabled {
        opacity: 0.65;
        cursor: not-allowed;
    }
}

// Ionic AlertController custom styling
::ng-deep ion-alert.logout-alert {
    --backdrop-opacity: 0.55;

    .alert-wrapper {
        border-radius: 18px;
        --max-width: 320px;
    }

    .alert-head {
        padding-top: 22px;
    }

    .alert-title {
        font-weight: 700;
        color: $text;
        font-size: 17px;
    }

    .alert-message {
        color: $text-sub;
        font-size: 13px;
        line-height: 1.5;
        padding-top: 6px;
    }

    .alert-button-group {
        padding: 8px;
    }

    .alert-button {
        border-radius: 10px;
        font-weight: 600;
        text-transform: none;
        letter-spacing: 0;
        font-size: 14px;
    }

    .logout-alert-cancel {
        color: $text-sub;
    }

    .logout-alert-confirm {
        color: #dc2626;
    }
}

// ─── ANIMATIONS ──────────────────────────────────────────────
@keyframes fadeSlideDown {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes panelFade {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
