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

body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a5f3f 0%, #2d7a5a 50%, #1a5f3f 100%);
    min-height: 100vh;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        repeating-linear-gradient(45deg, transparent, transparent 35px, rgba(255,255,255,.03) 35px, rgba(255,255,255,.03) 70px);
    pointer-events: none;
}

.container {
    max-width: 1200px;
    width: 100%;
    background: white;
    border-radius: 20px;
    box-shadow: 0 25px 70px rgba(0,0,0,0.4);
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.header {
    background: linear-gradient(135deg, #1a5f3f 0%, #2d7a5a 100%);
    color: white;
    padding: 35px 30px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -10%;
    width: 200px;
    height: 200px;
    background: rgba(255,255,255,0.05);
    border-radius: 50%;
}

.header::after {
    content: '';
    position: absolute;
    bottom: -50%;
    left: -10%;
    width: 200px;
    height: 200px;
    background: rgba(255,255,255,0.05);
    border-radius: 50%;
}

.header-content {
    position: relative;
    z-index: 1;
}

.header h1 {
    font-size: 2em;
    margin-bottom: 8px;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

.header .subtitle {
    opacity: 0.95;
    font-size: 1.15em;
    font-weight: 400;
    margin-top: 5px;
}

.header-icon {
    font-size: 2.5em;
    margin-bottom: 15px;
    opacity: 0.9;
}

.header-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.header-btn {
    padding: 10px 20px;
    background: rgba(255,255,255,0.2);
    color: white;
    border: 2px solid rgba(255,255,255,0.5);
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
}

.header-btn:hover {
    background: rgba(255,255,255,0.3);
    border-color: rgba(255,255,255,0.8);
    transform: translateY(-2px);
}

.content {
    padding: 40px;
}

.search-box {
    margin-bottom: 30px;
}

.search-box label {
    display: block;
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 10px;
    color: #2d5a3f;
}

.input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

#queryInput {
    flex: 1;
    padding: 15px 20px;
    font-size: 1em;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    transition: all 0.3s;
    font-family: inherit;
}

#queryInput:focus {
    outline: none;
    border-color: #2d7a5a;
    box-shadow: 0 0 0 3px rgba(45, 122, 90, 0.1);
}

#instructionsInput {
    width: 100%;
    padding: 12px 20px;
    font-size: 0.95em;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    transition: all 0.3s;
    font-family: inherit;
    resize: vertical;
    min-height: 100px;
}

#instructionsInput:focus {
    outline: none;
    border-color: #2d7a5a;
    box-shadow: 0 0 0 3px rgba(45, 122, 90, 0.1);
}

.instructions-container {
    margin-bottom: 15px;
}

.instructions-label {
    font-size: 0.95em;
    color: #666;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.instructions-help {
    font-size: 0.85em;
    color: #888;
    margin-top: 5px;
    font-style: italic;
}

#submitBtn {
    padding: 15px 40px;
    background: linear-gradient(135deg, #1a5f3f 0%, #2d7a5a 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
}

#submitBtn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(45, 122, 90, 0.4);
}

#submitBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.advanced-toggle {
    margin-bottom: 20px;
}

.toggle-btn {
    padding: 10px 20px;
    background: #f0f9f5;
    color: #2d7a5a;
    border: 2px solid #2d7a5a;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
}

.toggle-btn:hover {
    background: #2d7a5a;
    color: white;
}

.toggle-btn i {
    transition: transform 0.3s;
}

.toggle-btn.active i {
    transform: rotate(180deg);
}

.advanced-settings {
    display: none;
    background: #f8fafb;
    border: 2px solid #e8f5ef;
    border-radius: 10px;
    padding: 25px;
    margin-top: 15px;
    animation: slideDown 0.3s ease-out;
}

.advanced-settings.active {
    display: block;
}

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

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.setting-group label {
    font-size: 0.9em;
    font-weight: 600;
    color: #2d5a3f;
    display: flex;
    align-items: center;
    gap: 6px;
}

.setting-group input,
.setting-group select,
#profileSelect {
    padding: 10px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 0.9em;
    font-family: inherit;
    transition: all 0.2s;
}

.setting-group input:focus,
.setting-group select:focus,
#profileSelect:focus {
    outline: none;
    border-color: #2d7a5a;
    box-shadow: 0 0 0 3px rgba(45, 122, 90, 0.1);
}

.settings-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding-top: 15px;
    border-top: 2px solid #e8f5ef;
    flex-wrap: wrap;
}

.settings-btn {
    padding: 10px 20px;
    border: 2px solid #2d7a5a;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
}

.settings-btn.primary {
    background: #2d7a5a;
    color: white;
}

.settings-btn.primary:hover {
    background: #1a5f3f;
    transform: translateY(-1px);
}

.settings-btn.secondary {
    background: white;
    color: #2d7a5a;
}

.settings-btn.secondary:hover {
    background: #f0f9f5;
}

.loading {
    display: none;
    text-align: center;
    padding: 30px;
}

.loading.active {
    display: block;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #2d7a5a;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

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

.result-container {
    display: none;
}

.result-container.active {
    display: block;
    animation: fadeIn 0.5s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.answer-box {
    background: linear-gradient(135deg, #f0f9f5 0%, #e8f5ef 100%);
    border-right: 4px solid #2d7a5a;
    padding: 25px;
    border-radius: 10px;
    margin-bottom: 25px;
    position: relative;
}

.answer-box.error {
    background: linear-gradient(135deg, #fff5f5 0%, #ffe5e5 100%);
    border-right-color: #e53e3e;
}

.answer-box.warning {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border-right-color: #f59e0b;
}

.answer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.answer-box h3 {
    color: #2d7a5a;
    font-size: 1.3em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.answer-box.error h3 {
    color: #e53e3e;
}

.answer-box.warning h3 {
    color: #f59e0b;
}

.answer-text {
    font-size: 1.05em;
    line-height: 1.9;
    color: #333;
}

.answer-text p {
    margin-bottom: 1em;
}

.answer-text ul, .answer-text ol {
    margin: 1em 0;
    padding-right: 20px;
}

.answer-text li {
    margin-bottom: 0.5em;
}

.answer-text strong {
    color: #1a5f3f;
    font-weight: 600;
}

.copy-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.copy-btn {
    padding: 8px 16px;
    background: white;
    color: #2d7a5a;
    border: 2px solid #2d7a5a;
    border-radius: 8px;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
}

.copy-btn:hover {
    background: #2d7a5a;
    color: white;
    transform: translateY(-1px);
}

.copy-btn.copied {
    background: #10b981;
    border-color: #10b981;
    color: white;
}

.meta-info {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(45, 122, 90, 0.2);
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
    color: #666;
}

.meta-item i {
    color: #2d7a5a;
}

.meta-item strong {
    color: #333;
}

.sources-section {
    margin-top: 30px;
}

.sources-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.sources-header h3 {
    color: #2d5a3f;
    font-size: 1.3em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.copy-all-btn {
    padding: 10px 20px;
    background: linear-gradient(135deg, #1a5f3f 0%, #2d7a5a 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
}

.copy-all-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(45, 122, 90, 0.3);
}

.copy-all-btn.copied {
    background: #10b981;
}

.source-card {
    background: white;
    border: 2px solid #e8f5ef;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 15px;
    transition: all 0.3s;
}

.source-card:hover {
    border-color: #2d7a5a;
    box-shadow: 0 5px 15px rgba(45, 122, 90, 0.1);
}

.source-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    gap: 15px;
}

.source-title {
    font-weight: 600;
    color: #2d7a5a;
    font-size: 1.05em;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.source-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.source-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #f0f0f0;
}

.source-copy-btn {
    padding: 6px 12px;
    background: #f0f9f5;
    color: #2d7a5a;
    border: 1px solid #2d7a5a;
    border-radius: 6px;
    font-size: 0.8em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: inherit;
}

.source-copy-btn:hover {
    background: #2d7a5a;
    color: white;
}

.source-copy-btn.copied {
    background: #10b981;
    border-color: #10b981;
    color: white;
}

.source-expand-btn {
    padding: 6px 12px;
    background: #f0f0f5;
    color: #555;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.8em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: inherit;
}

.source-expand-btn:hover {
    background: #555;
    color: white;
    border-color: #555;
}

.source-info {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    font-size: 0.85em;
    color: #666;
    margin-bottom: 12px;
}

.source-info-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.source-info-item i {
    color: #2d7a5a;
}

.source-content {
    color: #555;
    line-height: 1.7;
    font-size: 0.95em;
    padding: 14px;
    background: #f8fafb;
    border-radius: 6px;
    border-right: 3px solid #e8f5ef;
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    white-space: nowrap;
}

.badge.similarity {
    background: #10b981;
    color: white;
}

.badge.rerank {
    background: #2d7a5a;
    color: white;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 15px;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalSlideIn 0.3s ease-out;
}

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

.modal-header {
    background: linear-gradient(135deg, #1a5f3f 0%, #2d7a5a 100%);
    color: white;
    padding: 25px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 15px 15px 0 0;
}

.modal-header h2 {
    font-size: 1.5em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 1.5em;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.modal-close:hover {
    background: rgba(255,255,255,0.3);
}

.modal-body {
    padding: 30px;
}

.modal-body textarea {
    width: 100%;
    min-height: 300px;
    padding: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.95em;
    resize: vertical;
}

.modal-body textarea:focus {
    outline: none;
    border-color: #2d7a5a;
    box-shadow: 0 0 0 3px rgba(45, 122, 90, 0.1);
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: #10b981;
    color: white;
    padding: 15px 25px;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    display: none;
    align-items: center;
    gap: 10px;
    z-index: 1000;
    animation: slideIn 0.3s;
}

.toast.show {
    display: flex;
}

.toast.error {
    background: #e53e3e;
}

.toast.warning {
    background: #f59e0b;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .input-group {
        flex-direction: column;
    }

    #submitBtn {
        width: 100%;
        justify-content: center;
    }

    .content {
        padding: 20px;
    }

    .header h1 {
        font-size: 1.5em;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .source-header {
        flex-direction: column;
    }

    .source-badges {
        width: 100%;
    }

    .answer-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .copy-buttons {
        width: 100%;
    }

    .copy-btn {
        flex: 1;
        justify-content: center;
    }

    .toast {
        right: 20px;
        left: 20px;
        bottom: 20px;
    }
}