/* ══════════════════════════════════════════════════════════════
   profile.css — User profile page styles
   Uses CSS variables from base.css exclusively.
   Replaces legacy profile.css (hardcoded colors, no dark mode).
   ══════════════════════════════════════════════════════════════ */

/* ── Page layout ──────────────────────────────────────────────── */

.profile-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--space-6) var(--container-padding);
}

/* ── Error state ──────────────────────────────────────────────── */

.profile-error {
    text-align: center;
    padding: var(--space-20) var(--space-6);
}

.profile-error h1 {
    font-family: var(--font-heading);
    font-size: var(--text-3xl);
    margin-bottom: var(--space-4);
}

.profile-error p {
    color: var(--text-secondary);
    margin-bottom: var(--space-8);
}

/* ══════════════════════════════════════════════════════════════
   PROFILE HEADER
   ══════════════════════════════════════════════════════════════ */

.profile-header {
    position: relative;
    text-align: center;
    padding-bottom: var(--space-10);
    margin-bottom: var(--space-8);
    border-bottom: 1px solid var(--border-color);
}

.profile-header__bg {
    position: absolute;
    top: 0;
    left: -50vw;
    right: -50vw;
    height: 180px;
    background: linear-gradient(135deg, var(--accent-lighter) 0%, var(--surface-tertiary) 100%);
    z-index: 0;
    border-radius: 0 0 var(--radius-2xl) var(--radius-2xl);
}

.profile-header__content {
    position: relative;
    z-index: 1;
    padding-top: 100px;
}

/* ── Avatar ───────────────────────────────────────────────────── */

.profile-avatar {
    display: inline-block;
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    border: 4px solid var(--background-color);
    background: var(--surface-secondary);
}

.profile-avatar--lg {
    width: 120px;
    height: 120px;
}

.profile-avatar--sm {
    width: 40px;
    height: 40px;
}

.profile-avatar__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.profile-avatar__initials {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-weight: 700;
    font-size: 2.5rem;
    font-family: var(--font-sans);
    user-select: none;
}

.profile-avatar--sm .profile-avatar__initials {
    font-size: 1rem;
}

/* ── Name, bio, joined ────────────────────────────────────────── */

.profile-header__name {
    font-family: var(--font-heading);
    font-size: var(--text-2xl);
    line-height: var(--leading-tight);
    margin: var(--space-4) 0 var(--space-2);
    color: var(--text-color);
}

.profile-header__bio {
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto var(--space-4);
    line-height: var(--leading-normal);
}

.profile-header__joined {
    color: var(--text-muted);
    font-size: var(--text-sm);
    margin: var(--space-2) 0 var(--space-4);
}

.profile-header__edit {
    display: inline-block;
    margin-top: var(--space-2);
}

/* ── Badges ───────────────────────────────────────────────────── */

.profile-badges {
    display: flex;
    justify-content: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}

.profile-badge {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--surface-tertiary);
    color: var(--accent-color);
    cursor: default;
    transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}

.profile-badge:hover {
    transform: scale(1.15);
    box-shadow: var(--shadow-md);
}

.profile-badge__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.profile-badge__icon svg {
    width: 20px;
    height: 20px;
}

/* Tooltip via data-tooltip */
.profile-badge[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-color);
    color: var(--background-color);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--text-xs);
    white-space: nowrap;
    z-index: 10;
    pointer-events: none;
    box-shadow: var(--shadow-md);
}

.profile-badge[data-tooltip]:hover::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--text-color);
    z-index: 10;
    pointer-events: none;
}

/* ── Stats ────────────────────────────────────────────────────── */

.profile-stats {
    display: flex;
    justify-content: center;
    gap: var(--space-8);
    margin: var(--space-4) 0;
}

.profile-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.profile-stat__count {
    font-weight: 700;
    font-size: var(--text-xl);
    color: var(--text-color);
}

.profile-stat__label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* ══════════════════════════════════════════════════════════════
   FEATURED RECIPE
   ══════════════════════════════════════════════════════════════ */

.profile-featured {
    max-width: 800px;
    margin: 0 auto var(--space-10);
}

.profile-featured__heading {
    font-family: var(--font-heading);
    font-size: var(--text-lg);
    margin-bottom: var(--space-4);
    color: var(--text-color);
}

.profile-featured__card {
    display: flex;
    gap: var(--space-6);
    text-decoration: none;
    color: inherit;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    background: var(--surface-primary);
    border: 1px solid var(--border-color);
    transition: box-shadow var(--transition-speed), transform var(--transition-speed);
}

.profile-featured__card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.profile-featured__image {
    position: relative;
    flex: 0 0 280px;
    min-height: 200px;
    overflow: hidden;
}

.profile-featured__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-featured__info {
    flex: 1;
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.profile-featured__info h3 {
    font-family: var(--font-heading);
    font-size: var(--text-lg);
    margin: 0 0 var(--space-2);
    color: var(--text-color);
}

.profile-featured__info p {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    margin: 0 0 var(--space-3);
    line-height: var(--leading-normal);
}

.profile-featured__rating {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.profile-featured__time {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-top: var(--space-2);
}

/* ══════════════════════════════════════════════════════════════
   TABS
   ══════════════════════════════════════════════════════════════ */

.profile-tabs {
    margin-bottom: var(--space-12);
}

.profile-tabs__nav {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    gap: 0;
    margin-bottom: var(--space-6);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.profile-tab-btn {
    flex: 0 0 auto;
    padding: var(--space-3) var(--space-6);
    border: none;
    background: none;
    font-size: var(--text-base);
    font-family: var(--font-sans);
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color var(--transition-speed), border-color var(--transition-speed);
    white-space: nowrap;
}

.profile-tab-btn:hover {
    color: var(--text-color);
}

.profile-tab-btn.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
    font-weight: 600;
}

/* Tab panels */
.profile-tab-panel {
    display: none;
}

.profile-tab-panel.active {
    display: block;
}

/* ── Tab grid ─────────────────────────────────────────────────── */

.profile-tab-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-6);
}

/* ── Recipe card (in tab) ─────────────────────────────────────── */

.profile-card {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--surface-primary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-speed), transform var(--transition-speed);
}

.profile-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.profile-card__image {
    position: relative;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background: var(--surface-tertiary);
}

.profile-card__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-card__body {
    padding: var(--space-4);
    flex: 1;
}

.profile-card__title {
    font-family: var(--font-heading);
    font-size: var(--text-base);
    line-height: var(--leading-snug);
    margin: 0 0 var(--space-2);
    color: var(--text-color);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.profile-card__rating {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    margin-bottom: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.profile-card__meta {
    display: flex;
    gap: var(--space-3);
    font-size: var(--text-sm);
    color: var(--text-muted);
}

/* ── Star display ─────────────────────────────────────────────── */

.star-display {
    display: inline-flex;
    gap: 1px;
}

.star {
    font-size: 0.9rem;
    line-height: 1;
}

.star--full {
    color: var(--star-active);
}

.star--half {
    color: var(--star-active);
    opacity: 0.6;
}

.star--empty {
    color: var(--star-inactive);
}

/* ── Review items ─────────────────────────────────────────────── */

.profile-review-item {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-light);
}

.profile-review-item:last-child {
    border-bottom: none;
}

.profile-review__thumb {
    flex: 0 0 80px;
    width: 80px;
    height: 80px;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--surface-tertiary);
}

.profile-review__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-review__content {
    flex: 1;
    min-width: 0;
}

.profile-review__recipe-name {
    font-weight: 600;
    color: var(--accent-color);
    text-decoration: none;
    font-size: var(--text-sm);
}

.profile-review__recipe-name:hover {
    text-decoration: underline;
}

.profile-review__rating {
    margin: var(--space-1) 0;
}

.profile-review__text {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    line-height: var(--leading-normal);
    margin: var(--space-2) 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.profile-review__meta {
    display: flex;
    gap: var(--space-4);
    font-size: var(--text-xs);
    color: var(--text-muted);
}

/* ── Empty state ──────────────────────────────────────────────── */

.profile-empty-state {
    text-align: center;
    padding: var(--space-12) var(--space-6);
    color: var(--text-secondary);
}

.profile-empty-state p {
    font-size: var(--text-lg);
    margin-bottom: var(--space-4);
}

/* ── Pagination ───────────────────────────────────────────────── */

.profile-pagination {
    display: flex;
    justify-content: center;
    gap: var(--space-2);
    margin-top: var(--space-8);
    flex-wrap: wrap;
}

.profile-pagination__btn {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border-color);
    background: var(--surface-primary);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-speed);
}

.profile-pagination__btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.profile-pagination__btn--active {
    background: var(--accent-color);
    color: #ffffff;
    border-color: var(--accent-color);
}

.profile-pagination__btn--active:hover {
    color: #ffffff;
}

/* ── Loading spinner ──────────────────────────────────────────── */

.profile-tab-loading {
    text-align: center;
    padding: var(--space-10);
    color: var(--text-muted);
}

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

.btn {
    display: inline-block;
    padding: var(--space-3) var(--space-6);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition-speed);
    border: none;
    font-family: var(--font-sans);
}

.btn--primary {
    background: var(--accent-color);
    color: #ffffff;
}

.btn--primary:hover {
    background: var(--accent-hover);
}

.btn--outline {
    background: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
}

.btn--outline:hover {
    background: var(--accent-color);
    color: #ffffff;
}

/* ── Uploaded recipe card ─────────────────────────────────────── */

.profile-upload-card {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--surface-primary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-speed), transform var(--transition-speed);
}

.profile-upload-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.profile-upload-card__body {
    padding: var(--space-4);
    flex: 1;
}

.profile-upload-card__title {
    font-family: var(--font-heading);
    font-size: var(--text-base);
    margin: 0 0 var(--space-2);
    color: var(--text-color);
}

.profile-upload-card__desc {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    margin: 0 0 var(--space-3);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.profile-upload-card__stats {
    display: flex;
    gap: var(--space-3);
    font-size: var(--text-xs);
    color: var(--text-muted);
}


/* ══════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
    .profile-tab-grid {
        grid-template-columns: 1fr;
    }

    .profile-featured__card {
        flex-direction: column;
    }

    .profile-featured__image {
        flex: none;
        min-height: 180px;
    }

    .profile-stats {
        gap: var(--space-4);
    }

    .profile-header__bg {
        height: 140px;
    }

    .profile-header__content {
        padding-top: 70px;
    }

    .profile-avatar--lg {
        width: 90px;
        height: 90px;
    }

    .profile-avatar__initials {
        font-size: 2rem;
    }

    .profile-review-item {
        flex-direction: column;
    }

    .profile-review__thumb {
        flex: none;
        width: 60px;
        height: 60px;
    }
}

@media (min-width: 480px) and (max-width: 767px) {
    .profile-tab-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    .profile-tab-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}


/* ══════════════════════════════════════════════════════════════
   DARK MODE
   ══════════════════════════════════════════════════════════════ */

:root[data-theme="dark"] .profile-header__bg {
    background: linear-gradient(135deg, #1e1b4b 0%, #1a1a2e 100%);
}

:root[data-theme="dark"] .profile-avatar {
    border-color: var(--background-color);
}

:root[data-theme="dark"] .profile-badge {
    background: var(--surface-tertiary);
    color: var(--accent-color);
}

:root[data-theme="dark"] .profile-badge[data-tooltip]:hover::after {
    background: var(--surface-elevated);
    color: var(--text-color);
}

:root[data-theme="dark"] .profile-badge[data-tooltip]:hover::before {
    border-top-color: var(--surface-elevated);
}

:root[data-theme="dark"] .profile-featured__card,
:root[data-theme="dark"] .profile-card,
:root[data-theme="dark"] .profile-upload-card {
    background: var(--surface-primary);
    border-color: var(--border-color);
}

:root[data-theme="dark"] .profile-tab-btn {
    color: var(--text-secondary);
}

:root[data-theme="dark"] .profile-tab-btn.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

:root[data-theme="dark"] .profile-pagination__btn {
    background: var(--surface-primary);
    border-color: var(--border-color);
    color: var(--text-secondary);
}

:root[data-theme="dark"] .profile-pagination__btn--active {
    background: var(--accent-color);
    color: #ffffff;
    border-color: var(--accent-color);
}

:root[data-theme="dark"] .profile-review__recipe-name {
    color: var(--accent-color);
}


/* ── Utility ──────────────────────────────────────────────────── */

.is-hidden { display: none !important; }

/* ══════════════════════════════════════════════════════════════
   EDIT PROFILE PAGE
   ══════════════════════════════════════════════════════════════ */

.edit-profile-page {
    max-width: 640px;
    margin: 0 auto;
    padding: var(--space-8) var(--container-padding);
}

.edit-profile-container {
    background: var(--surface-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-8);
    box-shadow: var(--shadow-sm);
}

.edit-profile__title {
    font-family: var(--font-heading);
    font-size: var(--text-2xl);
    margin-bottom: var(--space-6);
    color: var(--text-color);
}

.edit-profile__avatar-section {
    display: flex;
    align-items: center;
    gap: var(--space-6);
    margin-bottom: var(--space-8);
}

.edit-profile__avatar-controls {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.edit-profile__avatar-hint {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

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

.edit-profile__form .form-group {
    margin-bottom: var(--space-6);
    display: flex;
    flex-direction: column;
}

.edit-profile__form .form-group label {
    font-weight: 600;
    margin-bottom: var(--space-2);
    color: var(--text-color);
}

.form-input {
    width: 100%;
    padding: var(--space-3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    background: var(--surface-primary);
    color: var(--text-color);
    transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
    box-sizing: border-box;
}

.form-input:focus {
    border-color: var(--accent-color);
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-lighter);
}

textarea.form-input {
    resize: vertical;
    min-height: 100px;
}

.form-hint {
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-top: var(--space-1);
}

/* ── Pinned recipe display ───────────────────────────────────── */

.edit-profile__pinned-current {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-2);
}

.edit-profile__pinned-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.edit-profile__actions {
    display: flex;
    gap: var(--space-4);
    margin-top: var(--space-8);
}

/* Small button variant */
.btn--sm {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-sm);
}

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

/* ── Recipe picker modal ─────────────────────────────────────── */

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal[hidden] {
    display: none;
}

.modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal__content {
    position: relative;
    background: var(--surface-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    width: 90%;
    max-width: 580px;
    max-height: 70vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
}

.modal__title {
    font-family: var(--font-heading);
    font-size: var(--text-xl);
    font-weight: 600;
    margin-bottom: var(--space-4);
    color: var(--text-color);
}

.modal__close {
    margin-top: var(--space-4);
}

/* ── Recipe picker grid ──────────────────────────────────────── */

.recipe-picker-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.recipe-picker-item {
    display: flex;
    flex-direction: column;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    transition: border-color var(--transition-speed);
}

.recipe-picker-item:hover {
    border-color: var(--accent-color);
}

.recipe-picker-item__thumb {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
}

.recipe-picker-item__thumb--placeholder {
    background: var(--surface-tertiary);
    aspect-ratio: 4/3;
}

.recipe-picker-item__info {
    padding: var(--space-2) var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.recipe-picker-item__name {
    font-size: var(--text-sm);
    font-weight: 500;
    line-height: 1.3;
    color: var(--text-color);
}

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

.profile-toast {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-md);
    font-weight: 500;
    z-index: 2000;
    box-shadow: var(--shadow-lg);
}

.profile-toast[hidden] {
    display: none;
}

.profile-toast--success {
    background: #16a34a;
    color: #fff;
}

.profile-toast--error {
    background: #dc2626;
    color: #fff;
}

/* ── Dark mode — edit profile ────────────────────────────────── */

:root[data-theme="dark"] .edit-profile-container {
    background: var(--surface-secondary);
}

:root[data-theme="dark"] .form-input {
    background: var(--surface-tertiary);
    border-color: var(--border-color);
    color: var(--text-color);
}

:root[data-theme="dark"] .edit-profile__pinned-current {
    border-color: var(--border-color);
}

:root[data-theme="dark"] .modal__content {
    background: var(--surface-secondary);
}

:root[data-theme="dark"] .recipe-picker-item {
    border-color: var(--border-color);
}

/* ── Responsive — edit profile ───────────────────────────────── */

@media (max-width: 480px) {
    .edit-profile__avatar-section {
        flex-direction: column;
        align-items: flex-start;
    }

    .edit-profile__actions {
        flex-direction: column;
    }

    .edit-profile__actions .btn {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    .recipe-picker-grid {
        grid-template-columns: 1fr;
    }

    .edit-profile-container {
        padding: var(--space-5);
    }
}
