/* ===============================================
   CONTENT FLAG WIDGET STYLES
   Aphasia Studio - Accessible Content Flagging
   =============================================== */

/* -----------------------------------------------
   CSS CUSTOM PROPERTIES
   ----------------------------------------------- */
:root {
    /* Button positioning */
    --flag-button-top: 80px;
    --flag-button-right: 16px;
    --flag-button-mobile-size: 44px;
    --flag-button-z-index: 1000;
    
    /* Modal sizing */
    --flag-modal-max-width: 420px;
    --flag-modal-radius: 16px;
    
    /* Colors */
    --flag-primary: #1e3a5f;
    --flag-primary-light: #2d5a87;
    --flag-text-dark: #1E293B;
    --flag-text-medium: #374151;
    --flag-text-light: #6B7280;
    --flag-text-muted: #9CA3AF;
    --flag-border: #E5E7EB;
    --flag-border-light: #E2E8F0;
    --flag-bg-subtle: #F8FAFC;
    --flag-bg-light: #F3F4F6;
    
    /* Issue type colors */
    --flag-wrong: #DC2626;
    --flag-missing: #D97706;
    --flag-technical: #6366F1;
    --flag-inappropriate: #DC2626;
    --flag-difficulty: #8B5CF6;
    --flag-other: #6B7280;
}

/* -----------------------------------------------
   FLAG TRIGGER BUTTON
   ----------------------------------------------- */
.enhanced-flag-page-button {
    position: fixed;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 16px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
    transition: all 0.2s ease;
    z-index: var(--flag-button-z-index);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.enhanced-flag-page-button:hover {
    background: #dc2626;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);
}

/* Mobile flag button */
.enhanced-flag-page-button[data-mobile="true"] {
    padding: 0;
    width: var(--flag-button-mobile-size);
    height: var(--flag-button-mobile-size);
    border-radius: 50%;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.enhanced-flag-page-button[data-mobile="true"]:hover {
    transform: translateY(-1px) scale(1.05);
}

/* Position utility classes */
.flag-button-high { --flag-button-top: 60px; }
.flag-button-medium { --flag-button-top: 80px; }
.flag-button-low { --flag-button-top: 120px; }

.hide-flag-button .enhanced-flag-page-button {
    display: none;
}

/* -----------------------------------------------
   MODAL OVERLAY & CONTAINER
   ----------------------------------------------- */
.enhanced-flag-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 2000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    /* Hidden by default */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.enhanced-flag-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.enhanced-flag-modal-content {
    background: #fff;
    border-radius: var(--flag-modal-radius);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
    width: 100%;
    max-width: var(--flag-modal-max-width);
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* Animation */
    transform: translateY(20px) scale(0.95);
    transition: transform 0.2s ease;
}

.enhanced-flag-modal-overlay.active .enhanced-flag-modal-content {
    transform: translateY(0) scale(1);
}

/* -----------------------------------------------
   MODAL HEADER
   ----------------------------------------------- */
.enhanced-flag-modal-header {
    background: linear-gradient(135deg, var(--flag-primary) 0%, var(--flag-primary-light) 100%);
    color: #fff;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.enhanced-flag-modal-title {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: #fff;
}

.enhanced-flag-close-button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: background 0.15s ease;
}

.enhanced-flag-close-button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* -----------------------------------------------
   MODAL BODY
   ----------------------------------------------- */
.enhanced-flag-modal-body {
    flex: 1;
    overflow-y: auto;
}

/* -----------------------------------------------
   CONTENT SELECTION SECTION
   ----------------------------------------------- */
.enhanced-flag-question {
    font-size: 14px;
    color: var(--flag-text-light);
    margin: 0;
    padding: 20px 24px 12px;
    font-weight: 500;
    border-bottom: 1px solid var(--flag-border);
}

.enhanced-flag-content-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px 24px;
    max-height: 280px;
    overflow-y: auto;
}

/*.enhanced-flag-content-item {
    border: 2px solid var(--flag-border);
    border-radius: 12px;
    padding: 16px 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    background: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.enhanced-flag-content-item:hover {
    border-color: #CBD5E1;
    background: var(--flag-bg-subtle);
}

.enhanced-flag-content-item.selected {
    border-color: #10B981;
    background: #F0FDF4;
}

.enhanced-flag-content-item.selected::after {
    content: '✓';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 20px;
    height: 20px;
    background: #10B981;
    border-radius: 50%;
    color: #fff;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Content item icon 
.enhanced-flag-content-icon {
    width: 72px;
    height: 72px;
    background: #10B981;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    flex-shrink: 0;
}*/

.enhanced-flag-content-image {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 14px;
}

/*.enhanced-flag-content-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--flag-text-dark);
    line-height: 1.3;
}*/

/*.enhanced-flag-content-type {
    font-size: 12px;
    color: #64748B;
    background: var(--flag-border-light);
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
}*/

/* -----------------------------------------------
   ISSUE TYPE SELECTION
   ----------------------------------------------- */
.enhanced-flag-issue-types {
    padding: 20px 24px;
}

.enhanced-flag-section-label {
    font-size: 14px;
    color: var(--flag-text-light);
    margin-bottom: 12px;
    font-weight: 500;
    display: block;
}

.enhanced-flag-label-hint {
    color: var(--flag-text-muted);
    font-weight: 400;
}

.enhanced-flag-issue-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Issue type button */
.enhanced-flag-issue-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 18px 12px;
    border: 2px solid var(--flag-border);
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    font-family: inherit;
}

.enhanced-flag-issue-item:hover {
    border-color: #CBD5E1;
    background: var(--flag-bg-subtle);
}

.enhanced-flag-issue-item.selected {
    border-color: var(--issue-color, var(--flag-primary));
    background: var(--issue-bg, #EFF6FF);
}

.enhanced-flag-issue-item.selected::after {
    content: '✓';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 20px;
    height: 20px;
    background: var(--issue-color, var(--flag-primary));
    border-radius: 50%;
    color: #fff;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Issue icon container */
.enhanced-flag-issue-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    background: var(--flag-bg-light);
    color: var(--issue-color, var(--flag-text-medium));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    transition: all 0.15s ease;
}

.enhanced-flag-issue-item.selected .enhanced-flag-issue-icon {
    background: var(--issue-color, var(--flag-primary));
    color: #fff;
}

/* Issue label */
.enhanced-flag-issue-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--flag-text-medium);
    text-align: center;
    line-height: 1.3;
}

.enhanced-flag-issue-item.selected .enhanced-flag-issue-label {
    color: var(--issue-color, var(--flag-primary));
}

/* Issue type color variants */
.enhanced-flag-issue-item[data-issue="wrong_content"] {
    --issue-color: var(--flag-wrong);
    --issue-bg: #FEF2F2;
}

.enhanced-flag-issue-item[data-issue="missing_content"] {
    --issue-color: var(--flag-missing);
    --issue-bg: #FFFBEB;
}

.enhanced-flag-issue-item[data-issue="technical_problem"] {
    --issue-color: var(--flag-technical);
    --issue-bg: #EEF2FF;
}

.enhanced-flag-issue-item[data-issue="inappropriate"] {
    --issue-color: var(--flag-inappropriate);
    --issue-bg: #FEF2F2;
}

.enhanced-flag-issue-item[data-issue="wrong_difficulty"] {
    --issue-color: var(--flag-difficulty);
    --issue-bg: #F5F3FF;
}

.enhanced-flag-issue-item[data-issue="other"] {
    --issue-color: var(--flag-other);
    --issue-bg: #F9FAFB;
}

/* -----------------------------------------------
   DETAILS TEXTAREA
   ----------------------------------------------- */
.enhanced-flag-description-section {
    padding: 0 24px 20px;
}

.enhanced-flag-description-textarea {
    width: 100%;
    min-height: 80px;
    padding: 14px;
    border: 2px solid var(--flag-border);
    border-radius: 12px;
    font-size: 15px;
    font-family: inherit;
    resize: vertical;
    box-sizing: border-box;
    transition: border-color 0.15s ease;
}

.enhanced-flag-description-textarea:focus {
    outline: none;
    border-color: var(--flag-primary);
}

.enhanced-flag-description-textarea::placeholder {
    color: var(--flag-text-muted);
}

/* -----------------------------------------------
   MODAL FOOTER & BUTTONS
   ----------------------------------------------- */
.enhanced-flag-modal-actions {
    padding: 16px 24px;
    background: var(--flag-bg-subtle);
    border-top: 1px solid var(--flag-border);
    display: flex;
    gap: 12px;
}

.enhanced-flag-btn {
    flex: 1;
    padding: 14px 20px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.enhanced-flag-btn-secondary {
    background: #fff;
    color: var(--flag-text-medium);
    border: 2px solid var(--flag-border);
}

.enhanced-flag-btn-secondary:hover {
    background: var(--flag-bg-subtle);
    border-color: #CBD5E1;
}

.enhanced-flag-btn-primary {
    background: var(--flag-border);
    color: var(--flag-text-muted);
    cursor: default;
}

.enhanced-flag-btn-primary.active {
    background: linear-gradient(135deg, var(--flag-primary) 0%, var(--flag-primary-light) 100%);
    color: #fff;
    cursor: pointer;
}

.enhanced-flag-btn-primary.active:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(30, 58, 95, 0.3);
}

.enhanced-flag-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.enhanced-flag-btn.loading {
    pointer-events: none;
    opacity: 0.7;
}

/* -----------------------------------------------
   SUCCESS MESSAGE
   ----------------------------------------------- */
.enhanced-flag-success-message {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #10b981;
    color: white;
    padding: 16px 24px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    z-index: 3000;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
}

.enhanced-flag-success-message::before {
    content: '✓';
    width: 24px;
    height: 24px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.enhanced-flag-success-message.show {
    opacity: 1;
    transform: translateX(0);
}

/* -----------------------------------------------
   MOBILE RESPONSIVE
   ----------------------------------------------- */
@media (max-width: 480px) {
    .enhanced-flag-modal-content {
        margin: 10px;
        max-height: 95vh;
    }
    
    .enhanced-flag-content-grid {
        grid-template-columns: 1fr;
        max-height: 200px;
    }
    
    .enhanced-flag-issue-grid {
        grid-template-columns: 1fr;
    }
    
    .enhanced-flag-content-icon,
    .enhanced-flag-content-image {
        width: 56px;
        height: 56px;
        font-size: 28px;
    }
    
    .enhanced-flag-issue-icon {
        width: 48px;
        height: 48px;
        font-size: 24px;
    }
}

/* -----------------------------------------------
   ACCESSIBILITY
   ----------------------------------------------- */
.enhanced-flag-content-item:focus-visible,
.enhanced-flag-issue-item:focus-visible,
.enhanced-flag-close-button:focus-visible,
.enhanced-flag-btn:focus-visible {
    outline: 2px solid var(--flag-primary);
    outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .enhanced-flag-modal-overlay,
    .enhanced-flag-modal-content,
    .enhanced-flag-content-item,
    .enhanced-flag-issue-item,
    .enhanced-flag-btn,
    .enhanced-flag-success-message {
        transition: none;
    }
}

/* -----------------------------------------------
   INLINE FLAG BUTTON (embedded in widgets)
   ----------------------------------------------- */
.inline-flag-button,
body .naming-practice-root .inline-flag-button,
body .listening-practice-root .inline-flag-button,
body .category-exercise-root .inline-flag-button,
body .flashcard-exercise-root .inline-flag-button,
body .sfa-wheel-root .inline-flag-button {
    position: absolute !important;
    top: 8px;
    right: 8px;
    width: 28px !important;
    height: 28px !important;
    border-radius: 50% !important;
    background: rgba(107, 114, 128, 0.1) !important;
    background-color: rgba(107, 114, 128, 0.1) !important;
    background-image: none !important;
    border: 1px solid rgba(107, 114, 128, 0.2) !important;
    color: #6B7280 !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s ease !important;
    z-index: 10 !important;
    padding: 0 !important;
    line-height: 1 !important;
    min-width: 28px !important;
    min-height: 28px !important;
    box-shadow: none !important;
}

.inline-flag-button:hover,
body .naming-practice-root .inline-flag-button:hover,
body .listening-practice-root .inline-flag-button:hover,
body .category-exercise-root .inline-flag-button:hover,
body .flashcard-exercise-root .inline-flag-button:hover,
body .sfa-wheel-root .inline-flag-button:hover {
    background: rgba(239, 68, 68, 0.1) !important;
    background-color: rgba(239, 68, 68, 0.1) !important;
    border-color: rgba(239, 68, 68, 0.3) !important;
    color: #EF4444 !important;
    transform: scale(1.1) !important;
}

.inline-flag-button:focus-visible {
    outline: 2px solid var(--flag-primary, #1e3a5f);
    outline-offset: 2px;
}

.inline-flag-button .flag-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Alternative icon style - question mark variant */
.inline-flag-button.question-style .flag-icon::before {
    content: '?';
}

/* Tooltip on hover */
.inline-flag-button::after {
    content: attr(title);
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    padding: 6px 10px;
    background: #1F2937;
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
    z-index: 100;
}

.inline-flag-button:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Widget-specific positioning adjustments */

/* Ensure widget containers are positioned for absolute children */
.naming-practice-root,
.listening-practice-root,
.category-exercise-root,
.flashcard-exercise-root,
.sfa-wheel-root,
.vnest-root {
    position: relative;
}

/* For widgets with headers - position below header */
.naming-practice-root .inline-flag-button,
.listening-practice-root .inline-flag-button,
.category-exercise-root .inline-flag-button,
.flashcard-exercise-root .inline-flag-button,
.sfa-wheel-root .inline-flag-button,
.vnest-root .inline-flag-button {
    top: 12px;
    right: 12px;
}

/* Adjust for widgets with existing controls in top-right */
.naming-practice-root.has-settings-button .inline-flag-button {
    right: 56px;
}

/* Mobile adjustments */
@media (max-width: 480px) {
    .inline-flag-button {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .inline-flag-button::after {
        display: none; /* Hide tooltip on mobile */
    }
}

/* When widget is in compact/minimal mode */
.widget-compact .inline-flag-button {
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    font-size: 12px;
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
    .inline-flag-button {
        background: rgba(156, 163, 175, 0.15);
        border-color: rgba(156, 163, 175, 0.25);
        color: #9CA3AF;
    }

    .inline-flag-button:hover {
        background: rgba(239, 68, 68, 0.2);
        border-color: rgba(239, 68, 68, 0.4);
        color: #F87171;
    }
}

/* Hide when global flag button is present on page */
.hide-inline-flag-buttons .inline-flag-button {
    display: none;
}