/* Emma Progress Dashboard v3.2 - Memory Integration + RWD/Accordion Fix
 * Merges v3 Memory styles with v3.1's RWD improvements
 */

:root {
    /* Morandi Palette */
    --bg-primary: #FDFBF7;
    --bg-secondary: #F5F3EF;
    --text-primary: #5A5A5A;
    --text-secondary: #8A8A8A;
    --border-color: #E0DCD5;

    /* Status Colors */
    --color-done: #A2C388;
    --color-in-progress: #6695CC;
    --color-todo: #F4D03F;
    --color-warning: #C24F4F;

    /* Module Colors */
    --m1-color: #8E9E82;
    --m2-color: #C24F4F;
    --m3-color: #A2C388;
    --m4-color: #D4AF37;
    --m6-color: #6695CC;
    --m7-color: #F4D03F;
    --m9-color: #CDE2F5;
    --arcade-color: #B5A3C4;
    --profile-color: #E3DED1;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Border */
    --border-radius: 12px;
    --border-width: 2px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 1.0rem;
}

/* Font Hierarchy */
h1 { font-size: 2.2rem; font-weight: 700; }
h2 { font-size: 1.6rem; font-weight: 700; }
h3 { font-size: 1.2rem; font-weight: 700; }
.meta { font-size: 0.85rem; }

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--spacing-lg);
}

/* Header */
.dashboard-header {
    background: linear-gradient(135deg, var(--m1-color) 0%, var(--m6-color) 100%);
    border-radius: var(--border-radius);
    padding: var(--spacing-xl);
    margin-bottom: var(--spacing-lg);
    color: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.header-content h1 {
    font-size: 2.2rem;
}

.header-meta {
    display: flex;
    gap: var(--spacing-md);
    font-size: 0.85rem;
    opacity: 0.9;
    text-align: right;
}

/* Summary Stats */
.summary-section {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

.stat-card {
    background: white;
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--spacing-lg);
    text-align: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.stat-card.done { border-left: 4px solid var(--color-done); }
.stat-card.in-progress { border-left: 4px solid var(--color-in-progress); }
.stat-card.todo { border-left: 4px solid var(--color-todo); }
.stat-card.overall { border-left: 4px solid var(--m6-color); }

.stat-value { font-size: 2rem; font-weight: 700; color: var(--text-primary); }
.stat-label { font-size: 0.85rem; color: var(--text-secondary); margin-top: var(--spacing-xs); }

/* Section Headers */
.section-header {
    font-size: 1.6rem;
    margin-bottom: var(--spacing-md);
}

/* --- MEMORY STATUS BAR (from v3) --- */
.memory-status-section {
    margin-bottom: var(--spacing-lg);
}

.memory-status-bar {
    background: white;
    border: var(--border-width) solid var(--border-color);
    border-left: 4px solid var(--m6-color);
    border-radius: var(--border-radius);
    padding: var(--spacing-md) var(--spacing-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

.memory-status-title {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.memory-status-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.memory-status-info .device-badge {
    background: var(--m1-color);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.memory-status-stats {
    display: flex;
    gap: var(--spacing-md);
    font-size: 0.85rem;
}

.memory-status-stats span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* --- NEXT ACTIONS PANEL (from v3) --- */
.next-actions-section {
    margin-bottom: var(--spacing-xl);
    background: white;
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.next-actions-section h2 {
    font-size: 1.1rem;
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.next-actions-list {
    padding: var(--spacing-md);
}

.next-action-card {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
}

.next-action-card:last-child {
    margin-bottom: 0;
}

.next-action-title {
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
}

.next-action-anchors {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-xs);
}

.next-action-anchor {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.next-action-anchor:hover {
    background: var(--bg-primary);
    border-color: var(--m6-color);
}

.next-action-anchor.copied {
    background: #d4edda;
    border-color: #28a745;
}

/* Rich Menu Grid */
.rich-menu-section {
    margin-bottom: var(--spacing-xl);
}

.rich-menu-section h2 {
    font-size: 1.2rem;
    margin-bottom: var(--spacing-md);
}

.rich-menu-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-sm);
    background: white;
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
}

.rich-menu-cell {
    aspect-ratio: 1.5;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: var(--border-width) solid rgba(0, 0, 0, 0.1);
}

.rich-menu-cell:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.rich-menu-cell .cell-id { font-size: 1.2rem; font-weight: 700; }
.rich-menu-cell .cell-progress { font-size: 0.9rem; opacity: 0.9; margin-top: var(--spacing-xs); }

/* Modules Grid */
.modules-section h2 {
    font-size: 1.2rem;
    margin-bottom: var(--spacing-md);
}

.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--spacing-md);
}

.module-card {
    background: white;
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.module-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.module-card-header {
    padding: var(--spacing-md);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.module-card-header h3 { font-size: 1.2rem; }
.module-card-header .progress-badge { background: rgba(255, 255, 255, 0.2); padding: var(--spacing-xs) var(--spacing-sm); border-radius: 20px; font-size: 0.85rem; font-weight: 600; }

.module-card-body { padding: var(--spacing-md); }
.module-card-name { font-size: 0.95rem; color: var(--text-secondary); margin-bottom: var(--spacing-sm); }

.progress-bar { height: 8px; background: var(--bg-secondary); border-radius: 4px; overflow: hidden; margin-bottom: var(--spacing-sm); }
.progress-bar-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease; }

.module-stats { display: flex; gap: var(--spacing-md); font-size: 0.8rem; color: var(--text-secondary); }
.module-stats span { display: flex; align-items: center; gap: 4px; }
.module-stats .dot { width: 8px; height: 8px; border-radius: 50%; }
.module-stats .dot.done { background: var(--color-done); }
.module-stats .dot.in-progress { background: var(--color-in-progress); }
.module-stats .dot.todo { background: var(--color-todo); }

/* --- RECENT ACTIVITY TIMELINE (from v3) --- */
.recent-activity-section {
    margin-bottom: var(--spacing-xl);
    background: white;
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.recent-activity-section h2 {
    font-size: 1.1rem;
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.timeline-list {
    padding: var(--spacing-md);
    max-height: 400px;
    overflow-y: auto;
}

.timeline-entry {
    display: flex;
    gap: var(--spacing-md);
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--border-color);
}

.timeline-entry:last-child { border-bottom: none; }

.timeline-date {
    min-width: 60px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.timeline-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--m1-color);
    margin-top: 4px;
    flex-shrink: 0;
}

.timeline-dot.device-pc { background: var(--m6-color); }

.timeline-content { flex: 1; }
.timeline-topic { font-weight: 600; margin-bottom: 2px; }

.timeline-stats {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    gap: var(--spacing-sm);
}

.timeline-stats .device-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    padding: 1px 4px;
    border-radius: 2px;
    background: var(--bg-secondary);
}

/* --- ORPHANED TASKS (from v3) --- */
.orphaned-tasks-section {
    margin-bottom: var(--spacing-xl);
    background: white;
    border: var(--border-width) solid var(--border-color);
    border-left: 4px solid var(--color-warning);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.orphaned-header {
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.orphaned-header h2 {
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.orphaned-toggle {
    background: none;
    border: 1px solid var(--border-color);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.2s;
}

.orphaned-toggle:hover { background: var(--bg-primary); }

.orphaned-content {
    padding: var(--spacing-md);
    display: none;
}

.orphaned-content.expanded { display: block; }

.orphaned-category { margin-bottom: var(--spacing-md); }

.orphaned-category-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.orphaned-category-title.core { color: #dc3545; }
.orphaned-category-title.voice { color: #fd7e14; }
.orphaned-category-title.frontend { color: #20c997; }
.orphaned-category-title.backend { color: #6f42c1; }
.orphaned-category-title.general { color: var(--text-secondary); }

.orphaned-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-radius: 4px;
}

.orphaned-item:hover { background: var(--bg-secondary); }

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

.modal.active { display: flex; }

.modal-content {
    background: white;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 600px;
    min-width: 320px;
    min-height: 200px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Resizable Handle */
.resize-handle {
    position: absolute;
    bottom: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    background: transparent;
    cursor: nwse-resize;
    z-index: 1100;
}

.resize-handle::after {
    content: '';
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 8px;
    height: 8px;
    border-bottom: 2px solid var(--text-secondary);
    border-right: 2px solid var(--text-secondary);
    opacity: 0.5;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 { font-size: 1.2rem; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-secondary); }
.modal-body { padding: var(--spacing-lg); overflow-y: auto; flex-grow: 1; }

/* Feature List */
.feature-section { margin-bottom: var(--spacing-lg); }

.feature-section h4 {
    font-size: 1rem;
    font-weight: 600;
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: var(--spacing-md);
    color: var(--text-secondary);
}

.feature-item {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm);
    border-radius: 6px;
    background: var(--bg-secondary);
    margin-bottom: var(--spacing-xs);
    font-size: 0.9rem;
}

.feature-item .status-icon {
    flex-shrink: 0;
    margin-top: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: white;
    font-weight: bold;
}

.feature-item .status-icon.done { background: var(--color-done); }
.feature-item .status-icon.in-progress { background: var(--color-in-progress); }
.feature-item .status-icon.todo { background: var(--color-todo); }

.feature-item .feature-details { flex-grow: 1; }
.feature-item .feature-name { font-weight: 600; }
.feature-item .feature-meta { font-size: 0.8rem; color: var(--text-secondary); margin-top: var(--spacing-xs); }

/* Priority Badges */
.priority-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    color: white;
    text-transform: uppercase;
}
.priority-badge.p0 { background-color: #d9534f; }
.priority-badge.p1 { background-color: #f0ad4e; }
.priority-badge.p2 { background-color: #5bc0de; }
.priority-badge.p3 { background-color: #777777; }

/* Missing Data Warnings */
.missing-warning {
    display: inline-block;
    margin-top: 6px;
    padding: 4px 8px;
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: bold;
}
.feature-desc {
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-top: 4px;
    margin-bottom: 4px;
}

/* --- RESPONSIVE DESIGN (from v3.1) --- */
@media (max-width: 768px) {
    body {
        font-size: 15px;
    }
    #app {
        padding: var(--spacing-md);
    }
    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-sm);
    }
    .summary-section {
        grid-template-columns: repeat(3, 1fr);
    }
    .rich-menu-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .modules-grid {
        grid-template-columns: 1fr;
    }

    /* Accordion Styles for Mobile */
    .feature-section.is-accordion .feature-list {
        display: none;
    }
    .feature-section.is-accordion.is-open .feature-list {
        display: block;
    }
    .feature-section.is-accordion .section-header {
        cursor: pointer;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--spacing-sm) 0;
        user-select: none;
    }
    .feature-section.is-accordion .section-header::after {
        content: '▼';
        font-size: 0.8rem;
        transition: transform 0.2s;
    }
    .feature-section.is-accordion.is-open .section-header::after {
        transform: rotate(180deg);
    }
    
    /* Memory Status responsive */
    .memory-status-bar {
        flex-direction: column;
        align-items: flex-start;
    }
    .memory-status-info {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-xs);
    }
    .memory-status-stats {
        flex-wrap: wrap;
    }
}
