:root {
  --bg: #212121;
  --panel-bg: #2a2a2a;
  --bubble-user: #3a3a3a;
  --bubble-assistant: #2f2f2f;
  --bubble-error: #4a2626;
  --text: #ececec;
  --text-dim: #9b9b9b;
  --accent: #10a37f;
  --accent-dim: #0d8a6c;
  --border: #3d3d3d;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
}

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

.app-header {
  display: flex;
  align-items: baseline;
  gap: 0.6em;
  padding: 0.75em 1.2em;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.app-title {
  font-weight: 700;
  font-size: 1.1em;
}

.app-subtitle {
  color: var(--text-dim);
  font-size: 0.85em;
}

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Result viewer modal. Uses visibility (not display:none) so the Niivue
   canvas inside keeps a stable, non-zero layout size at all times -- it
   needs to be paintable off-screen to produce thumbnails even while the
   modal itself isn't shown to the user. */
.viewer-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
  z-index: 1000;
}

.viewer-modal.closed {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.viewer-modal-inner {
  position: relative;
  width: min(1100px, 92vw);
  height: min(720px, 86vh);
  background: #000;
  border-radius: 12px;
  overflow: hidden;
}

.viewer-modal-inner canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.viewer-modal-close {
  position: absolute;
  top: 0.6em;
  right: 0.7em;
  width: 2em;
  height: 2em;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  font-size: 1em;
  cursor: pointer;
  z-index: 1;
}

.viewer-modal-close:hover {
  background: rgba(0, 0, 0, 0.8);
}

.viewer-controls {
  position: absolute;
  left: 0.8em;
  bottom: 0.6em;
  display: flex;
  align-items: center;
  gap: 1em;
  background: rgba(0, 0, 0, 0.55);
  padding: 0.4em 0.8em;
  border-radius: 8px;
  font-size: 0.85em;
}

.overlay-toggle {
  display: flex;
  align-items: center;
  gap: 0.4em;
  cursor: pointer;
  user-select: none;
}

/* Inline result thumbnail shown inside an assistant chat bubble. */
.msg-thumb-wrap {
  margin-top: 0.5em;
}

.msg-thumb {
  display: block;
  width: 220px;
  max-width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #000;
  cursor: pointer;
}

.msg-thumb:hover {
  filter: brightness(1.15);
}

.msg-thumb-caption {
  margin-top: 0.3em;
  font-size: 0.78em;
  color: var(--text-dim);
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1em 1.2em;
  display: flex;
  flex-direction: column;
  gap: 0.9em;
}

.bubble-row {
  display: flex;
}

.bubble-row.user {
  justify-content: flex-end;
}

.bubble-row.assistant {
  justify-content: flex-start;
}

.bubble {
  max-width: 70%;
  padding: 0.6em 0.9em;
  border-radius: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  font-size: 0.95em;
}

.bubble-row.user .bubble {
  background: var(--bubble-user);
  border-bottom-right-radius: 4px;
}

.bubble-row.assistant .bubble {
  background: var(--bubble-assistant);
  border-bottom-left-radius: 4px;
}

.bubble.error {
  background: var(--bubble-error);
}

.bubble .file-name {
  display: block;
  margin-top: 0.35em;
  font-size: 0.8em;
  color: var(--text-dim);
}

.bubble .status-line {
  color: var(--text-dim);
  font-size: 0.85em;
}

.composer {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 0.5em;
  padding: 0.8em 1.2em 1.1em;
  border-top: 1px solid var(--border);
}

.attach-button {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.4em;
  height: 2.4em;
  border-radius: 50%;
  background: var(--panel-bg);
  cursor: pointer;
  font-size: 1.1em;
}

.attach-button:hover {
  background: var(--border);
}

.file-chip {
  flex-shrink: 0;
  max-width: 10em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--panel-bg);
  border-radius: 999px;
  padding: 0.35em 0.8em;
  font-size: 0.8em;
  color: var(--text-dim);
}

.query-input {
  flex: 1;
  resize: none;
  max-height: 8em;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  padding: 0.6em 1em;
  font-size: 0.95em;
  font-family: inherit;
}

.query-input:focus {
  outline: none;
  border-color: var(--accent);
}

.send-button {
  flex-shrink: 0;
  border: none;
  border-radius: 18px;
  background: var(--accent);
  color: #fff;
  padding: 0.6em 1.2em;
  font-size: 0.95em;
  cursor: pointer;
}

.send-button:hover {
  background: var(--accent-dim);
}

.send-button:disabled {
  background: var(--border);
  color: var(--text-dim);
  cursor: not-allowed;
}
