:root {
        color-scheme: dark;
        font-family: "Share Tech Mono", "Fira Code", monospace;
        background-color: #000;
        color: #16ff6e;
        font-size: 16px;
}

@media (max-width: 600px) {
        :root {
                font-size: 14px;
        }

        .variable-name {
                font-size: 0.85rem;
        }

        .variable-description {
                font-size: 0.75rem;
        }

        .slider-value,
        .custom-slider-value {
                font-size: 0.72rem;
        }
}

* {
	box-sizing: border-box;
}

html,
body {
	height: 100%;
}

body {
	margin: 0;
	min-height: 100vh;
	display: flex;
	justify-content: center;
	align-items: stretch;
	background: radial-gradient(circle at top, rgba(32, 128, 64, 0.45), transparent 70%), #010701;
	color: #16ff6e;
	overflow: hidden;
}

.app-shell {
        width: min(1600px, 100%);
	height: 100%;
	padding: clamp(20px, 6vh, 36px) clamp(16px, 4vw, 36px);
	display: flex;
	flex-direction: column;
	gap: 20px;
}

.app-header h1 {
        margin: 0;
        font-size: clamp(1.6rem, 2.6vw, 2.6rem);
        font-weight: 600;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: #32ff9b;
        text-shadow: 0 0 18px rgba(22, 255, 110, 0.45);
}

.qt-toggle {
        border: none;
        background: none;
        padding: 0;
        margin: 0;
        font: inherit;
        color: inherit;
        text-transform: inherit;
        letter-spacing: inherit;
        text-shadow: inherit;
        cursor: pointer;
        transition: color 0.2s ease, text-shadow 0.2s ease;
}

.qt-toggle:hover,
.qt-toggle:focus-visible,
.qt-toggle.active {
        color: #7affc9;
        text-shadow: 0 0 24px rgba(122, 255, 201, 0.6);
}

.qt-toggle:focus-visible {
        outline: 2px solid rgba(122, 255, 201, 0.6);
        outline-offset: 4px;
}

.app-main {
	flex: 1 1 auto;
	display: flex;
	flex-wrap: nowrap;
	gap: 24px;
	min-height: 0;
}

.chat-panel,
.right-panel {
	background: rgba(0, 8, 0, 0.92);
	border: 2px solid #0c2f16;
	box-shadow: inset 0 0 20px rgba(16, 255, 110, 0.08);
	padding: 24px;
	min-height: 0;
}

.chat-panel {
	flex: 1 1 0;
	display: flex;
	flex-direction: column;
	gap: 16px;
	overflow: hidden;
}

.chat-panel h2 {
	margin: 0;
	font-size: 1.1rem;
	letter-spacing: 0.06em;
	color: #39ffa6;
}

.chat-log {
	flex: 1 1 auto;
	background: rgba(0, 18, 0, 0.85);
	border: 1px solid #0c3817;
	padding: 16px;
	overflow-y: auto;
	font-size: 0.95rem;
	line-height: 1.4;
	white-space: pre-wrap;
	text-shadow: 0 0 10px rgba(17, 255, 110, 0.25);
	overflow-wrap: break-word;
	word-break: break-word;
}

.chat-entry {
        margin-bottom: 12px;
}

.chat-entry.system-hidden {
        display: none;
}

.chat-entry:last-child {
	margin-bottom: 0;
}

.chat-entry .speaker {
	font-weight: 600;
	color: #4cffc0;
}

.chat-entry .message {
        display: inline;
        margin-left: 6px;
}

.console-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        flex-wrap: wrap;
}

.console-title-group {
        display: flex;
        align-items: baseline;
        gap: 10px;
        min-width: 0;
}

.session-name-input {
        background: rgba(0, 30, 12, 0.4);
        border: 1px solid rgba(24, 160, 72, 0.7);
        color: #7affc9;
        font: inherit;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        padding: 6px 10px;
        border-radius: 4px;
        max-width: 160px;
        min-width: 120px;
}

.session-name-input::placeholder {
        color: rgba(122, 255, 201, 0.5);
}

.session-name-prefix {
        display: inline-block;
        min-width: 0;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: #7affc9;
        white-space: nowrap;
}

.battery-status {
        display: flex;
        align-items: center;
        gap: 10px;
        font-size: 0.85rem;
        letter-spacing: 0.08em;
}

.battery-text {
        color: rgba(122, 255, 201, 0.85);
        white-space: nowrap;
}

.battery-input {
        background: rgba(0, 30, 12, 0.4);
        border: 1px solid rgba(24, 160, 72, 0.7);
        color: #7affc9;
        font: inherit;
        width: 56px;
        padding: 4px 6px;
        text-align: right;
        border-radius: 4px;
        letter-spacing: 0.08em;
}

.battery-icon {
        display: flex;
        align-items: center;
        gap: 4px;
        padding-left: 2px;
}

.battery-body {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 3px;
        padding: 4px;
        border: 1px solid rgba(22, 255, 110, 0.45);
        border-radius: 4px;
        background: rgba(0, 18, 6, 0.4);
        box-shadow: inset 0 0 8px rgba(22, 255, 110, 0.2);
}

.battery-bar {
        width: 10px;
        height: 16px;
        border-radius: 2px;
        background: rgba(32, 96, 64, 0.3);
        transition: background 0.2s ease, box-shadow 0.2s ease;
}

.battery-bar.filled {
        background: linear-gradient(180deg, rgba(110, 255, 178, 0.95), rgba(24, 160, 88, 0.9));
        box-shadow: 0 0 8px rgba(48, 255, 166, 0.6);
}

.battery-cap {
        width: 6px;
        height: 14px;
        border-radius: 1px;
        border: 1px solid rgba(22, 255, 110, 0.45);
        background: rgba(0, 18, 6, 0.4);
        margin-right: 2px;
}

.chat-input-row {
	display: flex;
	gap: 12px;
}

.chat-input {
	flex: 1 1 auto;
	padding: 12px 14px;
	border: 1px solid #115c28;
	background: rgba(0, 30, 0, 0.8);
	color: #16ff6e;
	font-family: inherit;
}

.chat-input:disabled {
	opacity: 0.55;
}

button {
	font: inherit;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	cursor: pointer;
	border-radius: 0;
	border: 1px solid #116329;
	padding: 10px 16px;
	color: #16ff6e;
	background: rgba(0, 32, 0, 0.75);
	transition: background 0.15s ease, box-shadow 0.15s ease;
	box-shadow: 0 0 12px rgba(0, 255, 102, 0.18);
}

button:hover:enabled {
	background: rgba(16, 96, 32, 0.8);
	box-shadow: 0 0 16px rgba(0, 255, 128, 0.4);
}

button:disabled {
	opacity: 0.45;
	cursor: not-allowed;
	box-shadow: none;
}

button.primary {
	border-color: #1db954;
	background: linear-gradient(135deg, rgba(0, 60, 20, 0.9), rgba(0, 120, 40, 0.9));
}

button.primary:hover:enabled {
	background: linear-gradient(135deg, rgba(0, 96, 32, 0.95), rgba(0, 160, 48, 0.95));
}

.right-panel {
	flex: 1 1 0;
	display: flex;
	flex-direction: column;
	gap: 18px;
	overflow: hidden;
}

.panel-stack {
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	gap: 0;
	min-height: 0;
}

.panel {
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	gap: 16px;
	min-height: 0;
}

.panel[hidden] {
	display: none !important;
}

.status-line {
        margin: 0;
        font-size: 0.95rem;
        letter-spacing: 0.05em;
        color: #3cffab;
}

.role-presence {
        padding: 6px 0 2px;
}

.presence-duo {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px 18px;
        align-items: center;
}

.presence-item {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        min-width: 0;
        flex-wrap: nowrap;
}

.presence-label {
        text-transform: uppercase;
        letter-spacing: 0.1em;
        font-size: 0.82rem;
        color: #39ffa6;
}

.presence-indicator {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        font-size: 0.82rem;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: rgba(150, 220, 170, 0.8);
        white-space: nowrap;
}

.presence-indicator .presence-dot {
        width: 10px;
        height: 10px;
        border-radius: 50%;
        background: rgba(64, 96, 72, 0.7);
        box-shadow: 0 0 6px rgba(64, 96, 72, 0.4);
}

.presence-indicator.online {
        color: #42ffb1;
}

.presence-indicator.online .presence-dot {
        background: #42ffb1;
        box-shadow: 0 0 10px rgba(66, 255, 177, 0.6);
}

.presence-indicator.offline {
        color: rgba(120, 180, 140, 0.7);
}

.presence-indicator.offline .presence-dot {
        background: rgba(80, 120, 90, 0.7);
        box-shadow: 0 0 6px rgba(80, 120, 90, 0.35);
}

.field-group {
        display: flex;
        flex-direction: column;
        gap: 6px;
        font-size: 0.9rem;
        color: #1fff84;
}

.connection-controls {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px 16px;
        align-items: end;
}

.connection-controls .field-group {
        min-width: 0;
}

.field-label {
	text-transform: uppercase;
	letter-spacing: 0.1em;
}

select,
input[type="text"] {
	padding: 10px 12px;
	width: 100%;
	border: 1px solid #114d22;
	background: rgba(0, 24, 0, 0.8);
	color: #16ff6e;
	font-family: inherit;
}

.variables-panel {
        overflow: hidden;
        gap: 0;
}

.variables-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        margin-bottom: 0;
}

.variables-header .pending-notice {
        flex: 1 1 auto;
}

.variables-header .confirm-button {
        flex-shrink: 0;
        padding: 4px 10px;
        font-size: 0.7rem;
        letter-spacing: 0.18em;
        white-space: nowrap;
        min-width: 0;
}

.pending-notice {
        margin: 0;
        font-size: 0.95rem;
        color: rgba(50, 255, 155, 0.8);
}

.confirm-button.hidden {
        visibility: hidden;
        pointer-events: none;
}

.variables-scroll {
        flex: 1 1 auto;
        overflow-y: auto;
        padding-right: 6px;
        border: 1px solid #0c3817;
        background: rgba(0, 16, 0, 0.85);
}

.variables-actions {
        display: flex;
        gap: 12px;
        justify-content: flex-end;
        padding-top: 0;
}

.variables-actions .compact-button {
        padding: 6px 12px;
        font-size: 0.75rem;
        letter-spacing: 0.12em;
        box-shadow: 0 0 8px rgba(0, 255, 102, 0.18);
}

.variables-list {
	display: flex;
	flex-direction: column;
	gap: 0;
	padding: 0;
	margin: 0;
}

.category {
	border-bottom: 1px solid #0b3214;
}

.category:last-child {
	border-bottom: none;
}

.category-toggle {
        width: 100%;
        text-align: left;
        background: rgba(0, 40, 0, 0.75);
        border: none;
        padding: 10px 14px;
        position: relative;
        font-size: 0.9rem;
        line-height: 1.2;
}

.category-toggle::after {
	content: "+";
	position: absolute;
	right: 16px;
	top: 50%;
	transform: translateY(-50%);
	font-weight: 600;
}

.category.expanded .category-toggle::after {
	content: "-";
}

.category-content {
        display: flex;
        flex-direction: column;
        gap: 12px;
        padding: 12px 14px 14px;
}

.category.collapsed .category-content {
	display: none;
}

.variable-entry {
        display: flex;
        flex-direction: column;
        gap: 6px;
        padding: 8px 0;
        border-bottom: 1px dashed rgba(22, 255, 110, 0.18);
}

.variable-entry:last-child {
	border-bottom: none;
}

.variable-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 6px;
}

.variable-name {
        flex: 1 1 auto;
        font-weight: 600;
        letter-spacing: 0.05em;
        color: #38ffa4;
}

.variable-delete-button {
        border: none;
        background: rgba(255, 120, 120, 0.1);
        color: rgba(255, 190, 190, 0.85);
        font-size: 0.95rem;
        line-height: 1;
        padding: 2px 8px 4px;
        border-radius: 4px;
        cursor: pointer;
        transition: background 0.2s ease, color 0.2s ease;
}

.variable-delete-button:hover:not(:disabled),
.variable-delete-button:focus-visible {
        background: rgba(255, 120, 120, 0.3);
        color: rgba(255, 230, 230, 0.95);
        outline: none;
        box-shadow: 0 0 0 1px rgba(255, 140, 140, 0.4);
}

.variable-delete-button:disabled {
        opacity: 0.45;
        cursor: default;
}

.variable-description {
	margin: 0;
	font-size: 0.85rem;
	color: rgba(180, 255, 210, 0.75);
}

.slider-row {
        display: flex;
        align-items: center;
        gap: 8px;
}

.slider-row input[type="range"] {
	flex: 1 1 auto;
}

.slider-value {
	width: 48px;
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.checkbox-row label {
	display: flex;
	align-items: center;
	gap: 10px;
}

.checkbox-row input {
	width: 20px;
	height: 20px;
}

.text-row input {
	width: 100%;
}

.variable-entry.pending {
        background: rgba(0, 60, 24, 0.35);
}

.custom-new-variable {
        border-color: rgba(90, 255, 170, 0.45);
        background: rgba(0, 70, 28, 0.25);
}

.custom-creator {
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 12px 10px;
        border: 1px dashed rgba(35, 255, 150, 0.25);
        background: rgba(0, 30, 12, 0.3);
        border-radius: 6px;
}

.custom-creator-title {
        margin: 0;
        font-size: 0.85rem;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: rgba(120, 255, 190, 0.8);
}

.custom-field {
        display: flex;
        flex-direction: column;
        gap: 6px;
        font-size: 0.8rem;
        color: rgba(200, 255, 225, 0.75);
}

.custom-field input,
.custom-field textarea {
        padding: 6px 8px;
        background: rgba(0, 20, 8, 0.6);
        border: 1px solid rgba(40, 200, 120, 0.35);
        color: #dfffee;
        font-family: inherit;
        font-size: 0.85rem;
        border-radius: 4px;
        resize: vertical;
}

.custom-field textarea {
        min-height: 56px;
}

.custom-slider-row {
        display: flex;
        align-items: center;
        gap: 10px;
        font-size: 0.8rem;
        color: rgba(200, 255, 225, 0.75);
}

.custom-slider-row input[type="range"] {
        flex: 1 1 auto;
}

.custom-slider-value {
        width: 48px;
        text-align: right;
        font-variant-numeric: tabular-nums;
}

.custom-actions {
        display: flex;
        justify-content: flex-end;
}

.custom-actions .compact-button {
        padding: 6px 12px;
        font-size: 0.75rem;
}

.custom-error {
        margin: 0;
        font-size: 0.75rem;
        color: rgba(255, 120, 120, 0.75);
        min-height: 16px;
}

.tab-bar {
	display: flex;
	gap: 12px;
	border-top: 2px solid #0c2f16;
	padding-top: 16px;
}

.tab {
	flex: 1 1 0;
	text-align: center;
}

.tab.active {
	background: rgba(16, 96, 32, 0.85);
	border-color: #1db954;
	box-shadow: 0 0 14px rgba(0, 255, 128, 0.45);
}

.tab.locked {
	position: relative;
}

.tab.locked::after {
	content: "LOCKED";
	position: absolute;
	left: 50%;
	bottom: -18px;
	transform: translateX(-50%);
	font-size: 0.6rem;
	letter-spacing: 0.18em;
	color: rgba(64, 160, 96, 0.8);
}


.model-info {
        position: relative;
        display: flex;
        flex-direction: column;
        gap: 0;
        font-size: 0.95rem;
        flex: 1 1 auto;
        min-height: 0;
}

.model-notification-stack {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 18px 24px 12px;
        pointer-events: none;
        z-index: 2;
}

.model-notification-stack[hidden] {
        display: none;
}

.model-notification-item {
        pointer-events: auto;
        display: flex;
        align-items: flex-start;
        gap: 16px;
        padding: 12px 16px;
        border: 1px solid rgba(16, 255, 120, 0.35);
        border-left-width: 6px;
        background: rgba(4, 26, 14, 0.32);
        box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
        backdrop-filter: blur(1.2px);
        border-radius: 6px;
        max-width: min(520px, calc(100% - 48px));
        color: #9dd6ff;
        text-shadow: 0 0 12px rgba(0, 12, 6, 0.8);
}

.model-notification-body {
        display: flex;
        flex-direction: column;
        gap: 6px;
        flex: 1 1 auto;
        min-width: 0;
}

.model-notification-label {
        margin: 0;
        font-size: 0.8rem;
        letter-spacing: 0.18em;
        text-transform: uppercase;
        font-weight: 600;
        opacity: 0.9;
}

.model-notification-message {
        margin: 0;
        font-size: 0.95rem;
        line-height: 1.4;
        letter-spacing: 0.04em;
        white-space: pre-wrap;
        word-break: break-word;
}

.model-notification-dismiss {
        pointer-events: auto;
        margin-left: auto;
        border: none;
        background: transparent;
        color: inherit;
        font-size: 1.2rem;
        line-height: 1;
        font-weight: 600;
        cursor: pointer;
        padding: 0;
        transition: transform 0.2s ease, color 0.2s ease;
}

.model-notification-dismiss:hover,
.model-notification-dismiss:focus {
        color: #d0ffe6;
        transform: scale(1.1);
}

.model-notification-item.tier-notification {
        border-left-color: rgba(122, 191, 255, 0.9);
        color: #7abfff;
        text-shadow: 0 0 16px rgba(122, 191, 255, 0.45);
}

.model-notification-item.tier-warning {
        border-left-color: rgba(255, 210, 120, 0.95);
        color: #ffe38b;
        text-shadow: 0 0 18px rgba(255, 210, 120, 0.6);
}

.model-notification-item.tier-critical {
        border-left-color: rgba(255, 120, 120, 0.95);
        color: #ff8c8c;
        text-shadow: 0 0 18px rgba(255, 120, 120, 0.6);
}

.model-content {
        display: flex;
        align-items: stretch;
        gap: 24px;
        min-height: 0;
        flex: 1 1 auto;
        height: 100%;
}

.model-text {
        flex: 1 1 50%;
        padding: 16px;
        border: 1px solid #0c3817;
        background: rgba(0, 16, 0, 0.85);
        white-space: pre-wrap;
        line-height: 1.45;
        letter-spacing: 0.03em;
        max-height: min(796px, 100%);
        overflow-y: auto;
        box-shadow: inset 0 0 16px rgba(16, 255, 110, 0.12);
        min-height: 0;
}

.model-figure {
        flex: 0 1 480px;
        width: min(480px, 60%);
        max-width: 60%;
        margin: 0;
        display: flex;
        align-items: stretch;
        justify-content: flex-start;
        min-height: 0;
        align-self: flex-start;
}

.model-notification-controls {
        margin-top: 12px;
        padding: 12px;
        border: 1px solid #0c3817;
        background: rgba(0, 18, 0, 0.82);
        display: flex;
        flex-direction: column;
        gap: 8px;
        max-height: clamp(220px, 40vh, 360px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-gutter: stable;
}

.model-notification-title {
        margin: 0;
        font-size: 0.9rem;
        letter-spacing: 0.12em;
        text-transform: uppercase;
        color: #3effa9;
}

.notification-field {
        display: flex;
        flex-direction: column;
        gap: 4px;
        font-size: 0.82rem;
        color: #39ffa6;
}

.model-notification-controls select,
.model-notification-controls textarea {
        width: 100%;
        border: 1px solid #114d22;
        background: rgba(0, 24, 0, 0.8);
        color: #16ff6e;
        font-family: inherit;
        padding: 8px 10px;
}

.model-notification-controls textarea {
        resize: vertical;
        min-height: 72px;
        max-height: 200px;
        line-height: 1.35;
}

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

.notification-actions .compact-button {
        padding: 6px 10px;
        font-size: 0.72rem;
        letter-spacing: 0.12em;
        box-shadow: 0 0 8px rgba(0, 255, 102, 0.18);
}

.notification-actions .compact-button.secondary {
        border-color: #114d22;
        background: rgba(0, 24, 0, 0.65);
        color: rgba(120, 220, 160, 0.85);
        box-shadow: none;
}

.notification-actions .compact-button.secondary:hover:enabled {
        background: rgba(16, 64, 32, 0.7);
        color: #5dffb8;
}

.tab.notification-tier-warning {
        background: linear-gradient(135deg, rgba(90, 70, 0, 0.9), rgba(120, 90, 0, 0.95));
        border-color: #ffd866;
        color: #fff4d0;
        box-shadow: 0 0 18px rgba(255, 210, 80, 0.45);
}

.tab.notification-tier-critical {
        background: linear-gradient(135deg, rgba(96, 0, 0, 0.9), rgba(140, 0, 0, 0.95));
        border-color: #ff5c5c;
        color: #ffeaea;
        box-shadow: 0 0 18px rgba(255, 80, 80, 0.45);
}

.model-content,
.model-text,
.model-figure,
.model-image-frame {
        height: 100%;
}

.model-image-frame {
        flex: 1 1 auto;
        width: 100%;
        height: 100%;
        aspect-ratio: 480 / 796;
        max-height: 100%;
        border: 1px solid #0c3817;
        box-shadow: 0 0 18px rgba(16, 255, 110, 0.18);
        background: rgba(0, 8, 0, 0.9);
        display: flex;
        align-items: center;
        justify-content: center;
}

.model-image-frame img {
        width: 100%;
        height: 100%;
        object-fit: contain;
        display: block;
}

@media (max-width: 1024px) {
        .app-main {
                flex-direction: column;
        }

        .right-panel {
                min-height: 420px;
        }

        .tab-bar {
                flex-direction: column;
        }

        .tab.locked::after {
                position: static;
                display: block;
                margin-top: 6px;
                transform: none;
                text-align: center;
        }

        .model-content {
                flex-direction: column;
                align-items: stretch;
        }

        .model-figure {
                flex: 0 1 auto;
                width: 100%;
                max-width: none;
                align-self: stretch;
        }
}

/* =========================
   Mobile split layout patch
   ========================= */
@media (max-width: 768px) {
  /* Use dynamic viewport height to avoid iOS browser chrome issues */
  .app-shell {
    height: 100dvh;
    padding: 12px;
  }

  /* Split screen: top = console, bottom = right panel */
  .app-main {
    display: grid;
    grid-template-rows: 1fr 1fr;
    grid-template-columns: 1fr;
    gap: 12px;
    min-height: 0;
  }

  .chat-panel {
    grid-row: 1;
    min-height: 0;
  }

  .console-header {
    align-items: flex-start;
    gap: 10px;
  }

  .console-title-group {
    flex-wrap: wrap;
    gap: 6px;
  }

  .session-name-input {
    min-width: 0;
    width: 100%;
    max-width: 180px;
  }

  .battery-status {
    align-self: flex-end;
    gap: 6px;
    font-size: 0.78rem;
  }

  .battery-body {
    gap: 2px;
    padding: 3px;
  }

  .battery-bar {
    width: 8px;
    height: 14px;
  }

  .right-panel {
    grid-row: 2;
    position: relative;
    min-height: 0;
    /* room for bottom tab-bar (set below) + safe area */
    padding-bottom: calc(var(--tabbar-h, 56px) + env(safe-area-inset-bottom, 0px));
  }

  /* Bottom-pinned horizontal tab bar */
  .tab-bar {
    --tabbar-h: 56px;
    position: absolute;
    left: 0; 
    right: 0; 
    bottom: 0;
    height: var(--tabbar-h);
    display: flex;
    flex-direction: row !important;
    gap: 0;
    padding: 0 max(8px, env(safe-area-inset-left, 0px));
    border-top: 2px solid #0c2f16;
    background: rgba(0, 8, 0, 0.92);
  }

  .tab {
    flex: 1 1 0;
    border-left: none;
    border-right: none;
    padding: 12px 8px; /* tighter to fit all three */
  }

  /* Hide floating badge to save space */
  .tab.locked::after { 
    display: none; 
  }

  /* Panel content fills area above the tab bar */
  .panel-stack {
    position: absolute;
    inset: 0 0 var(--tabbar-h) 0; /* reserve space for tab bar */
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding-bottom: 8px;
  }

  .panel { 
    min-height: 0; 
  }

  .variables-panel,
  .model-info-panel { 
    overflow: hidden; 
  }

  .variables-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
  }

  /* Keep inputs comfy on tiny screens */
  .chat-input-row { gap: 8px; }
  .chat-input { padding: 10px 12px; }
  button { padding: 10px 12px; }

  /* Force the model overview to remain split with the artwork on the right */
  .model-content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    align-items: stretch;
    height: 100%;
  }

  .model-text,
  .model-figure {
    min-width: 0;
  }

  .model-figure {
    max-width: none;
    width: 100%;
    align-self: stretch;
    display: flex;
    align-items: stretch;
  }

  .model-image-frame {
    width: 100%;
    height: 100%;
  }

  .model-notification-controls {
    max-height: calc(100dvh - var(--tabbar-h, 56px) - 48px);
    padding: 10px;
    gap: 6px;
  }

  .model-notification-controls select,
  .model-notification-controls textarea {
    padding: 8px;
    font-size: 0.82rem;
  }

  .notification-actions {
    justify-content: stretch;
    gap: 8px;
  }

  .notification-actions .compact-button {
    flex: 1 1 48%;
  }
}

/* Ensure horizontal tabs on tablets too, overriding earlier column rule */
@media (max-width: 1024px) and (min-width: 769px) {
  .tab-bar { 
    flex-direction: row !important; 
  }
  .tab.locked::after { 
    position: static; 
    margin-top: 0; 
    display: none; 
  }
}

/* ===== FINAL OVERRIDE: Variables fit viewport; never hide under bottom tabs ===== */
@media (max-width: 768px) {
  /* 1) Bottom tabs must sit above content and reserve space */
  .tab-bar { 
    z-index: 10; /* ensure tabs render above panel content */
  }

  /* 2) Re-contain the right side so nothing can extend past the viewport */
  .app-shell,
  .app-main,
  .panel-stack {
    overflow: hidden !important; /* undo overflow: visible */
  }

  /* Keep panel-stack pinned above the tab bar (in case something else overrides it) */
  .panel-stack {
    position: absolute !important;
    inset: 0 0 var(--tabbar-h, 56px) 0 !important; /* always reserve tab bar */
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  /* 3) Variables panel is a column container; no horizontal spill */
  .variables-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 100vw;
    overflow: hidden !important; /* force containment */
  }

  /* 4) The ONLY scroller lives here. Cap it to the live viewport. */
  .variables-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;

    /* Prefer dvh (iOS/Android browser chrome aware); fall back to svh/vh */
    max-height: calc(100dvh - var(--tabbar-h, 56px) - 24px); /* 24px ≈ header/padding buffer */
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 8px); /* ensure last row stays above tabs */
    scrollbar-gutter: stable; /* avoids layout jiggle when scrollbar appears */
  }

  /* 5) Belt & suspenders: children can't force horizontal growth */
  .variables-scroll * { max-width: 100%; }
}
