:root {
    --page: #f4f7f8;
    --surface: #ffffff;
    --surface-soft: #eef4f5;
    --ink: #132024;
    --muted: #607078;
    --line: #d7e2e5;
    --brand: #11636d;
    --brand-dark: #0b444c;
    --accent: #c64e35;
    --accent-soft: #fff0dc;
    --match-line: #fff6d8;
    --match-text: #ffcf4d;
    --shadow: 0 18px 44px rgba(22, 42, 48, 0.1);
}

* {
    box-sizing: border-box;
}

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

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

button,
select,
input[type="checkbox"] {
    cursor: pointer;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    min-height: 66px;
    padding: 0 28px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    font-weight: 800;
    text-decoration: none;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--brand);
    color: #fff;
    font-size: 0.78rem;
    letter-spacing: 0;
}

.header-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    color: var(--muted);
    font-size: 0.84rem;
}

.header-stats span {
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.workspace {
    display: grid;
    grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
    gap: 18px;
    width: min(1540px, calc(100% - 32px));
    margin: 0 auto;
    padding: 18px 0;
}

.workspace.controls-hidden {
    grid-template-columns: minmax(0, 1fr);
}

.workspace.controls-hidden .control-panel {
    display: none;
}

.control-panel,
.viewer-panel {
    min-height: calc(100vh - 102px);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.control-panel {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 18px;
}

.panel-section {
    display: grid;
    gap: 10px;
}

.section-title,
.viewer-toolbar,
.action-row,
.view-actions {
    flex-wrap: wrap;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 1.35rem;
    line-height: 1.2;
}

h2 {
    font-size: 1.18rem;
    line-height: 1.25;
}

.eyebrow {
    margin-bottom: 4px;
    color: var(--brand);
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

label {
    color: var(--ink);
    font-size: 0.86rem;
    font-weight: 800;
}

textarea,
input[type="text"],
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfdfd;
    color: var(--ink);
}

textarea {
    min-height: 330px;
    padding: 12px;
    resize: vertical;
    font: 0.9rem/1.5 "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

input[type="text"],
select {
    min-height: 42px;
    padding: 0 11px;
}

textarea:focus,
input[type="text"]:focus,
select:focus,
button:focus-visible,
.code-frame:focus {
    border-color: var(--brand);
    outline: 3px solid rgba(17, 99, 109, 0.16);
}

.compact-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.option-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 4px;
}

.check-option {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    font-weight: 700;
}

.check-option input {
    width: 16px;
    height: 16px;
    accent-color: var(--brand);
}

button {
    min-height: 42px;
    border: 1px solid var(--brand);
    border-radius: 8px;
    background: var(--brand);
    color: #fff;
    padding: 0 14px;
    font-weight: 800;
}

button:hover {
    background: var(--brand-dark);
}

.secondary-button {
    border-color: var(--line);
    background: var(--surface-soft);
    color: var(--brand-dark);
}

.secondary-button:hover {
    background: #deebee;
}

.danger-button {
    border-color: #d69a8b;
    background: #fff4f1;
    color: #9e341e;
}

.danger-button:hover {
    background: #ffe7df;
}

.icon-button {
    width: 42px;
    padding: 0;
    font-size: 1.05rem;
}

.status-text {
    min-height: 22px;
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.4;
}

.viewer-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.viewer-toolbar {
    min-height: 74px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.viewer-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 0;
    flex: 1;
}

.viewer-layout.results-hidden {
    grid-template-columns: minmax(0, 1fr);
}

.viewer-layout.results-hidden .result-list {
    display: none;
}

.result-list {
    min-height: 0;
    max-height: calc(100vh - 178px);
    margin: 0;
    padding: 10px;
    overflow: auto;
    border-right: 1px solid var(--line);
    background: #f9fbfb;
    list-style: none;
}

.result-list li {
    margin-bottom: 8px;
}

.result-list button {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr);
    gap: 8px;
    width: 100%;
    min-height: 0;
    padding: 9px;
    border-color: var(--line);
    background: var(--surface);
    color: var(--ink);
    text-align: left;
}

.result-list button:hover,
.result-list button.active {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.result-line {
    color: var(--brand);
    font-weight: 800;
}

.result-preview {
    overflow: hidden;
    color: var(--muted);
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.78rem;
    line-height: 1.4;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.empty-results {
    padding: 12px;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.45;
}

.code-frame {
    min-width: 0;
    max-height: calc(100vh - 178px);
    overflow: auto;
    background: #ffffff;
}

pre {
    min-width: max-content;
    margin: 0;
    padding: 12px 0 18px;
}

code {
    display: block;
    background: transparent;
    font: 0.88rem/1.55 "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    tab-size: 4;
}

.code-line {
    display: grid;
    grid-template-columns: var(--gutter-width, 54px) minmax(680px, 1fr);
    min-height: 24px;
    border-left: 4px solid transparent;
}

.code-line.is-match {
    border-left-color: var(--accent);
    background: var(--match-line);
}

.code-line.is-current {
    box-shadow: inset 0 0 0 2px rgba(198, 78, 53, 0.28);
}

.line-number {
    position: sticky;
    left: 0;
    z-index: 1;
    padding: 0 12px;
    border-right: 1px solid var(--line);
    background: #eef4f5;
    color: #63747d;
    text-align: right;
    user-select: none;
}

.line-content {
    padding: 0 14px;
    white-space: pre;
}

.match-mark {
    border-radius: 4px;
    background: var(--match-text);
    color: #241c03;
    padding: 1px 0;
}

@media (max-width: 1100px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    .control-panel,
    .viewer-panel {
        min-height: auto;
    }

    .viewer-layout {
        grid-template-columns: 1fr;
    }

    .result-list {
        display: flex;
        gap: 8px;
        max-height: none;
        overflow-x: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .result-list li {
        min-width: 210px;
        margin-bottom: 0;
    }
}

@media (max-width: 720px) {
    .app-header {
        align-items: flex-start;
        flex-direction: column;
        padding: 12px 16px;
    }

    .header-stats {
        justify-content: flex-start;
    }

    .workspace {
        width: min(100% - 20px, 1540px);
        padding-top: 10px;
    }

    .compact-grid,
    .option-grid {
        grid-template-columns: 1fr;
    }

    .action-row {
        align-items: stretch;
        flex-direction: column;
    }

    .viewer-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .view-actions {
        justify-content: flex-start;
        width: 100%;
    }

    .view-actions .secondary-button {
        flex: 1 1 150px;
    }

    textarea {
        min-height: 260px;
    }

    .code-line {
        grid-template-columns: var(--gutter-width, 48px) minmax(520px, 1fr);
    }
}
