/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Compact Header */
.compact-header {
    background: white;
    padding: 15px 20px 10px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    position: sticky;
    top: 0;
    z-index: 100;
}

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

.header-content h1 {
    color: #2c3e50;
    margin: 0;
    font-size: 1.8em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Compact Feedback Link */
.feedback-link {
    padding: 6px 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 15px;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    transition: all 0.3s ease;
}

.feedback-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.feedback-link a {
    color: white;
    text-decoration: none;
    font-weight: 500;
    font-size: 12px;
}

.feedback-link a:hover {
    text-decoration: none;
}

/* Icon Buttons */
.btn-icon {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.btn-icon:hover {
    background: #e9ecef;
    transform: translateY(-1px);
}

/* Attention-grabbing indicator for first-time users */
.btn-icon.needs-attention {
    background: linear-gradient(45deg, #ff6b6b, #ee5a24);
    color: white;
    border-color: #ee5a24;
    animation: pulse-attention 2s infinite;
    box-shadow: 0 2px 8px rgba(238, 90, 36, 0.3);
}

.btn-icon.needs-attention:hover {
    background: linear-gradient(45deg, #ee5a24, #d63031);
    transform: translateY(-1px) scale(1.05);
}

@keyframes pulse-attention {
    0%, 100% { 
        box-shadow: 0 2px 8px rgba(238, 90, 36, 0.3); 
        transform: scale(1);
    }
    50% { 
        box-shadow: 0 4px 16px rgba(238, 90, 36, 0.6); 
        transform: scale(1.02);
    }
}

/* Search Bar */
.search-bar {
    border-top: 1px solid #e9ecef;
    padding-top: 15px;
}

.search-input-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.search-input-group input {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s ease;
}

.search-input-group input:focus {
    outline: none;
    border-color: #3498db;
}

.search-input-group input:disabled {
    background: #f8f9fa;
    color: #6c757d;
    cursor: not-allowed;
}

.search-input-group button:disabled {
    background: #e9ecef;
    color: #6c757d;
    cursor: not-allowed;
    border-color: #dee2e6;
}

/* First-time user guidance */
.first-time-message {
    margin-top: 15px;
    animation: slideDown 0.5s ease-out;
}

.welcome-message {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 20px;
    border-radius: 12px;
    text-align: center;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.welcome-message strong {
    color: #fff;
}

.welcome-message code {
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.9em;
}

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

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

.modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    padding: 20px 25px 15px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: #2c3e50;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #7f8c8d;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.modal-close:hover {
    background: #f8f9fa;
    color: #2c3e50;
}

.modal-body {
    padding: 25px;
}

/* Slide Panel Styles */
.slide-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 400px;
    height: 100%;
    background: white;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.slide-panel.open {
    transform: translateX(0);
}

.panel-content {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.panel-header {
    padding: 20px 25px 15px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
}

.panel-header h3 {
    margin: 0;
    color: #2c3e50;
}

.panel-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #7f8c8d;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.panel-close:hover {
    background: #e9ecef;
    color: #2c3e50;
}

.panel-body {
    padding: 25px;
    flex: 1;
    overflow-y: auto;
}

/* Library Panel Specific Styles */
.library-actions {
    margin-bottom: 20px;
    text-align: center;
}

.library-content {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

.library-empty {
    text-align: center;
    color: #7f8c8d;
    padding: 40px 20px;
    font-style: italic;
    line-height: 1.6;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px dashed #e9ecef;
}

/* Content Area - Now gets full space */
.content-area {
    background: white;
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    min-height: calc(100vh - 200px); /* Fill most of the screen */
}

/* Streaming indicator */
.streaming-indicator {
    color: #3498db;
    font-style: italic;
    padding: 15px;
    background: #ecf0f1;
    border-radius: 8px;
    border-left: 4px solid #3498db;
    animation: pulse 1.5s infinite;
    display: flex;
    align-items: center;
    gap: 10px;
}

.streaming-indicator::before {
    content: "✨";
    animation: rotate 2s linear infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

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

/* Form elements */
.api-keys {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.api-key-group {
    display: flex;
    flex-direction: column;
}

.api-key-group label {
    font-weight: 600;
    margin-bottom: 5px;
    color: #2c3e50;
}

.api-key-group input {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

.paper-input {
    margin-bottom: 20px;
}

.paper-input label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    color: #2c3e50;
}

.paper-input input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
}

/* Buttons */
.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.btn-success {
    background: #27ae60;
    color: white;
}

.btn-success:hover {
    background: #219a52;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Loading and messages */
.loading {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
}

.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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


/* Paper content */
.paper-content {
    max-height: calc(100vh - 300px); /* Dynamic height based on viewport */
    min-height: 500px; /* Minimum height for readability */
    overflow-y: auto;
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #e9ecef;
    font-size: 15px;
    line-height: 1.6;
}

/* Markdown styling within paper content */
.paper-content h1,
.paper-content h2,
.paper-content h3,
.paper-content h4,
.paper-content h5,
.paper-content h6 {
    margin-top: 20px;
    margin-bottom: 10px;
    color: #2c3e50;
    font-weight: 600;
}

.paper-content h1 {
    font-size: 1.5em;
    border-bottom: 2px solid #3498db;
    padding-bottom: 5px;
}

.paper-content h2 {
    font-size: 1.3em;
    border-bottom: 1px solid #bdc3c7;
    padding-bottom: 3px;
}

.paper-content h3 {
    font-size: 1.1em;
}

.paper-content ul,
.paper-content ol {
    margin: 10px 0;
    padding-left: 20px;
}

.paper-content li {
    margin-bottom: 5px;
}

.paper-content p {
    margin-bottom: 10px;
}

.paper-content strong {
    color: #2c3e50;
    font-weight: 600;
}

.paper-content em {
    color: #34495e;
}

.paper-content code {
    background: #ecf0f1;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.9em;
    color: #e74c3c;
}

.paper-content pre {
    background: #2c3e50;
    color: #ecf0f1;
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto;
    margin: 10px 0;
}

.paper-content pre code {
    background: none;
    color: inherit;
    padding: 0;
}

.paper-content blockquote {
    border-left: 4px solid #3498db;
    margin: 10px 0;
    padding: 10px 15px;
    background: #f8f9fa;
    font-style: italic;
}

/* Original content specific styling */
#original-content {
    white-space: pre-wrap;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 16px;
    line-height: 1.7;
    text-align: justify;
    max-width: none; /* Remove width restrictions */
}

#original-content p {
    margin-bottom: 18px;
    text-indent: 1.5em;
}

#original-content p:first-child {
    text-indent: 0;
}

/* Floating Notifications */
#notification-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    max-width: 400px;
    pointer-events: none;
}

.notification {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    margin-bottom: 10px;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transform: translateX(450px);
    transition: all 0.3s ease;
    pointer-events: auto;
    border-left: 4px solid;
}

.notification-show {
    transform: translateX(0);
}

.notification-success {
    border-left-color: #27ae60;
    background: #d4edda;
    color: #155724;
}

.notification-error {
    border-left-color: #e74c3c;
    background: #f8d7da;
    color: #721c24;
}

.notification-message {
    flex: 1;
    font-weight: 500;
    font-size: 14px;
}

.notification-close {
    background: none;
    border: none;
    font-size: 18px;
    font-weight: bold;
    color: inherit;
    cursor: pointer;
    padding: 0 0 0 10px;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.notification-close:hover {
    opacity: 1;
}

/* Mobile responsive notifications */
@media (max-width: 768px) {
    #notification-container {
        left: 20px;
        right: 20px;
        top: 10px;
        max-width: none;
    }
    
    .notification {
        transform: translateY(-100px);
    }
    
    .notification-show {
        transform: translateY(0);
    }
}

/* Q&A section */
.qa-section {
    margin-top: 20px;
}

/* Make Q&A tab fill available height */
#qa-tab {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 280px); /* Account for header, tabs, and padding */
}

#qa-tab.active {
    display: flex;
}

#qa-tab h4 {
    flex-shrink: 0;
    margin-bottom: 15px;
}

.qa-input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    margin-bottom: 10px;
    resize: vertical;
    min-height: 80px;
    flex-shrink: 0;
}

.qa-history {
    flex: 1;
    overflow-y: auto;
    background: #f8f9fa;
    padding: 15px;
    border-radius: 5px;
    border: 1px solid #e9ecef;
    margin-bottom: 15px;
    min-height: 200px;
}

.qa-item {
    margin-bottom: 15px;
    padding: 10px;
    background: white;
    border-radius: 5px;
    border-left: 4px solid #3498db;
    flex-shrink: 0;
}

.qa-question {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 5px;
}

.qa-answer {
    color: #555;
    line-height: 1.5;
}

/* Q&A button stays at bottom */
#qa-tab .btn {
    flex-shrink: 0;
    margin-top: auto;
}

/* Responsive adjustments for Q&A */
@media (max-width: 768px) {
    #qa-tab {
        height: calc(100vh - 320px); /* More space for mobile header */
    }
    
    .qa-history {
        min-height: 150px;
    }
}

/* Markdown styling within Q&A answers */
.qa-answer h1,
.qa-answer h2,
.qa-answer h3,
.qa-answer h4,
.qa-answer h5,
.qa-answer h6 {
    margin-top: 15px;
    margin-bottom: 8px;
    color: #2c3e50;
    font-weight: 600;
}

.qa-answer h2 {
    font-size: 1.2em;
    border-bottom: 1px solid #bdc3c7;
    padding-bottom: 2px;
}

.qa-answer h3 {
    font-size: 1.1em;
}

.qa-answer ul,
.qa-answer ol {
    margin: 8px 0;
    padding-left: 18px;
}

.qa-answer li {
    margin-bottom: 3px;
}

.qa-answer p {
    margin-bottom: 8px;
}

.qa-answer strong {
    color: #2c3e50;
    font-weight: 600;
}

.qa-answer em {
    color: #34495e;
}

.qa-answer code {
    background: #ecf0f1;
    padding: 1px 3px;
    border-radius: 2px;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.9em;
    color: #e74c3c;
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .api-keys {
        grid-template-columns: 1fr;
    }
    
    .button-group {
        flex-direction: column;
    }
    
    .feedback-link {
        padding: 8px 14px;
        border-radius: 18px;
        margin-top: 12px;
    }
    
    .feedback-link a {
        font-size: 12px;
    }
    
    /* Compact header mobile styles */
    .header-content {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    .header-actions {
        order: -1;
        justify-content: center;
    }
    
    .search-input-group {
        flex-direction: column;
    }
    
    .search-input-group input {
        margin-bottom: 10px;
    }
    
    /* Modal mobile styles */
    .modal-content {
        width: 95%;
        margin: 10px;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    /* Slide panel mobile styles */
    .slide-panel {
        width: 100%;
        left: 0;
    }
    
    .panel-body {
        padding: 20px;
    }
    
    /* Optimize paper content for mobile */
    .content-area {
        min-height: calc(100vh - 250px);
        padding: 15px;
    }
    
    .paper-content {
        max-height: calc(100vh - 350px);
        min-height: 300px;
        padding: 15px;
        font-size: 14px;
    }
    
    #original-content {
        font-size: 15px;
        line-height: 1.6;
    }
    
    /* Mobile guidance styles */
    .welcome-message {
        padding: 12px 16px;
        font-size: 13px;
        border-radius: 10px;
    }
    
    .btn-icon.needs-attention {
        animation: pulse-attention 1.5s infinite; /* Faster on mobile */
    }
}