* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #0d0d0d;
    color: #e0e0e0;
    overflow: hidden;
}

#app {
    display: grid;
    grid-template-areas:
        "top top top"
        "left viewport right";
    grid-template-columns: 280px 1fr 320px;
    grid-template-rows: 48px 1fr;
    height: 100vh;
    width: 100vw;
}

/* Top toolbar */
#topbar {
    grid-area: top;
    background: #181818;
    border-bottom: 1px solid #333;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
}

#topbar h1 {
    font-size: 1.1rem;
    margin: 0;
    color: #4fc3f7;
}

#topbar .spacer { flex: 1; }

#topbar select, #topbar input {
    width: auto;
    min-width: 180px;
    margin-top: 0;
}

#topbar button {
    width: auto;
    padding: 6px 14px;
    margin-top: 0;
}

#user-info {
    font-size: 0.8rem;
    color: #aaa;
}

/* Side panels */
#sidebar-left, #sidebar-right {
    background: #181818;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#sidebar-left {
    grid-area: left;
    border-right: 1px solid #333;
}

#sidebar-right {
    grid-area: right;
    border-left: 1px solid #333;
}

.panel-header {
    padding: 12px 14px;
    background: #1e1e1e;
    border-bottom: 1px solid #333;
    font-weight: 600;
    font-size: 0.9rem;
    color: #bbb;
}

.panel-content {
    flex: 1;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid #333;
    background: #1e1e1e;
}

.tab-btn {
    flex: 1;
    padding: 10px 4px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: #888;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
}

.tab-btn:hover { color: #ddd; }
.tab-btn.active {
    color: #4fc3f7;
    border-bottom-color: #4fc3f7;
    background: #252525;
}

.tab-panel {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    bottom: 12px;
    opacity: 0;
    pointer-events: none;
    overflow-y: auto;
    transition: opacity 0.15s;
}

.tab-panel.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 1;
}

/* Sections inside panels */
.section {
    background: #202020;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid #333;
}

.section h2, .section h3 {
    font-size: 0.85rem;
    margin: 0 0 10px;
    color: #aaa;
}

.hint {
    font-size: 0.8rem;
    color: #777;
    margin: 0 0 10px;
}

#scene-objects-list {
    max-height: 320px;
    overflow-y: auto;
}

.scene-list-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 8px;
    margin-bottom: 4px;
    border: 1px solid #333;
    border-radius: 4px;
    background: #161616;
    cursor: pointer;
    font-size: 0.8rem;
}

.scene-list-item:hover {
    border-color: #4fc3f7;
}

.scene-list-item.active {
    border-color: #ffd54f;
    background: #262009;
}

.scene-item-name {
    color: #eee;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scene-item-dims {
    color: #777;
    font-size: 0.72rem;
}

label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.8rem;
    color: #bbb;
}

input, select, button {
    width: 100%;
    padding: 7px 10px;
    margin-top: 4px;
    border: 1px solid #444;
    border-radius: 4px;
    background: #151515;
    color: #eee;
    font-size: 0.85rem;
}

input:focus, select:focus {
    outline: none;
    border-color: #4fc3f7;
}

button {
    background: #0277bd;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.15s;
}

button:hover { background: #01579b; }
button.secondary { background: #3a3a3a; color: #ddd; }
button.secondary:hover { background: #4a4a4a; }
button.danger { background: #c62828; }
button.danger:hover { background: #b71c1c; }
button.full { margin-top: 8px; }

.btn-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.btn-row button { margin-top: 0; }

.dims-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.dims-row label, .config-row label {
    font-size: 0.75rem;
    margin-bottom: 0;
}

.config-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.wall-toggles {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.wall-toggles label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    margin-bottom: 0;
}

.wall-toggles input {
    width: auto;
    margin-top: 0;
}

/* Object library */
.object-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.obj-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    background: #252525;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.obj-btn:hover {
    background: #2f2f2f;
    border-color: #4fc3f7;
}

.obj-icon {
    font-size: 1.4rem;
    margin-bottom: 4px;
}

.obj-label {
    font-size: 0.75rem;
    font-weight: 500;
}

/* Viewport */
#viewport {
    grid-area: viewport;
    position: relative;
    background: #0d0d0d;
}

#canvas-container {
    width: 100%;
    height: 100%;
}

#status-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.75);
    color: #ccc;
    padding: 8px 12px;
    font-size: 0.85rem;
    pointer-events: none;
}

#pricing-result {
    margin-top: 12px;
    padding: 10px;
    background: #151515;
    border-radius: 4px;
    font-size: 0.85rem;
}

#pricing-result div {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

#pricing-result .total {
    border-top: 1px solid #444;
    padding-top: 6px;
    margin-top: 6px;
    font-weight: 600;
    color: #4fc3f7;
}

#selected-info {
    font-size: 0.85rem;
    color: #4fc3f7;
    margin-bottom: 10px;
}

.gizmo-info {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0,0,0,0.7);
    color: #ffcc00;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    pointer-events: none;
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.hidden { display: none !important; }
.modal.hidden { display: none; }

.modal-content {
    background: #1e1e1e;
    padding: 24px;
    border-radius: 8px;
    width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    border: 1px solid #444;
}

.modal-content.wide {
    width: 90vw;
    max-width: 1200px;
}

.sheet-preview {
    display: inline-block;
    margin: 12px;
    vertical-align: top;
}

.sheet-preview h4 {
    margin: 0 0 6px;
}

.close {
    float: right;
    font-size: 1.5rem;
    cursor: pointer;
    color: #888;
}

.close:hover { color: #fff; }

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
    font-size: 0.8rem;
}

th, td {
    text-align: left;
    padding: 8px;
    border-bottom: 1px solid #444;
}

th { color: #aaa; }

.help ul {
    margin: 0;
    padding-left: 18px;
    font-size: 0.8rem;
    color: #888;
}

.help li { margin-bottom: 4px; }

.opening-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1f1f1f;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 6px 8px;
    margin-top: 6px;
    font-size: 0.75rem;
}

.opening-item button {
    width: auto;
    padding: 2px 8px;
    font-size: 0.8rem;
    margin-top: 0;
}

.opening-popup {
    position: absolute;
    top: 120px;
    left: 340px;
    z-index: 1200;
    background: #2a2a2a;
    border: 1px solid #555;
    border-radius: 8px;
    padding: 10px 12px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
    width: 280px;
}

.opening-popup-header {
    font-weight: 600;
    margin-bottom: 8px;
}

.opening-popup .btn-row {
    margin-top: 8px;
}

.opening-popup .btn-row button {
    margin: 0 4px 0 0;
}

#btn-opening-pick.active {
    background: #f39c12;
    color: #111;
    border-color: #f39c12;
}

.labels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.label {
    background: #fff;
    color: #111;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 10px;
    text-align: center;
    font-size: 0.8rem;
}

.label-title { font-weight: bold; margin-bottom: 4px; }
.label-part { color: #555; margin-bottom: 4px; }
.label-size { font-weight: bold; margin-bottom: 2px; }
.label-edge { color: #777; font-size: 0.7rem; margin-bottom: 6px; }
.label-qr { width: 100px; height: 100px; }

.mat-preview {
    display: inline-block;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: 1px solid #555;
    vertical-align: middle;
    margin-right: 6px;
}

@media (max-width: 1000px) {
    #app {
        grid-template-columns: 240px 1fr 260px;
    }
}
