html,
body {
    height: 100%;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    color: #333;
    line-height: 1.6;
}

.container {
    margin: 0 auto;
    padding: 0px;
    height: 100vh;
    min-height: 100vh;
    min-width: 100vw;
    display: flex;
    flex-direction: column;
}

#home #content {
    padding: 20px;
    flex-direction: column;
    overflow: visible;
    min-height: unset;
}

.sessions-panel {
    margin-top: 16px;
    max-width: 780px;
}

.sessions-panel h2 {
    font-size: 18px;
    margin-bottom: 8px;
}

#sessions-empty-state {
    color: #51606f;
}

#sessions-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.session-list-item {
    border: 1px solid #d9e2ec;
    border-radius: 6px;
    padding: 10px 12px;
    background: #ffffff;
}

.session-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.session-summary {
    color: #2a3a4a;
}

.session-open-link {
    color: #1f69cb;
    text-decoration: none;
    font-weight: 600;
}

.session-open-link:hover {
    text-decoration: underline;
}

.session-delete-button {
    background: none;
    border: none;
    color: #c0392b;
    cursor: pointer;
    font-weight: 600;
    padding: 0;
}

.session-delete-button:hover {
    text-decoration: underline;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
}

/* Best layout: tool-specific options sit centered in the middle of the top row,
   on a single line, between the tool buttons and the action buttons. When this
   doesn't fit, JS adds `.toolbar--stacked` to move the whole section to its own
   bottom row (see below) — flexbox alone can't keep it centered when it fits yet
   reorder it to the bottom when it doesn't. */
.toolbar-context {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
}

/* Collapse the context wrapper when no tool options are visible so it never
   contributes an empty row. */
.toolbar-context:not(:has(> :not(.hidden))) {
    display: none;
}

/* Next/fallback layout: the section can't fit beside the other groups, so it
   drops to its own full-width row at the bottom (`order: 1`). There it wraps its
   own controls internally only as a last resort — when even the full row is too
   narrow to hold them. */
.toolbar--stacked .toolbar-context {
    order: 1;
    flex-basis: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
}

/* Transient state used only while measuring the natural single-row width: force
   everything onto one unwrapped row at its content size so an overflow becomes
   detectable via scrollWidth. */
.toolbar--measuring,
.toolbar--measuring .toolbar-context,
.toolbar--measuring .toolbar-actions,
.toolbar--measuring .toolbar-collapsible-actions {
    flex-wrap: nowrap;
}
.toolbar--measuring .toolbar-context {
    flex: 0 0 auto;
    min-width: auto;
}

.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

/* Collapsible group of action buttons (copy/paste, history, zoom), toggled by
   the actions expand/collapse button. */
.toolbar-collapsible-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.dm-toolbox {
    display: flex;
    align-items: center;
    gap: 6px;
}

.environment-toolbar-palette {
    display: grid;
    grid-template-columns: repeat(12, 20px);
    gap: 4px;
}

.ray-toolbar,
.cone-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ray-toolbar-palette {
    display: grid;
    grid-template-columns: repeat(12, 20px);
    gap: 4px;
}

.ray-toolbar-snap-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: #475569;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

.number-combo-box {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: default;
}

.number-combo-box-label {
    font-size: 12px;
    color: #475569;
    white-space: nowrap;
}

.number-combo-box-control {
    position: relative;
    display: flex;
    align-items: center;
}

.number-combo-box-input {
    width: 52px;
    height: 28px;
    border: 1px solid #cbd5e1;
    border-right: none;
    border-radius: 4px 0 0 4px;
    padding: 0 6px;
    font-size: 13px;
    color: #0f172a;
    background: #ffffff;
    text-align: center;
    outline: none;
}

.number-combo-box-input:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.25);
    z-index: 1;
}

.number-combo-box-toggle {
    height: 28px;
    width: 20px;
    border: 1px solid #cbd5e1;
    border-radius: 0 4px 4px 0;
    background: #f1f5f9;
    color: #475569;
    font-size: 11px;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.number-combo-box-toggle:hover {
    background: #e2e8f0;
}

.number-combo-box-dropdown {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    min-width: 100%;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    z-index: 200;
    padding: 2px 0;
}

.number-combo-box-option {
    display: block;
    width: 100%;
    padding: 5px 10px;
    border: none;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font-size: 13px;
    color: #0f172a;
    white-space: nowrap;
}

.number-combo-box-option:hover {
    background: #eff6ff;
}

.number-combo-box-option-selected {
    background: #dbeafe;
    font-weight: 600;
}

.environment-toolbar-swatch {
    width: 20px;
    height: 20px;
    border: 1px solid rgba(15, 23, 42, 0.35);
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
}

.environment-toolbar-swatch-selected {
    outline: 2px solid #0f172a;
    outline-offset: 1px;
}

.environment-toolbar-patterns {
    display: flex;
    align-items: center;
    gap: 4px;
}

.environment-toolbar-pattern {
    width: 28px;
    height: 28px;
    border: 1px solid rgba(15, 23, 42, 0.35);
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
    background: #ffffff;
    color: #1e293b;
    font-size: 16px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.environment-toolbar-pattern-impassable {
    color: #b91c1c;
    border-color: rgba(185, 28, 28, 0.45);
}

.environment-toolbar-pattern-selected {
    outline: 2px solid #0f172a;
    outline-offset: 1px;
    background: #e2e8f0;
}

.environment-toolbar-outline {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 4px;
    font-size: 12px;
    color: #475569;
    white-space: nowrap;
    cursor: pointer;
}

.environment-toolbar-outline input {
    cursor: pointer;
    margin: 0;
}

.dm-tool-button {
    border: 1px solid #c9d6e3;
    background: #ffffff;
    color: #1e293b;
    width: 34px;
    height: 34px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.dm-tool-button:hover {
    background: #eff6ff;
    border-color: #60a5fa;
}

.dm-tool-button.dm-tool-button-selected {
    background: #dbeafe;
    border-color: #2563eb;
    box-shadow: inset 0 0 0 1px #2563eb;
}

h1, h2, h3, h4, h5, h6 {
    color: #2c3e50;
}

p {
    margin-top: 6px;
    margin-bottom: 6px;
}

#content {
    background-color: white;
    flex: 1;
    display: flex;
    flex-direction: row;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

#sidebar-root {
    flex: 0 0 320px;
    min-height: 0;
    height: 100%;
    border-right: 1px solid #d8dee7;
    background: #ffffff;
    overflow: hidden;
}

#main-panel {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#messages {
    flex: 0 0 auto;
    padding: 0 8px 8px;
    background: rgba(255, 255, 255, 0.96);
}

#grid-root {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
}

.grid-loading {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.9);
}

.grid-loading-spinner {
    width: 42px;
    height: 42px;
    border: 4px solid #d0d7e2;
    border-top-color: #2c7be5;
    border-radius: 50%;
    animation: grid-loading-spin 0.8s linear infinite;
}

@keyframes grid-loading-spin {
    to {
        transform: rotate(360deg);
    }
}

.hidden {
    display: none !important;
}

.action-link {
    display: inline-block;
    background: #2c7be5;
    color: #fff;
    text-decoration: none;
    padding: 10px 14px;
    border-radius: 4px;
    border: 0;
    cursor: pointer;
    line-height: 1;
}

.action-link:hover {
    background: #1f69cb;
}

.toolbar-button {
    border: 0;
    background: #2c7be5;
    color: #fff;
    text-decoration: none;
    padding: 10px 14px;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1;
}

.toolbar-button:hover {
    background: #1f69cb;
}

.toolbar-button:disabled {
    background: #95b7ea;
    cursor: not-allowed;
}

.toolbar-separator {
    width: 1px;
    height: 24px;
    background: #c9d6e3;
}

.error {
    margin-top: 0;
    color: #9e2a2b;
    background: #fdebec;
    border: 1px solid #f7c5c8;
    border-radius: 4px;
    padding: 10px;
}

#message-composer {
    margin-top: 8px;
    margin-bottom: 8px;
    padding-top: 8px;
    border-top: 1px solid #808080;
    display: flex;
    align-items: stretch;
    gap: 8px;
    width: 100%;
}

#message-input {
    flex: 1;
    min-width: 0;
    padding: 10px;
    border: 1px solid #c9d6e3;
    border-radius: 4px;
}

#send-button {
    border: 0;
    background: #2c7be5;
    color: #fff;
    padding: 10px 16px;
    border-radius: 4px;
    cursor: pointer;
}

#send-button:hover {
    background: #1f69cb;
}
