/* The page fills the window: toolbar at the top, tabs and status at the bottom, the view in between. */
:root {
    /* Oat's primary is near-black, so selection gets its own accent. */
    --highlight: light-dark(#2563eb, #60a5fa);
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    margin: 0;
}

body > nav { flex: none; padding-inline: var(--space-6); }

main {
    flex: 1;
    min-height: 20rem;
    display: flex;
    flex-direction: column;
    padding: var(--space-4) var(--space-6);
}

.panels { flex: 1; min-height: 0; }
[role="tabpanel"] { height: 100%; margin: 0; padding: 0; }

/* --- Toolbar */

.toolbar { margin-bottom: var(--space-4); }
.toolbar menu.buttons { margin: 0; }
.toolbar menu.buttons button { width: 2.25rem; height: 2.25rem; }

.toolbar svg {
    width: 1.15rem;
    height: 1.15rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.toolbar svg .solid { fill: currentColor; stroke-width: 1.5; }

#run .icon-stop, #run.running .icon-run { display: none; }
#run.running .icon-stop { display: block; }
#run.running { color: var(--danger); }

.toolbar .icon-move, .toolbar.moving .icon-add { display: none; }
.toolbar.moving .icon-move { display: block; }
#move-mode[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }

/* --- View tabs and status, below the view */

.tabbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-6);
    margin-top: var(--space-3);
}

/* Oat's tabs are inline-flex, which would otherwise override [hidden]. */
[role="tab"][hidden] { display: none; }

/* --- Table */

.sheet {
    position: relative;
    height: 100%;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-large);
    scroll-padding-top: 2.2rem;
    scroll-padding-left: 3rem;
    outline: none;
}

.sheet:focus-visible { border-color: var(--ring); }

.sheet table {
    width: auto;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.85rem;
    user-select: none;
}

.sheet tr { border: 0; }

.sheet th, .sheet td {
    padding: 0.3rem 0.6rem;
    min-width: 6rem;
    max-width: 24rem;
    height: 2rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: pre;
    border: 0;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--background);
    color: var(--foreground);
    cursor: cell;
}

.sheet thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    font-weight: bold;
    background: var(--faint);
}

.sheet th.rownum, .sheet th.corner {
    position: sticky;
    left: 0;
    z-index: 1;
    min-width: 3rem;
    text-align: right;
    font-weight: normal;
    color: var(--muted-foreground);
    background: var(--faint);
}

.sheet th.corner { z-index: 3; }

.sheet .sel-row, .sheet thead .sel-col { color: var(--highlight); font-weight: bold; }

.sheet .selected {
    outline: 2px solid var(--highlight);
    outline-offset: -2px;
}

.sheet:not(:focus-within) .selected { outline-color: var(--muted-foreground); }
.sheet.readonly td, .sheet.readonly th { cursor: default; opacity: 0.7; }

.sheet .cell-editor {
    position: absolute;
    z-index: 4;
    width: auto;
    margin: 0;
    padding: 0.3rem 0.6rem;
    font-size: 0.85rem;
    line-height: inherit;
    min-height: 0;
    resize: none;
    overflow: hidden;
    white-space: pre;
    border-radius: 0;
    border: 2px solid var(--highlight);
    box-shadow: 0 2px 8px rgb(0 0 0 / 0.25);
}

.sheet .empty {
    padding: var(--space-4);
    color: var(--muted-foreground);
}

/* --- CodeMirror, themed to match Oat */

.CodeMirror {
    height: 100%;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    background: var(--background);
    color: var(--foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius-large);
}

#script-dialog { width: min(100% - 2rem, 60rem); }
#script-dialog form > div { padding-block: var(--space-4); }
#script-dialog .CodeMirror { height: min(24rem, 50vh); }
#script-dialog footer { align-items: center; }
#hint { margin-right: auto; }

.CodeMirror-focused { border-color: var(--ring); }

.CodeMirror-gutters {
    background: var(--faint);
    border-right: 1px solid var(--border);
}

.CodeMirror-linenumber { color: var(--muted-foreground); }
.CodeMirror-cursor { border-left-color: var(--foreground); }
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: color-mix(in srgb, var(--highlight) 25%, transparent); }
.CodeMirror-readonly .CodeMirror-cursor { display: none; }

.cm-s-default .cm-comment { color: var(--muted-foreground); }
.cm-s-default .cm-string { color: var(--success); }
.cm-s-default .cm-keyword, .cm-s-default .cm-builtin { color: var(--highlight); }
.cm-s-default .cm-number { color: var(--danger); }
.cm-s-default .cm-variable-2, .cm-s-default .cm-variable-3 { color: var(--warning); }
.cm-s-default .cm-string-2 { color: var(--success); font-weight: bold; }
.cm-s-default .cm-keyword { font-weight: bold; }
.cm-s-default .cm-def { color: var(--foreground); font-style: italic; }
.cm-s-default .cm-operator { color: var(--muted-foreground); }

/* --- Status, script output and help */

#message {
    flex: 1;
    margin: 0.4rem 0 0;
    font-size: 0.85rem;
    text-align: right;
    color: var(--muted-foreground);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

#message.error, #output .error { color: var(--danger); }

#output {
    height: 100%;
    margin: 0;
    overflow: auto;
    padding: var(--space-4);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

#share-dialog fieldset.group { margin: 0 0 var(--space-2); }
#share-url { font-family: var(--font-mono); font-size: var(--text-8); }
