/* ===== Base Reset & Variables ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #e2e5ea;
    --text: #1a1d23;
    --text-secondary: #6b7280;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;

    /* Diff colors */
    --diff-delete-bg: #fde8e8;
    --diff-delete-text: #c53030;
    --diff-delete-border: #fc8181;
    --diff-insert-bg: #e6ffed;
    --diff-insert-text: #22543d;
    --diff-insert-border: #68d391;
    --diff-change-left-bg: #fff5f5;
    --diff-change-left-text: #c53030;
    --diff-change-right-bg: #f0fff4;
    --diff-change-right-text: #22543d;
    --diff-only-left-bg: #fff1f0;
    --diff-only-right-bg: #f0fff4;
    --diff-ignored-opacity: 0.35;

    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;
}

html { font-size: 15px; }
body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ===== Header ===== */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.8rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-inner { max-width: 1400px; margin: 0 auto; }
.logo {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.logo-img {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    object-fit: cover;
    vertical-align: middle;
}
.logo-sub {
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-left: 0.25rem;
}

/* ===== Input Section ===== */
.input-section {
    max-width: 1400px;
    margin: 1.5rem auto;
    padding: 0 1.5rem;
}
.input-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}
.input-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.input-card-label {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    color: var(--text);
}

/* File Upload */
.file-upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.file-upload-area:hover,
.file-upload-area.dragover {
    border-color: var(--accent);
    background: #f0f4ff;
}
.upload-icon {
    font-size: 1.8rem;
    display: block;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
}
.file-upload-placeholder p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.upload-hint { font-size: 0.8rem !important; margin-top: 0.15rem; }
.file-upload-selected {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
}
.file-name {
    font-weight: 500;
    word-break: break-all;
}
.file-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 1.1rem;
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    margin-left: auto;
}
.file-remove:hover { background: #fee; color: #c53030; }

/* Tabs */
.input-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 0.75rem;
    background: var(--bg);
    border-radius: 6px;
    padding: 2px;
}
.tab-btn {
    flex: 1;
    padding: 0.4rem 0.35rem;
    border: none;
    background: transparent;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-secondary);
    transition: all 0.15s;
    font-family: var(--font-sans);
    white-space: nowrap;
}
.tab-btn.active {
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

.text-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.15s;
}
.text-input:focus { border-color: var(--accent); }
.text-area {
    width: 100%;
    min-height: 80px;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    resize: vertical;
    outline: none;
    transition: border-color 0.15s;
}
.text-area:focus { border-color: var(--accent); }

/* Action Bar */
.action-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1rem;
    gap: 1rem;
}
.threshold-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.threshold-control input[type="range"] {
    width: 140px;
    accent-color: var(--accent);
}
#thresholdValue {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    min-width: 2.5em;
    color: var(--text);
    font-weight: 600;
}
.threshold-hint {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-left: 0.5rem;
}

.btn-compare {
    padding: 0.65rem 2rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    font-family: var(--font-sans);
}
.btn-compare:hover { background: var(--accent-hover); }
.btn-compare:active { transform: scale(0.98); }
.btn-compare:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

/* ===== Error Banner ===== */
.error-banner {
    max-width: 1400px;
    margin: 1rem auto;
    padding: 0.75rem 1.25rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    color: #991b1b;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    margin-left: 1.5rem;
    margin-right: 1.5rem;
}
.error-close {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: #991b1b;
    font-size: 1.1rem;
    padding: 0.1rem 0.3rem;
}

/* ===== Summary Section ===== */
.summary-section {
    max-width: 1400px;
    margin: 0 auto 1rem;
    padding: 0 1.5rem;
}
.summary-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.summary-stats {
    display: flex;
    gap: 1.5rem;
}
.stat {
    text-align: center;
}
.stat-num {
    display: block;
    font-size: 1.4rem;
    font-weight: 700;
    font-family: var(--font-mono);
    line-height: 1.2;
}
.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.stat-warn .stat-num { color: #d97706; }
.stat-info .stat-num { color: #2563eb; }
.stat-danger .stat-num { color: #dc2626; }

.diff-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.diff-nav-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.nav-btn {
    padding: 0.3rem 0.75rem;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text);
    transition: all 0.15s;
    font-family: var(--font-sans);
}
.nav-btn:hover { border-color: var(--accent); color: var(--accent); }
.nav-pos {
    font-size: 0.85rem;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    min-width: 3.5em;
    text-align: center;
}

.diff-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.6rem;
}
.diff-tag {
    padding: 0.15rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    cursor: pointer;
    border: 1px solid;
    transition: all 0.15s;
    white-space: nowrap;
}
.diff-tag.type-change {
    background: #fefce8;
    border-color: #fbbf24;
    color: #92400e;
}
.diff-tag.type-left-only {
    background: #fff1f0;
    border-color: #fc8181;
    color: #c53030;
}
.diff-tag.type-right-only {
    background: #f0fdf4;
    border-color: #68d391;
    color: #166534;
}
.diff-tag:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.diff-tag.ignored { opacity: var(--diff-ignored-opacity); text-decoration: line-through; }

/* ===== Diff Section ===== */
.diff-section {
    max-width: 1400px;
    margin: 0 auto 3rem;
    padding: 0 1.5rem;
}
.diff-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
}
.diff-col-header {
    padding: 0.65rem 1rem;
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.diff-col-header.left {
    border-right: 1px solid var(--border);
}

.diff-body {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow);
}
.diff-col {
    padding: 0.5rem 0;
}
.diff-divider {
    width: 1px;
    background: var(--border);
}

/* Diff rows */
.diff-row {
    padding: 0.5rem 1rem;
    line-height: 1.7;
    font-size: 0.9rem;
    border-bottom: 1px solid #f1f3f5;
    min-height: 2.2rem;
    transition: opacity 0.3s;
}
.diff-row:last-child { border-bottom: none; }

/* Match rows - normal text */
.diff-row.match { }

/* Diff highlight spans inside match rows */
.diff-row .diff-change {
    border-radius: 2px;
    padding: 0.05em 0.15em;
    margin: 0 1px;
}
.diff-col.left .diff-change {
    background: var(--diff-change-left-bg);
    color: var(--diff-change-left-text);
    text-decoration: line-through;
    text-decoration-color: rgba(197, 48, 48, 0.4);
}
.diff-col.right .diff-change {
    background: var(--diff-change-right-bg);
    color: var(--diff-change-right-text);
}
.diff-col.left .diff-delete {
    background: var(--diff-delete-bg);
    color: var(--diff-delete-text);
    text-decoration: line-through;
    text-decoration-color: rgba(197, 48, 48, 0.4);
    border-radius: 2px;
    padding: 0.05em 0.15em;
}
.diff-col.right .diff-insert {
    background: var(--diff-insert-bg);
    color: var(--diff-insert-text);
    border-radius: 2px;
    padding: 0.05em 0.15em;
}

/* Only-left / only-right rows */
.diff-row.only-left {
    background: var(--diff-only-left-bg);
    border-left: 3px solid var(--diff-delete-border);
}
.diff-row.only-right {
    background: var(--diff-only-right-bg);
    border-left: 3px solid var(--diff-insert-border);
}
.diff-row.placeholder {
    background: #fafafa;
    color: transparent;
    user-select: none;
}

/* Has-diff marker */
.diff-row.has-diff {
    border-left: 3px solid #fbbf24;
}

/* Ignored state */
.diff-row.ignored {
    opacity: var(--diff-ignored-opacity);
}

/* Ignore button */
.ignore-btn {
    float: right;
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.1rem 0.4rem;
    font-size: 0.7rem;
    color: var(--text-secondary);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    font-family: var(--font-sans);
}
.diff-row:hover .ignore-btn { opacity: 1; }
.ignore-btn:hover { background: #f1f3f5; }
.diff-row.ignored .ignore-btn { opacity: 1; }

/* Active diff highlight for navigation */
.diff-row.nav-active {
    box-shadow: inset 0 0 0 2px var(--accent);
    border-radius: 3px;
}

/* ===== Scrollbar ===== */
.diff-col::-webkit-scrollbar { width: 8px; }
.diff-col::-webkit-scrollbar-track { background: #f1f3f5; }
.diff-col::-webkit-scrollbar-thumb {
    background: #adb5bd;
    border-radius: 4px;
}
.diff-col::-webkit-scrollbar-thumb:hover { background: #868e96; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .input-panel { grid-template-columns: 1fr; }
    .diff-body { height: 70vh; }
    .summary-bar { flex-direction: column; align-items: flex-start; }
    .action-bar { flex-direction: column; align-items: stretch; }
}
