/**
 * Modal Styles
 *
 * Unified modal system consolidating the previous modal patterns.
 *
 * Two main patterns:
 * 1. .modal (generic modal) - for session editors, settings, etc.
 * 2. .learn-modal-overlay (lesson/auth modals) - for content-focused modals
 */

/* =====================================================================
   BODY SCROLL LOCK - Hide page scrollbar when any modal is open
   ===================================================================== */

body:has(.modal.active),
body:has(.learn-modal-overlay.active),
body:has(.notify-modal-overlay.active),
body:has(.save-prompt-modal.active) {
    overflow: hidden;
}

/* =====================================================================
   BASE MODAL - Generic overlay and content box
   ===================================================================== */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 1100;
    overflow: hidden;
    overscroll-behavior: contain;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 30px;
    width: 100%;
    max-width: 800px;
    max-height: calc(100vh - 80px);
    overflow: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h2 {
    font-size: 1.4rem;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-close:hover {
    color: var(--text);
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 25px;
    justify-content: flex-end;
}

/* =====================================================================
   FULL-SCREEN MOBILE MODAL PATTERN

   Use this pattern for any modal that should fill the entire screen on
   mobile. Content sits flush against the header and footer separators —
   no gaps, no extra padding bleeding in from the base styles.

   Required HTML structure:

     <div class="modal modal-fs" id="my-modal">
       <div class="modal-content modal-fs-content">

         <div class="modal-header">
           <h2>Title</h2>
           <button class="modal-close">×</button>
         </div>

         <div class="modal-scroll-body">
           ... scrollable form fields / content ...
         </div>

         <div class="modal-actions">
           <button class="btn-cancel">Cancel</button>
           <button class="btn-save">Save</button>
         </div>

       </div>
     </div>

   Notes:
   - Add `modal-fs` to the .modal overlay element
   - Add `modal-fs-content` to the inner content box (alongside modal-content)
   - .modal-scroll-body is the scrollable region between header and actions
   - To override padding/gap: #my-modal .modal-scroll-body { gap: 1.5rem; }
   - If your submit button lives outside the <form>, use form="form-id" on it
   ===================================================================== */

@media (max-width: 768px) {
    /* Overlay: full-screen, no centering padding */
    .modal.modal-fs {
        padding: 0;
        align-items: stretch;
    }

    /* Content box: flex column, clips overflow at separator edges */
    .modal-fs-content {
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        padding: 0 !important;
        max-height: 100% !important;
        height: 100%;
        border-radius: 0;
    }

    /* Header: pinned, flush — overrides base margin-bottom */
    .modal-fs-content .modal-header {
        flex-shrink: 0;
        margin-bottom: 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    /* Scroll body: expands to fill available space, scrolls internally */
    .modal-fs-content .modal-scroll-body {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 1rem;
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    /* Actions bar: pinned to bottom, flush — overrides base margin-top */
    .modal-fs-content .modal-actions {
        flex-shrink: 0;
        margin-top: 0;
        padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
        background: var(--bg-card);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
}

/* Mobile modal fixes */
@media (max-width: 768px) {
    .modal.active {
        padding: 16px;
        align-items: center;
        overflow: hidden;
    }

    .modal-content {
        padding: 20px;
        max-width: 100%;
        max-height: calc(100vh - 32px);
        border-radius: 8px;
        overflow: hidden;
        overflow-y: auto;
    }

    .modal-header h2 {
        font-size: 1.1rem;
    }
}

/* =====================================================================
   LEARN MODAL - For lessons, auth, upgrade flows
   ===================================================================== */

.learn-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 2rem;
}

.learn-modal-overlay.active {
    display: flex;
}

.learn-modal {
    background: var(--bg-card);
    border-radius: 1rem;
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid var(--border);
}

.learn-modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.learn-modal-title {
    font-size: 1.75rem;
    margin-bottom: 10px;
    font-weight: 700;
}

.learn-modal-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.learn-modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

.learn-modal-close:hover {
    color: var(--text);
}

.learn-modal-content {
    padding: 1.5rem;
}

.learn-modal-section-title {
    margin-bottom: 1rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.learn-modal-actions {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 1rem;
}

/* Mobile learn modal fixes */
@media (max-width: 768px) {
    .learn-modal-overlay.active {
        overflow-x: hidden;
    }

    .learn-modal {
        overflow-x: hidden;
    }
}

/* =====================================================================
   CONCEPT LIST - For lesson content
   ===================================================================== */

.concept-list {
    list-style: none;
}

.concept-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

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

.concept-icon {
    color: var(--accent);
    font-size: 1rem;
    margin-top: 0.125rem;
}

/* =====================================================================
   COMING SOON CARD - For unreleased lessons
   ===================================================================== */

.lesson-coming-soon {
    margin: 0rem 1rem 1.5rem 1rem;
    padding: 1.25rem;
    background: rgba(240, 198, 116, 0.1);
    border: 1px solid rgba(240, 198, 116, 0.3);
    border-radius: 0.75rem;
    text-align: center;
}

.coming-soon-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.coming-soon-text {
    font-size: 1.3rem;
    font-weight: 600;
    color: #f0c674;
    margin-bottom: 0.25rem;
}

.coming-soon-subtext {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.coming-soon-close {
    margin-top: 1rem;
    padding: 0.6rem 2rem;
    background: transparent;
    border: 1px solid rgba(240, 198, 116, 0.4);
    border-radius: 0.5rem;
    color: #f0c674;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.coming-soon-close:hover {
    background: rgba(240, 198, 116, 0.15);
    border-color: #f0c674;
}

/* =====================================================================
   NOTIFICATION MODAL
   ===================================================================== */

.notify-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
}

.notify-modal-overlay.active {
    display: flex;
}

.notify-modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 30px;
    max-width: 380px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.notify-modal-icon {
    width: 44px;
    height: 44px;
    margin: 0 auto 12px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.notify-modal-icon.info {
    background: rgba(59, 130, 246, 0.15);
    color: #3B82F6;
}

.notify-modal-icon.success {
    background: rgba(16, 185, 129, 0.15);
    color: #10B981;
}

.notify-modal-icon.warning {
    background: rgba(234, 179, 8, 0.15);
    color: #EAB308;
}

.notify-modal-icon.error {
    background: rgba(239, 68, 68, 0.15);
    color: #EF4444;
}

.notify-modal-icon.delete {
    background: rgba(239, 68, 68, 0.15);
    color: #EF4444;
}

.notify-modal-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
    text-align: center;
}

.notify-modal-message {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 0;
    white-space: pre-wrap;
    text-align: center;
}

.notify-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 24px;
}

.notify-modal-btn {
    padding: 8px 20px;
    border-radius: 6px;
    font-size: 0.9rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: none;
    cursor: pointer;
    color: var(--text);
}

.notify-modal-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.notify-modal-btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

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

.notify-modal-btn.danger {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.3);
    color: #EF4444;
}

.notify-modal-btn.danger:hover {
    background: rgba(239, 68, 68, 0.25);
}

.notify-modal-input {
    width: 100%;
    padding: 12px 14px;
    margin-top: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 16px; /* Must be >= 16px to prevent iOS Safari zoom on focus */
    transition: border-color 0.2s;
}

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

.notify-modal-input::placeholder {
    color: var(--text-muted);
}

/* =====================================================================
   SAVE PROMPT MODAL
   ===================================================================== */

.save-prompt-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.save-prompt-modal.active {
    display: flex;
}

.save-prompt-content {
    background: var(--bg-card, #16213e);
    border-radius: 1rem;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.save-prompt-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.save-prompt-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.save-prompt-message {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.save-prompt-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.save-prompt-btn-primary {
    padding: 0.75rem 1.5rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

.save-prompt-btn-secondary {
    padding: 0.5rem 1rem;
    background: none;
    color: var(--text-muted);
    border: none;
    font-size: 0.85rem;
    cursor: pointer;
    transition: color 0.2s;
}

.save-prompt-btn-secondary:hover {
    color: var(--text);
}

/* =====================================================================
   AUTH MODAL CONTENT
   ===================================================================== */

.auth-modal-content {
    max-width: 440px;
    width: 90vw;
    text-align: center;
    max-height: 90vh;
    overflow: visible;
}

.auth-modal-content .learn-modal-content {
    max-height: none;
    overflow: visible;
}

.auth-benefits {
    background: rgba(139, 92, 246, 0.08);
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.auth-benefits-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.auth-benefits-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: inline-grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.375rem 1.5rem;
    text-align: left;
}

.auth-benefits-list li {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.auth-benefits-list li::before {
    content: "\2713";
    color: #22c55e;
    font-weight: 600;
}

.auth-modal-content .learn-modal-content {
    overflow-y: auto;
    max-height: calc(90vh - 60px);
    padding-bottom: 2rem;
}

.auth-modal-content .learn-modal-content::-webkit-scrollbar {
    width: 8px;
}

.auth-modal-content .learn-modal-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

.auth-modal-content .learn-modal-content::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 4px;
}

@media (max-width: 768px) {
    #auth-modal.learn-modal-overlay {
        padding: 0;
        align-items: stretch;
        z-index: 1100;
    }

    #auth-modal .auth-modal-content {
        max-width: 100%;
        width: 100%;
        max-height: 100%;
        height: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .auth-modal-content .learn-modal-content {
        flex: 1;
        overflow-y: auto;
        max-height: none;
        padding: 0 1.5rem 2rem;
    }

    .auth-benefits-list {
        grid-template-columns: 1fr;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
}

/* =====================================================================
   AUTH FORM STYLES
   ===================================================================== */

.auth-modal-content .learn-modal-content::-webkit-scrollbar-thumb:hover {
    background: var(--accent-hover);
}

@media (max-width: 768px) {
    #auth-modal .learn-modal-header {
        padding: 1rem;
        flex-shrink: 0;
    }
    #auth-modal .learn-modal-content {
        flex: 1;
        overflow-y: auto;
        max-height: none;
        padding: 0 1.5rem 2rem;
    }
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-form.hidden {
    display: none;
}

.auth-form-group {
    text-align: left;
}

.auth-form-group label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.auth-form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text);
    font-size: 0.9rem;
}

.auth-form-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.auth-terms-group {
    margin-top: 0.5rem;
}

.auth-checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
}

.auth-checkbox-label input[type="checkbox"] {
    width: auto;
    margin-top: 0.2rem;
    cursor: pointer;
}

.auth-checkbox-label a {
    color: var(--accent);
    text-decoration: none;
}

.auth-checkbox-label a:hover {
    text-decoration: underline;
}

.auth-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #f87171;
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    margin: 0;
    display: none;
}

.auth-error.visible {
    display: block;
    margin-bottom: 1rem;
}

.auth-result-page {
    min-height: 60vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.auth-result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 2.5rem;
    max-width: 420px;
    width: 100%;
    text-align: center;
}

.auth-result-card h2 {
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
}

.auth-result-card h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.auth-result-card p {
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.auth-result-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.auth-result-success {
    color: #22c55e;
}

.auth-result-error {
    color: #ef4444;
}

.auth-result-loading {
    color: var(--text-muted);
    animation: pulse 1.5s ease-in-out infinite;
}

.auth-result-card .auth-form-group {
    text-align: left;
}

.auth-result-card .auth-btn {
    width: 100%;
    margin-top: 0.5rem;
}

.auth-forgot-link {
    text-align: right;
    margin: -0.25rem 0 0.75rem;
}

.auth-forgot-link a {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-decoration: none;
}

.auth-forgot-link a:hover {
    color: var(--accent);
}

.auth-switch-link {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.auth-switch-link a {
    color: var(--accent);
    text-decoration: none;
}

.auth-switch-link a:hover {
    text-decoration: underline;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1rem 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.auth-btn {
    width: 100%;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.auth-btn-primary {
    background: var(--accent);
    color: white;
}

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

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

.btn-create-account {
    padding: 0.5rem 1rem;
    margin-bottom: 8px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 0.375rem;
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

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

.btn-login-text {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0;
    transition: color 0.2s;
}

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

.mobile-nav-auth .btn-create-account {
    width: 100%;
    padding: 0.75rem;
    font-size: 0.9rem;
}

.mobile-nav-auth .btn-login-text {
    font-size: 0.9rem;
    text-align: center;
    padding: 0.5rem;
}

/* =====================================================================
   UPGRADE MODAL
   ===================================================================== */

.upgrade-plan-option:hover {
    background: rgba(139, 92, 246, 0.05);
}

@media (max-width: 768px) {
    #upgrade-modal.learn-modal-overlay {
        padding: 0;
        align-items: stretch;
        z-index: 1100;
    }
    #upgrade-modal .learn-modal {
        max-width: 100%;
        width: 100%;
        max-height: 100%;
        height: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }
    #upgrade-modal .learn-modal-header {
        padding: 1rem;
        flex-shrink: 0;
    }
    #upgrade-modal .learn-modal-content {
        flex: 1;
        overflow-y: auto;
        padding: 1rem;
    }
}

.btn-upgrade-header {
    padding: 0.4rem 0.875rem;
    background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
    color: white;
    border: none;
    border-radius: 0.375rem;
    font-weight: 600;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    margin-right: 0.5rem;
}

.btn-upgrade-header:hover {
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}
