:root,
[data-theme="light"] {
  --bg-app: #e2e8f0;
  --bg-ribbon: #f8fafc;
  --bg-ribbon-bar: #f1f5f9;
  --bg-panel: #ffffff;
  --bg-panel-header: #e2e8f0;
  --bg-panel-sub: #f8fafc;
  --bg-hover: #e0f2fe;
  --bg-active: #bae6fd;
  --bg-input: #ffffff;
  --bg-status: #1e293b;
  --text-status: #f8fafc;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
  --border-color: #cbd5e1;
  --border-strong: #94a3b8;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --accent-soft: rgba(2, 132, 199, 0.12);
  --accent-border: #38bdf8;
  --ts-red: #dc2626;
  --ts-green: #16a34a;
  --ts-amber: #d97706;
  --ts-purple: #7c3aed;
  --viewport-top: #cfe0f5;
  --viewport-bot: #f1f5f9;
  --shadow-float: 0 6px 20px rgba(15, 23, 42, 0.14);
}

[data-theme="dark"] {
  --bg-app: #090d16;
  --bg-ribbon: #0f172a;
  --bg-ribbon-bar: #131c31;
  --bg-panel: #111827;
  --bg-panel-header: #1e293b;
  --bg-panel-sub: #0f172a;
  --bg-hover: #1e293b;
  --bg-active: #1e3a5f;
  --bg-input: #090d16;
  --bg-status: #090d16;
  --text-status: #e2e8f0;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --border-color: #1e293b;
  --border-strong: #334155;
  --accent: #0ea5e9;
  --accent-hover: #38bdf8;
  --accent-soft: rgba(14, 165, 233, 0.16);
  --accent-border: #0284c7;
  --ts-red: #ef4444;
  --ts-green: #22c55e;
  --ts-amber: #f59e0b;
  --ts-purple: #a855f7;
  --viewport-top: #0f172a;
  --viewport-bot: #1e293b;
  --shadow-float: 0 8px 26px rgba(0, 0, 0, 0.48);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

html, body {
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  font-size: 12px;
  color: var(--text-main);
  background: var(--bg-app);
}

.mono {
  font-family: 'JetBrains Mono', 'Cascadia Mono', 'Consolas', monospace;
}

#app-shell {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

/* 1. TOPSOLId TITLE BAR */
.ts-titlebar {
  height: 34px;
  min-height: 34px;
  background: linear-gradient(90deg, #0f172a 0%, #1e293b 60%, #0f172a 100%);
  color: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  border-bottom: 1px solid #334155;
  gap: 10px;
  z-index: 30;
}

.ts-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.ts-logo-cube {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 55%, #991b1b 100%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 11px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.ts-brand-sub {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  background: rgba(56, 189, 248, 0.18);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.ts-title-center {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  max-width: 780px;
}

.ts-pkg-select {
  flex: 1;
  height: 24px;
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid #475569;
  border-radius: 4px;
  padding: 0 8px;
  font-size: 11.5px;
  outline: none;
}

.ts-pkg-select:focus {
  border-color: #38bdf8;
}

.ts-title-btn {
  height: 24px;
  padding: 0 9px;
  border-radius: 4px;
  border: 1px solid #475569;
  background: #1e293b;
  color: #f1f5f9;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: all 0.12s ease;
}

.ts-title-btn:hover {
  background: #334155;
  border-color: #64748b;
}

.ts-title-btn.primary {
  background: #0284c7;
  border-color: #38bdf8;
  color: #fff;
}

.ts-title-btn.primary:hover {
  background: #0369a1;
}

.ts-title-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ts-user-pill {
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 99px;
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.35);
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 2. TOPSOLID RIBBON BAR */
.ts-ribbon {
  background: var(--bg-ribbon);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 25;
}

.ts-ribbon-tabs {
  display: flex;
  align-items: center;
  height: 25px;
  padding: 0 8px;
  background: var(--bg-panel-header);
  border-bottom: 1px solid var(--border-color);
  gap: 2px;
}

.ts-rtab {
  padding: 3px 12px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
  position: relative;
  top: 1px;
}

.ts-rtab:hover {
  color: var(--text-main);
  background: rgba(148, 163, 184, 0.15);
}

.ts-rtab.active {
  color: var(--accent);
  background: var(--bg-ribbon-bar);
  border-color: var(--border-color);
}

.ts-ribbon-strip {
  height: 44px;
  min-height: 44px;
  background: var(--bg-ribbon-bar);
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 6px;
  overflow-x: auto;
}

.ts-rgroup {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 8px;
  border-right: 1px solid var(--border-color);
  height: 34px;
}

.ts-rgroup:last-child {
  border-right: none;
}

.ts-rgroup-title {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  margin-right: 3px;
  writing-mode: horizontal-tb;
  white-space: nowrap;
}

.ts-rbtn {
  height: 30px;
  padding: 0 8px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-main);
  font-size: 11px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.1s ease;
}

.ts-rbtn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.ts-rbtn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.ts-rbtn.accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-hover);
  font-weight: 600;
}

.ts-rbtn.accent:hover {
  background: var(--accent-hover);
}

/* 3. DOCUMENT TABS BAR */
.ts-doctabs {
  height: 26px;
  min-height: 26px;
  background: var(--bg-panel-header);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: flex-end;
  padding: 0 6px;
  gap: 3px;
  overflow-x: auto;
}

.ts-doctab {
  height: 23px;
  padding: 0 10px;
  border-radius: 4px 4px 0 0;
  border: 1px solid var(--border-color);
  border-bottom: none;
  background: var(--bg-panel-sub);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.ts-doctab.active {
  background: var(--bg-panel);
  color: var(--text-main);
  font-weight: 600;
  border-top: 2px solid var(--accent);
}

.ts-doctab-close {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-dim);
}

.ts-doctab-close:hover {
  background: var(--ts-red);
  color: #fff;
}

/* 4. MAIN WORKSPACE (LEFT DOCK + CENTER VIEWPORT + RIGHT DOCK) */
.ts-workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
  overflow: hidden;
}

.ts-dock {
  width: 310px;
  min-width: 220px;
  max-width: 520px;
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 15;
}

.ts-dock-left {
  border-right: 1px solid var(--border-color);
}

.ts-dock-right {
  width: 320px;
  border-left: 1px solid var(--border-color);
}

.ts-dock.collapsed {
  display: none !important;
}

.ts-splitter-v {
  width: 4px;
  cursor: col-resize;
  background: transparent;
  z-index: 20;
  transition: background 0.15s;
}

.ts-splitter-v:hover,
.ts-splitter-v.dragging {
  background: var(--accent);
}

.ts-splitter-h {
  height: 4px;
  cursor: row-resize;
  background: var(--border-color);
  z-index: 20;
  transition: background 0.15s;
}

.ts-splitter-h:hover,
.ts-splitter-h.dragging {
  background: var(--accent);
}

.ts-pane {
  display: flex;
  flex-direction: column;
  min-height: 80px;
  overflow: hidden;
}

.ts-pane-top {
  flex: 1.25;
}

.ts-pane-bot {
  flex: 1;
}

.ts-pane-header {
  height: 26px;
  min-height: 26px;
  background: var(--bg-panel-header);
  border-bottom: 1px solid var(--border-color);
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-main);
}

.ts-pane-toolbar {
  padding: 5px 6px;
  background: var(--bg-panel-sub);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ts-search-input {
  width: 100%;
  height: 24px;
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0 8px;
  font-size: 11px;
  outline: none;
}

.ts-search-input:focus {
  border-color: var(--accent);
}

.ts-pill-row {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: wrap;
}

.ts-pill {
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 600;
  border-radius: 3px;
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-muted);
  cursor: pointer;
}

.ts-pill:hover {
  border-color: var(--accent);
  color: var(--text-main);
}

.ts-pill.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.ts-tree-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 0;
}

/* TREE NODES (TOPSOLID ENTITIES & PDM) */
.ts-tree-group {
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.ts-tree-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  min-height: 23px;
  cursor: pointer;
  font-size: 11.5px;
  color: var(--text-main);
  transition: background 0.08s;
}

.ts-tree-row:hover {
  background: var(--bg-hover);
}

.ts-tree-row.selected {
  background: var(--bg-active);
  font-weight: 600;
}

.ts-tree-row.hidden-part {
  opacity: 0.46;
}

.ts-tree-caret {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.ts-tree-check {
  width: 13px;
  height: 13px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.ts-tree-icon {
  width: 15px;
  text-align: center;
  font-size: 12px;
  flex-shrink: 0;
}

.ts-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
}

.ts-tree-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ts-tree-badge {
  font-size: 9.5px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-panel-header);
  color: var(--text-muted);
  font-family: 'JetBrains Mono', Consolas, monospace;
  flex-shrink: 0;
}

.ts-tree-act {
  opacity: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 10.5px;
}

.ts-tree-row:hover .ts-tree-act {
  opacity: 1;
}

.ts-tree-act:hover {
  background: var(--accent);
  color: #fff;
}

/* 5. CENTER 3D VIEWPORT & TOPSOLID FLOATING CAMERA TOOLBAR */
.ts-viewport-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: linear-gradient(180deg, var(--viewport-top) 0%, var(--viewport-bot) 100%);
  overflow: hidden;
}

#viewport-canvas {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

/* Top-left viewport HUD info */
.ts-vp-hud-top {
  position: absolute;
  top: 10px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 10;
}

.ts-vp-doc-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 5px;
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(8px);
  color: #f8fafc;
  border: 1px solid rgba(148, 163, 184, 0.28);
  font-size: 11.5px;
  box-shadow: var(--shadow-float);
}

.ts-vp-banner {
  pointer-events: auto;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 5px;
  background: rgba(2, 132, 199, 0.92);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  box-shadow: var(--shadow-float);
}

.ts-vp-banner.visible {
  display: inline-flex;
}

/* Right vertical floating camera toolbar (TopSolid 7 style) */
.ts-cam-bar {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 5px;
  border-radius: 6px;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-float);
  z-index: 12;
}

.ts-cam-btn {
  width: 30px;
  height: 28px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  position: relative;
  transition: all 0.1s ease;
}

.ts-cam-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.ts-cam-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-hover);
}

.ts-cam-sep {
  height: 1px;
  background: var(--border-color);
  margin: 2px 0;
}

/* Interactive Section Cut Floating Bar */
.ts-cut-hud {
  position: absolute;
  bottom: 48px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(8px);
  color: #f8fafc;
  border: 1px solid #38bdf8;
  box-shadow: var(--shadow-float);
  z-index: 14;
}

.ts-cut-hud.visible {
  display: flex;
}

/* Measurement Floating Panel */
.ts-measure-hud {
  position: absolute;
  top: 60px;
  left: 12px;
  width: 310px;
  display: none;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border-radius: 7px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(10px);
  color: #f8fafc;
  border: 1px solid #38bdf8;
  box-shadow: var(--shadow-float);
  z-index: 14;
}

.ts-measure-hud.visible {
  display: flex;
}

.ts-measure-result {
  background: rgba(2, 6, 23, 0.75);
  border: 1px solid #334155;
  border-radius: 5px;
  padding: 7px 9px;
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 11px;
  line-height: 1.5;
}

/* 3D Measurement Callout Labels */
.ts-dim-label {
  position: absolute;
  transform: translate(-50%, -100%);
  padding: 3px 7px;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.92);
  color: #38bdf8;
  border: 1px solid #38bdf8;
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  z-index: 11;
}

/* Zoom Window rubberband */
#zoom-window-box {
  position: absolute;
  border: 1.5px dashed #0284c7;
  background: rgba(2, 132, 199, 0.15);
  pointer-events: none;
  display: none;
  z-index: 20;
}

/* Bottom-left Triad & Bottom-right Scale Bar */
.ts-triad-wrap {
  position: absolute;
  bottom: 8px;
  left: 10px;
  width: 82px;
  height: 82px;
  pointer-events: auto;
  z-index: 11;
}

.ts-scale-wrap {
  position: absolute;
  bottom: 12px;
  right: 54px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: none;
  z-index: 11;
}

.ts-scale-text {
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-main);
  text-shadow: 0 0 3px var(--bg-panel);
}

.ts-scale-bar {
  width: 110px;
  height: 6px;
  border-left: 2px solid var(--ts-red);
  border-right: 2px solid var(--ts-red);
  border-bottom: 2px solid var(--ts-red);
}

/* Inspector & Preview Card in Right Dock */
.ts-props-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ts-prop-grid {
  display: grid;
  grid-template-columns: 95px 1fr;
  gap: 4px 8px;
  font-size: 11px;
  align-items: center;
}

.ts-prop-key {
  color: var(--text-muted);
  font-weight: 600;
}

.ts-prop-val {
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 6. BOTTOM STATUS BAR */
.ts-statusbar {
  height: 24px;
  min-height: 24px;
  background: var(--bg-status);
  color: var(--text-status);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  font-size: 11px;
  z-index: 30;
}

.ts-status-left,
.ts-status-right {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.ts-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
}

/* 7. AUTHENTICATION GATE (@topsolid.com ONLY) */
#auth-gate {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 25%, #1e293b 0%, #090d16 75%);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
}

.auth-card {
  width: 100%;
  max-width: 430px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 26px;
  color: #f8fafc;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
}

.auth-input {
  width: 100%;
  height: 38px;
  border-radius: 6px;
  border: 1px solid #334155;
  background: #090d16;
  color: #f8fafc;
  padding: 0 12px;
  font-size: 13px;
  outline: none;
}

.auth-input:focus {
  border-color: #38bdf8;
}

.auth-btn {
  width: 100%;
  height: 38px;
  border-radius: 6px;
  border: none;
  background: #0284c7;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.auth-btn:hover {
  background: #0369a1;
}

/* Loading & Drag-Drop Overlay */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #f8fafc;
  z-index: 50;
}

#loading-overlay.visible {
  display: flex;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(56, 189, 248, 0.25);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Modal Dialog (Legal / Feedback / Export STEP) */
.ts-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 13, 22, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}

.ts-modal-backdrop.visible {
  display: flex;
}

.ts-modal {
  width: 100%;
  max-width: 480px;
  background: var(--bg-panel);
  color: var(--text-main);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow-float);
}

@media (max-width: 900px) {
  .ts-dock-left, .ts-dock-right {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 280px;
    z-index: 40;
    box-shadow: var(--shadow-float);
  }
  .ts-dock-left { left: 0; }
  .ts-dock-right { right: 0; }
  .ts-splitter-v { display: none; }
  .ts-ribbon-tabs { overflow-x: auto; white-space: nowrap; }
  .ts-rtab { white-space: nowrap; flex-shrink: 0; }
  .ts-brand-sub, #active-quality-badge { display: none; }
}
