:root {
    --bg: #0d1117;
    --panel: #161b22;
    --panel-2: #1c2330;
    --border: #30363d;
    --text: #c9d1d9;
    --muted: #8b949e;
    --accent: #58a6ff;
    --accent-2: #1f6feb;
    --danger: #f85149;
    --ok: #3fb950;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: .75rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.tagline { color: var(--muted); font-size: .85rem; }
.tabs { display: flex; gap: .25rem; }
.tab {
    color: var(--muted); text-decoration: none; font-size: .9rem; font-weight: 600;
    padding: .35rem .8rem; border-radius: 8px;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active { color: #fff; background: var(--accent-2); }
.lang-switch { margin-left: auto; display: flex; gap: .35rem; font-size: .8rem; }
.lang-switch a { color: var(--muted); text-decoration: none; padding: .15rem .35rem; border-radius: 5px; }
.lang-switch a.active { color: #fff; background: var(--panel-2); }

.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.section-head h1 { margin-top: 0; }

.wrap { max-width: 960px; margin: 0 auto; padding: 1.5rem; }

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.upload-card h1 { margin-top: 0; }

h1 { font-size: 1.5rem; }
h2.section-title { font-size: 1.1rem; color: var(--muted); margin: 1.5rem 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.error { color: var(--danger); }

.upload-form { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }
input[type=file] { color: var(--muted); }

button, .button {
    display: inline-block;
    background: var(--accent-2);
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: .6rem 1.1rem;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
button:hover, .button:hover { background: var(--accent); }
button.secondary, .button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }

/* Gallery grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
.tile {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    color: var(--text);
    transition: border-color .15s;
    display: flex;
    flex-direction: column;
}
.tile:hover { border-color: var(--accent); }
.tile-link { text-decoration: none; color: inherit; display: block; }
.tile-actions {
    display: flex; align-items: center; gap: .75rem;
    padding: .4rem .6rem; border-top: 1px solid var(--border);
    font-size: .8rem;
}
.tile-actions a { color: var(--accent); text-decoration: none; }
.tile-actions a:hover { text-decoration: underline; }
.tile-actions .inline-form { margin-left: auto; }
.thumb { position: relative; aspect-ratio: 1 / 1; background: #0b0f14; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge {
    position: absolute; top: .5rem; right: .5rem;
    font-size: .7rem; padding: .15rem .5rem; border-radius: 999px;
    background: rgba(0,0,0,.65); text-transform: uppercase; letter-spacing: .04em;
}
.badge-done { color: var(--ok); }
.badge-error { color: var(--danger); }
.badge-running, .badge-queued, .badge-new { color: var(--accent); }
.tile-meta { padding: .5rem .6rem; display: flex; flex-direction: column; gap: .1rem; }
.tile-meta .name { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-meta .date { font-size: .72rem; color: var(--muted); }

/* Editor */
.editor { position: relative; margin: 1rem 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #0b0f14; }
#outline-canvas { display: block; width: 100%; touch-action: none; cursor: crosshair; }
.editor-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1rem; }
.editor-hint { color: var(--muted); font-size: .82rem; margin: .25rem 0 0; }
#dimensions { color: var(--accent); font-size: .85rem; font-weight: 600; margin: .5rem 0 0; }

/* Per-edge meter inputs, overlaid at each edge midpoint */
.edge-len {
    position: absolute;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: 2px;
    background: rgba(13, 17, 23, 0.85);
    border: 1px solid var(--accent-2);
    border-radius: 6px;
    padding: 1px 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.edge-len-input {
    width: 46px;
    background: transparent;
    border: 0;
    color: var(--text);
    font-size: .8rem;
    text-align: right;
    padding: 1px 0;
    -moz-appearance: textfield;
}
.edge-len-input::-webkit-outer-spin-button,
.edge-len-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.edge-len-input:focus { outline: none; }
.edge-len-unit { color: var(--muted); font-size: .7rem; }
.editor.lengths-hidden .edge-len { display: none; }

/* Buttons: danger + inline form */
button.danger, .button.danger {
    background: transparent; color: var(--danger); border: 1px solid var(--danger);
}
button.danger:hover, .button.danger:hover { background: var(--danger); color: #fff; }
.inline-form { display: inline; margin: 0; }
.link-danger {
    background: none; border: 0; color: var(--danger); cursor: pointer;
    font: inherit; padding: 0; text-decoration: underline;
}

/* Progress */
.progress { display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: 1.5rem; text-align: center; }
.spinner {
    width: 34px; height: 34px; border-radius: 50%;
    border: 3px solid var(--border); border-top-color: var(--accent);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Viewer */
.viewer { width: 100%; height: 520px; background: #0b0f14; border-radius: 10px; margin: 1rem 0; --poster-color: transparent; }

/* Component catalog */
.comp-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.comp-card { }
.comp-viewer { position: relative; aspect-ratio: 4 / 3; background: #0b0f14; }
.comp-model { width: 100%; height: 100%; --poster-color: transparent; }
.comp-body { padding: .6rem .7rem; display: flex; flex-direction: column; gap: .25rem; }
.comp-name { font-weight: 600; }
.comp-desc { font-size: .8rem; }
.comp-specs { margin: .35rem 0 0; display: flex; flex-direction: column; gap: .15rem; }
.comp-specs div { display: flex; gap: .5rem; font-size: .8rem; }
.comp-specs dt { color: var(--muted); min-width: 58px; margin: 0; }
.comp-specs dd { margin: 0; color: var(--text); }
.badge-feet, .badge-frame, .badge-tube, .badge-deck { color: var(--accent); }

/* Scaffolding scene */
.scene-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1.25rem; margin: 1rem 0; }
@media (max-width: 720px) { .scene-layout { grid-template-columns: 1fr; } }
.scene-view .viewer { height: 480px; margin: 0; }
.scene-placeholder { display: flex; align-items: center; justify-content: center; height: 480px;
    background: #0b0f14; border: 1px dashed var(--border); border-radius: 10px; text-align: center; padding: 1rem; }
.scene-side { display: flex; flex-direction: column; gap: 1rem; }
.scene-form { display: flex; flex-direction: column; gap: .75rem; background: var(--panel-2);
    border: 1px solid var(--border); border-radius: 10px; padding: 1rem; }
.bom { width: 100%; border-collapse: collapse; font-size: .85rem; }
.bom td { padding: .3rem .25rem; border-bottom: 1px solid var(--border); }
.bom .bom-qty { text-align: right; color: var(--accent); font-variant-numeric: tabular-nums; }
.bom .bom-kg { text-align: right; color: var(--muted); white-space: nowrap; }
.bom tfoot td { border-top: 2px solid var(--border); border-bottom: 0; font-weight: 700; padding-top: .5rem; }

/* Component form */
.comp-form { display: flex; flex-direction: column; gap: 1rem; max-width: 640px; margin-top: 1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field > span { font-size: .82rem; color: var(--muted); }
.field input, .field select {
    background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); padding: .5rem .6rem; font-size: .95rem;
}
.field input[type=color] { padding: .2rem; height: 40px; width: 60px; }
.field-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 120px; }
