/* Profile Page Styles */

/* Base Variables */
:root {
    --primary-color: #3b82f6;
    --secondary-color: #60a5fa;
    --danger-color: #ef4444;
    --dark-color: #1f2937;
    --light-color: #f9fafb;
    --text-color: #374151;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --border-radius: 0.5rem;
    --profile-section-title-color: #1f2937;
    --profile-section-title-icon-color: #3b82f6;
    --profile-section-title-size: 1.25rem;
    --profile-section-title-weight: 600;
    --profile-section-title-gap: 0.5rem;
    --profile-section-title-icon-size: 1rem;
    --profile-section-title-icon-width: 1.25rem;
    --profile-card-title-size: 1rem;
    --profile-anchor-offset: 106px;
    --profile-teacher-anchor-offset: 106px;
}

/* General Layout */
html,
body {
    /* `hidden` creates a scroll container that prevents the profile header
       from sticking to the viewport. `clip` keeps horizontal overflow bounded
       without changing the sticky containing block. */
    overflow-x: clip;
}

.main-content {
    flex: 1;
    min-height: calc(100vh - 70px);
    overflow-y: auto;
    overflow-x: hidden;
}

body[data-unified-profile="true"] .main-content {
    /* The teacher Profile's section navigation sticks to the viewport. Keep
       this ancestor out of the vertical scrolling chain. */
    overflow-y: visible;
    overflow-x: clip;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    overflow-x: hidden;
}

/* Header Styles */
.profile-page-shell {
    position: relative;
}

.profile-page-shell > #my-space-header-placeholder {
    position: sticky;
    top: 0;
    z-index: 1000;
    width: 100%;
}

.profile-page-shell > #my-space-header-placeholder .main-header {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    width: 100% !important;
}

/*
 * Keep profile hash targets visible below the sticky page header. Teacher
 * targets also account for the sticky section navigation on smaller screens.
 */
.profile-section[id] {
    scroll-margin-top: var(--profile-anchor-offset);
}

.teacher-profile-container :is(
    #overview,
    #profileUsageTitle,
    .profile-settings-section[data-profile-section],
    .profile-subsection[id],
    .profile-access-host[id]
) {
    scroll-margin-top: var(--profile-teacher-anchor-offset);
}

.main-header {
    background: white;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo {
    height: 40px;
    width: auto;
    border-radius: 22%;
}

.logo-section h1 {
    font-size: 1.5rem;
    margin: 0;
    color: var(--primary-color);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-link {
    color: var(--text-color);
    text-decoration: none;
    padding: 0.5rem 1rem;
    transition: all 0.3s ease;
    border-radius: var(--border-radius);
}

.nav-link:hover {
    color: var(--primary-color);
    background-color: rgba(79, 70, 229, 0.1);
}

.profile-link {
    display: flex;
    align-items: center;
}

.profile-pic {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 0.5rem;
}

/* Profile Header */
.profile-header {
    background: white;
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 2rem;
}

.profile-avatar-section {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.avatar-container {
    position: relative;
}

.user-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid var(--primary-color);
}

.profile-info h2 {
    margin: 0 0 0.5rem 0;
    color: var(--dark-color);
}

.user-email {
    margin: 0.25rem 0;
    color: var(--text-color);
}

.user-role {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0;
    color: var(--primary-color);
}

.member-since {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0;
    color: var(--text-color);
    font-size: 0.875rem;
}

/* Profile Content */
.profile-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.profile-section {
    background: white;
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
}

:is(.profile-section>h3, .section-header h2, .section-header h3, .limit-header h3) {
    margin: 0;
    color: var(--profile-section-title-color);
    display: flex;
    align-items: center;
    gap: var(--profile-section-title-gap);
    font-size: var(--profile-section-title-size);
    font-weight: var(--profile-section-title-weight);
    line-height: 1.3;
}

:is(.profile-section>h3, .section-header h2, .section-header h3, .limit-header h3) i {
    color: var(--profile-section-title-icon-color);
    flex: 0 0 var(--profile-section-title-icon-width);
    width: var(--profile-section-title-icon-width);
    text-align: center;
    font-size: var(--profile-section-title-icon-size);
}

.profile-section>h3 {
    margin-bottom: 1.5rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

/* Form Styles */
.profile-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--dark-color);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    background: white;
    min-height: 44px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-group input:disabled,
.form-group select:disabled {
    background: var(--light-color);
    cursor: not-allowed;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

.form-actions.visually-hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Profile Picture Management */
.avatar-upload-section {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 20px;
    background: var(--light-color);
    border-radius: var(--border-radius);
}

.avatar-preview-container {
    flex-shrink: 0;
}

.avatar-preview {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.avatar-actions {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.avatar-guidelines {
    margin: 0;
    color: #6b7280;
    font-size: 0.9rem;
}

.avatar-action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.btn-danger-text {
    color: var(--danger-color);
    border: 1px solid var(--danger-color);
}

.btn-danger-text:hover {
    background: rgba(239, 68, 68, 0.08);
    border-color: var(--danger-color);
    color: var(--danger-color);
}

@media (max-width: 768px) {
    .avatar-upload-section {
        flex-direction: column;
        text-align: center;
    }

    .avatar-action-buttons {
        width: 100%;
        flex-direction: column;
    }

    .avatar-action-buttons .btn {
        width: 100%;
    }
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    text-decoration: none;
    min-height: 44px;
    justify-content: center;
    line-height: 1.4;
    font-weight: 500;
}

/* Primary colors and shadows come from the shared main.css button style. */
.btn.btn-primary {
    padding: 16px 24px;
    font-weight: 700;
}

.btn-secondary {
    background-color: var(--light-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

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

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

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

.btn-outline:hover {
    background: var(--light-color);
    border-color: #9ca3af;
}

/* Danger Zone */
.danger-zone {
    border: 2px solid var(--danger-color);
}

.danger-zone h3 {
    color: var(--danger-color);
}

/* Footer */
.footer {
    background: var(--dark-color);
    color: white;
    padding: 3rem 0 1rem;
    margin-top: 4rem;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.footer-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.footer-brand .logo {
    height: 32px;
    border-radius: 22%;
}

.brand-name {
    font-size: 1.25rem;
    font-weight: 600;
}

.footer-links {
    display: flex;
    gap: 3rem;
}

.footer-column h4 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
}

.footer-column a {
    display: block;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    margin-bottom: 0.5rem;
    transition: color 0.3s ease;
}

.footer-column a:hover {
    color: white;
}

.footer-bottom {
    text-align: center;
    padding-top: 2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.footer-bottom p {
    margin: 0;
    color: rgba(255, 255, 255, 0.6);
}

/* Responsive Design */
@media (max-width: 768px) {
    :root {
        --profile-anchor-offset: 80px;
        --profile-teacher-anchor-offset: 155px;
    }

    .header-container {
        padding: 1rem;
    }

    .logo-section h1 {
        font-size: 1.25rem;
    }

    .container {
        padding: 1rem;
    }

    .profile-avatar-section {
        flex-direction: column;
        text-align: center;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions .btn {
        width: 100%;
    }

    .footer-content {
        flex-direction: column;
        gap: 2rem;
    }

    .footer-links {
        flex-direction: column;
        gap: 1.5rem;
    }
}

@media (max-width: 480px) {
    :root {
        --profile-anchor-offset: 68px;
        --profile-teacher-anchor-offset: 143px;
    }
}

/* Limits Partial Styles */
.limits-partial .section-header {
    margin-bottom: 20px;
}

.limits-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
}

.limit-card {
    background: white;
    border: 1px solid #e1e5e9;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.limit-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.limit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
}

.month-indicator {
    font-size: 0.875rem;
    color: #6b7280;
    font-weight: 500;
}

.limit-items {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.limit-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.limit-label {
    font-weight: 500;
    color: #374151;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.limit-progress-container {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    justify-content: flex-end;
}

.limit-progress-bar {
    flex: 1;
    height: 8px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    min-width: 100px;
    max-width: 200px;
}

.limit-progress-fill {
    height: 100%;
    background: #10b981;
    border-radius: 4px;
    transition: width 0.5s ease, background-color 0.3s ease;
    min-width: 0;
}

.limit-progress-fill.warning {
    background: #f59e0b;
}

.limit-progress-fill.danger {
    background: #ef4444;
}

.limit-progress-fill.unlimited {
    background: linear-gradient(90deg, #10b981 0%, #3b82f6 100%);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.8;
    }
}

.limit-value {
    font-weight: 500;
    color: #374151;
    font-size: 0.9rem;
    min-width: 60px;
    text-align: right;
}

@media (max-width: 768px) {
    .limit-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .limit-progress-container {
        width: 100%;
        justify-content: flex-start;
    }

    .limit-progress-bar {
        max-width: none;
    }
}

/* Security Cards Grid */
.security-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.security-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px;
}

.security-card h4 {
    margin: 0 0 8px 0;
    color: var(--profile-section-title-color);
    display: flex;
    align-items: center;
    gap: var(--profile-section-title-gap);
    font-size: var(--profile-card-title-size);
    font-weight: var(--profile-section-title-weight);
    line-height: 1.3;
}

.security-card h4 i {
    color: var(--profile-section-title-icon-color);
    flex: 0 0 var(--profile-section-title-icon-width);
    width: var(--profile-section-title-icon-width);
    text-align: center;
    font-size: var(--profile-section-title-icon-size);
}

.security-card p {
    margin: 0 0 16px 0;
    color: #64748b;
    font-size: 0.9rem;
    line-height: 1.5;
}

.security-card.danger {
    background: #fef2f2;
    border-color: #fecaca;
}

.security-card.danger h4 {
    color: #dc2626;
}

.security-card.danger h4 i {
    color: #dc2626;
}

/* Warning Button */
.btn-warning {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #1f2937;
    border: none;
}

.btn-warning:hover {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

#logoutBtn,
#logoutConfirmBtn {
    color: #fff;
}

/* Language Display Section */
.language-display-container {
    padding: 16px 0;
}

.current-language-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.language-toggle-row {
    justify-content: space-between;
    gap: 16px;
}

.language-toggle-copy {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.language-label {
    color: #64748b;
    font-size: 0.95rem;
}

.language-value {
    font-weight: 600;
    color: #1e293b;
    font-size: 1rem;
    margin-right: 8px;
}

.language-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    border-radius: 999px;
    background: #eff6ff;
    border: 1px solid rgba(59, 130, 246, 0.18);
}

.language-toggle-option {
    border: 0;
    background: transparent;
    color: #475569;
    border-radius: 999px;
    padding: 10px 16px;
    min-width: 56px;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.language-toggle-option:hover {
    color: #0f172a;
    transform: translateY(-1px);
}

.language-toggle-option.is-active {
    background: #3b82f6;
    color: #ffffff;
    box-shadow: 0 10px 24px rgba(59, 130, 246, 0.22);
}

.section-description.small {
    color: #94a3b8;
    font-size: 0.85rem;
    margin: 0;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 16px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    color: #1f2937;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-header h2 i {
    color: #3b82f6;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6b7280;
    padding: 4px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}

.modal-close:hover {
    background-color: #f3f4f6;
    color: #1f2937;
}

.modal-body {
    padding: 24px;
}

.modal-body p {
    margin: 0;
    color: #4b5563;
    font-size: 1rem;
    line-height: 1.6;
}

.modal-actions {
    padding: 16px 24px 24px;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Body overflow when modal is open */
body.modal-open {
    overflow: hidden;
}

@media (max-width: 768px) {
    .security-grid {
        grid-template-columns: 1fr;
    }

    .current-language-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .language-toggle-row {
        align-items: stretch;
    }

    .language-toggle {
        width: 100%;
        justify-content: space-between;
    }

    .language-toggle-option {
        flex: 1;
    }
}
