:root {
    --primary: #6f42c1;
    --primary-light: #8b5cf6;
    --bg: #0f0f1a;
    --bg-card: #1a1a2e;
    --text: #e4e4e7;
    --text-muted: #a1a1aa;
    --border: #2e2e4a;
    --success: #22c55e;
    --error: #ef4444;
    --upload-bg: #252542;
    --upload-border: #3d3d6d;
    --warning: #f59e0b;
    --diff-removed: rgba(239, 68, 68, 0.2);
    --diff-removed-border: rgba(239, 68, 68, 0.4);
    --diff-added: rgba(34, 197, 94, 0.2);
    --diff-added-border: rgba(34, 197, 94, 0.4);
    --diff-modified: rgba(245, 158, 11, 0.2);
    --diff-modified-border: rgba(245, 158, 11, 0.4);
}

/* Light Theme Variables */
[data-theme="light"] {
    --bg: #f8f9fa;
    --bg-card: #ffffff;
    --text: #212529;
    --text-muted: #6c757d;
    --border: #dee2e6;
    --upload-bg: #f8f9fa;
    --upload-border: #ced4da;
    --diff-removed: rgba(239, 68, 68, 0.15);
    --diff-removed-border: rgba(239, 68, 68, 0.3);
    --diff-added: rgba(34, 197, 94, 0.15);
    --diff-added-border: rgba(34, 197, 94, 0.3);
    --diff-modified: rgba(245, 158, 11, 0.15);
    --diff-modified-border: rgba(245, 158, 11, 0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, var(--bg) 0%, #1a1a2e 100%);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

/* Offline Indicator */
.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(90deg, var(--warning), #d97706);
    color: white;
    text-align: center;
    padding: 0.75rem;
    font-weight: 500;
    z-index: 1000;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

/* Install Prompt */
.install-prompt {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    z-index: 999;
    animation: slideUp 0.3s ease;
    max-width: 350px;
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.install-content {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

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

.install-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.install-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.install-btn:hover {
    background: var(--primary-light);
    transform: translateY(-1px);
}

.dismiss-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: all 0.2s;
}

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

.hidden {
    display: none !important;
}

/* Theme Toggle Button */
.theme-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.5rem;
    transition: all 0.3s ease;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .theme-toggle {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Smooth theme transition */
body, .tool-box, header, textarea, button, .upload-section, .stats, .install-prompt {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.container { max-width: 900px; margin: 0 auto; padding: 2rem; }

header { 
    text-align: center; 
    margin-bottom: 2rem; 
    padding: 2rem;
    background: var(--bg-card);
    border-radius: 16px;
    border: 1px solid var(--border);
}

.logo {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary-light), #ffd700);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

header p {
    color: var(--text-muted);
    font-size: 1.1rem;
}

.tool-box {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid var(--border);
}

.mode-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    justify-content: center;
}

.mode-btn {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
}

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

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

/* Upload Section */
.upload-section {
    margin-bottom: 1.5rem;
    padding: 2rem;
    background: var(--upload-bg);
    border: 2px dashed var(--upload-border);
    border-radius: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.upload-section:hover {
    border-color: var(--primary-light);
    background: rgba(111, 66, 193, 0.1);
}

.upload-section.dragover {
    border-color: var(--primary);
    background: rgba(111, 66, 193, 0.2);
    transform: scale(1.02);
}

.upload-content {
    pointer-events: none;
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.upload-text {
    font-size: 1.1rem;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.upload-hint {
    font-size: 0.9rem;
    color: var(--primary-light);
    margin-bottom: 0.5rem;
}

.upload-types {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.upload-section.has-file {
    border-color: var(--success);
    background: rgba(34, 197, 94, 0.1);
}

.file-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--success);
}

.file-info .file-name {
    font-weight: 600;
}

.file-info .file-size {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.editor-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.input-section, .output-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

textarea {
    width: 100%;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.9rem;
    resize: vertical;
    min-height: 150px;
    transition: border-color 0.2s;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    justify-content: center;
}

.action-row {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.actions button {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

.actions button.primary:hover {
    background: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(111, 66, 193, 0.3);
}

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

.actions button.secondary:hover {
    border-color: var(--primary);
    background: rgba(111, 66, 193, 0.1);
}

.actions button.secondary.active {
    background: rgba(111, 66, 193, 0.2);
    border-color: var(--primary);
    color: var(--primary-light);
}

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

/* First action row - undo/redo */
.action-row:first-child button {
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    min-width: 80px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.stat {
    text-align: center;
}

.stat span {
    color: var(--text-muted);
    font-size: 0.8rem;
    display: block;
    margin-bottom: 0.25rem;
}

.stat.saved {
    color: var(--success);
    font-weight: 600;
}

/* ============================================
   DIFF VIEW STYLES
   ============================================ */

.diff-view {
    margin-top: 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg);
}

.diff-header {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.diff-stat {
    text-align: center;
    padding: 0.5rem;
    background: var(--bg);
    border-radius: 8px;
}

.diff-stat.saved {
    background: var(--diff-added);
    border: 1px solid var(--diff-added-border);
}

.diff-stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.diff-stat-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.diff-stat.saved .diff-stat-value {
    color: var(--success);
}

.diff-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    max-height: 400px;
    overflow-y: auto;
}

.diff-side {
    border-right: 1px solid var(--border);
    overflow: hidden;
}

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

.diff-side-header {
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
    text-align: center;
}

.diff-line {
    display: flex;
    align-items: flex-start;
    padding: 0.25rem 0;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.8rem;
    line-height: 1.5;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.diff-line-num {
    width: 40px;
    text-align: right;
    padding-right: 0.75rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    flex-shrink: 0;
    user-select: none;
}

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

.diff-line.removed {
    background: var(--diff-removed);
    border-left: 3px solid var(--error);
}

.diff-line.added {
    background: var(--diff-added);
    border-left: 3px solid var(--success);
}

.diff-line.modified {
    background: var(--diff-modified);
    border-left: 3px solid var(--warning);
}

.diff-line.unchanged {
    border-left: 3px solid transparent;
}

.diff-legend {
    display: flex;
    justify-content: center;
    gap: 2rem;
    padding: 1rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
}

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

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

.diff-legend-color.removed {
    background: var(--diff-removed);
    border: 2px solid var(--diff-removed-border);
}

.diff-legend-color.added {
    background: var(--diff-added);
    border: 2px solid var(--diff-added-border);
}

.diff-legend-color.unchanged {
    background: var(--bg);
    border: 2px solid var(--border);
}

/* Scrollbar styles for diff */
.diff-container::-webkit-scrollbar {
    width: 8px;
}

.diff-container::-webkit-scrollbar-track {
    background: var(--bg);
}

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

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

footer { 
    text-align: center; 
    margin-top: 2rem; 
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

footer a {
    color: var(--primary-light);
    text-decoration: none;
    transition: color 0.2s;
}

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

#offline-status {
    font-weight: 500;
}

@media (max-width: 768px) {
    .container { padding: 1rem; padding-top: 3rem; }
    h1 { font-size: 1.5rem; }
    .mode-selector { flex-direction: column; }
    .mode-btn { width: 100%; }
    .upload-section { padding: 1.5rem; }
    button { padding: 0.75rem 1rem; font-size: 0.9rem; }
    .actions { flex-direction: column; }
    .install-prompt {
        left: 10px;
        right: 10px;
        bottom: 10px;
        max-width: none;
    }
    .diff-container {
        grid-template-columns: 1fr;
        max-height: 300px;
    }
    .diff-side {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .diff-side:last-child {
        border-bottom: none;
    }
    .diff-header {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    .diff-legend {
        flex-direction: column;
        gap: 0.75rem;
        align-items: center;
    }
}

/* Print styles */
@media print {
    .install-prompt,
    .offline-indicator,
    footer,
    .theme-toggle {
        display: none !important;
    }
    body {
        background: white;
        color: black;
    }
    textarea {
        border: 1px solid #ccc;
    }
    .diff-container {
        max-height: none;
    }
}
