:root {
  --bg-color: #0d0d1a;
  --scene-aspect: 1672 / 941;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-color);
  color: #eee;
  font-family: "Courier New", monospace;
}

.office-scene {
  position: relative;
  aspect-ratio: var(--scene-aspect);
  width: 100vw;
  max-height: 100vh;
  background-image: url('/assets/office.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  margin: auto;
}

@media (min-aspect-ratio: 1672/941) {
  .office-scene { height: 100vh; width: auto; max-height: none; }
}

.character {
  position: absolute;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
  user-select: none;
  bottom: 0;
  transform-origin: center bottom;
  transform: translateX(-50%);
}

#boss {
  left: 50%;
  bottom: 5%;        /* стоит перед своим столом, не за ним */
  height: 20%;
  width: auto;
  z-index: 3;        /* поверх стола */
  transition: left 2s ease-in-out, bottom 2s ease-in-out;
}

#boss.at-board {
  left: 70.28%;
  bottom: 60%;
}

#whiteboard-text {
  position: absolute;
  left: 60.41%;
  top: 8.50%;
  width: 19.74%;
  height: 12.22%;
  font-family: monospace;
  font-weight: bold;
  font-size: 1.05vw;
  color: #2a2a2a;
  padding: 6px 10px;
  line-height: 1.2;
  text-align: left;
  opacity: 0;
  transition: opacity 0.5s ease;
  z-index: 1;
  pointer-events: none;
  white-space: pre-wrap;
  overflow: hidden;
  word-break: break-word;
}

#whiteboard-text {
  border: 2px dashed transparent;
  background: transparent;
}
#whiteboard-text.visible { opacity: 1; }
#whiteboard-text.writing {
  border-color: rgba(0, 0, 0, 0.12);
  background: rgba(255, 255, 245, 0.08);
}
#whiteboard-text .cursor { animation: blink 0.7s infinite; }
@keyframes blink {
  0%, 49%   { opacity: 1; }
  50%, 100% { opacity: 0; }
}

#agents-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.agent {
  position: absolute;
  width: 7%;
  height: 11%;
  z-index: 2;        /* агенты стоят ПОВЕРХ стола, перед ним */
  border: 2px solid #fff;
  border-radius: 4px;
  color: #fff;
  font-family: monospace;
  font-size: 0.85vw;
  text-align: center;
  padding: 4px;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.6);
  transform-origin: center bottom;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .3s ease, filter .3s ease, box-shadow .3s ease;
  pointer-events: none;
  user-select: none;
  text-shadow: 1px 1px 0 #000;
  word-break: break-word;
  line-height: 1.1;
  overflow: hidden;
}

/* fade-in on spawn; idle/working below control the resting opacity */
.agent.visible { opacity: 1; }

@keyframes agent-bounce {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50%      { transform: translateX(-50%) translateY(-10px); }
}

/* stands quietly — dimmed, no bounce */
.agent.idle {
  opacity: 0.5;
  filter: grayscale(0.4) brightness(0.85);
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.6);
}

/* working — bright, glowing, bouncing */
.agent.working {
  opacity: 1;
  filter: none;
  box-shadow: 0 0 14px rgba(96, 165, 250, 0.7), 0 0 8px rgba(0, 0, 0, 0.6);
  animation: agent-bounce 0.6s ease-in-out infinite;
}

#ws-status {
  position: fixed;
  top: 12px;
  right: 12px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #c0392b;
  transition: background 0.3s;
  box-shadow: 0 0 6px currentColor;
  z-index: 100;
}

#ws-status.connected { background: #00ff66; }

@media (max-width: 600px) {
  #whiteboard-text { font-size: 2.6vw; padding: 3px 6px; }
}

/* ============================================================
   Three-column app shell  (sidebar | office | chat)
   Added on top of the office styles above — nothing above is changed.
   ============================================================ */

body { display: block; align-items: stretch; justify-content: stretch; }

.app-layout {
  display: grid;
  grid-template-columns: 240px 1fr 420px;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  background: #14141c;
  border-right: 1px solid #2a2a3a;
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#new-chat-btn {
  padding: 10px 14px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}
#new-chat-btn:hover { background: #1d4ed8; }
#chats-list { list-style: none; padding: 0; margin: 0; }
#chats-list li {
  padding: 10px 12px;
  border-radius: 6px;
  color: #ccc;
  cursor: pointer;
  font-size: 13px;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#chats-list li:hover { background: #1f1f2e; }
#chats-list li.active { background: #2563eb; color: white; }
#chats-list li .title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#chats-list li .del { opacity: 0.4; padding: 2px 6px; cursor: pointer; }
#chats-list li .del:hover { opacity: 1; color: #ff6b6b; }

.office-column {
  background: #0d0d1a;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.office-column .office-scene {
  width: 100%;
  height: auto;
  max-height: 100%;
  margin: 0;
}
@media (max-aspect-ratio: 1672/941) {
  .office-column .office-scene { width: 100%; height: auto; }
}

.chat-panel {
  background: #18181f;
  border-left: 1px solid #2a2a3a;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid #2a2a3a;
  font-size: 14px;
  color: #ccc;
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
.msg {
  padding: 10px 14px;
  border-radius: 12px;
  max-width: 90%;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user { background: #2563eb; color: white; align-self: flex-end; }
.msg.assistant { background: #1f1f2e; color: #e5e5e5; align-self: flex-start; }
.msg.thinking { background: #1f1f2e; color: #888; font-style: italic; align-self: flex-start; }
.msg.thinking::after {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  margin-left: 4px;
  border-radius: 50%;
  background: #888;
  animation: blink 0.8s infinite;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #2a2a3a;
}
#prompt-input {
  flex: 1;
  background: #0d0d1a;
  color: white;
  border: 1px solid #2a2a3a;
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  resize: none;
}
#prompt-input:focus { outline: none; border-color: #2563eb; }
#send-btn {
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0 16px;
  font-size: 18px;
  cursor: pointer;
}
#send-btn:hover:not(:disabled) { background: #1d4ed8; }
#send-btn:disabled { background: #2a2a3a; cursor: not-allowed; }

/* ---------- image attachments ---------- */
.composer { flex-direction: column; gap: 8px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
#attach-btn {
  background: #1f1f2e; color: #ccc; border: 1px solid #2a2a3a;
  border-radius: 8px; padding: 0 12px; height: 42px; font-size: 18px; cursor: pointer;
}
#attach-btn:hover { background: #2a2a3a; }
.attach-preview { display: flex; gap: 8px; flex-wrap: wrap; }
.attach-preview:empty { display: none; }
.attach-preview .thumb {
  position: relative; width: 56px; height: 56px; border-radius: 8px;
  overflow: hidden; border: 1px solid #2a2a3a;
}
.attach-preview .thumb img { width: 100%; height: 100%; object-fit: cover; }
.attach-preview .thumb .rm {
  position: absolute; top: 0; right: 0; background: rgba(0,0,0,0.7);
  color: white; width: 18px; height: 18px; font-size: 12px; line-height: 18px;
  text-align: center; cursor: pointer; border-bottom-left-radius: 6px;
}
.msg img.msg-img {
  max-width: 220px; max-height: 220px; border-radius: 8px; margin-top: 6px; display: block;
}
.composer.dragover { outline: 2px dashed #2563eb; outline-offset: 4px; border-radius: 8px; }

/* ============================================================
   Markdown + KaTeX rendering — dark theme, scoped to assistant msgs
   ============================================================ */

/* Rendered markdown produces block elements; drop the pre-wrap so blank
   lines between them don't double up. */
.msg.assistant { line-height: 1.6; white-space: normal; }
.msg.assistant p { margin: 0 0 8px; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3 {
  margin: 12px 0 6px; line-height: 1.3; color: #fff;
}
.msg.assistant h1 { font-size: 18px; }
.msg.assistant h2 { font-size: 16px; }
.msg.assistant h3 { font-size: 14px; }
.msg.assistant ul, .msg.assistant ol { margin: 6px 0 8px; padding-left: 22px; }
.msg.assistant li { margin: 2px 0; }
.msg.assistant code {
  background: #0d0d1a; padding: 2px 5px; border-radius: 4px;
  font-family: 'Courier New', monospace; font-size: 12px;
}
.msg.assistant pre {
  background: #0d0d1a; border: 1px solid #2a2a3a; border-radius: 8px;
  padding: 12px; overflow-x: auto; margin: 8px 0;
}
.msg.assistant pre code { background: none; padding: 0; font-size: 12px; }
.msg.assistant blockquote {
  border-left: 3px solid #2563eb; margin: 8px 0; padding: 2px 12px; color: #aaa;
}
.msg.assistant table {
  border-collapse: collapse; margin: 8px 0; font-size: 12px; width: 100%;
}
.msg.assistant th, .msg.assistant td {
  border: 1px solid #2a2a3a; padding: 6px 10px; text-align: left;
}
.msg.assistant th { background: #1f1f2e; }
.msg.assistant a { color: #60a5fa; }
.msg.assistant hr { border: none; border-top: 1px solid #2a2a3a; margin: 12px 0; }
/* формулы KaTeX чуть крупнее для читаемости */
.msg.assistant .katex { font-size: 1.05em; }
.msg.assistant .katex-display { margin: 10px 0; overflow-x: auto; overflow-y: hidden; }

/* ---------- готовый проект — карточка-файл в ленте чата ---------- */
.msg.file-card {
  background: #1f1f2e; border: 1px solid #1d4d2e; border-radius: 12px;
  padding: 12px 14px; display: flex; align-items: center; gap: 12px;
  align-self: flex-start; max-width: 90%;
}
.msg.file-card .fc-icon { font-size: 26px; }
.msg.file-card .fc-info { display: flex; flex-direction: column; }
.msg.file-card .fc-name { color: #fff; font-size: 13px; font-weight: bold; }
.msg.file-card .fc-size { color: #888; font-size: 11px; }
.msg.file-card .fc-dl {
  margin-left: auto; background: #16a34a; color: #fff; border: none;
  border-radius: 6px; padding: 8px 16px; cursor: pointer; font-size: 13px;
}
.msg.file-card .fc-dl:hover { background: #15803d; }
