:root {
  --bg: #060807;
  --surface: #0d1110;
  --surface-2: #151a18;
  --surface-3: #1c2320;
  --ink: #eef5ec;
  --muted: #8f9a92;
  --line: #28332d;
  --line-2: #354038;
  --brand: #b6f000;
  --brand-dim: rgba(182, 240, 0, .12);
  --brand-dark: #4f8e22;
  --blue: #5eb3ff;
  --amber: #f4b942;
  --red: #f87171;
  --canvas-bg: #0a0e0c;
  --canvas-grid: rgba(182, 240, 0, .06);
  --shadow: 0 12px 32px rgba(0, 0, 0, .45);
  --radius: 10px;
  --radius-sm: 7px;
  --header-h: 52px;
  --toolbar-h: 58px;
  --panel-w: 248px;
  color-scheme: dark;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }

button, .file-action {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  min-height: 34px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s, background .15s, color .15s, transform .1s;
}

button:hover, .file-action:hover {
  border-color: var(--line-2);
  background: var(--surface-3);
}

button:active { transform: scale(.98); }

button:disabled {
  cursor: not-allowed;
  opacity: .4;
}

/* Atalhos — discretos, visíveis no hover */
button[data-key], .file-action[data-key] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

button[data-key]::after,
.file-action[data-key]::after {
  content: attr(data-key);
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
}

button[data-key]:hover::after,
.file-action[data-key]:hover::after { display: inline-flex; }

button.wide[data-key] { justify-content: space-between; }
button.wide[data-key]::after { display: inline-flex; opacity: .55; font-size: 9px; }

button.primary {
  background: var(--brand);
  color: #0a0d08;
  border-color: var(--brand-dark);
  font-weight: 700;
}

button.primary:hover { background: #c9ff1f; }

button.quiet { background: transparent; }

button.danger {
  border-color: rgba(248, 113, 113, .4);
  color: var(--red);
  background: rgba(248, 113, 113, .08);
}

button.danger-soft {
  border-color: rgba(248, 113, 113, .3);
  color: var(--red);
  background: rgba(248, 113, 113, .05);
}

.wide { width: 100%; }

.hidden { display: none !important; }

/* ---------- layout principal ---------- */
.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

/* ---------- header ---------- */
.topbar {
  display: grid;
  gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}

.topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
  padding: 0 14px;
  height: var(--header-h);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  background: #000;
  border-radius: 8px;
  flex-shrink: 0;
}

.brand-text { min-width: 0; }

h1, h2, p { margin: 0; }

h1 {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -.01em;
}

.brand p, .brand-text p {
  color: var(--muted);
  font-size: 11.5px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
  transition: color .15s, border-color .15s, background .15s;
}

.back-link:hover {
  color: var(--brand);
  border-color: var(--line);
  background: var(--surface-2);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* menus dropdown */
.menu-wrap { position: relative; }

.menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.menu-btn:hover { border-color: var(--brand-dark); }

.menu-btn svg { opacity: .7; }

.menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 40;
  min-width: 180px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: none;
}

.menu-wrap.is-open .menu-panel { display: grid; gap: 2px; }

.menu-panel button,
.menu-panel .file-action {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  border-color: transparent;
  background: transparent;
  min-height: 34px;
  font-size: 13px;
}

.menu-panel button:hover,
.menu-panel .file-action:hover {
  background: var(--surface-2);
  border-color: var(--line);
}

.menu-panel .file-action { position: relative; overflow: hidden; }
.menu-panel .file-action input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.menu-divider {
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}

/* ---------- toolbar de ferramentas ---------- */
.toolbar-row {
  display: flex;
  align-items: stretch;
  min-height: var(--toolbar-h);
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 6px 10px;
  border-right: 1px solid var(--line);
  flex-shrink: 0;
}

.tool-group-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  padding: 0 2px;
  margin-right: 4px;
  user-select: none;
}

.tool-group-tools {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: nowrap;
}

/* botões de ferramenta */
.tool, .mod-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 52px;
  min-height: 44px;
  padding: 5px 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.1;
  cursor: pointer;
  transition: all .15s;
}

.tool svg, .mod-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.tool:hover, .mod-btn:hover {
  color: var(--ink);
  background: var(--surface-2);
  border-color: var(--line);
}

.tool.is-active {
  color: var(--brand);
  background: var(--brand-dim);
  border-color: rgba(182, 240, 0, .35);
}

.tool.is-active svg { stroke: var(--brand); }

.tool.primary-tool {
  color: var(--brand);
  border-color: rgba(182, 240, 0, .25);
}

.tool.primary-tool.is-active {
  background: var(--brand);
  color: #0a0d08;
  border-color: var(--brand);
}

.tool.primary-tool.is-active svg { stroke: #0a0d08; }

.tool.road-tool, .asphalt-action {
  color: var(--amber);
}

.mod-btn.is-active {
  color: var(--blue);
  background: rgba(94, 179, 255, .1);
  border-color: rgba(94, 179, 255, .3);
}

#autoDimBtn {
  min-width: auto;
  flex-direction: row;
  gap: 6px;
  padding: 7px 12px;
  font-size: 12px;
  min-height: 44px;
}

#autoDimBtn[data-key]::after { display: none; }

/* abas de visualização */
.view-tabs {
  display: flex;
  gap: 0;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.view-tab {
  position: relative;
  min-height: 38px;
  padding: 8px 18px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.view-tab:hover { color: var(--ink); background: transparent; }

.view-tab.is-active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  background: transparent;
}

.view-tab[data-key]::after { display: none; }

/* ---------- workspace ---------- */
.view-pane { min-height: 0; }

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: var(--panel-w) minmax(360px, 1fr) var(--panel-w);
  gap: 0;
  background: var(--bg);
}

/* ---------- painéis laterais ---------- */
.panel {
  min-height: 0;
  overflow: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.right-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.panel-section {
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child { border-bottom: 0; }

.panel-section > summary,
.panel-section > h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: default;
  list-style: none;
  user-select: none;
}

details.panel-section > summary { cursor: pointer; }
details.panel-section > summary::-webkit-details-marker { display: none; }

details.panel-section > summary::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform .2s;
  flex-shrink: 0;
}

details.panel-section[open] > summary::after { transform: rotate(-135deg); }

.panel-body {
  padding: 0 14px 14px;
  display: grid;
  gap: 8px;
}

/* camadas */
.layer-list { display: grid; gap: 4px; }

.layer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
  transition: background .15s, border-color .15s;
}

.layer-item:hover { background: var(--surface-2); }

.layer-item input { accent-color: var(--brand); width: 15px; height: 15px; }

/* biblioteca */
.lib-grid { display: grid; gap: 5px; }

.lib-grid button {
  justify-content: flex-start;
  text-align: left;
  font-size: 12.5px;
  min-height: 36px;
  padding: 8px 10px;
}

.asphalt-action {
  color: var(--amber) !important;
  border-color: rgba(244, 185, 66, .3) !important;
  background: rgba(244, 185, 66, .06) !important;
}

.compact .panel-body { gap: 6px; }

.stats {
  display: grid;
  gap: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.stats div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  font-size: 12.5px;
  border-bottom: 1px solid var(--line);
}

.stats div:last-child { border-bottom: 0; }

.stats dt { color: var(--muted); margin: 0; }
.stats dd { margin: 0; color: var(--brand); font-weight: 700; }

.edge-list { display: grid; gap: 4px; }

.edge-list button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  padding: 6px 10px;
  font-size: 12.5px;
  text-align: left;
}

.edge-list button.is-selected {
  color: #0a0d08;
  border-color: var(--brand);
  background: var(--brand);
}

/* ---------- área do canvas ---------- */
.canvas-zone {
  min-width: 0;
  min-height: 0;
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  background: var(--canvas-bg);
}

.canvas-header {
  display: grid;
  gap: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.canvas-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.ctrl-group label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.ctrl-group input[type="number"] {
  width: 52px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
}

.ctrl-group input[type="checkbox"] { accent-color: var(--brand); }

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
}

.toggle-pill:has(input:checked) {
  color: var(--brand);
  border-color: rgba(182, 240, 0, .35);
  background: var(--brand-dim);
}

.ortho-field select {
  min-height: 28px;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
}

.osnap-menu { position: relative; }

.osnap-menu summary {
  list-style: none;
  cursor: pointer;
  min-height: 28px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: var(--surface-2);
  font-size: 12px;
}

.osnap-menu summary::-webkit-details-marker { display: none; }

.osnap-panel {
  position: absolute;
  top: 36px;
  left: 0;
  z-index: 20;
  width: 280px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.osnap-panel label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  font-size: 12.5px;
}

.osnap-panel input { accent-color: var(--brand); }

.osnap-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
}

.osnap-actions button { flex: 1; min-height: 30px; font-size: 12px; }

.canvas-command-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
}

.command-field {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
}

.command-field input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12.5px;
}

.command-field input:focus {
  outline: none;
  border-color: var(--brand-dark);
  box-shadow: 0 0 0 2px var(--brand-dim);
}

.status {
  flex-shrink: 0;
  font-size: 11.5px;
  font-family: "Cascadia Code", Consolas, monospace;
  color: var(--brand);
  min-width: 180px;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

#cadCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--canvas-bg);
  cursor: crosshair;
}

.mini-help {
  position: absolute;
  left: 14px;
  bottom: 14px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: rgba(13, 17, 16, .92);
  border: 1px solid var(--line);
  font-size: 11.5px;
  pointer-events: none;
  backdrop-filter: blur(8px);
}

/* ---------- perfil 3D ---------- */
.profile-view {
  min-height: 0;
  display: grid;
  grid-template-columns: var(--panel-w) minmax(420px, 1fr);
  gap: 0;
  background: var(--bg);
}

.profile-panel {
  border-right: 1px solid var(--line);
}

.profile-canvas-zone {
  min-height: 0;
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  background: var(--canvas-bg);
}

#profileCanvas {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--canvas-bg);
}

.profile-legend { display: grid; gap: 6px; }

.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.legend-swatch {
  width: 18px;
  height: 12px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 3px;
}

/* ---------- formulários ---------- */
.field {
  display: grid;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--surface-2);
  color: var(--ink);
  transition: border-color .15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brand-dark);
}

.field textarea { resize: vertical; min-height: 66px; }

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.selection-form { display: grid; gap: 9px; }

.empty, .distance-list {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.distance-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.distance-item:last-child { border-bottom: 0; }
.distance-item strong { color: var(--brand); }

.distance-summary {
  margin-bottom: 3px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

/* ---------- menu de contexto ---------- */
.context-menu {
  position: fixed;
  z-index: 50;
  min-width: 190px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.context-menu button {
  width: 100%;
  display: block;
  min-height: 34px;
  padding: 7px 10px;
  text-align: left;
  border-color: transparent;
  background: transparent;
  font-size: 13px;
}

.context-menu button:hover {
  border-color: var(--line);
  background: var(--surface-2);
}

.file-action {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
}

.file-action input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* ---------- responsivo ---------- */
@media (max-width: 1180px) {
  :root { --panel-w: 220px; }

  .workspace {
    grid-template-columns: var(--panel-w) minmax(300px, 1fr);
    grid-template-rows: minmax(480px, 1fr) auto;
  }

  .right-panel {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: 300px;
  }

  .profile-view {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(480px, 1fr);
  }

  .profile-panel { max-height: 280px; }
}

@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; }

  .left-panel { order: 2; max-height: 260px; border-right: 0; border-top: 1px solid var(--line); }
  .right-panel { order: 3; max-height: none; }
  .canvas-zone { order: 1; min-height: 480px; }

  .tool-group-label { display: none; }
  .tool, .mod-btn { min-width: 44px; font-size: 0; }
  .tool svg, .mod-btn svg { width: 20px; height: 20px; }

  .back-link span { display: none; }
}
