:root {
    --bg: #eef0f3;
    --panel: #ffffff;
    --text: #1d2125;
    --muted: #68717d;
    --line: #d5d9df;
    --accent: #2f5d8a;
    --accent-text: #ffffff;
    --danger: #b3261e;
    --ok: #2e7d32;
    --warn: #8a6d00;
    --canvas-bg: #2a2d31;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
    --radius: 6px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
}

canvas {
    display: block;
}

h2, h3, h4 {
    margin: 0 0 8px;
}

h3 {
    font-size: 15px;
}

h4 {
    font-size: 14px;
}

.hidden {
    display: none !important;
}

.muted {
    color: var(--muted);
}

.small {
    font-size: 12px;
}

kbd {
    display: inline-block;
    min-width: 22px;
    padding: 1px 5px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #f7f8fa;
    font: 12px monospace;
    text-align: center;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
    font: inherit;
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    min-width: 0;
}

textarea {
    width: 100%;
    min-height: 70px;
    font: 12px monospace;
}

.btn {
    font: inherit;
    padding: 5px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
}

.btn:hover:not(:disabled) {
    background: #f1f3f6;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

.btn-primary:hover:not(:disabled) {
    background: #264d73;
}

.btn-danger {
    color: var(--danger);
}

.btn-dev {
    border-style: dashed;
}

.btn.round {
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 50%;
    font-size: 16px;
}

.link {
    font: inherit;
    border: none;
    background: none;
    padding: 0;
    color: var(--accent);
    cursor: pointer;
    text-align: left;
}

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

.status {
    margin: 6px 0;
    min-height: 1em;
    font-size: 13px;
}

.status.error {
    color: var(--danger);
}

.status.ok {
    color: var(--ok);
}

.hint {
    margin: 0 0 10px;
    padding: 6px 8px;
    border-left: 3px solid var(--accent);
    background: #f4f7fb;
    font-size: 13px;
}

.inline-field {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 6px 0;
}

.form-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 6px;
}

.stack-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stack-form label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.stack-form input {
    width: 120px;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#app-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    min-height: 50px;
}

.header-room {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

#room-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#scene-status {
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

#workspace {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
}

#canvas-area {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    background: var(--canvas-bg);
    overflow: hidden;
}

#canvas {
    width: 100%;
    height: 100%;
    outline: none;
    touch-action: none;
}

.ctl {
    position: absolute;
    display: flex;
    gap: 8px;
    align-items: center;
    z-index: 5;
}

.ctl .btn {
    box-shadow: var(--shadow);
}

.ctl-top-left {
    left: 16px;
    top: 16px;
}

.ctl-top-right {
    right: 16px;
    top: 16px;
}

.ctl-bottom-left {
    left: 16px;
    bottom: 16px;
    flex-wrap: wrap;
    max-width: calc(100% - 200px);
}

.ctl-bottom-right {
    right: 16px;
    bottom: 16px;
}

.zoom-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px;
    background: var(--panel);
    border-radius: 20px;
    box-shadow: var(--shadow);
}

.zoom-group .btn {
    box-shadow: none;
    border: none;
}

#zoom-label {
    width: 42px;
    text-align: center;
    font-weight: 600;
    font-size: 13px;
}

.mode-toggle {
    display: inline-flex;
    box-shadow: var(--shadow);
    border-radius: var(--radius);
}

.mode-toggle .btn {
    box-shadow: none;
    border-radius: 0;
}

.mode-toggle .btn:first-child {
    border-radius: var(--radius) 0 0 var(--radius);
}

.mode-toggle .btn:last-child {
    border-radius: 0 var(--radius) var(--radius) 0;
}

.pan-grid {
    display: grid;
    grid-template-columns: repeat(3, 34px);
    grid-template-rows: repeat(3, 34px);
    gap: 4px;
}

.pan-up { grid-column: 2; grid-row: 1; }
.pan-left { grid-column: 1; grid-row: 2; }
.pan-right { grid-column: 3; grid-row: 2; }
.pan-down { grid-column: 2; grid-row: 3; }

#walkthrough-controls {
    position: absolute;
    left: 16px;
    top: 16px;
    z-index: 6;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 320px;
}

.walkthrough-help {
    background: var(--panel);
    border-radius: var(--radius);
    padding: 8px 12px;
    box-shadow: var(--shadow);
    font-size: 13px;
}

.walkthrough-help p {
    margin: 4px 0;
}

#selection-toolbar {
    position: absolute;
    left: 0;
    bottom: 0;
    z-index: 7;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px;
    max-width: calc(100% - 32px);
    background: var(--panel);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.toolbar-row {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
}

#rotation-panel,
.toolbar-panel {
    border-top: 1px solid var(--line);
    padding-top: 6px;
}

#rotation-slider {
    width: 100%;
}

.rotation-row {
    display: flex;
    gap: 4px;
    justify-content: center;
}

#rotation-input {
    width: 56px;
    text-align: center;
}

.toolbar-panel label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 3px 0;
}

.toolbar-panel input[type="number"] {
    width: 90px;
}

.material-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.material-row select {
    max-width: 200px;
}

#loading-cover {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--canvas-bg);
    color: #fff;
}

.loading-box {
    width: min(320px, 80%);
    text-align: center;
}

#unity-progress {
    margin-top: 8px;
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
    overflow: hidden;
}

#unity-progress-full {
    width: 0;
    height: 100%;
    background: #fff;
}

#sidebar {
    flex: 0 0 360px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--panel);
    border-left: 1px solid var(--line);
}

#sidebar-tabs {
    display: flex;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--line);
}

#sidebar-tabs .tab {
    flex: 1 1 auto;
    font: inherit;
    font-size: 13px;
    padding: 9px 6px;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    cursor: pointer;
    color: var(--muted);
}

#sidebar-tabs .tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

#sidebar-content {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px;
}

.search-row {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.search-row input {
    flex: 1 1 auto;
}

.breadcrumb {
    margin-bottom: 8px;
    font-size: 13px;
}

.filter-panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px;
    margin-bottom: 10px;
}

.filter-group {
    border: none;
    padding: 0;
    margin: 0 0 8px;
}

.filter-group legend {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 4px;
}

.filter-option {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 0 10px 4px 0;
    font-size: 13px;
}

.range-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.range-row input {
    width: 90px;
}

.category-grid,
.preset-grid,
.floor-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.category-card,
.preset-card,
.floor-card {
    font: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    cursor: pointer;
    text-align: center;
}

.category-card:hover,
.preset-card:hover,
.floor-card:hover {
    border-color: var(--accent);
}

.category-card img {
    width: 100%;
    height: 70px;
    object-fit: contain;
}

.product-count {
    margin-bottom: 6px;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.product-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
}

.product-image {
    height: 110px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-image:hover {
    border-color: var(--accent);
}

.product-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.product-text {
    display: flex;
    flex-direction: column;
}

.info-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    padding: 0;
    border-radius: 50%;
    font-style: italic;
}

.swatch-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 8px;
}

.swatch {
    aspect-ratio: 1;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    cursor: pointer;
    padding: 0;
}

.swatch.small {
    width: 22px;
    height: 22px;
    display: inline-block;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}

.overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(24, 27, 31, 0.6);
}

.card {
    background: var(--panel);
    border-radius: 8px;
    padding: 20px;
    box-shadow: var(--shadow);
    width: min(380px, 100%);
}

#login-form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
}

.rooms-card {
    width: min(900px, 100%);
    max-height: 100%;
    display: flex;
    flex-direction: column;
}

.rooms-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.rooms-head-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.rooms-grid {
    flex: 1 1 auto;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
    padding: 2px;
}

.room-card {
    font: inherit;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    cursor: pointer;
    text-align: left;
}

.room-card:hover,
.room-card.active {
    border-color: var(--accent);
}

.room-card img,
.room-thumb-empty {
    width: 100%;
    height: 110px;
    object-fit: cover;
    border-radius: 4px;
    background: #eceef1;
}

.room-thumb-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 12px;
}

.rooms-local {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 12px;
    border-top: 1px solid var(--line);
    margin-top: 12px;
}

.dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(24, 27, 31, 0.35);
}

.dialog {
    background: var(--panel);
    border-radius: 8px;
    box-shadow: var(--shadow);
    width: min(380px, 100%);
    max-height: 100%;
    display: flex;
    flex-direction: column;
}

.dialog.wide {
    width: min(720px, 100%);
}

.dialog-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
}

.dialog-head h3 {
    margin: 0;
}

.dialog-body {
    padding: 14px;
    overflow-y: auto;
}

.info-layout {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}

.info-image {
    width: 220px;
    max-width: 100%;
    height: 200px;
    object-fit: contain;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.info-image.empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
}

.info-text {
    flex: 1 1 240px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.info-text .price {
    font-weight: 600;
}

.description {
    white-space: pre-line;
    font-size: 13px;
}

.variant-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.variant-row {
    display: grid;
    grid-template-columns: 40px 1fr auto auto;
    gap: 8px;
    align-items: center;
}

.variant-row img,
.variant-thumb-empty {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.shopping-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.shopping-table th,
.shopping-table td {
    padding: 5px 6px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

.shopping-table .num {
    text-align: right;
}

.shopping-table tfoot td {
    font-weight: 600;
}

#devtools {
    position: fixed;
    left: 8px;
    top: 58px;
    bottom: 8px;
    width: min(400px, calc(100% - 16px));
    z-index: 40;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border: 1px dashed var(--muted);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.devtools-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
}

.devtools-head .muted {
    flex: 1 1 auto;
    font-size: 12px;
}

.devtools-body {
    overflow-y: auto;
    padding: 8px 10px;
}

.devtools-body details {
    border-bottom: 1px solid var(--line);
    padding: 6px 0;
}

.devtools-body summary {
    cursor: pointer;
    font-weight: 600;
}

.dev-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 6px 0;
}

.dev-row input {
    flex: 1 1 140px;
}

.dev-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin: 6px 0;
}

.dev-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-height: 260px;
    overflow-y: auto;
}

.dev-item {
    font: inherit;
    font-size: 12px;
    text-align: left;
    padding: 4px 8px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #f7f8fa;
    cursor: pointer;
}

.dev-item:hover {
    background: #e9ecf0;
}

.dev-log {
    max-height: 170px;
    overflow: auto;
    white-space: pre-wrap;
    font: 12px monospace;
    background: #f7f8fa;
    padding: 6px;
    border-radius: 4px;
}

#curtains-panel {
    position: fixed;
    right: 376px;
    bottom: 16px;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--panel);
    border: 1px dashed var(--muted);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

#toasts {
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    z-index: 70;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    pointer-events: none;
}

.toast {
    padding: 7px 14px;
    border-radius: var(--radius);
    background: #2b3036;
    color: #fff;
    box-shadow: var(--shadow);
    font-size: 13px;
}

.toast.ok {
    background: var(--ok);
}

.toast.error {
    background: var(--danger);
}

.toast.warn {
    background: var(--warn);
}

@media (max-width: 800px) {
    #workspace {
        flex-direction: column;
    }

    #sidebar {
        flex: 0 0 45%;
        border-left: none;
        border-top: 1px solid var(--line);
    }

    #curtains-panel {
        right: 16px;
        bottom: 50%;
    }

    .ctl-bottom-left {
        max-width: calc(100% - 150px);
    }
}

/* Trisgine build: controls whose page API command is not in this build are disabled with a tooltip. */
.unavailable,
input:disabled,
select:disabled,
textarea:disabled,
.dev-item:disabled,
.preset-card:disabled,
.product-image:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

label.unavailable input {
    opacity: 1;
}

.floor-card.active,
.preset-card.active {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.swatch.active {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

#loading-detail {
    margin-top: 8px;
    min-height: 1.4em;
    color: rgba(255, 255, 255, 0.7);
    white-space: pre-line;
}

#loading-cover.error #loading-title {
    color: #ff9a8f;
    font-weight: 600;
}

#loading-cover.error #unity-progress {
    display: none;
}

body.bare {
    background: #000;
}

body.bare #app-header,
body.bare #sidebar,
body.bare #canvas-controls,
body.bare #walkthrough-controls,
body.bare #selection-toolbar,
body.bare #devtools {
    display: none !important;
}

/* Controls wait for the furniture; the empty room shows meanwhile. */
body.furnishing #sidebar > *,
body.furnishing #canvas-controls,
body.furnishing #selection-toolbar {
    visibility: hidden;
}

body.room-busy #canvas {
    cursor: progress;
}

body.bare .overlay {
  display: none !important;
}
