/* ── Text compare ───────────────────────────────────────────────────────────
   Layout for /text-compare. Colour comes from the workspace theme variables so
   the page follows the active theme like the rest of the workspace.
   ────────────────────────────────────────────────────────────────────────── */

/* The .workspace-* chrome lives inside TextEditor.razor's <style> block, which is
   only in the DOM while that page is rendered. Standalone pages therefore carry
   their own copy — json-editor.css does the same. Worth extracting into a shared
   workspace-shell.css if a third standalone page appears. */

.text-compare-page {
    --compare-added: #2ea043;
    --compare-removed: #f85149;
    --compare-changed: #d29922;

    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 100%;
    min-height: 0;
    padding-top: 4px;
    overflow: hidden;
}

.text-compare-page .workspace-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-shrink: 0;
    padding: 8px 14px;
    border: 1px solid var(--workspace-border);
    border-radius: 18px;
    background: var(--workspace-surface);
}

.text-compare-page .workspace-title-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1 1 auto;
    min-width: 0;
}

.text-compare-page .workspace-kicker-row {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
}

.text-compare-page .workspace-kicker {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--workspace-text);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}

.text-compare-page .workspace-kicker-dot {
    width: 5px;
    height: 5px;
    border-radius: 999px;
    background: var(--workspace-accent);
}

.text-compare-page .workspace-breadcrumb {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    font-size: 11px;
    color: var(--workspace-text-muted);
}

.text-compare-page .workspace-breadcrumb-sep {
    color: var(--workspace-text-subtle);
}

.text-compare-page .workspace-breadcrumb-current {
    color: var(--workspace-accent);
    font-weight: 700;
}

.text-compare-page .workspace-heading-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
}

.text-compare-page .workspace-heading-row h1 {
    margin: 0;
    color: var(--workspace-text);
    font-size: 17px;
    font-weight: 800;
    line-height: 1.2;
    white-space: nowrap;
}

.text-compare-page .workspace-subtitle {
    margin: 0;
    flex: 1 1 auto;
    min-width: 0;
    color: var(--workspace-text-muted);
    font-size: 12px;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.text-compare-page .workspace-topbar-meta {
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
}

.text-compare-page .workspace-status-card {
    display: flex;
    align-items: center;
    gap: 9px;
    max-width: 220px;
    padding: 6px 10px;
    border-radius: 12px;
    background: var(--workspace-surface-soft);
    border: 1px solid var(--workspace-border);
}

.text-compare-page .workspace-status-card .mud-icon-root {
    font-size: 17px !important;
}

.text-compare-page .workspace-status-copy {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.text-compare-page .workspace-status-copy span {
    color: var(--workspace-text-muted);
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1.2;
    text-transform: uppercase;
}

.text-compare-page .workspace-status-copy strong {
    color: var(--workspace-text);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.25;
}

.text-compare-page .pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-shrink: 0;
    padding: 8px 14px;
    border-bottom: 1px solid var(--workspace-border);
    background: var(--workspace-surface-soft);
}

/* ── Input state ─────────────────────────────────────────────────────────── */

.compare-inputs {
    display: flex;
    gap: 12px;
    flex: 1 1 auto;
    min-height: 0;
}

.compare-pane {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    border: 1px solid var(--workspace-border);
    border-radius: 14px;
    background: var(--workspace-surface);
    overflow: hidden;
}

.compare-pane-title {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--workspace-text);
}

.compare-pane-meta {
    font-size: 11px;
    color: var(--workspace-text-muted);
}

.compare-textarea {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    resize: none;
    border: 0;
    outline: none;
    padding: 12px 14px;
    background: transparent;
    color: var(--workspace-text);
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.55;
}

.compare-textarea::placeholder {
    color: var(--workspace-text-subtle);
}

/* ── Action bar ──────────────────────────────────────────────────────────── */

.compare-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    flex-shrink: 0;
    padding: 8px 12px;
    border: 1px solid var(--workspace-border);
    border-radius: 14px;
    background: var(--workspace-surface);
}

.compare-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.compare-badge {
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    border: 1px solid transparent;
}

.compare-badge--added {
    color: var(--compare-added);
    border-color: rgba(46, 160, 67, 0.35);
    background: rgba(46, 160, 67, 0.12);
}

.compare-badge--removed {
    color: var(--compare-removed);
    border-color: rgba(248, 81, 73, 0.35);
    background: rgba(248, 81, 73, 0.12);
}

.compare-badge--changed {
    color: var(--compare-changed);
    border-color: rgba(210, 153, 34, 0.35);
    background: rgba(210, 153, 34, 0.12);
}

.compare-badge--identical {
    color: var(--workspace-text);
    border-color: var(--workspace-border);
    background: var(--workspace-surface-soft);
}

.compare-warning {
    flex-shrink: 0;
    padding: 9px 12px;
    border-radius: 12px;
    border: 1px solid rgba(210, 153, 34, 0.35);
    background: rgba(210, 153, 34, 0.1);
    color: var(--workspace-text);
    font-size: 12px;
    line-height: 1.45;
}

/* ── Result table ────────────────────────────────────────────────────────── */

.compare-result {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    border: 1px solid var(--workspace-border);
    border-radius: 14px;
    background: var(--workspace-surface);
    overflow: hidden;
}

.compare-result-head {
    display: flex;
    flex-shrink: 0;
    border-bottom: 1px solid var(--workspace-border);
    background: var(--workspace-surface-soft);
}

.compare-result-head-cell {
    flex: 1 1 0;
    min-width: 0;
    padding: 8px 14px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--workspace-text-muted);
}

.compare-result-head-cell + .compare-result-head-cell {
    border-left: 1px solid var(--workspace-border);
}

.compare-result-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
}

.compare-row {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.compare-cell {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    flex: 1 1 0;
    min-width: 0;
    padding: 2px 12px 2px 0;
}

.compare-cell--right {
    border-left: 1px solid var(--workspace-border);
}

.compare-gutter {
    flex-shrink: 0;
    width: 44px;
    padding-right: 8px;
    text-align: right;
    color: var(--workspace-text-subtle);
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 11.5px;
    line-height: 1.6;
    user-select: none;
}

.compare-text {
    min-width: 0;
    color: var(--workspace-text);
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 12.5px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Row tinting. The added colour goes on the right cell only, removed on the
   left only, so an insertion does not paint an empty cell green. */
.compare-row--added .compare-cell--right {
    background: rgba(46, 160, 67, 0.13);
}

.compare-row--removed .compare-cell--left {
    background: rgba(248, 81, 73, 0.13);
}

.compare-row--changed .compare-cell--left {
    background: rgba(248, 81, 73, 0.09);
}

.compare-row--changed .compare-cell--right {
    background: rgba(46, 160, 67, 0.09);
}

.compare-row--added .compare-cell--left,
.compare-row--removed .compare-cell--right {
    background: rgba(255, 255, 255, 0.02);
}

/* Word-level highlight inside a changed line. */
.compare-word {
    padding: 0 1px;
    border-radius: 3px;
    background: transparent;
    color: inherit;
    font-weight: 600;
}

.compare-row--changed .compare-cell--left .compare-word {
    background: rgba(248, 81, 73, 0.32);
}

.compare-row--changed .compare-cell--right .compare-word {
    background: rgba(46, 160, 67, 0.32);
}

.compare-empty {
    padding: 28px;
    text-align: center;
    color: var(--workspace-text-muted);
    font-size: 13px;
}

/* ── Light theme ─────────────────────────────────────────────────────────── */

/* light.css sets `.theme-light span { color: var(--bepa-text) !important; }` across
   the whole app, which would flatten the gutters and repaint the coloured badges in
   body-text ink. These win it back — same approach the workspace pages already take. */

.theme-light .compare-gutter,
.theme-light .compare-pane-meta,
.theme-light .text-compare-page .workspace-status-copy span,
.theme-light .text-compare-page .workspace-breadcrumb > span {
    color: var(--workspace-text-muted) !important;
}

/* Needs the element qualifier to outrank the `> span` rule above it. */
.theme-light .text-compare-page .workspace-breadcrumb > span.workspace-breadcrumb-current {
    color: var(--workspace-accent) !important;
}

.theme-light .compare-badge--added {
    color: var(--compare-added) !important;
}

.theme-light .compare-badge--removed {
    color: var(--compare-removed) !important;
}

.theme-light .compare-badge--changed {
    color: var(--compare-changed) !important;
}

.theme-light .compare-row {
    border-bottom-color: rgba(0, 0, 0, 0.05);
}

.theme-light .compare-row--added .compare-cell--left,
.theme-light .compare-row--removed .compare-cell--right {
    background: rgba(0, 0, 0, 0.02);
}

.theme-light .compare-word {
    font-weight: 700;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
    .compare-inputs {
        flex-direction: column;
    }

    .compare-pane {
        flex: 1 1 0;
        min-height: clamp(180px, 26vh, 300px);
    }

    /* Two columns of monospace text do not fit; stack each row's sides instead. */
    .compare-row {
        flex-direction: column;
    }

    .compare-cell--right {
        border-left: 0;
        border-top: 1px dashed var(--workspace-border);
    }

    .compare-result-head-cell:last-child {
        display: none;
    }

    .compare-result-head-cell:first-child::after {
        content: " / Changed";
    }
}
