:root {
  --navy: #061d3f;
  --navy-2: #0b315f;
  --blue: #0b5cff;
  --blue-2: #eaf1ff;
  --ink: #10213f;
  --muted: #60708d;
  --line: #d9e1ee;
  --line-strong: #c8d3e4;
  --panel: #ffffff;
  --surface: #f7f9fc;
  --success: #15895a;
  --warning: #e49b0f;
  --shadow: 0 12px 36px rgba(18, 42, 82, 0.14);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: #eef2f8;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; min-width: 320px; height: 100%; margin: 0; overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { color: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: 94px minmax(0, 1fr);
  grid-template-rows: 80px minmax(0, 1fr) 54px;
  width: 100%; height: 100%; min-height: 650px;
  background: var(--surface);
}

.brand {
  grid-column: 1; grid-row: 1;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 12px; color: white; background: var(--navy);
  border-bottom: 1px solid rgba(255,255,255,.14);
}
.brand-mark { width: 34px; height: 34px; flex: 0 0 auto; }
.brand strong { display: block; font-size: 18px; letter-spacing: .01em; white-space: nowrap; }
.brand small { display: block; margin-top: 2px; color: #aebed6; font-size: 10px; letter-spacing: .08em; }

.topbar {
  grid-column: 2; grid-row: 1;
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px; background: white; border-bottom: 1px solid var(--line);
  min-width: 0; z-index: 20;
}
.selectors { display: flex; align-items: center; gap: 10px; min-width: 0; }
.select-card {
  position: relative; width: 205px; height: 58px; padding: 8px 40px 8px 13px;
  text-align: left; border: 1px solid var(--line-strong); border-radius: 6px; background: white;
  cursor: pointer; transition: .18s ease;
}
.select-card:hover, .select-card.open { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(11,92,255,.08); }
.select-card .label { display: block; color: var(--muted); font-size: 11px; }
.select-card .value { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-weight: 600; white-space: nowrap; }
.select-card .chevron { position: absolute; right: 13px; top: 23px; }
.type-badge { display: inline-flex; padding: 3px 7px; border-radius: 4px; font-size: 10px; font-weight: 500; }
.type-badge.structural { color: #087343; background: #e5f7ee; border: 1px solid #b9e9d1; }
.type-badge.drawing { color: #064fd7; background: #eaf1ff; border: 1px solid #c7d8ff; }
.type-badge.model3d { color: #6b43c6; background: #f1ecff; border: 1px solid #ded2ff; }

.top-actions { display: flex; align-items: center; justify-content: center; gap: 2px; margin-left: auto; }
.icon-action {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-width: 58px; height: 58px; padding: 5px; border: 0; border-radius: 6px; background: transparent;
  font-size: 10px; cursor: pointer; transition: background .15s;
}
.icon-action:hover { background: var(--blue-2); color: var(--blue); }
.icon-action:disabled { color: #a8b3c5; cursor: default; background: transparent; }
.icon-action svg { width: 21px; height: 21px; }
.divider { width: 1px; height: 34px; margin: 0 5px; background: var(--line); }
.profile { display: flex; align-items: center; gap: 9px; padding-left: 8px; min-width: 152px; }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border: 2px solid var(--blue); border-radius: 50%; background: #e5bb95; font-weight: 700; color: #5d311b; }
.profile strong { display: block; font-size: 12px; }
.profile small { color: var(--muted); font-size: 10px; }
.profile > svg { width: 16px; height: 16px; margin-left: auto; }
.select-card .chevron svg { width: 16px; height: 16px; }

.sidebar {
  grid-column: 1; grid-row: 2 / 4; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--navy) 0%, #052953 100%); color: white; z-index: 15;
}
.nav-item {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 15px 4px; min-height: 74px; border: 0; background: transparent; color: #fff;
  font-size: 12px; cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,.07); }
.nav-item.active { background: #0a396f; }
.nav-item.active::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--blue); }
.nav-item svg { width: 25px; height: 25px; }
.nav-spacer { flex: 1; }
.mia { position: relative; width: 46px; height: 46px; margin: 10px auto 14px; border: 1px solid #86a4ca; border-radius: 50%; display: grid; place-items: center; }
.mia::after { content: ""; position: absolute; right: 0; bottom: 2px; width: 9px; height: 9px; border: 2px solid var(--navy); border-radius: 50%; background: #55d486; }

.workspace { grid-column: 2; grid-row: 2; display: grid; grid-template-columns: 260px minmax(440px, 1fr) 306px; min-height: 0; min-width: 0; }
.panel { background: white; min-width: 0; min-height: 0; overflow: auto; }
.left-panel { border-right: 1px solid var(--line); }
.right-panel { border-left: 1px solid var(--line); }
.panel-header { display: flex; align-items: center; justify-content: space-between; height: 54px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; font-size: 16px; }
.ghost-button { display: grid; place-items: center; width: 32px; height: 32px; border: 0; background: transparent; border-radius: 5px; cursor: pointer; }
.ghost-button:hover { background: var(--surface); color: var(--blue); }
.tree { padding: 12px 14px; font-size: 13px; }
.tree-row { display: flex; align-items: center; gap: 9px; min-height: 40px; padding: 0 8px; border-radius: 5px; cursor: pointer; }
.tree-row:hover { background: var(--surface); }
.tree-row.selected { color: var(--blue); background: var(--blue-2); }
.tree-row.indent { margin-left: 24px; }
.tree-row svg { width: 18px; height: 18px; flex: 0 0 auto; }
.tree-row .count { margin-left: auto; color: var(--muted); }
.tree-heading { margin: 12px 8px 6px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }

.canvas-area { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #fbfcfe; }
.canvas-toolbar { position: absolute; top: 16px; left: 18px; z-index: 5; display: flex; gap: 8px; }
.view-select, .small-toolset { height: 34px; border: 1px solid var(--line-strong); border-radius: 5px; background: white; box-shadow: 0 3px 10px rgba(18,42,82,.06); }
.view-select { min-width: 152px; padding: 0 12px; }
.small-toolset { display: flex; align-items: center; padding: 0 4px; }
.small-toolset button { width: 30px; height: 28px; border: 0; background: white; border-radius: 4px; cursor: pointer; }
.small-toolset button:hover { background: var(--blue-2); color: var(--blue); }
.scene { width: 100%; height: 100%; min-height: 480px; }
.scene text { font-family: Inter, "Segoe UI", sans-serif; }
.scene .member { fill: none; stroke: #536074; stroke-width: 10; stroke-linecap: square; }
.scene .member-light { fill: none; stroke: #7f8b9b; stroke-width: 5; }
.scene .brace { stroke: #788497; stroke-width: 3; }
.scene .selected-member { stroke: #0864ff; stroke-width: 12; filter: drop-shadow(0 0 4px rgba(8,100,255,.3)); }
.scene .gridline { stroke: #68a4ff; stroke-width: 1.5; stroke-dasharray: 7 5; }
.scene .foot { fill: #aeb5c0; stroke: #6a7483; }
.scene .support { fill: #167c47; }

.details-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); }
.tab-button { height: 46px; border: 0; background: white; color: var(--muted); cursor: pointer; }
.tab-button.active { color: var(--blue); box-shadow: inset 0 -2px var(--blue); }
.details-body { padding: 16px; }
.hint { display: flex; justify-content: space-between; margin-bottom: 16px; color: var(--muted); font-size: 11px; }
.field { display: block; margin-bottom: 13px; }
.field > span { display: block; margin: 0 0 6px; color: var(--muted); font-size: 11px; }
.field input, .field textarea, .field select {
  width: 100%; min-height: 36px; padding: 8px 10px; color: var(--ink); border: 1px solid var(--line); border-radius: 5px; background: white; outline: none;
}
.field textarea { min-height: 64px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(11,92,255,.08); }
.related-card { margin-top: 16px; padding: 14px; border: 1px solid var(--line); border-radius: 7px; }
.related-card .eyebrow { color: var(--muted); font-size: 10px; }
.related-card h3 { margin: 8px 0 4px; font-size: 14px; }
.related-card p { margin: 0 0 12px; color: var(--muted); font-size: 11px; }
.text-link { padding: 0; border: 0; color: var(--blue); background: none; font-size: 11px; font-weight: 600; cursor: pointer; }

.model-menu {
  position: fixed; z-index: 100; width: 320px; max-height: calc(100vh - 110px); overflow: auto;
  padding: 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: white; box-shadow: var(--shadow);
}
.model-menu h3 { margin: 0 0 10px; font-size: 15px; }
.search-box { display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 5px; }
.search-box svg { width: 18px; height: 18px; flex: 0 0 auto; }
.search-box input { width: 100%; border: 0; outline: 0; }
.menu-group h4 { margin: 14px 7px 5px; color: var(--muted); font-size: 10px; letter-spacing: .07em; }
.model-option { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; width: 100%; padding: 9px 7px; border: 0; border-radius: 5px; background: white; text-align: left; cursor: pointer; }
.model-option > svg { width: 21px; height: 21px; }
.model-option:hover, .model-option.active { background: var(--blue-2); }
.model-option strong { display: block; font-size: 12px; }
.model-option small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }
.menu-actions { margin: 10px -12px -12px; padding: 8px 12px; border-top: 1px solid var(--line); }
.menu-action { display: block; width: 100%; padding: 8px; border: 0; background: white; color: var(--blue); text-align: left; cursor: pointer; }
.menu-action:hover { background: var(--surface); }

.bottom-bar {
  grid-column: 2; grid-row: 3; display: flex; align-items: center; gap: 0; padding: 0 22px;
  border-top: 1px solid var(--line); background: white; z-index: 20; font-size: 11px;
}
.status-item { display: flex; align-items: center; gap: 7px; min-width: 150px; padding: 0 22px; border-right: 1px solid var(--line); white-space: nowrap; }
.status-item:first-child { padding-left: 0; }
.status-spacer { flex: 1; }
.status-button { width: 42px; height: 34px; border: 1px solid var(--line); background: white; cursor: pointer; }
.status-button:hover { color: var(--blue); background: var(--blue-2); }

.drawing-shell .workspace { grid-template-columns: 250px minmax(500px, 1fr) 290px; }
.drawing-title { min-width: 190px; }
.drawing-title strong { display: block; font-size: 16px; }
.drawing-title small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.linked-badge { display: flex; align-items: center; gap: 7px; padding: 8px 10px; border: 1px solid #bde5cf; border-radius: 5px; background: #ebf8f1; color: #18724c; font-size: 11px; }
.primary-outline { height: 40px; padding: 0 15px; border: 1px solid var(--blue); border-radius: 5px; background: white; color: var(--ink); cursor: pointer; }
.primary-outline:hover { color: var(--blue); background: var(--blue-2); }
.primary-outline svg { width: 19px; height: 19px; vertical-align: middle; }
.tools-list { padding: 12px; }
.tool-section-title { margin: 10px 10px 7px; font-size: 12px; }
.tool-button { display: flex; align-items: center; gap: 14px; width: 100%; height: 42px; padding: 0 12px; border: 0; border-radius: 5px; background: transparent; cursor: pointer; text-align: left; }
.tool-button:hover, .tool-button.active { background: var(--blue-2); color: var(--blue); }
.tool-button svg { width: 21px; height: 21px; }
.tool-separator { height: 1px; margin: 12px 8px; background: var(--line); }
.drawing-canvas { cursor: crosshair; touch-action: none; }
.drawing-canvas.select-mode { cursor: default; }
.drawing-grid { fill: url(#dot-grid); }
.drawing-object { stroke: #0b5cff; stroke-width: 3; fill: none; vector-effect: non-scaling-stroke; }
.drawing-object.user-object { stroke: #153a70; }
.drawing-object.selected { stroke: #ff8a00; }
.node { fill: white; stroke: #0b5cff; stroke-width: 2.5; }
.dim { stroke: #55637b; stroke-width: 1.2; fill: none; }
.canvas-hint { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); padding: 8px 12px; border-radius: 18px; color: white; background: rgba(6,29,63,.8); font-size: 11px; opacity: 0; pointer-events: none; transition: opacity .2s; }
.canvas-hint.show { opacity: 1; }
.linked-card { padding: 13px; border: 1px solid var(--line); border-radius: 7px; }
.linked-card h3 { display: flex; align-items: center; gap: 7px; margin: 0 0 12px; font-size: 13px; }
.linked-card h3 svg, .linked-badge svg { width: 18px; height: 18px; flex: 0 0 auto; }
.linked-card p { margin: 5px 0; font-size: 11px; color: var(--muted); }
.linked-card .connected { color: var(--success); }
.full-button { width: 100%; height: 36px; margin-top: 12px; border: 1px solid var(--line); border-radius: 5px; background: white; cursor: pointer; }
.full-button:hover { color: var(--blue); border-color: var(--blue); }
.check { display: flex; align-items: center; gap: 7px; }
.check input { accent-color: var(--blue); }
.zoom-control { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.zoom-control button { width: 34px; height: 32px; border: 0; background: white; cursor: pointer; font-size: 18px; }

.toast { position: fixed; z-index: 1000; left: 50%; bottom: 72px; transform: translate(-50%, 20px); padding: 10px 16px; border-radius: 6px; color: white; background: #10213f; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s ease; font-size: 12px; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.mobile-only { display: none; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 72px minmax(0, 1fr); }
  .brand { padding: 12px; justify-content: center; }
  .brand-copy { display: none; }
  .workspace, .drawing-shell .workspace { grid-template-columns: 220px minmax(420px, 1fr) 270px; }
  .select-card { width: 175px; }
  .top-actions .icon-action:nth-of-type(n+6) { display: none; }
  .profile { min-width: auto; }
  .profile-copy { display: none; }
  .status-item { min-width: auto; }
}

@media (max-width: 900px) {
  html, body, #app { overflow: auto; }
  .app-shell { min-height: 720px; grid-template-columns: 60px minmax(0, 1fr); grid-template-rows: 70px minmax(0, 1fr) 50px; }
  .workspace, .drawing-shell .workspace { grid-template-columns: minmax(0, 1fr); }
  .left-panel, .right-panel { position: fixed; top: 70px; bottom: 50px; z-index: 60; width: min(320px, calc(100vw - 60px)); box-shadow: var(--shadow); transition: transform .2s; }
  .left-panel { left: 60px; transform: translateX(-110%); }
  .right-panel { right: 0; transform: translateX(110%); }
  .left-panel.mobile-open, .right-panel.mobile-open { transform: translateX(0); }
  .canvas-area { grid-column: 1; }
  .topbar { gap: 8px; padding: 0 10px; }
  .selectors .select-card:first-child { display: none; }
  .select-card { width: 170px; height: 52px; }
  .drawing-title { min-width: 0; }
  .drawing-title small { display: none; }
  .linked-badge { display: none; }
  .top-actions .icon-action { display: none; }
  .top-actions .icon-action:nth-of-type(3), .top-actions .icon-action:nth-of-type(4) { display: flex; min-width: 44px; }
  .primary-outline { display: none; }
  .profile { padding: 0; }
  .mobile-only { display: grid; }
  .sidebar .nav-item { min-height: 64px; font-size: 9px; }
  .nav-item svg { width: 21px; }
  .bottom-bar { padding: 0 10px; }
  .status-item:nth-child(n+3) { display: none; }
  .scene { min-height: 600px; }
}

@media (max-width: 560px) {
  .app-shell { grid-template-columns: 52px minmax(0, 1fr); }
  .brand-mark { width: 30px; }
  .topbar { grid-column: 2; }
  .left-panel { left: 52px; }
  .select-card { width: 145px; }
  .select-card .type-badge { display: none; }
  .drawing-title strong { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .profile { display: none; }
  .top-actions { margin-left: auto; }
  .canvas-toolbar { left: 10px; }
  .small-toolset { display: none; }
  .status-item { padding: 0 10px; }
  .model-menu { width: min(310px, calc(100vw - 68px)); }
}
