/**
 * CORNERSTONE Article Modal CSS - Phase 4
 * Mobile-first responsive design with CRT theme integration
 * 
 * @version 1.0.0
 * @date October 25, 2025
 * @author CursorAI (Lucky Chat)
 * 
 * Features:
 * - Mobile-first responsive design
 * - Desktop 60/40 split (Story left, Comments right)
 * - Mobile tabs (Story/Comments)
 * - Theme integration via CSS variables
 * - Touch gestures support
 * - Accessibility compliance (WCAG 2.1 AA)
 * - Performance optimized (GPU acceleration)
 */

/* ============================================================
   SPLIT VIEW TOGGLE BUTTON
   ============================================================ */

.split-view-toggle {
    display: flex;
    align-items: center;
}

.split-toggle-btn {
    background: var(--crt-background, #000000);
    border: 1px solid var(--crt-glow, #00ffd5);
    color: var(--crt-primary, #008000);
    font-size: 1rem;
    padding: 0rem 0rem;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 24px;
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px;
    font-family: 'Source Code Pro', monospace;
}

.split-toggle-btn:hover {
    background-color: var(--crt-glow, #00ffd5);
    color: var(--bg-color, #000000);
    box-shadow: 0 0 10px var(--crt-glow, #00ffd5);
}

.split-toggle-btn.active {
    background: var(--crt-background, #000000);
    color: var(--crt-primary, #008000);
    text-shadow: 0 0 8px var(--crt-primary, #008000), 0 0 16px var(--crt-primary, #008000), 0 0 24px var(--crt-primary, #008000);
    box-shadow: 0 0 12px var(--crt-primary, #008000);
    font-size: 1rem;
    padding: 0rem 0rem;
    min-width: 24px;
    min-height: 24px;
}

.split-toggle-btn.inactive {
    background: var(--crt-background, #000000);
    color: var(--crt-primary, #008000);
    text-shadow: none;
    font-size: 1rem;
    padding: 0rem 0rem;
    min-width: 24px;
    min-height: 24px;
}

/* ============================================================
   MODAL OVERLAY
   ============================================================ */

.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 9998;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* ============================================================
   MODAL CONTAINER
   ============================================================ */

.modal-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: 100vh;
    background-color: var(--bg-color, #000000);
    color: var(--text-color, #ffffff);
    border: 2px solid var(--crt-glow, #00ffd5);
    box-shadow: 0 0 20px var(--crt-glow, #00ffd5);
    font-family: 'Source Code Pro', monospace;
    position: relative;
    will-change: transform;
    transform: translateZ(0);
    /* GPU acceleration */
}

/* ============================================================
   MODAL HEADER
   ============================================================ */

.modal-header {
    display: flex;
    flex-direction: column;
    padding: 0.5rem;
    border-bottom: 1px solid var(--crt-glow, #00ffd5);
    background-color: var(--bg-color, #000000);
    flex-shrink: 0;
    position: relative;
}

.modal-title {
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--crt-glow, #00ffd5);
    text-shadow: 0 0 5px var(--crt-glow, #00ffd5);
    margin: 0;
    padding: 0.5rem;
    padding-right: 2.5rem;
    /* Space for close button */
    line-height: 1.3;
    overflow: visible;
    white-space: normal;
    word-wrap: break-word;
    max-height: 3.9rem;
    /* Allow for 3 lines */
    overflow-y: auto;
}

.modal-close {
    background: none;
    border: 1px solid var(--crt-glow, #00ffd5);
    color: var(--text-color, #ffffff);
    font-size: 1rem;
    cursor: pointer;
    padding: 0rem;
    min-width: 28px;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    border-radius: 2px;
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

.modal-close:hover {
    background-color: var(--crt-glow, #00ffd5);
    color: var(--bg-color, #000000);
    box-shadow: 0 0 10px var(--crt-glow, #00ffd5);
}

/* ============================================================
   BOTTOM TOOLBAR
   ============================================================ */

.modal-toolbar {
    display: flex;
    background-color: var(--bg-color, #000000);
    border-top: 1px solid var(--crt-glow, #00ffd5);
    flex-shrink: 0;
    padding: 0.5rem;
    gap: 0.5rem;
}

.tab-button {
    flex: 1;
    background: none;
    border: 1px solid var(--crt-glow, #00ffd5);
    color: var(--text-color, #ffffff);
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-family: 'Source Code Pro', monospace;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    border-radius: 2px;
    min-height: 40px;
}

.tab-button:hover {
    background-color: var(--crt-glow, #00ffd5);
    color: var(--bg-color, #000000);
    box-shadow: 0 0 10px var(--crt-glow, #00ffd5);
}

.tab-button.active {
    background-color: var(--crt-glow, #00ffd5);
    color: var(--bg-color, #000000);
    box-shadow: 0 0 15px var(--crt-glow, #00ffd5);
}

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

.modal-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
    height: 100%;
    min-height: 0;
}

/* ============================================================
   STORY PANE
   ============================================================ */

.story-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-color, #000000);
    height: 100%;
    min-height: 0;
    border-right: 1px solid var(--crt-glow, #00ffd5);
    /* Allow flex item to shrink */
}

.story-iframe {
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 100%;
    /* FIXED: was 400px, now 100% to fill parent */
    border: none;
    background-color: var(--bg-color, #000000);
    color: var(--crt-primary, #008000);
    font-family: 'Source Code Pro', monospace;
    display: block;
    overflow: auto;
    /* Allow scrolling if content is too tall */
}

/* Remove glow effects from iframe content */
.story-iframe * {
    text-shadow: none !important;
    box-shadow: none !important;
}

/* Ensure iframe content uses CRT primary color without glow */
.story-iframe body {
    color: var(--crt-primary, #008000) !important;
    text-shadow: none !important;
    background-color: var(--bg-color, #000000) !important;
}

/* ============================================================
   COMMENTS PANE
   ============================================================ */

.comments-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-color, #000000);
}

.comments-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--scanline, #333);
    background-color: var(--bg-color, #000000);
    flex-shrink: 0;
}

.comments-header h3 {
    margin: 0;
    color: var(--crt-glow, #00ffd5);
    font-size: 1rem;
}

#comment-count {
    color: var(--accent-color, #ff0);
    font-weight: bold;
    font-size: 0.9rem;
}

.comments-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background-color: var(--bg-color, #000000);
}

.comment-item {
    margin-bottom: 1rem;
    padding: 0.75rem;
    border-left: 3px solid var(--accent-color, #ff0);
    background-color: var(--scanline, #333);
    border-radius: 2px;
}

.comment-author {
    font-weight: bold;
    color: var(--crt-glow, #00ffd5);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.comment-text {
    color: var(--text-color, #ffffff);
    line-height: 1.4;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.comment-time {
    color: var(--accent-color, #ff0);
    font-size: 0.8rem;
    opacity: 0.8;
}

/* ============================================================
   LOADING STATES
   ============================================================ */

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--text-color, #ffffff);
    font-style: italic;
}

.loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid var(--crt-glow, #00ffd5);
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 0.5rem;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.error {
    color: var(--accent-color, #ff0);
    text-align: center;
    padding: 2rem;
    font-style: italic;
}

.no-comments {
    color: var(--text-color, #ffffff);
    text-align: center;
    padding: 2rem;
    font-style: italic;
    opacity: 0.7;
}

/* ============================================================
   RESPONSIVE DESIGN
   ============================================================ */

/* Mobile-first: Single pane with bottom toolbar */
@media (max-width: 768px) {
    .modal-content {
        flex-direction: column;
        height: 100%;
    }

    .story-pane {
        border-right: none;
        border-bottom: 1px solid var(--crt-glow, #00ffd5);
        flex: 1 1 100%;
        /* Take full width and height in mobile */
        min-height: 0;
        /* Allow flex item to shrink */
    }

    .story-iframe {
        width: 100%;
        height: 100%;
        min-height: 60vh;
        /* Ensure good height on mobile */
    }

    .story-pane:not(.active) {
        display: none;
    }

    .comments-pane {
        flex: 1 1 100%;
        /* Take full width and height in mobile when active */
    }

    .comments-pane:not(.active) {
        display: none;
    }
}

/* Desktop: Split visible with bottom toolbar */
@media (min-width: 769px) {
    .modal-content {
        flex-direction: row;
    }

    .story-pane {
        flex: 0 0 60%;
        /* 60% width */
        border-right: 1px solid var(--crt-glow, #00ffd5);
    }

    .comments-pane {
        flex: 0 0 40%;
        /* 40% width */
    }

    .story-pane,
    .comments-pane {
        display: flex !important;
    }
}

/* ============================================================
   ACCESSIBILITY
   ============================================================ */

/* Focus management */
.modal-overlay:focus {
    outline: none;
}

.tab-button:focus,
.modal-close:focus {
    outline: 2px solid var(--accent-color, #ff0);
    outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .modal-overlay {
        animation: none;
    }

    .loading::after {
        animation: none;
    }

    .tab-button,
    .modal-close {
        transition: none;
    }
}

/* High contrast support */
@media (prefers-contrast: high) {
    .story-pane {
        border-right: 2px solid #fff;
    }

    .comment-item {
        border-left: 4px solid #fff;
        background-color: #000;
    }
}

/* ============================================================
   PERFORMANCE OPTIMIZATIONS
   ============================================================ */

/* GPU acceleration for smooth animations */
.modal-container,
.story-iframe,
.comments-list {
    will-change: transform;
    transform: translateZ(0);
}

/* Optimize repaints */
.modal-content {
    contain: layout style paint;
}

/* Reduce layout thrashing */
.modal-container {
    contain: layout style;
}

/* ============================================================
   THEME INTEGRATION
   ============================================================ */

/* Matrix theme specific */
[data-theme="matrix"] .modal-title {
    color: #00ff00;
    text-shadow: 0 0 5px #00ff00;
}

[data-theme="matrix"] .tab-button.active {
    background-color: #00ff00;
    color: #000;
}

/* Amber theme specific */
[data-theme="amber"] .modal-title {
    color: #ffaa00;
    text-shadow: 0 0 5px #ffaa00;
}

[data-theme="amber"] .tab-button.active {
    background-color: #ffaa00;
    color: #000;
}

/* White terminal theme specific */
[data-theme="white-terminal"] .modal-title {
    color: #ffffff;
    text-shadow: 0 0 5px #ffffff;
}

[data-theme="white-terminal"] .tab-button.active {
    background-color: #ffffff;
    color: #000;
}