/* CSS Variables for theming */
:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --border-color: #30363d;
    --accent-primary: #58a6ff;
    --accent-hover: #79c0ff;
    --added-bg: #1a4721;
    --added-text: #3fb950;
    --added-highlight: #2ea04333;
    --removed-bg: #5d1a1a;
    --removed-text: #f85149;
    --removed-highlight: #f8514933;
    --unchanged-bg: transparent;
    --line-number-bg: #161b22;
    --line-number-text: #6e7681;
    --header-gradient: linear-gradient(135deg, #1a1f2c 0%, #0d1117 100%);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --font-mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

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

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

.logo-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-primary) 0%, #a371f7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

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

/* Controls Section */
.controls-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.view-toggle {
    display: flex;
    gap: 0.5rem;
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-primary {
    background: var(--accent-primary);
    color: #ffffff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-secondary:hover {
    background: var(--border-color);
    border-color: var(--text-muted);
}

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

.btn-toggle.active {
    background: var(--accent-primary);
    color: #ffffff;
    border-color: var(--accent-primary);
}

.btn-toggle:hover:not(.active) {
    background: var(--border-color);
    color: var(--text-primary);
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-file {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    cursor: pointer;
}

.btn-file:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

/* Input Section */
.input-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.input-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.panel-header h2 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
}

.file-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.lang-select {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
}

.lang-select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Textarea with Line Numbers */
.textarea-wrapper {
    display: flex;
    flex: 1;
    min-height: 300px;
    position: relative;
}

.line-numbers {
    width: 50px;
    background: var(--line-number-bg);
    border-right: 1px solid var(--border-color);
    padding: 1rem 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.5;
    color: var(--line-number-text);
    text-align: right;
    user-select: none;
    overflow: hidden;
}

.line-numbers span {
    display: block;
}

textarea {
    flex: 1;
    padding: 1rem;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.5;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: none;
    resize: none;
    outline: none;
    tab-size: 4;
}

textarea::placeholder {
    color: var(--text-muted);
}

textarea:focus {
    background: var(--bg-tertiary);
}

/* Results Section */
.results-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

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

.results-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.stats {
    display: flex;
    gap: 1rem;
}

.stat {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
}

.stat-added {
    background: var(--added-highlight);
    color: var(--added-text);
}

.stat-removed {
    background: var(--removed-highlight);
    color: var(--removed-text);
}

.stat-unchanged {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

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

/* Diff Container */
.diff-container {
    overflow-x: auto;
}

/* Side by Side Diff */
.diff-side-by-side {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-width: 100%;
}

.diff-panel {
    border-right: 1px solid var(--border-color);
}

.diff-panel:last-child {
    border-right: none;
}

.diff-panel-header {
    padding: 0.75rem 1rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.diff-panel-content {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.5;
}

/* Diff Lines */
.diff-line {
    display: flex;
    min-height: 1.5em;
}

.diff-line-number {
    width: 50px;
    padding: 0 0.75rem;
    text-align: right;
    color: var(--line-number-text);
    background: var(--line-number-bg);
    user-select: none;
    flex-shrink: 0;
    border-right: 1px solid var(--border-color);
}

.diff-line-content {
    flex: 1;
    padding: 0 1rem;
    white-space: pre;
    overflow-x: auto;
}

.diff-line.added {
    background: var(--added-highlight);
}

.diff-line.added .diff-line-number {
    background: var(--added-bg);
    color: var(--added-text);
}

.diff-line.added .diff-line-content {
    color: var(--added-text);
}

.diff-line.removed {
    background: var(--removed-highlight);
}

.diff-line.removed .diff-line-number {
    background: var(--removed-bg);
    color: var(--removed-text);
}

.diff-line.removed .diff-line-content {
    color: var(--removed-text);
}

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

.diff-line.empty .diff-line-number {
    background: var(--bg-tertiary);
}

/* Inline Diff */
.diff-inline {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.5;
}

.diff-inline .diff-line-prefix {
    width: 20px;
    text-align: center;
    color: var(--text-muted);
    flex-shrink: 0;
}

.diff-inline .diff-line.added .diff-line-prefix {
    color: var(--added-text);
}

.diff-inline .diff-line.removed .diff-line-prefix {
    color: var(--removed-text);
}

/* Character-level highlighting */
.char-added {
    background: var(--added-bg);
    color: var(--added-text);
    border-radius: 2px;
}

.char-removed {
    background: var(--removed-bg);
    color: var(--removed-text);
    border-radius: 2px;
}

/* Syntax Highlighting */
.syntax-keyword { color: #ff7b72; }
.syntax-string { color: #a5d6ff; }
.syntax-number { color: #79c0ff; }
.syntax-comment { color: #8b949e; font-style: italic; }
.syntax-function { color: #d2a8ff; }
.syntax-operator { color: #ff7b72; }
.syntax-punctuation { color: #c9d1d9; }
.syntax-class { color: #ffa657; }
.syntax-variable { color: #ffa657; }
.syntax-tag { color: #7ee787; }
.syntax-attribute { color: #79c0ff; }
.syntax-property { color: #79c0ff; }

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

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

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

.footer a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .input-section {
        grid-template-columns: 1fr;
    }

    .diff-side-by-side {
        grid-template-columns: 1fr;
    }

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

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

    .header h1 {
        font-size: 1.75rem;
    }

    .tagline {
        font-size: 1rem;
    }

    .main-content {
        padding: 1rem;
    }

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

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

    .action-buttons {
        justify-content: center;
    }

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

    .file-actions {
        width: 100%;
        justify-content: flex-start;
    }

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

    .stats {
        flex-wrap: wrap;
    }

    .export-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .textarea-wrapper {
        min-height: 200px;
    }

    .diff-line-number {
        width: 40px;
        padding: 0 0.5rem;
        font-size: 0.75rem;
    }

    .diff-line-content {
        padding: 0 0.5rem;
        font-size: 0.75rem;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.5rem;
    }

    .logo {
        width: 36px;
        height: 36px;
    }

    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }

    .btn svg {
        width: 14px;
        height: 14px;
    }

    .view-toggle {
        flex-direction: column;
        width: 100%;
    }

    .view-toggle .btn {
        width: 100%;
        justify-content: center;
    }

    .line-numbers {
        width: 35px;
        font-size: 0.6875rem;
        padding: 1rem 0.25rem;
    }

    textarea {
        font-size: 0.8125rem;
        padding: 0.75rem;
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.results-section {
    animation: fadeIn 0.3s ease;
}

/* Print Styles */
@media print {
    .controls-section,
    .input-section,
    .export-actions,
    .header,
    .footer {
        display: none !important;
    }

    .results-section {
        border: none !important;
    }

    .diff-line.added {
        background: #e6ffec !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .diff-line.removed {
        background: #ffebe9 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}
