/* ==================== Unified Reviews Styling (Modernized) ==================== */

:root {
    /* Color Palette */
    --primary-color: #2196F3;
    --primary-dark: #1976D2;
    --success-color: #4CAF50;
    --success-bg: #E8F5E9;
    --warning-color: #FF9800;
    --warning-bg: #FFF3E0;
    --danger-color: #F44336;
    --danger-bg: #FFEBEE;
    --text-main: #333333;
    --text-muted: #666666;
    --bg-body: #F8F9FA;
    --bg-white: #FFFFFF;

    /* Spacing & Borders */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-hover: 0 8px 24px rgba(0,0,0,0.12);
    --transition-speed: 0.25s;
}

/* ==================== Layout & Stats ==================== */

/* Stats Header */
.reviews-stats-header {
    display: flex;
    gap: 24px;
    align-items: center;
    flex-wrap: wrap;
    padding: 16px 0;
}

.stat-item {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-white);
    padding: 8px 16px;
    border-radius: 20px;
    box-shadow: var(--shadow-sm);
}

.stat-item span {
    font-weight: 700;
    color: var(--primary-color);
    margin-left: 6px;
}

/* Filters Grid */
.reviews-filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
    align-items: center;
}

.filter-select,
.filter-input {
    padding: 12px 16px;
    border: 1px solid #e0e0e0;
    border-radius: var(--radius-md);
    font-size: 14px;
    background: var(--bg-white);
    transition: all var(--transition-speed) ease;
    width: 100%;
    box-sizing: border-box; /* Ensures padding doesn't break width */
}

.filter-select:hover,
.filter-input:hover {
    border-color: #b0bec5;
}

.filter-select:focus,
.filter-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.15); /* Accessible Focus Ring */
}

/* Checkbox Filter Group */
.filter-group.filter-checkboxes {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    padding: 12px 16px;
    background: var(--bg-white);
    border: 1px solid #e0e0e0;
    border-radius: var(--radius-md);
}

.filter-label {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-main);
    margin-right: 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-main);
    transition: color var(--transition-speed) ease;
}

.checkbox-label:hover {
    color: var(--primary-color);
}

.checkbox-label input[type="checkbox"] {
    cursor: pointer;
    width: 18px;
    height: 18px;
    accent-color: var(--primary-color);
}

.checkbox-label span {
    user-select: none;
}

/* ==================== Collapsible Sections ==================== */

.reviews-section {
    margin-bottom: 32px;
}

.reviews-section.collapsed .reviews-cards-list {
    display: none;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: var(--bg-white);
    border-radius: var(--radius-md);
    cursor: pointer;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid transparent;
    transition: all var(--transition-speed) ease;
}

.section-header:hover {
    border-color: #e0e0e0;
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.section-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-main);
}

.toggle-icon {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 1rem;
    color: var(--text-muted);
}

.reviews-section:not(.collapsed) .toggle-icon {
    transform: rotate(180deg);
}

/* ==================== Card Design ==================== */

.reviews-cards-list {
    display: flex;
    flex-direction: column;
    gap: 32px; /* Increased from 16px for better separation */
}

.sentence-card, .history-card {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md); /* Increased from shadow-sm for more prominence */
    border: 2px solid #e8e8e8; /* Thicker, more visible border */
    border-left: 5px solid #E0E0E0;
    cursor: pointer;
    position: relative;
    transition: all var(--transition-speed) ease;

    /* Add stronger visual containment */
    isolation: isolate; /* Creates stacking context to contain child elements */
}

.sentence-card:hover, .history-card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-3px);
}

.sentence-card:active, .history-card:active {
    transform: scale(0.99);
}

/* --- Semantic Coloring (Optimized) --- */

/* Failure / Low Score */
.sentence-card[data-score^="0.0"],
.sentence-card[data-score^="0.1"],
.sentence-card[data-score^="0.2"],
.sentence-card[data-score^="0.3"],
.sentence-card[data-score^="0.4"] {
    background: linear-gradient(to right, var(--danger-bg), #fff 30%);
    border-left-color: var(--danger-color);
}

/* Average / Medium Score */
.sentence-card[data-score^="0.5"],
.sentence-card[data-score^="0.6"],
.sentence-card[data-score^="0.7"] {
    background: linear-gradient(to right, var(--warning-bg), #fff 30%);
    border-left-color: var(--warning-color);
}

/* Good / High Score */
.sentence-card[data-score^="0.8"],
.sentence-card[data-score^="0.9"] {
    background: linear-gradient(to right, var(--success-bg), #fff 30%);
    border-left-color: #8BC34A;
}

/* Perfect Score */
.sentence-card[data-score="1"],
.sentence-card[data-score="1.0"] {
    background: linear-gradient(to right, #C8E6C9, #fff 40%);
    border-left-color: var(--success-color);
}

/* History Status Colors */
.history-card.completed {
    border-left-color: var(--success-color);
    background: linear-gradient(to right, #f1f8e9, #fff 15%);
}

.history-card.skipped {
    border-left-color: var(--warning-color);
    background: linear-gradient(to right, #fff8e1, #fff 15%);
}

/* Edited Badge */
.history-card.edited {
    border-left-color: #FF5722;
}

.history-card.edited::after {
    content: 'EDITED';
    position: absolute;
    top: 0;
    right: 20px;
    background: #FF5722;
    color: white;
    padding: 4px 10px;
    border-radius: 0 0 6px 6px; /* Bookmark style */
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 4px rgba(255,87,34,0.3);
}

/* Card Content Layout */
.card-header-review, .history-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start; /* Better alignment for multi-line titles */
    margin-bottom: 16px;
    gap: 12px;
}

.card-title-review, .history-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.4;
    flex: 1;
}

/* Badges */
.score-badge, .history-status-badge {
    padding: 4px 12px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.score-badge.score-low { background: var(--danger-bg); color: var(--danger-color); }
.score-badge.score-mid { background: var(--warning-bg); color: #F57C00; }
.score-badge.score-high { background: #E8F5E9; color: #2E7D32; }
.score-badge.score-perfect {
    background: var(--success-color);
    color: white;
    box-shadow: 0 2px 8px rgba(76,175,80,0.3);
}

/* ==================== Word Display ==================== */

.words-display {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px; /* More space above to separate from sentence */
    margin-bottom: 0; /* Remove bottom margin - card padding handles it */
    padding-top: 16px; /* Internal padding for breathing room */
    border-top: 1px solid #f0f0f0; /* Subtle divider line */
}

.word-box {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 14px;
    border: 1px solid transparent;
    position: relative;
}

/* Icons moved inside using Flexbox logic ideally, but keeping ::before for compatibility */
.word-box.verified {
    background: var(--success-bg);
    border-color: rgba(76,175,80,0.3);
    color: #1B5E20;
    padding-right: 32px; /* Make room for icon */
}

.word-box.verified::before {
    content: "✓"; /* Cleaner than emoji */
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    font-weight: bold;
}

.word-box.unverified {
    background: var(--danger-bg);
    border-color: rgba(244,67,54,0.3);
    color: #B71C1C;
    padding-right: 32px;
}

.word-box.unverified::before {
    content: "✕";
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    font-weight: bold;
}

.word-box.edited {
    background: var(--warning-bg);
    border-color: rgba(255,152,0,0.3);
    color: #E65100;
    padding-right: 32px;
}

.word-box.edited::before {
    content: "✎";
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
}

/* Meta Data */
.card-meta-review, .history-card-meta {
    display: flex;
    gap: 16px;
    margin-top: 16px;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid #f0f0f0;
    padding-top: 12px;
}

.card-meta-review span, .history-card-meta span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* ==================== Modals & Forms ==================== */

.review-score-display {
    text-align: center;
    margin-bottom: 32px;
    padding: 32px;
    background: radial-gradient(circle at center, #E3F2FD 0%, #ffffff 70%);
    border-radius: var(--radius-lg);
    border: 1px solid #BBDEFB;
}

.review-score-display h3 {
    margin: 0;
    font-size: 28px;
    color: #1976D2;
}

#live-score {
    font-weight: 700;
    color: #0D47A1;
    transition: all 0.5s ease;
}

#live-score-emoji {
    font-size: 32px;
    display: inline-block;
    transition: all 0.5s ease;
}

.sentence-display-section {
    margin-bottom: 24px;
}

.sentence-display-section h4 {
    margin-bottom: 12px;
    color: #333;
    font-size: 16px;
}

.edit-section {
    margin: 24px 0;
    padding: 24px;
    background: #FAFAFA;
    border-radius: var(--radius-md);
    border: 1px solid #eee;
}

.edit-section h4 {
    margin-bottom: 16px;
    color: #333;
}

.edit-word-item {
    background: var(--bg-white);
    border: 1px solid #eee;
    border-left: 4px solid var(--warning-color);
    padding: 20px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.word-pair-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.word-pair-header h5 {
    margin: 0;
    color: #E65100;
    font-size: 14px;
}

.quick-actions {
    display: flex;
    gap: 8px;
}

/* Inputs inside Modal */
.edit-word-current {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.edit-word-current label {
    font-weight: 500;
    color: #666;
    min-width: 80px;
}

.edit-word-current span {
    padding: 6px 12px;
    background: #FFEBEE;
    border: 1px solid #F44336;
    border-radius: 4px;
    color: #C62828;
    font-weight: 500;
}

.edit-word-input {
    display: flex;
    align-items: center;
    gap: 12px;
}

.edit-word-input label {
    font-weight: 500;
    color: #333;
    min-width: 80px;
}

.edit-word-input input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: var(--radius-sm);
    transition: 0.2s;
}

.edit-word-input input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
    outline: none;
}

/* Buttons */
.btn-xs {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    border: none;
}

.btn-xs.btn-success {
    background: var(--success-bg);
    color: #1B5E20;
    border: 1px solid rgba(76,175,80,0.2);
}
.btn-xs.btn-success:hover { background: #C8E6C9; }

.btn-xs.btn-secondary {
    background: #eee;
    color: #555;
}
.btn-xs.btn-secondary:hover { background: #e0e0e0; }

/* Sentence Metadata */
.sentence-metadata {
    margin-top: 24px;
    padding: 16px;
    background: #F5F5F5;
    border-radius: 8px;
}

.sentence-metadata p {
    margin: 8px 0;
    color: #666;
    font-size: 14px;
}

.sentence-metadata strong {
    color: #333;
}

/* Edit Warning Banner */
.edit-warning-banner {
    background: linear-gradient(135deg, #FFF3E0 0%, #FFE0B2 100%);
    border-left: 4px solid #FF9800;
    padding: 16px;
    margin-bottom: 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.edit-warning-banner i {
    font-size: 24px;
    color: #F57C00;
}

.edit-warning-banner .warning-content {
    flex: 1;
}

.edit-warning-banner strong {
    color: #E65100;
    display: block;
    margin-bottom: 4px;
}

.edit-warning-banner p {
    margin: 0;
    color: #666;
    font-size: 14px;
}

/* ==================== Timeline ==================== */

.edit-history-section {
    margin-top: 32px;
}

.edit-history-section h4 {
    margin: 0 0 20px 0;
    color: #333;
    font-size: 16px;
}

.edit-timeline {
    position: relative;
    padding-left: 32px;
}

/* The line */
.edit-timeline::before {
    content: '';
    position: absolute;
    left: 11px; /* Center line with marker */
    top: 8px;
    bottom: 0;
    width: 2px;
    background: #E0E0E0;
}

.timeline-item {
    position: relative;
    margin-bottom: 28px;
}

.timeline-item:last-child {
    margin-bottom: 0;
}

.timeline-marker {
    position: absolute;
    left: -32px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg-white);
    border: 2px solid var(--text-muted);
    z-index: 2;
    /* Center icon if used */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.timeline-marker.edit { border-color: var(--warning-color); color: var(--warning-color); }
.timeline-marker.completed { border-color: var(--success-color); color: var(--success-color); background: var(--success-bg); }
.timeline-marker.skipped { border-color: #FFC107; }

.timeline-content {
    background: var(--bg-white);
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid #eee;
    box-shadow: var(--shadow-sm);
}

.timeline-content strong {
    color: #333;
    display: block;
    margin-bottom: 4px;
}

.timeline-content .timeline-meta {
    font-size: 13px;
    color: #666;
    margin-bottom: 8px;
}

.timeline-content .timeline-changes {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #E0E0E0;
}

.timeline-change-item {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    padding: 8px;
    background: #fafafa;
    border-radius: 4px;
    font-size: 13px;
}

.timeline-change-item .old-value { color: var(--danger-color); text-decoration: line-through; opacity: 0.7; }
.timeline-change-item .new-value { color: var(--success-color); font-weight: 600; }
.timeline-change-item i { color: var(--text-muted); font-size: 10px; }

/* Badge for sidebar */
.badge {
    display: inline-block;
    padding: 2px 8px;
    margin-left: 8px;
    background: #F44336;
    color: white;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

/* Empty State */
.empty-state, .empty-history-state {
    text-align: center;
    padding: 60px 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.empty-history-state i {
    font-size: 64px;
    color: #BDBDBD;
    margin-bottom: 16px;
}

.empty-history-state h3 {
    margin: 0 0 12px 0;
    color: #666;
}

.empty-history-state p {
    color: #999;
    margin-bottom: 24px;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: 32px;
}

/* Loading State */
.history-loading {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}

.history-loading i {
    font-size: 32px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Review Modal */
.review-modal-content {
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
}

/* ==================== Responsive ==================== */

@media (max-width: 768px) {
    .reviews-stats-header {
        flex-direction: column;
        align-items: flex-start;
    }

    /* Grid handles filters automatically, but we can tweak spacing */
    .reviews-filters {
        gap: 12px;
    }

    .sentence-card, .history-card {
        padding: 16px;
    }

    .edit-word-current, .edit-word-input {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .edit-word-current label, .edit-word-input label {
        min-width: auto;
    }

    .edit-word-input input {
        width: 100%;
    }

    /* Better word wrapping on mobile */
    .words-display {
        gap: 8px;
    }

    .word-box {
        font-size: 13px;
        padding: 6px 10px;
        /* Adjust icon padding */
        padding-right: 26px;
    }

    .history-card-header {
        flex-direction: column;
    }

    .history-status-badge {
        margin-left: 0;
        margin-top: 8px;
    }

    .history-card-meta {
        flex-direction: column;
        gap: 8px;
    }

    .edit-timeline {
        padding-left: 30px;
    }

    .timeline-marker {
        width: 20px;
        height: 20px;
        left: -28px;
    }

    .review-modal-content {
        max-width: 95%;
    }
}

/* Scroll to Top Button */
.scroll-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.4);
    transition: all var(--transition-speed) ease;
    z-index: 1000;
}

.scroll-to-top:hover {
    background: var(--primary-dark);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(33, 150, 243, 0.6);
}

.scroll-to-top i {
    font-size: 18px;
}

/* Accessibility: Reduce Motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
