/* CSS Variables */
:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #6b7280;
    --secondary-hover: #4b5563;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;

    --bg-color: #f8fafc;
    --surface-color: #ffffff;
    --border-color: #e2e8f0;
    --text-color: #1e293b;
    --text-muted: #64748b;

    --added-bg: #dcfce7;
    --added-text: #166534;
    --removed-bg: #fee2e2;
    --removed-text: #991b1b;
    --changed-bg: #fef3c7;
    --changed-text: #92400e;

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

    --transition: all 0.2s ease;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0f172a;
        --surface-color: #1e293b;
        --border-color: #334155;
        --text-color: #f1f5f9;
        --text-muted: #94a3b8;

        --added-bg: #14532d;
        --added-text: #86efac;
        --removed-bg: #7f1d1d;
        --removed-text: #fca5a5;
        --changed-bg: #78350f;
        --changed-text: #fcd34d;
    }
}

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

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

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

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

/* Header */
.header {
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    text-align: center;
}

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

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

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

.subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
}

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

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

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

.toggle-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.875rem;
}

.toggle-btn:hover {
    background: var(--bg-color);
    color: var(--text-color);
}

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

.options {
    display: flex;
    gap: 1.5rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-muted);
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
    content: '';
    width: 5px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-bottom: 2px;
}

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

.btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

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

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

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

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

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

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

.text-input-container {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

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

.input-header label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-color);
}

.paste-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.paste-btn:hover {
    background: var(--surface-color);
    color: var(--primary-color);
    border-color: var(--primary-color);
}

textarea {
    width: 100%;
    height: 200px;
    padding: 1rem;
    border: none;
    resize: vertical;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    background: var(--surface-color);
    color: var(--text-color);
}

textarea:focus {
    outline: none;
}

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

/* Diff Output */
.diff-output {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    min-height: 300px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-muted);
    text-align: center;
    min-height: 300px;
}

.empty-state svg {
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    font-size: 0.95rem;
}

/* Side by Side View */
.side-by-side {
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.diff-panel {
    overflow-x: auto;
}

.diff-panel-header {
    padding: 0.75rem 1rem;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 0.875rem;
    position: sticky;
    top: 0;
}

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

.diff-panel-header.original {
    color: var(--removed-text);
}

.diff-panel-header.modified {
    color: var(--added-text);
}

/* Diff Lines */
.diff-line {
    display: flex;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
    font-size: 0.8125rem;
    line-height: 1.6;
    min-height: 1.6em;
}

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

.line-content {
    flex: 1;
    padding: 0 1rem;
    white-space: pre-wrap;
    word-break: break-all;
}

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

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

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

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

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

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

/* Inline View */
.inline-view .diff-line {
    border-bottom: 1px solid var(--border-color);
}

.inline-view .diff-line:last-child {
    border-bottom: none;
}

.inline-view .line-prefix {
    width: 24px;
    text-align: center;
    font-weight: 600;
    flex-shrink: 0;
}

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

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

/* Hide line numbers when disabled */
.hide-line-numbers .line-number {
    display: none;
}

/* Word-level highlighting */
.word-added {
    background: rgba(16, 185, 129, 0.3);
    border-radius: 2px;
    padding: 0 2px;
}

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

/* Stats */
.stats {
    display: flex;
    gap: 2rem;
    justify-content: center;
    padding: 1rem;
    margin-top: 1.5rem;
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

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

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

.stat-value {
    font-weight: 700;
    font-size: 1.125rem;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-sm);
}

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

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

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

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-color);
    color: var(--bg-color);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

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

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

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

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

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

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

    .main-content {
        padding: 1rem;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

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

    .toggle-btn span {
        display: none;
    }

    .toggle-btn {
        padding: 0.625rem;
    }

    .options {
        justify-content: center;
        flex-wrap: wrap;
    }

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

    .input-section {
        grid-template-columns: 1fr;
    }

    textarea {
        height: 150px;
    }

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

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

    .stats {
        flex-wrap: wrap;
        gap: 1rem;
        justify-content: center;
    }

    .line-number {
        min-width: 40px;
        padding: 0 0.5rem;
    }

    .line-content {
        padding: 0 0.5rem;
    }
}

@media (max-width: 480px) {
    .btn span {
        display: none;
    }

    .btn {
        padding: 0.625rem;
    }

    .checkbox-label {
        font-size: 0.8125rem;
    }

    .diff-line {
        font-size: 0.75rem;
    }

    .line-number {
        min-width: 32px;
        font-size: 0.75rem;
    }
}

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

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

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

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

/* Focus Styles */
button:focus-visible,
textarea:focus-visible,
input:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .header,
    .controls,
    .input-section,
    .action-buttons,
    .footer {
        display: none;
    }

    .diff-output {
        border: none;
        box-shadow: none;
    }

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

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