/* CSS Variables */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #6b7280;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;

    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;

    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;

    --border-color: #e5e7eb;
    --border-radius: 12px;
    --border-radius-sm: 8px;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px 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);

    --addition-bg: #dcfce7;
    --addition-border: #86efac;
    --addition-text: #166534;

    --deletion-bg: #fee2e2;
    --deletion-border: #fca5a5;
    --deletion-text: #991b1b;

    --modification-bg: #fef3c7;
    --modification-border: #fcd34d;
    --modification-text: #92400e;

    --transition: all 0.2s ease;
}

/* Reset & Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: var(--bg-primary);
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--primary-color);
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.tagline {
    color: var(--text-secondary);
    margin-top: 0.5rem;
    font-size: 1rem;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Upload Section */
.upload-section {
    margin-bottom: 2rem;
}

.upload-container {
    display: flex;
    gap: 2rem;
    align-items: stretch;
}

.upload-box {
    flex: 1;
    background: var(--bg-primary);
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 2rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    position: relative;
}

.upload-box:hover {
    border-color: var(--primary-color);
    background: var(--bg-secondary);
}

.upload-box.dragover {
    border-color: var(--primary-color);
    background: rgba(79, 70, 229, 0.05);
}

.upload-box.has-file {
    border-style: solid;
    border-color: var(--success-color);
    background: rgba(16, 185, 129, 0.05);
}

.upload-content {
    text-align: center;
}

.upload-content svg {
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.upload-content h3 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.upload-content p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.file-types {
    display: inline-block;
    margin-top: 0.75rem;
    padding: 0.25rem 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 9999px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.file-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius-sm);
    margin-top: 1rem;
}

.file-info .file-name {
    font-size: 0.875rem;
    color: var(--text-primary);
    word-break: break-all;
}

.remove-file {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    padding: 0.25rem;
    transition: var(--transition);
}

.remove-file:hover {
    color: var(--danger-color);
}

.upload-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 1rem;
}

.upload-divider span {
    background: var(--primary-color);
    color: white;
    font-weight: 700;
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    border-radius: 9999px;
}

/* Text Input Toggle */
.text-input-toggle {
    text-align: center;
    margin-top: 1.5rem;
}

.text-input-section {
    margin-top: 1.5rem;
}

.text-input-container {
    display: flex;
    gap: 2rem;
}

.text-input-box {
    flex: 1;
}

.text-input-box label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.text-input-box textarea {
    width: 100%;
    height: 200px;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-family: inherit;
    font-size: 0.875rem;
    resize: vertical;
    transition: var(--transition);
}

.text-input-box textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Compare Actions */
.compare-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 2rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

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

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-tertiary);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Results Section */
.results-section {
    margin-top: 2rem;
}

/* Summary Panel */
.summary-panel {
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.summary-panel h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.summary-stats {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius-sm);
    min-width: 150px;
}

.stat-item.additions {
    background: var(--addition-bg);
}

.stat-item.deletions {
    background: var(--deletion-bg);
}

.stat-item.modifications {
    background: var(--modification-bg);
}

.stat-item.unchanged {
    background: var(--bg-tertiary);
}

.stat-icon {
    font-size: 1.5rem;
    font-weight: 700;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
}

.stat-item.additions .stat-icon {
    color: var(--addition-text);
}

.stat-item.deletions .stat-icon {
    color: var(--deletion-text);
}

.stat-item.modifications .stat-icon {
    color: var(--modification-text);
}

.stat-item.unchanged .stat-icon {
    color: var(--text-secondary);
}

.stat-content {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* View Controls */
.view-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.view-toggle {
    display: flex;
    background: var(--bg-primary);
    border-radius: var(--border-radius-sm);
    padding: 0.25rem;
    box-shadow: var(--shadow-sm);
}

.view-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: none;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.view-btn:hover {
    color: var(--text-primary);
}

.view-btn.active {
    background: var(--primary-color);
    color: white;
}

.export-controls {
    display: flex;
    gap: 0.5rem;
}

/* Comparison Container */
.comparison-container {
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* Side by Side View */
.side-by-side-view {
    display: flex;
}

.diff-panel {
    flex: 1;
    min-width: 0;
}

.side-by-side-view .diff-panel:first-child {
    border-right: 1px solid var(--border-color);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.panel-title {
    font-weight: 600;
    font-size: 0.875rem;
}

.panel-filename {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.diff-content {
    padding: 1rem;
    font-family: 'SF Mono', 'Consolas', 'Monaco', 'Andale Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    max-height: 600px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Diff Lines */
.diff-line {
    padding: 0.125rem 0.5rem;
    margin: 0 -0.5rem;
    display: flex;
}

.line-number {
    color: var(--text-muted);
    min-width: 3rem;
    padding-right: 1rem;
    user-select: none;
    text-align: right;
    flex-shrink: 0;
}

.line-content {
    flex: 1;
}

.diff-line.addition {
    background: var(--addition-bg);
}

.diff-line.deletion {
    background: var(--deletion-bg);
}

.diff-line.modification {
    background: var(--modification-bg);
}

/* Inline Highlights */
.highlight-add {
    background: rgba(16, 185, 129, 0.3);
    padding: 0 2px;
    border-radius: 2px;
}

.highlight-del {
    background: rgba(239, 68, 68, 0.3);
    padding: 0 2px;
    border-radius: 2px;
    text-decoration: line-through;
}

/* Unified View */
.unified-view .diff-panel {
    width: 100%;
}

.unified-line-prefix {
    color: var(--text-muted);
    min-width: 1.5rem;
    display: inline-block;
}

/* Legend */
.legend {
    display: flex;
    justify-content: center;
    gap: 2rem;
    padding: 1rem;
    margin-top: 1rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

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

.legend-color.addition {
    background: var(--addition-bg);
    border: 1px solid var(--addition-border);
}

.legend-color.deletion {
    background: var(--deletion-bg);
    border: 1px solid var(--deletion-border);
}

.legend-color.modification {
    background: var(--modification-bg);
    border: 1px solid var(--modification-border);
}

/* Footer */
.footer {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 1.5rem 2rem;
    text-align: center;
}

.footer p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

.footer a:hover {
    text-decoration: underline;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-overlay[hidden] {
    display: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-overlay p {
    margin-top: 1rem;
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .upload-container {
        flex-direction: column;
    }

    .upload-divider {
        padding: 1rem 0;
    }

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

    .side-by-side-view {
        flex-direction: column;
    }

    .side-by-side-view .diff-panel:first-child {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .summary-stats {
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 1rem;
    }

    .logo h1 {
        font-size: 1.5rem;
    }

    .main-content {
        padding: 1rem;
    }

    .upload-box {
        padding: 1.5rem;
        min-height: 150px;
    }

    .compare-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .btn {
        justify-content: center;
    }

    .view-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .view-toggle {
        justify-content: center;
    }

    .export-controls {
        justify-content: center;
    }

    .stat-item {
        flex: 1;
        min-width: 120px;
        padding: 0.75rem 1rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .diff-content {
        font-size: 0.75rem;
        max-height: 400px;
    }

    .legend {
        flex-wrap: wrap;
        gap: 1rem;
    }
}

@media (max-width: 480px) {
    .logo {
        flex-direction: column;
        gap: 0.5rem;
    }

    .logo h1 {
        font-size: 1.25rem;
    }

    .tagline {
        font-size: 0.875rem;
    }

    .upload-content h3 {
        font-size: 1rem;
    }

    .summary-stats {
        flex-direction: column;
    }

    .stat-item {
        width: 100%;
    }
}

/* Print Styles */
@media print {
    .header,
    .upload-section,
    .view-controls,
    .legend,
    .footer,
    .loading-overlay {
        display: none !important;
    }

    .results-section {
        margin-top: 0;
    }

    .comparison-container {
        box-shadow: none;
        border: 1px solid #000;
    }

    .diff-content {
        max-height: none;
        overflow: visible;
    }
}
