/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-deep:    #0c0e17;
    --bg-panel:   #12141f;
    --bg-glass:   rgba(22, 25, 40, 0.72);
    --bg-surface: #1b1e30;
    --accent-a:   #5b8cff;
    --accent-b:   #8a5bff;
    --text:       #e7eaf6;
    --muted:      #838cb0;
    --border:     rgba(255, 255, 255, 0.09);
    --danger:     #f2555f;
    --topbar:     52px;
}

html, body {
    height: 100%;
    background: var(--bg-deep);
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 13px;
    overflow: hidden;
}

.hidden { display: none !important; }

/* ── Topbar ────────────────────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar);
    background: linear-gradient(180deg, var(--bg-panel), rgba(18,20,31,.85));
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 20px; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark {
    width: 26px; height: 26px; border-radius: 7px;
    background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 800; letter-spacing: .02em; color: #fff;
    box-shadow: 0 2px 10px rgba(90, 110, 255, .35);
}
.brand-name { font-size: 15px; font-weight: 800; letter-spacing: .01em; }
.tagline { color: var(--muted); font-size: 12px; padding-left: 12px; border-left: 1px solid var(--border); }

.unit-toggle {
    margin-left: auto;
    display: flex; background: var(--bg-surface);
    border: 1px solid var(--border); border-radius: 8px; padding: 2px; gap: 2px;
}
.unit-btn {
    background: transparent; border: none; color: var(--muted);
    font-family: inherit; font-size: 11.5px; font-weight: 700;
    padding: 5px 10px; border-radius: 6px; cursor: pointer;
    transition: background .15s, color .15s;
}
.unit-btn:hover { color: var(--text); }
.unit-btn.active { background: linear-gradient(135deg, var(--accent-a), var(--accent-b)); color: #fff; }

.quote-cta {
    display: flex; align-items: center; gap: 7px;
    background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
    color: #fff; border: none; border-radius: 8px;
    padding: 7px 14px; font-size: 12.5px; font-weight: 700;
    font-family: inherit; cursor: pointer;
    box-shadow: 0 2px 12px rgba(90, 110, 255, .3);
    transition: opacity .15s, transform .15s;
}
.quote-cta:hover { opacity: .9; transform: translateY(-1px); }

/* ── Upload Panel ──────────────────────────────────────────────────────────── */
#upload-panel {
    height: calc(100vh - var(--topbar));
    display: flex; align-items: center; justify-content: center;
    background:
        radial-gradient(ellipse 900px 500px at 50% 30%, rgba(91,140,255,.10), transparent 60%),
        radial-gradient(ellipse 700px 500px at 80% 80%, rgba(138,91,255,.08), transparent 60%);
}
.upload-center { width: 440px; }

#drop-zone {
    border: 1.5px dashed var(--border);
    border-radius: 18px;
    padding: 60px 40px;
    text-align: center; cursor: pointer;
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    transition: border-color .2s, background .2s, transform .2s;
    display: block;
}
#drop-zone:hover, #drop-zone.drag-over {
    border-color: var(--accent-a);
    background: rgba(91, 140, 255, .07);
    transform: translateY(-2px);
}
.drop-icon      { color: var(--accent-a); margin-bottom: 16px; display: flex; justify-content: center; }
.drop-primary   { font-size: 18px; font-weight: 700; margin-bottom: 5px; }
.drop-secondary { color: var(--muted); margin-bottom: 18px; }
.drop-hint      { font-size: 11px; color: var(--muted); opacity: .75; letter-spacing: .02em; }

/* ── Viewer Panel ──────────────────────────────────────────────────────────── */
#viewer-panel { height: calc(100vh - var(--topbar)); }
#viewer { position: relative; width: 100%; height: 100%; overflow: hidden; background: var(--bg-deep); }
#viewer canvas { display: block; width: 100% !important; height: 100% !important; }
#viewer.measuring canvas { cursor: crosshair; }

/* ── Floating toolbar ──────────────────────────────────────────────────────── */
#toolbar {
    position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
    display: flex; align-items: center; gap: 3px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 13px;
    padding: 5px;
    z-index: 10;
    box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.tool-btn {
    width: 34px; height: 34px;
    border: none; border-radius: 9px;
    background: transparent; color: var(--muted);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, color .15s;
}
.tool-btn:hover { background: var(--bg-surface); color: var(--text); }
.tool-btn.active { background: linear-gradient(135deg, var(--accent-a), var(--accent-b)); color: #fff; }
.tool-sep { width: 1px; height: 20px; background: var(--border); margin: 0 3px; }

/* ── Axis indicator ────────────────────────────────────────────────────────── */
#axis-indicator {
    position: absolute; top: 16px; right: 16px;
    width: 96px; height: 96px; pointer-events: none; z-index: 5;
    border-radius: 12px; overflow: hidden;
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
}
.axis-label {
    position: absolute; font-size: 10px; font-weight: 700; line-height: 1;
    transform: translate(-50%, -50%); pointer-events: none;
    text-shadow: 0 0 5px rgba(0,0,0,.9);
    color: var(--text);
}

/* ── Contextual tool panel (Section / Measure) ────────────────────────────── */
#tool-panel {
    position: absolute; top: 66px; left: 50%; transform: translateX(-50%);
    display: flex; align-items: center; gap: 10px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 12px;
    z-index: 10;
    box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.tp-axis-group { display: flex; gap: 2px; background: var(--bg-surface); border-radius: 8px; padding: 2px; }
.tp-axis-btn {
    width: 24px; height: 24px; border: none; border-radius: 6px;
    background: transparent; color: var(--muted);
    font-size: 11px; font-weight: 700; cursor: pointer;
    transition: background .15s, color .15s;
}
.tp-axis-btn:hover { color: var(--text); }
.tp-axis-btn.active { background: linear-gradient(135deg, var(--accent-a), var(--accent-b)); color: #fff; }
.tp-axis-btn.wide { width: auto; padding: 0 11px; }

#section-slider {
    width: 140px; accent-color: var(--accent-a);
    background: transparent; cursor: pointer;
}

.tp-icon-btn {
    display: flex; align-items: center; justify-content: center; gap: 5px;
    height: 26px; padding: 0 10px; border: none; border-radius: 7px;
    background: var(--bg-surface); color: var(--muted);
    font-size: 11.5px; font-weight: 600; cursor: pointer;
    transition: background .15s, color .15s;
}
.tp-icon-btn:hover { background: rgba(255,255,255,.08); color: var(--text); }
.tp-icon-btn.primary { background: linear-gradient(135deg, var(--accent-a), var(--accent-b)); color: #fff; }
.tp-icon-btn.primary:hover { opacity: .9; }
.tp-icon-btn:disabled { opacity: .5; cursor: not-allowed; }

.tp-label { font-size: 12px; color: var(--muted); white-space: nowrap; }

#measure-hint { font-size: 12px; color: var(--muted); line-height: 1.4; max-width: 250px; }

/* ── Measurement overlays ──────────────────────────────────────────────────── */
.measure-label {
    position: absolute; transform: translate(-50%, -50%);
    background: rgba(20, 22, 34, .9);
    border: 1px solid rgba(255, 215, 100, .4);
    color: #ffd764;
    font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums;
    padding: 3px 8px; border-radius: 6px;
    white-space: nowrap; pointer-events: none;
    z-index: 8;
}

/* ── Zoom controls ─────────────────────────────────────────────────────────── */
#zoom-controls {
    position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
    display: flex; flex-direction: column; gap: 5px; z-index: 5;
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 5px;
}
.zoom-btn {
    width: 30px; height: 30px;
    background: transparent; color: var(--muted);
    border: none; border-radius: 8px;
    font-size: 17px; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, color .15s;
}
.zoom-btn:hover { background: var(--bg-surface); color: var(--text); }

/* ── Model info card ───────────────────────────────────────────────────────── */
#info-card {
    position: absolute; bottom: 16px; left: 16px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 13px;
    padding: 12px 15px;
    z-index: 5; min-width: 190px;
    box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
#info-filename {
    font-size: 12.5px; font-weight: 700;
    margin-bottom: 8px; padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    word-break: break-all; line-height: 1.4;
}
.info-row {
    display: flex; justify-content: space-between; align-items: center;
    gap: 16px; font-size: 11.5px; padding: 2.5px 0;
}
.info-row span { color: var(--muted); }
.info-row b { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Analysis results (draft / wall thickness) ────────────────────────────── */
#analysis-card {
    position: absolute; bottom: 16px; right: 16px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 13px;
    padding: 12px 15px;
    z-index: 5; min-width: 190px;
    box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.analysis-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 8px; padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
#analysis-title { font-size: 12.5px; font-weight: 700; }
.analysis-header button {
    width: 20px; height: 20px; border: none; background: transparent;
    color: var(--muted); font-size: 15px; line-height: 1; cursor: pointer;
    border-radius: 5px; transition: background .15s, color .15s;
}
.analysis-header button:hover { background: var(--bg-surface); color: var(--text); }
#analysis-nominal {
    display: block; font-size: 11px; font-weight: 600; color: var(--text);
    margin-bottom: 8px; font-variant-numeric: tabular-nums;
}
.legend-gradient-wrap { position: relative; margin-bottom: 5px; }
.legend-gradient-bar { height: 8px; border-radius: 3px; }
#analysis-nominal-tick {
    position: absolute; top: -3px; width: 2px; height: 14px;
    background: #fff; border-radius: 1px; transform: translateX(-1px);
    box-shadow: 0 0 0 1px rgba(0,0,0,.4);
}
.legend-gradient-labels {
    display: flex; justify-content: space-between;
    font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums;
}

#analysis-tooltip {
    position: fixed; z-index: 20; pointer-events: none;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 4px 9px;
    font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
    box-shadow: 0 6px 16px rgba(0,0,0,.35);
}

/* ── Body tree (multi-body files) ──────────────────────────────────────────── */
#body-tree {
    position: absolute; top: 16px; left: 16px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 13px;
    padding: 10px 8px;
    z-index: 5; min-width: 170px; max-width: 240px;
    max-height: calc(100% - 32px); overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.body-tree-header {
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted); padding: 2px 7px 8px;
}
.body-row {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 7px; border-radius: 8px; cursor: pointer;
    font-size: 12.5px; transition: background .15s;
}
.body-row:hover { background: var(--bg-surface); }
.body-row .body-eye {
    display: flex; flex-shrink: 0; color: var(--accent-a);
}
.body-row.body-hidden { color: var(--muted); }
.body-row.body-hidden .body-eye { color: var(--muted); opacity: .5; }
.body-row .body-name {
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.body-opacity-btn {
    display: flex; flex-shrink: 0; align-items: center; justify-content: center;
    width: 22px; height: 22px; border: none; border-radius: 6px;
    background: transparent; color: var(--muted); cursor: pointer;
    transition: background .15s, color .15s;
}
.body-opacity-btn:hover { background: rgba(255,255,255,.08); color: var(--text); }
.body-opacity-btn.active { color: var(--accent-a); }
.body-opacity-btn:disabled { opacity: .35; cursor: not-allowed; pointer-events: none; }

/* ── Loading overlay ───────────────────────────────────────────────────────── */
#loading-overlay {
    position: absolute; inset: 0;
    background: rgba(12,14,23,.9);
    backdrop-filter: blur(4px);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 16px; z-index: 20;
}
.spinner {
    width: 38px; height: 38px;
    border: 3px solid var(--border);
    border-top-color: var(--accent-a);
    border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-progress { color: var(--muted); font-size: 13px; }

/* ── Error toast ───────────────────────────────────────────────────────────── */
.error-toast {
    position: absolute; bottom: 16px; right: 16px;
    background: var(--danger); color: #fff;
    padding: 11px 15px; border-radius: 10px;
    font-size: 13px; z-index: 30; max-width: 340px; line-height: 1.4;
    box-shadow: 0 8px 24px rgba(242, 85, 95, .3);
}

/* ── Request Quote modal ───────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(8, 9, 15, .65);
    backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}
.modal-panel {
    width: 100%; max-width: 480px; max-height: calc(100vh - 48px);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    display: flex; flex-direction: column;
    box-shadow: 0 24px 64px rgba(0,0,0,.5);
    overflow: hidden;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-title { font-size: 15px; font-weight: 800; }
.modal-close {
    width: 26px; height: 26px; border: none; background: transparent;
    color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer;
    border-radius: 6px; transition: background .15s, color .15s;
}
.modal-close:hover { background: var(--bg-surface); color: var(--text); }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-sub { color: var(--muted); font-size: 12.5px; line-height: 1.6; margin-bottom: 16px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block; font-size: 11px; font-weight: 700; color: var(--muted);
    text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px;
}
.form-group .req { color: var(--danger); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; background: var(--bg-surface); border: 1px solid var(--border);
    color: var(--text); font-family: inherit; font-size: 13px;
    padding: 9px 11px; border-radius: 8px; outline: none;
    transition: border-color .15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    border-color: var(--accent-a);
}
.form-group textarea { resize: vertical; min-height: 64px; line-height: 1.5; }
.form-group select { cursor: pointer; }

.form-error {
    background: rgba(242, 85, 95, .1); border: 1px solid rgba(242, 85, 95, .3);
    color: #ff9aa2; font-size: 12px; padding: 9px 11px; border-radius: 8px;
    margin-bottom: 12px;
}

.modal-submit {
    width: 100%; padding: 11px; border: none; border-radius: 9px;
    background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
    color: #fff; font-family: inherit; font-size: 13.5px; font-weight: 700;
    cursor: pointer; transition: opacity .15s, transform .15s;
}
.modal-submit:hover:not(:disabled) { opacity: .9; transform: translateY(-1px); }
.modal-submit:disabled { opacity: .5; cursor: not-allowed; }

.modal-success { text-align: center; padding: 24px 8px; }
.success-icon {
    width: 52px; height: 52px; margin: 0 auto 14px;
    border-radius: 50%; background: rgba(46, 200, 89, .12);
    border: 2px solid #2ec859; color: #2ec859;
    display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.success-title { font-size: 15px; font-weight: 800; margin-bottom: 5px; }
.success-sub { color: var(--muted); font-size: 12.5px; }

@media (max-width: 520px) {
    .form-row { grid-template-columns: 1fr; }
    .tagline { display: none; }
}
