/*
 * MIT License
 * Copyright (c) 2026 Timo Heimonen <timo.heimonen@proton.me>
 * See LICENSE file for full terms at github.com/timoheimonen/diffvoid
 */

:root {
    --bg-color: #ffffff;
    --text-color: #1a1a1a;
    --toggle-bg: #f0f0f0;
    --toggle-hover: #e0e0e0;
    --field-bg: #fafafa;
    --border-color: #e0e0e0;
    --border-focus: #999999;
    --diff-match: #16a34a;
    --diff-mismatch: #dc2626;
    --diff-missing-bg: rgba(220, 38, 38, 0.12);
    --diff-gutter-color: #9ca3af;
    --placeholder-color: #c0c0c0;
}

[data-theme="dark"] {
    --bg-color: #0d0d0d;
    --text-color: #e6e6e6;
    --toggle-bg: #1a1a1a;
    --toggle-hover: #2a2a2a;
    --field-bg: #141414;
    --border-color: #2a2a2a;
    --border-focus: #555555;
    --diff-match: #4ade80;
    --diff-mismatch: #f87171;
    --diff-missing-bg: rgba(248, 113, 113, 0.12);
    --diff-gutter-color: #555555;
    --placeholder-color: #3a3a3a;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.2s ease, color 0.2s ease;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    flex-shrink: 0;
}

header h1 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
    opacity: 0.7;
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.header-links {
    font-size: 10px;
    display: flex;
    gap: 8px;
}

.link-separator {
    opacity: 0.3;
}

.header-links a {
    color: var(--text-color);
    opacity: 0.5;
    text-decoration: none;
}

.header-links a:hover {
    opacity: 0.8;
}

.mismatch-counter {
    font-size: 13px;
    font-weight: 600;
    color: var(--diff-mismatch);
    background-color: rgba(220, 38, 38, 0.12);
    padding: 6px 12px;
    border-radius: 4px;
    margin: 0 auto;
}

.mismatch-counter.all-match {
    color: var(--diff-match);
    background-color: rgba(22, 163, 74, 0.12);
}

.copy-clean-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 auto;
}

.copy-clean-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--toggle-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    color: var(--text-color);
    font-size: 11px;
    font-weight: 600;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    opacity: 0;
    pointer-events: none;
}

.copy-clean-btn.visible {
    opacity: 1;
    pointer-events: auto;
}

.copy-clean-btn:hover {
    background: var(--toggle-hover);
    border-color: var(--border-focus);
}

.copy-clean-btn svg {
    stroke: currentColor;
}

.copy-clean-btn.copy-success {
    background-color: rgba(22, 163, 74, 0.2);
    border-color: var(--diff-match);
    color: var(--diff-match);
}

[data-theme="dark"] .copy-clean-btn.copy-success {
    background-color: rgba(74, 222, 128, 0.2);
}

[data-theme="dark"] .mismatch-counter {
    background-color: rgba(248, 113, 113, 0.12);
}

[data-theme="dark"] .mismatch-counter.all-match {
    background-color: rgba(74, 222, 128, 0.12);
}

main {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.text-field {
    flex: none;
    width: calc(50% - 2.5px);
    height: 100%;
    padding: 1rem 1.5rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    background-color: var(--field-bg);
    color: var(--text-color);
    border: none;
    outline: none;
    overflow-y: auto;
    overflow-x: hidden;
    white-space: pre-wrap;
    word-break: break-word;
    cursor: text;
    position: relative;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.text-field.is-empty::before {
    content: attr(data-placeholder);
    color: var(--placeholder-color);
    pointer-events: none;
    position: absolute;
    top: 1rem;
    left: 1.5rem;
}

.text-field:focus {
    background-color: var(--bg-color);
}

.divider {
    flex: none;
    width: 5px;
    height: 100%;
    cursor: col-resize;
    background-color: var(--border-color);
    transition: background-color 0.2s ease, width 0.1s ease;
    position: relative;
}

.divider:hover {
    background-color: var(--border-focus);
    width: 7px;
    margin: 0 -1px;
}

.divider.dragging {
    background-color: var(--diff-mismatch);
    width: 7px;
    margin: 0 -1px;
}

body.resizing {
    user-select: none;
    cursor: col-resize;
}

body.resizing .text-field,
body.resizing .diff-gutter {
    cursor: col-resize;
}

#theme-toggle {
    position: relative;
}

.icon-button {
    background: var(--toggle-bg);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-color);
    transition: background-color 0.2s ease;
}

.icon-button:hover {
    background: var(--toggle-hover);
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

#clear-button {
    position: relative;
}

.sun-icon,
.moon-icon {
    position: absolute;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

[data-theme="light"] .sun-icon {
    opacity: 1;
    transform: scale(1);
}

[data-theme="light"] .moon-icon {
    opacity: 0;
    transform: scale(0.8);
}

[data-theme="dark"] .sun-icon {
    opacity: 0;
    transform: scale(0.8);
}

[data-theme="dark"] .moon-icon {
    opacity: 1;
    transform: scale(1);
}

.diff-line {
    display: flex;
    min-height: 1.6em;
    margin: 0 -1.5rem;
    padding: 0;
}

.diff-gutter {
    flex-shrink: 0;
    width: 2.8rem;
    padding: 0 0.4rem 0 0;
    text-align: right;
    color: var(--diff-gutter-color);
    font-size: 11px;
    border-right: 1px solid var(--border-color);
    margin-right: 0.6rem;
    user-select: none;
    cursor: default;
}

.diff-content {
    flex: 1;
    min-width: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.diff-match {
    color: var(--text-color);
}

.diff-mismatch {
    color: var(--diff-mismatch);
}

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

.diff-line-mismatch .diff-gutter {
    color: var(--diff-mismatch);
    opacity: 0.6;
}

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

.diff-line-missing .diff-content {
    display: block;
    width: 100%;
    min-height: 1.6em;
}

.invisible-char {
    display: inline-block;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85em;
    font-weight: bold;
    padding: 0 2px;
    margin: 0 1px;
    border-radius: 2px;
    vertical-align: middle;
    line-height: 1;
}

.invisible-zwsp::before {
    content: "|";
}

.invisible-zwnj::before {
    content: "[ZWNJ]";
}

.invisible-zwj::before {
    content: "[ZWJ]";
}

.invisible-hair::before {
    content: "[HS]";
}

.invisible-nbsp::before {
    content: "[NBSP]";
}

.invisible-nnbsp::before {
    content: "[NNBSP]";
}

.invisible-shy::before {
    content: "[SHY]";
}

.invisible-ensp::before {
    content: "[EN]";
}

.invisible-emsp::before {
    content: "[EM]";
}

.invisible-thin::before {
    content: "[THIN]";
}

.invisible-figure::before {
    content: "[FIG]";
}

.invisible-punct::before {
    content: "[PUNCT]";
}

.invisible-mmsp::before {
    content: "[MMSP]";
}

.invisible-wj::before {
    content: "[WJ]";
}

.invisible-bom::before {
    content: "[BOM]";
}

.invisible-ideo::before {
    content: "[IDEO]";
}

.invisible-lrm::before {
    content: "[LRM]";
}

.invisible-rlm::before {
    content: "[RLM]";
}

.invisible-mvs::before {
    content: "[MVS]";
}

.invisible-space::before {
    content: "[SP]";
}

.invisible-regular-space {
    display: inline-block;
    width: 0.5em;
    height: 0.9em;
    background-color: rgba(220, 38, 38, 0.4);
    border-radius: 1px;
    vertical-align: middle;
    margin: 0 1px;
}

[class^="invisible-"]:not(.invisible-char):not(.invisible-regular-space) {
    color: var(--diff-mismatch);
    background-color: rgba(220, 38, 38, 0.15);
}

[data-theme="dark"] [class^="invisible-"]:not(.invisible-char):not(.invisible-regular-space) {
    color: var(--diff-mismatch);
    background-color: rgba(248, 113, 113, 0.15);
}

[data-theme="dark"] .invisible-regular-space {
    background-color: rgba(248, 113, 113, 0.5);
}
