* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: #1a1a2e; overflow: hidden; font-family: 'Segoe UI', system-ui, sans-serif; display: flex; }
#viewer-container { flex: 1; position: relative; min-width: 0; }
#canvas { display: block; width: 100%; height: 100vh; }
#chat-panel {
  width: 380px; height: 100vh; background: #12122a;
  border-left: 1px solid rgba(100,120,255,0.3);
  display: flex; flex-direction: column; flex-shrink: 0;
  overflow: hidden;
}
#chat-panel.hidden { display: none; }
#chat-panel.fullscreen {
  width: 100vw; position: fixed; top: 0; left: 0; z-index: 100;
  background: #0d0d1e;
}
#chat-panel.fullscreen #chat-login {
  max-width: 360px; margin: 0 auto;
}
.dagny-mascot {
  text-align: center; margin-bottom: 16px;
}
.dagny-mascot svg { width: 80px; height: 80px; }
.dagny-mascot h2 { color: #8ab4f8; font-size: 20px; margin-top: 8px; font-weight: 400; }
.dagny-mascot p { color: #6070a0; font-size: 12px; margin-top: 4px; }
#chat-header {
  padding: 10px 14px; background: rgba(20,20,40,0.95);
  border-bottom: 1px solid rgba(100,120,255,0.2);
  display: flex; align-items: center; justify-content: space-between;
}
#chat-header h3 { color: #8ab4f8; font-size: 14px; margin: 0; }
#chat-toggle {
  position: absolute; top: 50%; right: 0; z-index: 30; transform: translateY(-50%);
  background: none; color: rgba(138,180,248,0.5); border: none;
  padding: 16px 2px; cursor: pointer; font-size: 16px;
  line-height: 1; text-align: center;
}
#chat-toggle:hover { color: #8ab4f8; }
#chat-login {
  padding: 20px; display: flex; flex-direction: column; gap: 10px;
  justify-content: center; flex: 1;
}
#chat-login label { color: #aaa; font-size: 12px; }
#chat-login input {
  width: 100%; padding: 8px 10px; background: #1a1a2e; color: #e0e0e0;
  border: 1px solid #4a6fa5; border-radius: 4px; font-size: 13px;
}
#chat-login button {
  padding: 8px; background: #2a5a8c; color: #fff; border: none;
  border-radius: 4px; cursor: pointer; font-size: 13px; margin-top: 4px;
}
#chat-login button:hover { background: #3a6a9c; }
#chat-login .error { color: #e04040; font-size: 12px; }
#chat-messages {
  flex: 1; overflow-y: auto; padding: 12px; display: flex;
  flex-direction: column; gap: 8px;
}
.chat-msg { padding: 8px 12px; border-radius: 8px; font-size: 13px; line-height: 1.5; max-width: 95%; word-wrap: break-word; }
.chat-msg.user { background: #1e2a48; color: #d0d8f0; align-self: flex-end; border-bottom-right-radius: 2px; border: 1px solid rgba(138,180,248,0.15); }
.chat-msg.assistant { background: #1a1e2e; color: #c8cee0; align-self: flex-start; border-bottom-left-radius: 2px; border: 1px solid rgba(138,180,248,0.1); }
.chat-msg.assistant h2, .chat-msg.assistant h3, .chat-msg.assistant h4 { color: #8ab4f8; margin: 4px 0 2px; font-size: 13px; }
.chat-msg.assistant code { background: rgba(138,180,248,0.1); padding: 1px 4px; border-radius: 3px; font-size: 12px; color: #8ab4f8; }
.chat-msg.assistant pre { background: rgba(0,0,0,0.3); padding: 8px; border-radius: 4px; margin: 4px 0; overflow-x: auto; }
.chat-msg.assistant ul { margin: 4px 0; padding-left: 16px; }
.chat-msg.assistant li { margin: 2px 0; }
.chat-msg.assistant strong { color: #a0b8e0; }
.chat-msg.system { background: rgba(138,180,248,0.05); color: #8090b0; align-self: center; font-size: 11px; border: 1px solid rgba(138,180,248,0.1); text-align: center; }
.chat-msg.system strong { color: #8ab4f8; font-style: normal; }
.chat-msg.system code { background: rgba(138,180,248,0.1); padding: 2px 6px; border-radius: 3px; font-size: 11px; color: #a0b0d0; cursor: pointer; }
@keyframes thought-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}
.chat-msg.thinking {
  background: linear-gradient(135deg, #1a1a3a 0%, #1e2244 100%);
  color: #b0b8d0; align-self: flex-start; font-size: 12px;
  border-radius: 12px; padding: 10px 14px;
  position: relative; margin-bottom: 8px;
  border: 1px solid rgba(138,180,248,0.15);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  animation: thought-pulse 2s ease-in-out infinite;
  max-width: 95%; min-height: 60px; max-height: 50vh; overflow-y: auto;
  scroll-behavior: smooth; flex-shrink: 0;
}
.chat-msg.thinking h2, .chat-msg.thinking h3, .chat-msg.thinking h4 { color: #8ab4f8; margin: 4px 0 2px; font-size: 12px; }
.chat-msg.thinking code { background: rgba(138,180,248,0.1); padding: 1px 4px; border-radius: 3px; font-size: 11px; color: #8ab4f8; }
.chat-msg.thinking strong { color: #c0c8e0; }
.chat-msg.thinking hr { border: none; border-top: 1px solid rgba(138,180,248,0.1); margin: 6px 0; }
.thinking-toggle {
  display: inline-flex; align-items: center; gap: 4px;
  background: none; border: 1px solid rgba(138,180,248,0.15); color: #6878a0;
  padding: 3px 8px; border-radius: 12px; cursor: pointer; font-size: 11px;
  margin-top: 4px; align-self: flex-start;
}
.thinking-toggle:hover { color: #8ab4f8; border-color: rgba(138,180,248,0.3); }
.thinking-toggle .brain { font-size: 13px; }
.thinking-saved {
  display: none; max-height: 180px; overflow-y: auto;
  background: linear-gradient(135deg, #1a1a3a 0%, #1e2244 100%);
  color: #b0b8d0; font-size: 12px; border-radius: 12px; padding: 10px 14px;
  border: 1px solid rgba(138,180,248,0.15); margin-top: 4px;
  max-width: 95%; align-self: flex-start; scroll-behavior: smooth;
}
.thinking-saved.open { display: block; }
.thinking-saved h2, .thinking-saved h3, .thinking-saved h4 { color: #8ab4f8; margin: 4px 0 2px; font-size: 12px; }
.thinking-saved code { background: rgba(138,180,248,0.1); padding: 1px 4px; border-radius: 3px; font-size: 11px; color: #8ab4f8; }
.thinking-saved hr { border: none; border-top: 1px solid rgba(138,180,248,0.1); margin: 6px 0; }
#chat-input-area {
  padding: 10px; background: rgba(20,20,40,0.95);
  border-top: 1px solid rgba(100,120,255,0.2);
  display: flex; gap: 6px;
}
#chat-input {
  flex: 1; padding: 8px 10px; background: #1a1a2e; color: #e0e0e0;
  border: 1px solid #4a6fa5; border-radius: 4px; font-size: 13px;
  resize: none; height: 38px; font-family: inherit;
}
#chat-input:focus { outline: none; border-color: #8ab4f8; }
#chat-send {
  padding: 8px 16px; background: #2a5a8c; color: #fff; border: none;
  border-radius: 4px; cursor: pointer; font-size: 13px;
}
#chat-send:hover { background: #3a6a9c; }
#chat-send:disabled { opacity: 0.5; cursor: default; }
#info-panel {
  position: absolute; top: 12px; left: 12px;
  background: rgba(20,20,40,0.92); color: #e0e0e0;
  padding: 14px 18px; border-radius: 8px; min-width: 220px; max-width: 260px;
  font-size: 13px; line-height: 1.6;
  border: 1px solid rgba(100,120,255,0.3); backdrop-filter: blur(8px);
  max-height: 90vh; overflow-y: auto;
  z-index: 20;
}
#info-panel h3 { color: #8ab4f8; margin-bottom: 6px; font-size: 15px; cursor: pointer; }
#info-panel-body { }
#info-panel.collapsed #info-panel-body { display: none; }
#info-panel.collapsed { }
#info-panel h3::after { content: ' ▼'; font-size: 10px; opacity: 0.5; }
#info-panel.collapsed h3::after { content: ' ▶'; }
#controls {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(20,20,40,0.92); color: #aaa;
  padding: 10px 14px; border-radius: 8px; font-size: 12px;
  border: 1px solid rgba(100,120,255,0.2);
  display: flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: center;
}
#controls label { margin-right: 14px; cursor: pointer; }
#controls input[type=checkbox] { margin-right: 4px; }
#legend {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(20,20,40,0.92); color: #ccc;
  padding: 8px 18px; border-radius: 8px; font-size: 12px;
  border: 1px solid rgba(100,120,255,0.2);
  display: flex; gap: 16px; z-index: 10; flex-wrap: wrap; justify-content: center;
}
@media (max-width: 768px) {
  #info-panel { max-width: 180px; font-size: 11px; padding: 8px 12px; }
  #info-panel h3 { font-size: 13px; }
  #controls { font-size: 10px; padding: 6px 8px; gap: 2px; }
  #controls label { margin-right: 6px; }
  #legend { font-size: 10px; padding: 4px 10px; gap: 8px; display: none; }
  #edit-tools { display: none !important; }
}
@media (max-width: 480px) {
  #info-panel { max-width: 150px; font-size: 10px; top: 6px; left: 6px; padding: 6px 10px; }
  #info-panel.collapsed { }
  #controls { bottom: 6px; font-size: 9px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  #info-panel { max-width: 200px; max-height: 80vh; font-size: 11px; top: 6px; left: 6px; padding: 8px 12px; }
  #info-panel h3 { font-size: 12px; margin-bottom: 3px; }
  #controls { bottom: 4px; font-size: 10px; padding: 4px 8px; }
  #legend { display: none; }
}
.legend-item { display: flex; align-items: center; margin: 3px 0; }
.legend-color { width: 14px; height: 14px; border-radius: 2px; margin-right: 8px; }
#edit-tools {
  position: absolute; bottom: 12px; right: 12px;
  background: rgba(20,20,40,0.92); color: #aaa;
  padding: 10px 14px; border-radius: 8px; font-size: 12px;
  border: 1px solid rgba(100,120,255,0.2);
  display: flex; gap: 6px; flex-wrap: wrap; max-width: 360px;
}
#edit-tools button {
  background: #2a3a5c; color: #ccc; border: 1px solid #4a6fa5;
  padding: 5px 10px; border-radius: 4px; cursor: pointer; font-size: 12px;
}
#edit-tools button:hover { background: #3a5a8c; }
#edit-tools button.active { background: #4a8fd4; color: #fff; }
#edit-tools button:disabled { opacity: 0.4; cursor: default; }
#save-status { color: #5cb85c; font-size: 11px; margin-top: 4px; width: 100%; }
#floor-selector {
  position: absolute; top: 150px; left: 12px;
  background: rgba(20,20,40,0.92); color: #ccc;
  padding: 10px 14px; border-radius: 8px; font-size: 12px;
  border: 1px solid rgba(100,120,255,0.2);
}
#floor-selector button {
  display: block; width: 100%; margin: 3px 0;
  background: #2a3a5c; color: #ccc; border: 1px solid #4a6fa5;
  padding: 6px 14px; border-radius: 4px; cursor: pointer; font-size: 13px;
}
#floor-selector button:hover { background: #3a5a8c; }
#floor-selector button.active { background: #4a8fd4; color: #fff; }
#view-mode {
  position: absolute; top: 80px; right: 12px;
  background: rgba(20,20,40,0.92); color: #ccc;
  padding: 8px 12px; border-radius: 8px; font-size: 12px;
  border: 1px solid rgba(100,120,255,0.2);
}
#view-mode button {
  background: #2a3a5c; color: #ccc; border: 1px solid #4a6fa5;
  padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 12px; margin: 2px;
}
#view-mode button:hover { background: #3a5a8c; }
#view-mode button.active { background: #4a8fd4; color: #fff; }
