/*
 * file.css - text tools module styles
 * Compare toolbar, twin text editors, the diff result view and statistics badges
 */

/* ========== toolbar ========== */
.diff-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    padding: 0.9rem 1rem;
    margin-bottom: 1.25rem;
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
}

.diff-toolbar .btn i {
    font-size: 0.88rem;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    margin: 0 0.35rem;
    background: var(--border-color);
}

/* compare options (checkboxes) */
.diff-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    margin-left: auto;
}

.diff-options label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.87rem;
    color: var(--light-text);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

.diff-options label:hover {
    color: var(--text-color);
}

/* ========== twin editor area ========== */
.diff-editors {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
}

.diff-editor {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.diff-editor:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.editor-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border-color);
}

.editor-title {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-color);
    margin-right: auto;
}

.editor-title i {
    color: var(--primary-color);
    font-size: 0.85rem;
}

.editor-header .mini-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.32rem 0.7rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--light-text);
    transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

.editor-header .mini-btn:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
    background: var(--primary-soft);
}

.editor-header .mini-btn i {
    font-size: 0.75rem;
}

/* large text areas */
.diff-editor textarea {
    width: 100%;
    height: 300px;
    padding: 0.9rem 1rem;
    border: none;
    border-radius: 0;
    resize: vertical;
    outline: none;
    box-shadow: none;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-color);
    background: var(--surface);
    white-space: pre;
    overflow: auto;
}

.diff-editor textarea:focus {
    border: none;
    box-shadow: none;
}

.diff-editor textarea.drag-over {
    background: var(--primary-soft);
}

.editor-status {
    display: flex;
    align-items: center;
    padding: 0.45rem 1rem;
    background: var(--surface-muted);
    border-top: 1px solid var(--border-color);
    font-size: 0.78rem;
    color: var(--light-text);
}

/* ========== result panel ========== */
.diff-result {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.diff-result.hidden {
    display: none;
}

/* result header: statistics + view switch + navigation */
.result-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 1rem;
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border-color);
}

.view-toggle {
    display: inline-flex;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    margin-left: auto;
}

.view-toggle button {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.38rem 0.85rem;
    background: var(--surface);
    border: none;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--light-text);
    transition: background-color 0.2s ease, color 0.2s ease;
}

.view-toggle button.active {
    background: var(--primary-color);
    color: #fff;
}

.view-toggle button:not(.active):hover {
    background: var(--surface-muted);
    color: var(--text-color);
}

.nav-diff {
    display: inline-flex;
    gap: 0.35rem;
}

.nav-diff button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--light-text);
    font-size: 0.8rem;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.nav-diff button:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

/* statistics badges */
#diffSummary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.28rem 0.7rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge i {
    font-size: 0.72rem;
}

.badge-diff {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

.badge-same {
    background: rgba(34, 197, 94, 0.12);
    color: #16a34a;
}

.badge-add {
    background: rgba(34, 197, 94, 0.1);
    color: #16a34a;
}

.badge-del {
    background: rgba(239, 68, 68, 0.08);
    color: #dc2626;
}

.badge-change {
    background: rgba(245, 158, 11, 0.12);
    color: #b45309;
}

.badge-info {
    background: var(--surface-muted);
    border: 1px solid var(--border-color);
    color: var(--light-text);
}

/* ========== diff views ========== */
.diff-view {
    position: relative;
    max-height: 560px;
    overflow: auto;
    background: var(--surface);
    font-family: var(--font-mono);
    font-size: 0.83rem;
    line-height: 1.6;
}

/* side-by-side view: line numbers + content, twice */
.diff-view:not(.unified) .diff-row {
    display: grid;
    grid-template-columns: 3.2em minmax(0, 1fr) 3.2em minmax(0, 1fr);
    border-bottom: 1px solid rgba(226, 232, 240, 0.5);
}

/* unified view: two line numbers + marker + content */
.diff-view.unified .diff-row {
    display: grid;
    grid-template-columns: 3.2em 3.2em 1.6em minmax(0, 1fr);
    border-bottom: 1px solid rgba(226, 232, 240, 0.5);
}

.diff-row .ln {
    padding: 0.1rem 0.55rem;
    text-align: right;
    color: #94a3b8;
    background: var(--surface-muted);
    border-right: 1px solid var(--border-color);
    user-select: none;
    font-size: 0.76rem;
    white-space: nowrap;
    overflow: hidden;
}

.diff-row .cell {
    padding: 0.1rem 0.75rem;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.diff-row .cell:nth-of-type(1) {
    border-right: 1px solid var(--border-color);
}

.diff-view.unified .u-mark {
    text-align: center;
    color: var(--light-text);
    user-select: none;
    font-weight: 700;
}

/* line level diff colouring */
.diff-del,
.u-del {
    background: rgba(239, 68, 68, 0.06);
}

.diff-del .cell,
.u-del .cell {
    background: rgba(239, 68, 68, 0.05);
}

.diff-add,
.u-add {
    background: rgba(34, 197, 94, 0.06);
}

.diff-add .cell,
.u-add .cell {
    background: rgba(34, 197, 94, 0.05);
}

.diff-change .cell:first-of-type {
    background: rgba(239, 68, 68, 0.05);
}

.diff-change .cell:last-of-type {
    background: rgba(34, 197, 94, 0.05);
}

.diff-del .ln,
.u-del .ln,
.diff-change .ln:first-child {
    color: #dc2626;
}

.diff-add .ln,
.u-add .ln,
.diff-change .ln:nth-child(3) {
    color: #16a34a;
}

.u-del .u-mark {
    color: #dc2626;
}

.u-add .u-mark {
    color: #16a34a;
}

/* inline character level diff highlight */
.diff-view mark {
    padding: 0.08em 0.1em;
    border-radius: 3px;
    color: inherit;
}

mark.inline-del {
    background: rgba(239, 68, 68, 0.28);
}

mark.inline-add {
    background: rgba(34, 197, 94, 0.3);
}

/* the line the navigation currently points at */
.diff-row.current-diff {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

.diff-truncated {
    padding: 0.75rem 1rem;
    text-align: center;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--light-text);
    background: var(--surface-muted);
}

/* ========== responsive ========== */
@media (max-width: 900px) {
    .diff-editors {
        grid-template-columns: 1fr;
    }

    .diff-options {
        margin-left: 0;
        width: 100%;
    }
}

@media (max-width: 768px) {
    .toolbar-divider {
        display: none;
    }

    .view-toggle {
        margin-left: 0;
    }

    .diff-editor textarea {
        height: 220px;
    }

    /* On narrow screens hide the second line number column of the side-by-side view to save space */
    .diff-view:not(.unified) .diff-row {
        grid-template-columns: 2.6em minmax(0, 1fr) 2.6em minmax(0, 1fr);
    }
}
