/* CAD Studio (/cad-studio). It wears Video Studio's frame and panels
   (video-studio.css), as 3D Studio does: menus and Export along the top,
   then Part or Drawing and the tools, then the parts list, the view (3D, or
   the 2D canvas for sketches and drawings) with the status line under it,
   and the settings. On a phone the side panels become sheets opened from
   tabs. */

/* ---- Start screen ---- */
.cd-new .st-new-row + .st-new-row { margin-top: 12px; }
.cd-new .st-new-row > .st-field { flex: 0 0 auto; }

/* ---- The frame ---- */
.cd-work { grid-template-rows: auto auto minmax(0, 1fr); }
.cd-body { grid-template-columns: 272px minmax(0, 1fr) 300px; }
.cd-main { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; min-width: 0; min-height: 0; }
.cd-menu { max-height: 72vh; overflow-y: auto; scrollbar-width: thin; }
.cd-menu-head { margin: 6px 10px 2px; color: var(--accent-strong); font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.08em; text-transform: uppercase; }
.cd-app.is-picking .cd-canvas { cursor: crosshair; }

/* ---- The tool bar ---- */
.cd-bar { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 4px 8px; background: var(--surface); border-bottom: 1px solid var(--border); }
.cd-bar > .seg, .cd-finish { flex: none; }
.cd-finish { display: inline-flex; align-items: center; gap: 5px; }
.cd-tools { display: flex; align-items: center; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.cd-tools::-webkit-scrollbar { display: none; }
.cd-tools .vs-ib { flex: none; }
.cd-tool.is-on { color: var(--tint-text); background: var(--tint); }
.cd-tools-gap { flex: none; width: 1px; height: 22px; margin: 0 6px; background: var(--border); }
.cd-bar-btn { flex: none; }
.cd-bar-field { display: inline-flex; align-items: center; gap: 5px; flex: none; color: var(--muted); font-size: 0.74rem; }
.cd-bar-num { width: 64px; padding: 3px 6px; border-radius: 0; font-size: 0.78rem; }
.cd-view-btns, .cd-btn-group { display: flex; align-items: center; gap: 3px; flex: none; }
.cd-view-btns { margin-left: auto; }
.cd-btn-group[hidden] { display: none; }
#cd-snap.is-on, #cd-orthomode.is-on { color: var(--tint-text); background: var(--tint); }
.cd-ortho { min-width: 62px; }
.cd-views { width: auto; min-width: 92px; }

/* ---- The views ---- */
.cd-view { position: relative; grid-row: 1; grid-column: 1; min-width: 0; min-height: 0; overflow: hidden; background: #2b2b31; }
.cd-view[hidden] { display: none; }
.cd-view2d { background: #1d1b26; }
.cd-canvas, .cd-canvas2d { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
.cd-canvas2d { cursor: crosshair; }
.cd-app[data-space="drawing"] .cd-canvas2d:focus-visible, .cd-app[data-space="sketch"] .cd-canvas2d:focus-visible { box-shadow: inset 0 0 0 1px var(--accent); }
.cd-labels { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.cd-label { position: absolute; padding: 2px 6px; color: #14111f; background: #ffd060; font: 600 0.72rem/1.3 var(--mono); white-space: nowrap; transform: translate(-50%, -130%); }
.cd-inline { position: absolute; z-index: 4; width: 96px; padding: 3px 6px; border-radius: 0; font: 0.8rem var(--mono); }
.cd-axes { position: absolute; right: 10px; top: 10px; z-index: 2; width: 60px; height: 60px; border-radius: 50%; background: rgba(20, 17, 31, 0.35); }
.cd-axis { position: absolute; display: grid; place-items: center; width: 18px; height: 18px; padding: 0; color: #14111f; border: 0; border-radius: 50%; font: 700 10px/1 var(--mono); cursor: pointer; }
.cd-axis:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.cd-msg { position: absolute; left: 10px; right: 84px; bottom: 40px; z-index: 3; margin: 0; pointer-events: none; }
.cd-msg:not(:empty) { width: fit-content; max-width: calc(100% - 94px); padding: 6px 10px; color: var(--text); background: rgba(20, 17, 31, 0.86); border: 1px solid var(--border); border-radius: 0; }
.cd-msg[data-kind="warn"] { border-color: #e8b44f; }
.cd-msg[data-kind="ok"] { border-color: #2ec4b6; }
.cd-loading { position: absolute; left: 50%; top: 45%; z-index: 3; margin: 0; padding: 8px 14px; color: var(--text); background: rgba(20, 17, 31, 0.86); border: 1px solid var(--border); transform: translate(-50%, -50%); }

/* ---- The status line ---- */
.cd-status { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 3px 8px; color: var(--muted); background: var(--surface); border-top: 1px solid var(--border); font: 0.72rem/1.4 var(--mono); }
.cd-status-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: pre; }
.cd-status[data-state="full"] .cd-status-text { color: #2ec4b6; }
.cd-status[data-state="bad"] .cd-status-text { color: #ff7a7a; }
.cd-cmd { flex: 0 1 240px; min-width: 0; padding: 2px 7px; border-radius: 0; font: 0.74rem var(--mono); }
.cd-app[data-space="part"] .cd-cmd { display: none; }

/* ---- Parts list ---- */
.cd-lib-body { padding: 10px; overflow-y: auto; scrollbar-width: thin; }
.cd-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
.cd-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 2px 6px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 0; font: inherit; font-size: 0.68rem; text-align: center; cursor: pointer; transition: border-color 140ms ease, color 140ms ease; }
.cd-tile:hover { color: var(--text); border-color: var(--accent); }
.cd-tile:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.cd-tile-icon { display: grid; place-items: center; color: var(--text); }

.cd-tree { margin: 0 0 8px; padding: 0; list-style: none; }
.cd-tree-row { display: flex; align-items: center; gap: 6px; padding: 4px 6px; color: var(--muted); font-size: 0.78rem; cursor: pointer; }
.cd-tree-row:hover { background: rgba(255, 255, 255, 0.04); }
.cd-tree-row.is-sel { color: var(--text); background: var(--tint); }
.cd-tree-row.is-off .cd-tree-name { opacity: 0.45; text-decoration: line-through; }
.cd-tree-row.is-err { box-shadow: inset 2px 0 0 #ff7a7a; }
.cd-tree-row:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.cd-tree-num { flex: none; width: 18px; color: var(--muted); font: 0.66rem var(--mono); text-align: right; }
.cd-tree-icon { display: grid; place-items: center; flex: none; color: var(--accent-strong); }
.cd-tree-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cd-tree-val { flex: none; font: 0.72rem var(--mono); }
.cd-tree-tag { flex: none; padding: 0 5px; font: 0.6rem/1.6 var(--mono); text-transform: uppercase; border: 1px solid var(--border); }
.cd-tree-tag.is-cut { color: #ff9a9a; border-color: #ff9a9a; }
.cd-tree-tag.is-new { color: #7ee2b8; border-color: #7ee2b8; }
.cd-tree-warn { display: grid; place-items: center; flex: none; color: #ffb86b; }
.cd-eye { display: grid; place-items: center; flex: none; width: 24px; height: 22px; padding: 0; color: var(--muted); background: none; border: 0; border-radius: 0; cursor: pointer; }
.cd-eye:hover { color: var(--text); }
.cd-eye:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.cd-swatch { flex: none; width: 12px; height: 12px; border: 1px solid rgba(0, 0, 0, 0.4); }

.cd-layers { margin: 0 0 8px; padding: 0; list-style: none; }
.cd-layer { display: grid; grid-template-columns: 18px 22px minmax(0, 1fr) 24px 24px; grid-template-areas: "pick col name eye lock" ". . lt lt count"; align-items: center; gap: 3px 4px; padding: 4px 2px; border-bottom: 1px solid var(--border); }
.cd-layer > .cd-layer-pick { grid-area: pick; }
.cd-layer > .cd-layer-col { grid-area: col; }
.cd-layer > .cd-layer-name { grid-area: name; }
.cd-layer > .cd-eye { grid-area: eye; }
.cd-layer > .cd-lock { grid-area: lock; }
.cd-layer > .cd-layer-lt { grid-area: lt; width: 100%; }
.cd-layer > .cd-layer-count { grid-area: count; }
.cd-layer.is-cur { background: var(--tint); }
.cd-layer-pick { flex: none; width: 20px; padding: 0; color: var(--accent-strong); background: none; border: 0; cursor: pointer; }
.cd-layer-col { flex: none; width: 22px; height: 22px; padding: 0; }
.cd-layer-name { flex: 1 1 auto; min-width: 0; padding: 2px 5px; border-radius: 0; font-size: 0.76rem; }
.cd-layer-lt { flex: none; width: 76px; padding: 2px 4px; font-size: 0.7rem; }
.cd-layer-count { flex: none; min-width: 18px; color: var(--muted); font: 0.64rem var(--mono); text-align: right; }

/* ---- Settings ---- */
.cd-field .vs-numwrap { flex: 0 1 auto; }
.cd-num { width: 92px; min-width: 0; }
.cd-input { width: 100%; min-width: 0; padding: 5px 9px; border-radius: 0; font-size: 0.8rem; }
.cd-vec { align-items: center; }
.cd-v3s { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; flex: 1 1 auto; min-width: 0; }
.cd-v2s { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cd-v3-wrap { position: relative; display: block; min-width: 0; }
.cd-v3-ax { position: absolute; left: 6px; top: 50%; font: 700 0.6rem/1 var(--mono); transform: translateY(-50%); pointer-events: none; }
.cd-ax-x .cd-v3-ax { color: #e0606a; }
.cd-ax-y .cd-v3-ax { color: #7cc46a; }
.cd-ax-z .cd-v3-ax { color: #6a9ae6; }
.cd-v3 { width: 100%; min-width: 0; padding-left: 18px; }
.cd-danger { color: #ff9a9a; }
.cd-stats { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; margin: 0 0 8px; font-size: 0.78rem; }
.cd-stats dt { color: var(--muted); }
.cd-stats dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
.vs-insp-hint.is-error { color: #ff9a9a; }

/* ---- Dialogs ---- */
.cd-dlg { display: grid; gap: 10px; min-width: min(380px, 80vw); }
.cd-dlg .vs-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cd-dlg .vs-field > .input, .cd-dlg .vs-field > .vs-select { flex: 1 1 auto; min-width: 0; max-width: 300px; }
.cd-dlg-preview { width: 100%; max-width: 380px; height: auto; border: 1px solid var(--border); border-radius: 4px; background: #000; }
.cd-dlg-opts { display: grid; gap: 10px; }
.cd-dlg-num { width: 110px; flex: none; }
.cd-planes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.cd-checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 12px; }

/* ---- Phones ---- */
@media (max-width: 760px) {
  .cd-new .st-new-row > .st-field { flex: 1 1 100%; }
  .cd-new .seg { flex-wrap: wrap; }
  .cd-work { grid-template-rows: auto auto minmax(0, 1fr) auto; }
  .cd-body { grid-template-columns: minmax(0, 1fr); }
  .cd-main { height: 100%; }
  .cd-bar { gap: 4px; padding: 3px 6px; overflow-x: auto; scrollbar-width: none; }
  .cd-bar::-webkit-scrollbar { display: none; }
  .cd-tools { flex: none; overflow: visible; }
  .cd-tools .vs-ib { width: 36px; height: 36px; }
  .cd-view-btns { margin-left: 6px; }
  .cd-ortho, .cd-views { display: none; }
  .cd-msg { right: 76px; }
  .cd-axes { width: 54px; height: 54px; }
  .cd-cmd { flex-basis: 140px; }
}

/* A sketch is drawn over the 3D view, which looks straight at its plane. */
.cd-app[data-space="sketch"] .cd-view2d { background: transparent; }
.cd-app[data-space="sketch"] #cd-view3d { pointer-events: none; }
.cd-app[data-space="sketch"] .cd-axes { display: none; }

/* The rollback bar in the feature tree, and the features under it. */
.cd-rollback { display: flex; align-items: center; gap: 2px; padding: 0 6px; height: 22px; cursor: ns-resize; touch-action: none; }
.cd-rollback-line { flex: 1; height: 3px; border-radius: 2px; background: var(--accent); }
.cd-rollback .cd-eye[disabled] { opacity: 0.3; }
.cd-tree-row.is-rolled { opacity: 0.45; }

/* Looking around while sketching: the 3D view takes the pointer, the sketcher steps aside. */
.cd-app[data-space="sketch"].is-looking #cd-view3d { pointer-events: auto; }
.cd-app[data-space="sketch"].is-looking .cd-view2d { visibility: hidden; }
.cd-app[data-space="sketch"].is-looking .cd-axes { display: block; }
.cd-app[data-space="sketch"].is-looking .cd-tool, .cd-app[data-space="sketch"].is-looking .cd-con { opacity: 0.4; pointer-events: none; }
