/* ========================================
   DiffChecker.css - 文字差異比對器樣式
   Created: 2024-11-20
   ======================================== */

/* ⚠️ DO NOT redefine global classes!
   Read GLOBAL_CSS_CLASSES.md before adding styles.
   Global classes: .glass-card, .form-input, .btn-custom, .btn-sponsor, etc.
   Only define diff-specific styles below.
*/

/* ===========================================
   Main Diff Container - Dual Column Layout
   =========================================== */
.diff-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 15px;
    width: 100%;
}

@media (max-width: 991px) {
    .diff-container {
        grid-template-columns: 1fr;
    }
}

/* ===========================================
   Textarea with Line Numbers & Highlights
   =========================================== */
.textarea-with-lines {
    position: relative;
    display: flex;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.line-numbers {
    position: relative;
    width: 45px;
    background: #f8f9fa;
    border-right: 1px solid #dee2e6;
    padding: 10px 5px;
    text-align: right;
    font-family: 'Courier New', Consolas, Monaco, monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #6c757d;
    user-select: none;
    overflow: hidden;
    flex-shrink: 0;
}

.line-numbers div {
    padding-right: 8px;
}

.diff-textarea-inline {
    flex: 1;
    font-family: 'Courier New', Consolas, Monaco, monospace;
    font-size: 14px;
    line-height: 1.6;
    tab-size: 4;
    -moz-tab-size: 4;
    white-space: pre;
    word-wrap: normal;
    padding: 10px 12px;
    border: none !important;
    outline: none !important;
    resize: none;
    background: transparent;
    position: relative;
    z-index: 2;
    overflow-x: auto;
    overflow-y: auto;
    min-height: 400px;
}

.diff-textarea-inline:focus {
    box-shadow: none !important;
}

.diff-highlights {
    position: absolute;
    top: 0;
    left: 45px;
    right: 0;
    bottom: 0;
    padding: 10px 12px;
    font-family: 'Courier New', Consolas, Monaco, monospace;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre;
    word-wrap: normal;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}

.diff-highlights div {
    position: relative;
}

/* Highlight line backgrounds */
.highlight-line-added {
    background: rgba(40, 167, 69, 0.15);
}

.highlight-line-deleted {
    background: rgba(220, 53, 69, 0.15);
}

.highlight-line-modified {
    background: rgba(255, 193, 7, 0.15);
}

.highlight-line-same {
    background: transparent;
}

/* ===========================================
   Diff Display - Line-by-Line View
   =========================================== */
#diffResultContainer {
    margin-top: 15px;
}

.diff-scroll-sync {
    overflow-y: auto;
    overflow-x: auto;
    max-height: 600px;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    background: #fff;
    position: relative;
    font-family: 'Courier New', Consolas, Monaco, monospace;
    font-size: 13px;
    line-height: 1.5;
}

.diff-pane {
    width: 100%;
    min-width: 0;
}

.diff-pane h5 {
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: 600;
    color: #495057;
    padding: 8px 10px;
    background: #f8f9fa;
    border-radius: 6px;
}

.diff-line {
    display: flex;
    align-items: flex-start;
    min-height: 24px;
    transition: background-color 0.15s ease;
    padding: 3px 0;
}

.diff-line:hover {
    background: rgba(0, 0, 0, 0.03);
}

.diff-line-number {
    position: sticky;
    left: 0;
    min-width: 50px;
    max-width: 50px;
    text-align: right;
    padding-right: 10px;
    padding-left: 5px;
    color: #6c757d;
    user-select: none;
    background: #f8f9fa;
    border-right: 1px solid #dee2e6;
    font-size: 12px;
    flex-shrink: 0;
}

.diff-line-content {
    flex: 1;
    padding: 2px 10px;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    min-height: 20px;
}

/* Fix empty line display */
.diff-line-content:empty::before {
    content: '\00a0'; /* non-breaking space */
    color: transparent;
}

/* ===========================================
   Diff Line Types - Color Coding
   =========================================== */
.diff-line-added {
    background: #d4edda;
    border-left: 3px solid #28a745;
}

.diff-line-added .diff-line-number {
    background: #c3e6cb;
    color: #155724;
}

.diff-line-deleted {
    background: #f8d7da;
    border-left: 3px solid #dc3545;
}

.diff-line-deleted .diff-line-number {
    background: #f5c6cb;
    color: #721c24;
}

.diff-line-modified {
    background: #fff3cd;
    border-left: 3px solid #ffc107;
}

.diff-line-modified .diff-line-number {
    background: #ffeeba;
    color: #856404;
}

.diff-line-same {
    background: transparent;
}

.diff-line-same .diff-line-content {
    color: #6c757d;
}

/* ===========================================
   Character-Level Highlighting
   =========================================== */
.diff-char-highlight {
    background: rgba(255, 193, 7, 0.6);
    font-weight: 600;
    padding: 1px 2px;
    border-radius: 2px;
}

.diff-line-added .diff-char-highlight {
    background: rgba(40, 167, 69, 0.4);
}

.diff-line-deleted .diff-char-highlight {
    background: rgba(220, 53, 69, 0.4);
}

/* ===========================================
   Collapsed Section - Hidden Identical Lines
   =========================================== */
.diff-collapsed-section {
    background: #f8f9fa;
    border-top: 1px dashed #dee2e6;
    border-bottom: 1px dashed #dee2e6;
    padding: 8px 12px;
    text-align: center;
    color: #6c757d;
    font-style: italic;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.diff-collapsed-section:hover {
    background: #e9ecef;
    color: #495057;
}

.diff-collapsed-section i {
    margin-right: 5px;
}

/* ===========================================
   Statistics Badges
   =========================================== */
#statsContainer {
    margin-bottom: 20px;
}

.stat-badge {
    padding: 12px 8px;
    border-radius: 8px;
    background: #f8f9fa;
    transition: all 0.2s ease;
    text-align: center;
}

.stat-badge:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 5px;
    line-height: 1;
}

.stat-label {
    font-size: 11px;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.stat-added {
    background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
}

.stat-added .stat-value {
    color: #28a745;
}

.stat-deleted {
    background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
}

.stat-deleted .stat-value {
    color: #dc3545;
}

.stat-modified {
    background: linear-gradient(135deg, #fff3cd 0%, #ffeeba 100%);
}

.stat-modified .stat-value {
    color: #ffc107;
}

/* ===========================================
   View Mode Tabs
   =========================================== */
.diff-mode-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.diff-mode-tab {
    padding: 8px 15px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    color: #495057;
}

.diff-mode-tab:hover {
    border-color: #667eea;
    color: #667eea;
}

.diff-mode-tab.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-color: #667eea;
}

.diff-mode-tab i {
    margin-right: 5px;
}

/* ===========================================
   Unified Diff View (Git-style)
   =========================================== */
.diff-unified {
    font-family: 'Courier New', Consolas, Monaco, monospace;
    font-size: 13px;
    line-height: 1.5;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 15px;
    overflow-x: auto;
    max-height: 500px;
    overflow-y: auto;
}

.diff-unified-header {
    color: #6c757d;
    font-weight: 600;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #dee2e6;
}

.diff-unified-hunk {
    color: #17a2b8;
    background: #e7f5ff;
    padding: 3px 8px;
    margin: 8px 0;
    border-radius: 4px;
}

/* ===========================================
   Legend
   =========================================== */
.diff-legend {
    font-size: 14px;
    color: #495057;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
}

.diff-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend-box {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid rgba(0,0,0,0.1);
}

.legend-added {
    background: rgba(40, 167, 69, 0.3);
}

.legend-deleted {
    background: rgba(220, 53, 69, 0.3);
}

.legend-modified {
    background: rgba(255, 193, 7, 0.3);
}

.legend-same {
    background: transparent;
    border: 1px solid #dee2e6;
}

/* ===========================================
   Empty State
   =========================================== */
.diff-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #6c757d;
}

.diff-empty-state i {
    font-size: 48px;
    color: #dee2e6;
    margin-bottom: 15px;
}

.diff-empty-state h4 {
    color: #495057;
    margin-bottom: 8px;
    font-size: 18px;
}

.diff-empty-state p {
    font-size: 14px;
}

/* ===========================================
   Loading Indicator
   =========================================== */
.diff-loading {
    text-align: center;
    padding: 40px 20px;
    color: #667eea;
}

.diff-loading i {
    font-size: 32px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===========================================
   Mobile Optimizations
   =========================================== */
@media (max-width: 767px) {
    .diff-textarea {
        font-size: 12px;
        min-height: 150px;
    }

    .diff-line-number {
        min-width: 40px;
        max-width: 40px;
        font-size: 11px;
    }

    .diff-scroll-sync {
        font-size: 12px;
        max-height: 400px;
    }

    .stat-badge {
        padding: 10px 5px;
    }

    .stat-value {
        font-size: 20px;
    }

    .stat-label {
        font-size: 10px;
    }

    .diff-mode-tab {
        font-size: 13px;
        padding: 6px 12px;
    }
}

/* ===========================================
   Dark Mode Support (Future Enhancement)
   =========================================== */
@media (prefers-color-scheme: dark) {
    .diff-scroll-sync {
        background: #2d3748;
        border-color: #4a5568;
    }

    .diff-line-number {
        background: #1a202c;
        border-color: #4a5568;
        color: #a0aec0;
    }

    .diff-unified {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
}
