* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #202124;
    background: #f6f7f9;
}

.app {
    display: grid;
    grid-template-columns:
        minmax(240px, var(--message-column, 320px))
        8px
        minmax(380px, var(--script-column, 1fr))
        8px
        minmax(260px, var(--output-column, 340px));
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    min-height: 100vh;
    padding: 16px;
}

.app-header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 52px;
    padding: 0 2px 8px;
}

.app-header h1 {
    margin: 0;
    color: #172033;
    font-size: 22px;
    font-weight: 750;
}

.help-button {
    min-width: 36px;
    width: 36px;
    min-height: 36px;
    padding: 0;
    border-color: #c7ccd5;
    border-radius: 999px;
    color: #26313f;
    background: #ffffff;
    font-size: 18px;
    line-height: 1;
}

.help-button:hover {
    border-color: #0969da;
    color: #0969da;
}

.column-resizer {
    min-width: 8px;
    border-radius: 6px;
    cursor: col-resize;
    background: transparent;
    position: relative;
    touch-action: none;
}

.column-resizer::before {
    content: "";
    position: absolute;
    top: 8px;
    bottom: 8px;
    left: 3px;
    width: 2px;
    border-radius: 999px;
    background: #d5d9e0;
}

.column-resizer:hover::before,
.column-resizer.is-dragging::before {
    background: #0969da;
}

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

.editor,
.output,
.message-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    border: 1px solid #d5d9e0;
    border-radius: 8px;
    background: #ffffff;
}

.output {
    gap: 0;
}

header,
.output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 56px;
    padding: 12px 16px;
    border-bottom: 1px solid #d5d9e0;
}

h1,
h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 650;
}

button {
    min-width: 64px;
    min-height: 36px;
    border: 1px solid #1f6feb;
    border-radius: 6px;
    color: #ffffff;
    background: #1f6feb;
    font-weight: 650;
    cursor: pointer;
}

.actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.button-tooltip {
    display: inline-flex;
}

.actions label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #394150;
    font-size: 14px;
}

.help-dialog {
    width: min(560px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    padding: 0;
    border: 1px solid #d5d9e0;
    border-radius: 8px;
    color: #202124;
    background: #ffffff;
    box-shadow: 0 24px 80px rgb(23 32 51 / 22%);
}

.help-dialog::backdrop {
    background: rgb(23 32 51 / 42%);
}

.help-dialog-content {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 48px);
}

.help-dialog-header {
    min-height: 52px;
    padding: 12px 16px;
}

.help-dialog-header h2 {
    font-size: 16px;
}

.help-close-button {
    min-width: 32px;
    width: 32px;
    min-height: 32px;
    padding: 0;
    border-color: #c7ccd5;
    color: #26313f;
    background: #ffffff;
    font-size: 22px;
    line-height: 1;
}

.help-dialog-body {
    overflow: auto;
    padding: 16px;
    color: #26313f;
    font-size: 14px;
    line-height: 1.55;
}

.help-dialog-body p {
    margin: 0 0 14px;
}

.help-dialog-body p:last-child {
    margin-bottom: 0;
}

.help-contact-links {
    text-align: center;
}

.help-dialog-body a {
    color: #0969da;
    overflow-wrap: anywhere;
}

.syntax-status,
.debug-capacity {
    max-width: min(360px, 34vw);
    min-height: 28px;
    padding: 5px 9px;
    overflow: hidden;
    border: 1px solid #c7ccd5;
    border-radius: 6px;
    color: #26313f;
    background: #ffffff;
    font-size: 12px;
    font-weight: 650;
    line-height: 16px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.debug-capacity {
    border-color: #d5d9e0;
    color: #394150;
    background: #f6f7f9;
}

.syntax-status.is-valid {
    border-color: #8ccf9f;
    color: #0f5132;
    background: #eefaf2;
}

.syntax-status.is-invalid {
    border-color: #f0b4b8;
    color: #842029;
    background: #fff1f2;
}

.syntax-status.is-pending {
    color: #5f6673;
}

.upload-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    min-height: 32px;
    padding: 0 12px;
    border: 1px solid #c7ccd5;
    border-radius: 6px;
    color: #26313f;
    background: #ffffff;
    font-size: 13px;
    font-weight: 650;
    cursor: pointer;
}

.upload-button input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

button:disabled {
    border-color: #c7ccd5;
    color: #8a93a3;
    background: #eef1f5;
}

.run-button:disabled span,
.continue-button:disabled span {
    border-left-color: #8a93a3;
}

.stop-button:disabled span {
    background: #8a93a3;
}

.step-over-button:disabled span::before {
    color: #8a93a3;
}

.run-button {
    min-width: 40px;
    width: 40px;
    padding: 0;
    border-color: #2da44e;
    background: #2da44e;
}

.run-button span {
    display: block;
    width: 0;
    height: 0;
    margin: 0 auto;
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
    border-left: 11px solid #ffffff;
    transform: translateX(1px);
}

.debug-icon-button {
    position: relative;
    min-width: 40px;
    width: 40px;
    padding: 0;
    border-color: #c7ccd5;
    color: #26313f;
    background: #ffffff;
}

.continue-button span {
    display: block;
    width: 0;
    height: 0;
    margin: 0 auto;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 10px solid #2da44e;
    transform: translateX(1px);
}

.stop-button span {
    display: block;
    width: 12px;
    height: 12px;
    margin: 0 auto;
    border-radius: 2px;
    background: #cf222e;
}

.step-over-button span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin: 0 auto;
}

.step-over-button span::before {
    content: "↓";
    color: #0969da;
    font-size: 22px;
    font-weight: 800;
    line-height: 1;
}

.editor-body {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr);
    flex: 1;
    min-height: 0;
}

.line-gutter {
    overflow: hidden;
    padding: 16px 0;
    border-right: 1px solid #d5d9e0;
    background: #f1f3f6;
    font: 14px/1.5 "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

.line-number {
    position: relative;
    display: block;
    width: 100%;
    min-width: 0;
    min-height: 21px;
    height: 21px;
    padding: 0 8px 0 18px;
    border: 0;
    border-radius: 0;
    color: #697181;
    background: transparent;
    font: inherit;
    font-weight: 500;
    text-align: right;
    cursor: pointer;
}

.line-number::before {
    content: "";
    position: absolute;
    left: 7px;
    top: 50%;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    transform: translateY(-50%);
    background: transparent;
}

.line-number:hover {
    color: #202124;
    background: #e5e9ef;
}

.line-number.has-breakpoint::before {
    background: #d1242f;
}

.line-number.is-disabled {
    color: #a3aab5;
    cursor: not-allowed;
}

.line-number.is-disabled:hover {
    background: transparent;
}

.line-number.is-current {
    color: #0f5132;
    background: #d9f3e6;
}

.line-number.is-current::after {
    content: "";
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #238636;
}

.line-number.has-syntax-error {
    color: #842029;
    background: #fff1f2;
}

.line-number.has-syntax-error::after {
    content: "";
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #cf222e;
}

.textarea-wrap {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 0;
}

.line-highlight {
    position: absolute;
    left: 0;
    right: 0;
    z-index: 0;
    display: none;
    pointer-events: none;
    background: #e5f6ed;
    border-top: 1px solid #b7e0c6;
    border-bottom: 1px solid #b7e0c6;
}

textarea,
pre {
    flex: 1;
    width: 100%;
    margin: 0;
    padding: 16px;
    overflow: auto;
    border: 0;
    outline: none;
    font: 14px/1.5 "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

textarea {
    position: relative;
    z-index: 1;
    resize: none;
    background: transparent;
}

.output-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.message-panel {
    min-height: 0;
}

.message-panel label,
.output-panel label,
.kv-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px;
    color: #394150;
    font-size: 13px;
    font-weight: 650;
}

.kv-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.kv-section-header button {
    min-width: 28px;
    width: 28px;
    min-height: 28px;
    padding: 0;
    border-color: #c7ccd5;
    color: #26313f;
    background: #ffffff;
    font-size: 18px;
    line-height: 1;
}

.kv-table {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.kv-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr) 30px;
    gap: 6px;
}

.readonly-kv-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
}

.kv-row input {
    min-width: 0;
    height: 32px;
    padding: 0 8px;
    border: 1px solid #d5d9e0;
    border-radius: 6px;
    background: #fbfcfe;
}

.kv-remove {
    min-width: 30px;
    min-height: 32px;
    padding: 0;
    border-color: #d5d9e0;
    color: #697181;
    background: #ffffff;
    font-size: 13px;
}

.kv-remove::before {
    content: "\1F5D1";
}

.kv-toggle {
    align-self: flex-start;
    min-width: 0;
    min-height: 28px;
    padding: 0 10px;
    border-color: #c7ccd5;
    color: #26313f;
    background: #ffffff;
    font-size: 12px;
}

.message-panel textarea,
.output-panel textarea {
    min-height: 120px;
    padding: 10px;
    border: 1px solid #d5d9e0;
    border-radius: 6px;
    background: #fbfcfe;
}

.output-panel {
    flex: 1;
}

.output-message-section {
    flex: 0 0 auto;
}

.body-field {
    flex: 1 1 auto;
    min-height: 0;
}

.body-field textarea {
    flex: 1 1 auto;
    max-height: none;
}

.readonly-kv-cell,
.empty-kv-row {
    min-height: 32px;
    padding: 7px 8px;
    overflow-wrap: anywhere;
    border: 1px solid #d5d9e0;
    border-radius: 6px;
    background: #fbfcfe;
    color: #26313f;
    font-weight: 500;
}

.empty-kv-row {
    color: #697181;
}

#status {
    color: #5f6673;
    font-size: 13px;
}

.error-panel {
    margin: auto 12px 12px;
    max-height: 160px;
    padding: 10px 12px;
    overflow: auto;
    border: 1px solid #f0b4b8;
    border-radius: 6px;
    color: #842029;
    background: #fff1f2;
    font: 13px/1.45 "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.error-panel.is-empty {
    border-color: #c7ccd5;
    color: #5f6673;
    background: #ffffff;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 650;
}

.variable-popup {
    position: fixed;
    z-index: 20;
    max-width: min(420px, calc(100vw - 24px));
    max-height: min(420px, calc(100vh - 24px));
    padding: 9px 11px;
    overflow: auto;
    border: 1px solid #b7bdc8;
    border-radius: 6px;
    color: #202124;
    background: #fffef8;
    box-shadow: 0 12px 30px rgba(31, 35, 40, 0.18), 0 2px 8px rgba(31, 35, 40, 0.12);
    font: 13px/1.45 "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
    pointer-events: none;
}

.variable-popup-line {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.variable-popup-name {
    color: #0645ad;
    font-weight: 700;
}

.variable-popup-value {
    color: #1f2328;
}

.variable-popup-meta {
    margin-top: 5px;
    color: #697181;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 12px;
}

@media (max-width: 800px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(260px, auto) minmax(420px, 1fr) minmax(320px, auto);
    }

    .column-resizer {
        display: none;
    }

    .syntax-status {
        max-width: 100%;
        flex: 1 1 100%;
    }
}
