:root {
    color-scheme: dark;
    --bg: #0b0d10;
    --panel: #11151a;
    --panel-2: #171c22;
    --border: #2a313a;
    --text: #e7ebef;
    --muted: #8f9aa6;
    --accent: #d34444;
    --accent-hover: #ec5656;
    --success: #45b36b;
    --warning: #e3a53f;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select {
    font: inherit;
}

.app-shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) 28px;
    width: 100%;
    height: 100%;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 20px;
    min-height: 68px;
    padding: 10px 14px;
    background: linear-gradient(180deg, #171b20 0%, #111419 100%);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.24);
    z-index: 5;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 220px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(145deg, #ed4c4c, #8c2020);
    box-shadow: 0 0 28px rgba(211, 68, 68, 0.24);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-weight: 800;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
}

.toolbar {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: thin;
    padding-bottom: 1px;
}

.toolbar button,
.toolbar select {
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel-2);
    color: var(--text);
    padding: 0 12px;
    white-space: nowrap;
}

.toolbar button {
    cursor: pointer;
    transition: border-color 120ms ease, background-color 120ms ease, transform 120ms ease;
}

.toolbar button:hover:not(:disabled) {
    border-color: #495462;
    background: #20262d;
}

.toolbar button:active:not(:disabled) {
    transform: translateY(1px);
}

.toolbar button.primary {
    border-color: #b23737;
    background: linear-gradient(180deg, var(--accent), #a82f2f);
    font-weight: 700;
}

.toolbar button.primary:hover:not(:disabled) {
    background: linear-gradient(180deg, var(--accent-hover), #b73737);
}

.toolbar button:disabled {
    color: #65707b;
    cursor: not-allowed;
    opacity: 0.62;
}

.field-group {
    display: grid;
    gap: 3px;
}

.field-group > span {
    color: var(--muted);
    font-size: 10px;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.editor-area {
    position: relative;
    min-height: 0;
    background: #1e1e1e;
}

#editor {
    width: 100%;
    height: 100%;
}

.loading-overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: #11151a;
    color: var(--muted);
    font-size: 14px;
    letter-spacing: 0.02em;
    z-index: 4;
}

.loading-overlay.hidden {
    display: none;
}

.statusbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-width: 0;
    padding: 0 10px;
    background: #15191e;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
}

.status-left,
.status-right {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.status-left {
    overflow: hidden;
}

#statusText {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dirty-indicator {
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #53606d;
}

.dirty-indicator.dirty {
    background: var(--warning);
    box-shadow: 0 0 8px rgba(227, 165, 63, 0.65);
}

.dirty-indicator.saved {
    background: var(--success);
}

@media (max-width: 900px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
    }

    .brand {
        min-width: 0;
    }

    .toolbar {
        align-items: flex-end;
    }
}


.loading-overlay.error {
    padding: 24px;
    color: #ff9b9b;
    text-align: center;
    line-height: 1.5;
}
