* {
    box-sizing: border-box;
}

:root {
    color-scheme: dark;
    --background: #101317;
    --panel: #191e25;
    --panel-light: #222934;
    --border: #353e49;
    --text: #ffffff;
    --muted: #aeb7c2;
    --accent: #4f8de8;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--background);
    color: var(--text);
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-light);
    color: var(--text);
    cursor: pointer;
}

button:hover:not(:disabled) {
    border-color: var(--accent);
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #0d1014;
    color: var(--text);
}

input,
select {
    margin-top: 8px;
    padding: 10px 12px;
}

textarea {
    resize: vertical;
}

label {
    color: var(--muted);
}

.top-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 30px;
    padding: 28px 32px;
    border-bottom: 1px solid var(--border);
}

.top-header h1 {
    margin: 10px 0 8px;
}

.top-header p {
    margin: 0;
    color: var(--muted);
}

.back-link {
    color: #8cbaff;
    text-decoration: none;
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.danger-button {
    border-color: #704141;
    background: #3c2424;
}

.tab-bar {
    display: flex;
    gap: 8px;
    padding: 14px 20px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    background: #13171c;
}

.tab-button {
    white-space: nowrap;
}

.tab-button.active {
    border-color: var(--accent);
    background: var(--accent);
}

.workspace {
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding: 24px 32px 50px;
}

.tool-panel,
.persistent-editor-panel {
    min-width: 0;
}

.tool-panel {
    padding-bottom: 22px;
    border-bottom: 1px solid var(--border);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.panel-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    margin-bottom: 20px;
}

.panel-heading h2 {
    margin: 0 0 8px;
}

.panel-heading p {
    margin: 0;
    color: var(--muted);
}

.editor-status {
    display: flex;
    gap: 16px;
    color: var(--muted);
}

.editor-wrapper {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    height: 650px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #0d1014;
}

.editor-line-numbers {
    min-width: 58px;
    height: 100%;
    padding: 18px 12px;
    overflow: hidden;
    border-right: 1px solid var(--border);
    background: #151a20;
    color: #6f7b88;
    font-family: Consolas, "Courier New", monospace;
    font-size: 15px;
    line-height: 1.55;
    text-align: right;
    white-space: pre;
    user-select: none;
}

.code-editor {
    height: 100%;
    min-height: 0;
    padding: 18px;
    border: 0;
    border-radius: 0;
    resize: none;
    outline: none;
    overflow: auto;
    font-family: Consolas, "Courier New", monospace;
    font-size: 15px;
    line-height: 1.55;
    white-space: pre;
}

.code-editor:focus {
    box-shadow: inset 0 0 0 1px var(--accent);
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 18px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
}

.checkbox-row {
    display: flex;
    flex-wrap: wrap;
    gap: 22px;
    margin-top: 18px;
}

.checkbox-row label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-row input {
    width: auto;
    margin: 0;
}

.result-box,
.compare-results {
    margin-top: 18px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
    color: var(--muted);
}

.compare-editor {
    display: block;
    min-height: 360px;
    margin-top: 8px;
    padding: 14px;
    font-family: Consolas, "Courier New", monospace;
}

.match-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 24px;
    margin-bottom: 12px;
}

.match-heading h3 {
    margin: 0;
}

.match-heading span {
    color: var(--muted);
}

.match-list {
    display: grid;
    gap: 10px;
    max-height: 320px;
    overflow-y: auto;
}

.match-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    padding: 13px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--panel);
    cursor: pointer;
}

.match-item:hover {
    border-color: var(--accent);
    background: var(--panel-light);
}

.match-item.selected {
    border-color: var(--accent);
    box-shadow: inset 4px 0 0 var(--accent);
}

.match-line-number {
    min-width: 65px;
    color: #8cbaff;
    font-weight: bold;
}

.match-code {
    min-width: 0;
    font-family: Consolas, "Courier New", monospace;
}

.match-original-line {
    overflow: hidden;
    color: var(--muted);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.match-change {
    margin-top: 7px;
    color: var(--text);
}

.match-old-value {
    color: #e5a0a0;
    text-decoration: line-through;
}

.match-arrow {
    margin: 0 8px;
    color: var(--muted);
}

.match-new-value {
    color: #9dd5a5;
    font-weight: bold;
}

.empty-message {
    padding: 20px;
    border: 1px dashed var(--border);
    border-radius: 9px;
    color: var(--muted);
    text-align: center;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.summary-card {
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
}

.summary-card span {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
}

.summary-card strong {
    font-size: 26px;
}

.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
}

th,
td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

th {
    color: var(--muted);
}

tbody tr {
    cursor: pointer;
}

tbody tr:hover {
    background: var(--panel-light);
}

.history-list {
    display: grid;
    gap: 10px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
}

.compare-line {
    display: grid;
    grid-template-columns: 65px 1fr;
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    font-family: Consolas, "Courier New", monospace;
}

.compare-line.changed {
    background: #3a2f1f;
}

.compare-line.added {
    background: #1f3a2a;
}

.compare-line.removed {
    background: #3a2222;
}

.compare-line.same {
    color: var(--muted);
}

@media (max-width: 800px) {
    .top-header {
        flex-direction: column;
    }

    .workspace {
        padding: 20px 16px 40px;
    }

    .panel-heading {
        flex-direction: column;
    }

    .editor-wrapper {
        height: 500px;
    }
}
