* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif;
  background: #0f0f1a;
  color: #e0e0e0;
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #16162a;
  border-bottom: 1px solid #2a2a45;
  z-index: 10;
}
.toolbar h1 {
  margin: 0;
  font-size: 16px;
  color: #fff;
  margin-right: 12px;
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border-right: 1px solid #2a2a45;
}
.toolbar-group:last-child { border-right: none; }
.toolbar label {
  font-size: 12px;
  color: #aaa;
}
.toolbar input[type="file"] {
  display: none;
}
.toolbar button, .file-btn {
  background: #2b6cb0;
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.2s;
}
.toolbar button:hover, .file-btn:hover { background: #3182ce; }
.toolbar button.danger { background: #c53030; }
.toolbar button.danger:hover { background: #e53e3e; }
.toolbar button.secondary { background: #4a5568; }
.toolbar button.secondary:hover { background: #718096; }
.toolbar select {
  background: #1a1a2e;
  color: #e0e0e0;
  border: 1px solid #4a5568;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 13px;
}
.toolbar input[type="range"] {
  width: 80px;
}

/* Main layout */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* 3D Viewport */
.viewport {
  flex: 1;
  position: relative;
  min-width: 0;
  min-height: 200px;
  background: #0f0f1a;
}
.viewport-overlay {
  position: absolute;
  top: 8px; left: 8px;
  pointer-events: none;
  z-index: 5;
}
.overlay-hint {
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 12px;
  margin-bottom: 6px;
  backdrop-filter: blur(4px);
}

/* Sidebar */
.sidebar {
  width: 520px;
  min-width: 420px;
  max-width: 50vw;
  background: #16162a;
  border-left: 1px solid #2a2a45;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px;
  border-bottom: 1px solid #2a2a45;
  overflow: hidden;
}
.sidebar-section:last-child {
  border-bottom: none;
  flex: 0 0 auto;
  max-height: 45%;
}
.sidebar-section h3 {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: #fff;
}

.wp-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}
.wp-toolbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.wp-toolbar button {
  background: #2b6cb0;
  color: #fff;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.wp-toolbar button:hover { background: #3182ce; }

/* Waypoint table */
.wp-table-wrap {
  flex: 1;
  overflow: auto;
  border: 1px solid #2a2a45;
  border-radius: 6px;
}
.wp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.wp-table th {
  background: #1e1e3f;
  color: #fff;
  padding: 6px 4px;
  text-align: center;
  font-weight: 600;
  border-bottom: 1px solid #2a2a45;
  position: sticky;
  top: 0;
  z-index: 2;
  white-space: nowrap;
}
.wp-table td {
  padding: 4px;
  border-bottom: 1px solid #252545;
  text-align: center;
  white-space: nowrap;
}
.wp-table tr:nth-child(even) { background: #1a1a35; }
.wp-table tr:hover { background: #252550; }
.wp-table tr.selected { background: #2b6cb0 !important; }
.wp-table input, .wp-table select {
  width: 64px;
  background: #0f0f1a;
  color: #e0e0e0;
  border: 1px solid #4a5568;
  padding: 4px 2px;
  border-radius: 3px;
  font-size: 12px;
  text-align: center;
}
.wp-table input.small { width: 44px; }
.wp-table input.medium { width: 70px; }
.wp-table select { width: 100px; min-width: 80px; }
.wp-table .idx-cell {
  width: 28px;
  text-align: center;
  color: #aaa;
  font-weight: 600;
}
.wp-table .act-cell { text-align: left; }
.wp-table .act-cell select { width: 140px; }
.wp-table button.del {
  background: #c53030;
  color: #fff;
  border: none;
  padding: 3px 8px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
}
.wp-table button.del:hover { background: #e53e3e; }
.wp-table button.nav {
  background: #4a5568;
  color: #fff;
  border: none;
  padding: 2px 4px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 10px;
}
.wp-table button.nav:hover { background: #718096; }

/* Import/Export */
#io-panel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#io-panel textarea {
  flex: 1;
  min-height: 80px;
  background: #0f0f1a;
  color: #e0e0e0;
  border: 1px solid #4a5568;
  border-radius: 4px;
  padding: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  resize: vertical;
}
.io-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.io-row button {
  background: #2b6cb0;
  color: #fff;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.io-row button:hover { background: #3182ce; }

/* Resizer */
.resizer {
  background: #2a2a45;
  flex-shrink: 0;
  transition: background 0.2s;
}
.resizer:hover {
  background: #4a5568;
}
.main:not(.layout-bottom) .resizer {
  width: 6px;
  cursor: col-resize;
}
.main.layout-bottom .resizer {
  height: 6px;
  cursor: row-resize;
}

/* Layout: bottom */
.main.layout-bottom {
  flex-direction: column;
}
.main.layout-bottom .viewport {
  flex: 1;
  min-height: 0;
}
.main.layout-bottom .sidebar {
  width: 100%;
  min-width: auto;
  max-width: 100%;
  height: 320px;
  min-height: 200px;
  flex-direction: row;
  border-left: none;
  border-top: 1px solid #2a2a45;
}
.main.layout-bottom .sidebar-section {
  flex: 1;
  border-bottom: none;
  border-right: 1px solid #2a2a45;
  max-height: none;
}
.main.layout-bottom .sidebar-section:last-child {
  border-right: none;
  flex: 1;
  max-height: none;
}
.main.layout-bottom .wp-body {
  flex-direction: row;
}
.main.layout-bottom .wp-toolbar {
  flex-direction: column;
  flex-shrink: 0;
  margin-bottom: 0;
}
.main.layout-bottom .wp-toolbar button,
.main.layout-bottom .wp-toolbar .file-btn {
  text-align: center;
}

/* Responsive */
@media (max-width: 900px) {
  .sidebar { width: 100%; max-width: 100%; resize: none; }
  .main { flex-direction: column; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #0f0f1a; }
::-webkit-scrollbar-thumb { background: #4a5568; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #718096; }

/* Number input without spinner */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type=number] { -moz-appearance: textfield; }
