/* Modern CSS Styles for LaTeX Diff Tool */

/* CSS Variables for consistent theming */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #059669;
    --danger-color: #dc2626;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --border-radius: 8px;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --diff-delete-bg: #fee2e2;
    --diff-delete-text: #991b1b;
    --diff-insert-bg: #dcfce7;
    --diff-insert-text: #166534;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--background-color);
    font-size: 16px;
}

/* Ad sidebar styles */
.ad-sidebar {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 160px;
    height: 600px;
    z-index: 100;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 8px;
}

.ad-sidebar-left {
    left: 20px;
}

.ad-sidebar-right {
    right: 20px;
}

.ad-sidebar .adsbygoogle {
    width: 100% !important;
    height: 100% !important;
}

/* Container and layout */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Adjust container margins when ads are present */
body:has(.ad-sidebar) .container {
    margin-left: 200px;
    margin-right: 200px;
    max-width: calc(1400px - 400px);
}

/* Fallback for browsers that don't support :has() */
@supports not selector(:has(.ad-sidebar)) {
    .container-with-ads {
        margin-left: 200px;
        margin-right: 200px;
        max-width: calc(1400px - 400px);
    }
}

/* Header styles */
.header {
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem 0;
    background: linear-gradient(135deg, var(--primary-color), #3b82f6);
    color: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    max-width: 600px;
    margin: 0 auto;
}

/* Input section styles */
.input-section {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.input-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.input-container {
    display: flex;
    flex-direction: column;
}

.input-label {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
}

.latex-input {
    width: 100%;
    min-height: 300px;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-family: 'Courier New', 'Monaco', monospace;
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background-color: #fafafa;
}

.latex-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.latex-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Button styles */
.button-container {
    text-align: center;
}

.compare-button {
    background: linear-gradient(135deg, var(--primary-color), #3b82f6);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow);
    min-width: 200px;
}

.compare-button:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--primary-hover), var(--primary-color));
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.compare-button:active {
    transform: translateY(0);
}

.compare-button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.compare-button.loading {
    background: var(--secondary-color);
}

.button-loader {
    color: white;
}

/* Results section styles */
.results-section {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.results-title {
    font-size: 1.8rem;
    color: var(--text-primary);
    margin-bottom: 2rem;
    text-align: center;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 1rem;
}

/* Text results styles */
.text-results {
    margin-bottom: 3rem;
}

.text-results h3 {
    font-size: 1.4rem;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
}

.text-output-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.text-output-container {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.text-output-container h4 {
    background: var(--background-color);
    padding: 1rem;
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

.text-output {
    padding: 1.5rem;
    font-family: 'Courier New', 'Monaco', monospace;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    background: #fafafa;
    min-height: 150px;
    max-height: 400px;
    overflow-y: auto;
}

/* Diff results styles */
.diff-results h3 {
    font-size: 1.4rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.diff-legend {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--background-color);
    border-radius: var(--border-radius);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
}

.diff-delete-demo {
    background-color: var(--diff-delete-bg);
}

.diff-insert-demo {
    background-color: var(--diff-insert-bg);
}

.legend-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.diff-output-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.diff-output-container {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.diff-output-container h4 {
    background: var(--background-color);
    padding: 1rem;
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

.diff-output {
    padding: 1.5rem;
    font-family: 'Courier New', 'Monaco', monospace;
    font-size: 14px;
    line-height: 1.6;
    background: #fafafa;
    min-height: 150px;
    max-height: 500px;
    overflow-y: auto;
    word-wrap: break-word;
}

/* Diff highlighting styles */
.diff-delete {
    background-color: var(--diff-delete-bg);
    color: var(--diff-delete-text);
    padding: 0.1em 0.2em;
    border-radius: 3px;
    text-decoration: line-through;
}

.diff-insert {
    background-color: var(--diff-insert-bg);
    color: var(--diff-insert-text);
    padding: 0.1em 0.2em;
    border-radius: 3px;
    font-weight: 600;
}

/* Error message styles */
.error-message {
    background-color: #fee2e2;
    color: var(--danger-color);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    border: 1px solid #fecaca;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

/* Responsive design */
@media (max-width: 1024px) {
    .container {
        padding: 1rem;
    }
    
    .header h1 {
        font-size: 2rem;
    }
    
    .input-group,
    .text-output-group,
    .diff-output-group {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    .latex-input {
        min-height: 200px;
    }
    
    /* Hide ads on smaller screens */
    .ad-sidebar {
        display: none;
    }
}

@media (max-width: 640px) {
    .container {
        padding: 0.5rem;
    }
    
    .header {
        margin-bottom: 2rem;
        padding: 1.5rem 1rem;
    }
    
    .header h1 {
        font-size: 1.8rem;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    .input-section,
    .results-section {
        padding: 1.5rem;
        margin-bottom: 1.5rem;
    }
    
    .diff-legend {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .compare-button {
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
        min-width: 180px;
    }
}

/* Scrollbar styling for better visual consistency */
.text-output::-webkit-scrollbar,
.diff-output::-webkit-scrollbar {
    width: 8px;
}

.text-output::-webkit-scrollbar-track,
.diff-output::-webkit-scrollbar-track {
    background: var(--border-color);
    border-radius: 4px;
}

.text-output::-webkit-scrollbar-thumb,
.diff-output::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 4px;
}

.text-output::-webkit-scrollbar-thumb:hover,
.diff-output::-webkit-scrollbar-thumb:hover {
    background: var(--text-primary);
}

/* Focus indicators for accessibility */
.compare-button:focus,
.latex-input:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Differences List Styles */
.differences-list-section {
    margin-top: 3rem;
}

.differences-list-section h3 {
    font-size: 1.4rem;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
}

.differences-summary {
    margin-bottom: 2rem;
    padding: 1rem;
    background: var(--background-color);
    border-radius: var(--border-radius);
    text-align: center;
}

.summary-stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stat-number {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: lowercase;
}

.differences-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.difference-item {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--surface-color);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: all 0.2s ease;
}

.difference-item:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}

.difference-item.addition {
    border-left: 4px solid var(--success-color);
}

.difference-item.deletion {
    border-left: 4px solid var(--danger-color);
}

.difference-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--background-color);
    border-bottom: 1px solid var(--border-color);
}

.difference-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.875rem;
}

.addition .difference-icon {
    background-color: var(--diff-insert-bg);
    color: var(--diff-insert-text);
}

.deletion .difference-icon {
    background-color: var(--diff-delete-bg);
    color: var(--diff-delete-text);
}

.difference-type {
    font-weight: 600;
    color: var(--text-primary);
}

.addition .difference-type {
    color: var(--success-color);
}

.deletion .difference-type {
    color: var(--danger-color);
}

.difference-position {
    margin-left: auto;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.difference-content {
    padding: 1.25rem;
}

.difference-text {
    font-family: 'Courier New', 'Monaco', monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    background: #fafafa;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 1rem;
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-x: auto;
    max-height: 200px;
    overflow-y: auto;
}

.addition .difference-text {
    background: var(--diff-insert-bg);
    border-color: var(--success-color);
}

.deletion .difference-text {
    background: var(--diff-delete-bg);
    border-color: var(--danger-color);
}

.no-differences {
    text-align: center;
    padding: 2rem;
    background: var(--background-color);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.no-differences p {
    font-size: 1.1rem;
    color: var(--success-color);
    margin: 0;
}

/* Responsive adjustments for differences list */
@media (max-width: 640px) {
    .difference-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .difference-position {
        margin-left: 0;
        flex-basis: 100%;
        margin-top: 0.5rem;
    }
    
    .summary-stats {
        gap: 1rem;
    }
    
    .stat-number {
        font-size: 1.25rem;
    }
}

/* Scrollbar styling for difference text */
.difference-text::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.difference-text::-webkit-scrollbar-track {
    background: var(--border-color);
    border-radius: 3px;
}

.difference-text::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 3px;
}

.difference-text::-webkit-scrollbar-thumb:hover {
    background: var(--text-primary);
}

/* Print styles */
@media print {
    .header,
    .input-section,
    .button-container {
        display: none;
    }
    
    .results-section {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .difference-item {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #000;
        margin-bottom: 1rem;
    }
    
    .difference-item:hover {
        transform: none;
    }
}