/* AI History Dropdown Container */
.ai-history-dropdown {
    position: relative;
    display: inline-block;
}

/* Base font for all AI history content */
.ai-history-menu,
.ai-history-modal-content {
    font-family: 'Heebo', Tahoma, Arial, sans-serif;
}

/* AI History Menu (Dropdown Panel) */
.ai-history-menu {
    position: absolute;
    top: 100%;
    left: -10px;
    margin-top: 8px;
    width: 380px;
    max-width: calc(100vw - 40px);
    max-height: 450px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    z-index: 3000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    direction: rtl;
    overflow: hidden;
}

.ai-history-dropdown.open .ai-history-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Header */
.ai-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
    background: linear-gradient(135deg, #f8fafc, #f1f5f9);
}

.ai-history-title {
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #374151;
}

.ai-history-title i {
    color: #1e3a5f;
}

.ai-history-close {
    background: none;
    border: none;
    font-size: 16px;
    color: #6b7280;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.ai-history-close:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* Filters */
.ai-history-filters {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    border-bottom: 1px solid #e2e8f0;
    background: white;
}

.ai-history-filters .filter-btn {
    padding: 5px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    background: white;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    color: #6b7280;
}

.ai-history-filters .filter-btn:hover {
    background: rgba(30, 58, 95, 0.1);
    border-color: #1e3a5f;
    color: #1e3a5f;
}

.ai-history-filters .filter-btn.active {
    background: #1e3a5f;
    color: white;
    border-color: #1e3a5f;
}

/* Content */
.ai-history-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    max-height: 350px;
}

/* Custom scrollbar */
.ai-history-content::-webkit-scrollbar {
    width: 6px;
}

.ai-history-content::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.ai-history-content::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #1e3a5f, #2d4a6f);
    border-radius: 3px;
}

.ai-history-content::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #162d4a, #1e3a5f);
}

.ai-history-empty {
    text-align: center;
    color: #9ca3af;
    padding: 30px 16px;
    font-size: 13px;
}

/* Entry */
.ai-history-entry {
    background: #f9fafb;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 10px;
    overflow: hidden;
    transition: all 0.15s ease;
}

.ai-history-entry:hover {
    border-color: #9ca3af;
    box-shadow: 0 2px 8px rgba(156, 163, 175, 0.1);
}

.ai-history-entry .entry-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: white;
    border-bottom: 1px solid #e2e8f0;
}

.ai-history-entry .entry-icon {
    font-size: 14px;
}

.ai-history-entry .entry-label {
    font-weight: 500;
    flex: 1;
    font-size: 13px;
    color: #374151;
}

.ai-history-entry .entry-time {
    font-size: 11px;
    color: #9ca3af;
}

.ai-history-entry .entry-delete {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px;
    opacity: 0;
    transition: all 0.15s ease;
    border-radius: 4px;
}

.ai-history-entry:hover .entry-delete {
    opacity: 1;
}

.ai-history-entry .entry-delete:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* Entry Body */
.ai-history-entry .entry-body {
    padding: 12px;
}

.ai-history-entry .entry-section {
    margin-bottom: 12px;
}

.ai-history-entry .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: 12px;
    color: #6b7280;
}

.ai-history-entry .section-content {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 8px;
    font-size: 12px;
    line-height: 1.5;
    max-height: 80px;
    overflow: hidden;
}

.ai-history-entry .original-text {
    border-bottom: 1px solid #ef4444;
    border-right: none;
    border-radius: 6px 6px 0 0;
}

.ai-history-entry .corrected-text {
    border-bottom: 1px solid #1e3a5f;
    border-right: none;
    border-radius: 6px 6px 0 0;
}

/* Suggestions */
.ai-history-entry .suggestions-list {
    margin-bottom: 8px;
}

.ai-history-entry .suggestion-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 12px;
}

.ai-history-entry .suggestion-original {
    color: #6b7280;
    text-decoration: underline;
    text-decoration-color: #ef4444;
    text-underline-offset: 2px;
}

.ai-history-entry .suggestion-arrow {
    color: #9ca3af;
    font-size: 11px;
}

.ai-history-entry .suggestion-replacement {
    color: #1f2937;
}

.ai-history-entry .more-suggestions {
    text-align: center;
    color: #6b7280;
    font-size: 11px;
    padding: 6px;
}

/* Buttons */
.ai-history-entry .copy-btn,
.ai-history-menu .copy-btn {
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.15s ease;
}

.ai-history-entry .copy-btn:hover,
.ai-history-menu .copy-btn:hover {
    background: rgba(30, 58, 95, 0.1);
    color: #1e3a5f;
    border-color: #1e3a5f;
}

.ai-history-entry .view-full-btn {
    display: block;
    width: 100%;
    padding: 8px;
    background: #f3f4f6;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.15s ease;
}

.ai-history-entry .view-full-btn:hover {
    background: rgba(30, 58, 95, 0.1);
    color: #1e3a5f;
}

/* Entry Actions */
.ai-history-entry .entry-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* Modal */
.ai-history-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.ai-history-modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 20px;
    position: relative;
    direction: rtl;
}

.ai-history-modal .modal-close {
    position: absolute;
    top: 15px;
    left: 15px;
    background: none;
    border: none;
    font-size: 20px;
    color: #6b7280;
    cursor: pointer;
}

/* Full View */
.ai-history-full-view .full-view-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e5e7eb;
}

.ai-history-full-view .full-view-section {
    margin-bottom: 20px;
}

.ai-history-full-view .full-view-section h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: #6b7280;
}

.ai-history-full-view .full-text-box {
    position: relative;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 15px;
}

.ai-history-full-view .full-text-box pre {
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.7;
}

.ai-history-full-view .full-text-box .copy-btn.floating {
    position: absolute;
    top: 10px;
    left: 10px;
}

.ai-history-full-view .full-text-box.original-text-box {
    border-bottom: 1px solid #ef4444;
}

.ai-history-full-view .full-text-box.corrected-text-box {
    border-bottom: 1px solid #1e3a5f;
}

/* Full Suggestions */
.ai-history-full-view .full-suggestions-list {
    margin-bottom: 20px;
}

.ai-history-full-view .full-suggestion-item {
    display: flex;
    gap: 15px;
    padding: 15px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin-bottom: 10px;
}

.ai-history-full-view .suggestion-number {
    width: 30px;
    height: 30px;
    background: #1e3a5f;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.ai-history-full-view .suggestion-content {
    flex: 1;
}

.ai-history-full-view .suggestion-original-wrapper,
.ai-history-full-view .suggestion-replacement-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.ai-history-full-view .full-suggestion-item .suggestion-original {
    flex: 1;
    display: block;
    padding: 8px;
    background: #f9fafb;
    border-radius: 4px;
    color: #6b7280;
    text-decoration: underline;
    text-decoration-color: #ef4444;
    text-underline-offset: 2px;
}

.ai-history-full-view .full-suggestion-item .suggestion-arrow {
    display: block;
    text-align: center;
    color: #9ca3af;
    margin: 5px 0;
}

.ai-history-full-view .full-suggestion-item .suggestion-replacement {
    flex: 1;
    display: block;
    padding: 8px;
    background: #f9fafb;
    border-radius: 4px;
    color: #1f2937;
}

.ai-history-full-view .copy-btn-small {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    background: white;
    color: #9ca3af;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.ai-history-full-view .copy-btn-small:hover {
    background: #f3f4f6;
    color: #1e3a5f;
    border-color: #1e3a5f;
}

.ai-history-full-view .suggestion-explanation {
    margin-top: 10px;
    padding: 8px;
    background: #f3f4f6;
    border-radius: 4px;
    font-size: 12px;
    color: #6b7280;
}

.ai-history-full-view .copy-btn.full-width {
    width: 100%;
    padding: 12px;
    font-size: 14px;
}

/* Full View Actions (copy all button) */
.ai-history-full-view .full-view-actions {
    margin-bottom: 15px;
}

.ai-history-full-view .full-view-actions .copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    background: linear-gradient(135deg, #1e3a5f, #2d4a6f);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-history-full-view .full-view-actions .copy-btn:hover {
    background: linear-gradient(135deg, #162d4a, #1e3a5f);
    box-shadow: 0 4px 12px rgba(30, 58, 95, 0.3);
}

/* Toast */
.ai-history-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 3000;
    animation: ai-history-toast-in 0.3s ease;
}

@keyframes ai-history-toast-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Toolbar Button */
#aiHistoryBtn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 2px;
    width: auto;
    padding: 8px 6px;
}

#aiHistoryBtn::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 6px;
    height: 6px;
    background: #1e3a5f;
    border-radius: 50%;
    display: none;
}

#aiHistoryBtn.has-history::after {
    display: block;
}

/* Animation for entries when dropdown opens */
.ai-history-dropdown.open .ai-history-entry {
    animation: slideInEntry 0.2s ease forwards;
}

@keyframes slideInEntry {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-history-entry:nth-child(1) { animation-delay: 0.05s; }
.ai-history-entry:nth-child(2) { animation-delay: 0.1s; }
.ai-history-entry:nth-child(3) { animation-delay: 0.15s; }
.ai-history-entry:nth-child(4) { animation-delay: 0.2s; }
.ai-history-entry:nth-child(5) { animation-delay: 0.25s; }
