/* Open WebUI Theme overrides for Nexus Agent */
body.open-webui-theme {
  margin: 0;
  padding: 0;
  background-color: #171717; /* Dark Gray bg */
  color: #ececec;
  font-family: 'Inter', sans-serif;
  overflow: hidden; /* App layout takes over */
  /* Mobile browser chrome: prefer dynamic viewport */
  height: 100vh;
  height: 100dvh;
}

.open-webui-theme .app-layout {
  display: flex;
  /* 72px fixed navbar; use dvh so mobile URL bars don't push input off-screen */
  height: calc(100vh - 72px);
  height: calc(100dvh - 72px);
  max-height: calc(100dvh - 72px);
  width: 100%;
  overflow: hidden;
  margin-top: 72px;
}

/* Sidebar */
.agent-sidebar {
  width: 260px;
  background-color: #0d0d0d;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #2d2d2d;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.new-agent-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #2d2d2d;
  color: #ececec;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  justify-content: center;
  transition: background 0.2s;
}

.new-agent-btn:hover { background: #3d3d3d; }

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px;
}

.history-label {
  font-size: 0.75rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 16px 0 8px 8px;
  font-weight: 600;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.history-list li {
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  color: #cfcfcf;
  transition: background 0.2s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-list li:hover { background: #222; }
.history-list li.active { background: #2d2d2d; font-weight: 500; color: #fff; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid #2d2d2d;
}

/* Main Agent Area */
.agent-main {
  flex: 1;
  min-width: 0;
  min-height: 0; /* allow flex child to shrink so input stays visible */
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: #171717;
  overflow: hidden;
}

.status-indicator {
  font-size: 0.8rem;
  padding: 4px 12px;
  border-radius: 999px;
  font-weight: 500;
  border: 1px solid #333;
}

.status-indicator.offline {
  background: #222;
  color: #aaa;
}

.status-indicator.online {
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
  border-color: rgba(16, 185, 129, 0.3);
}

.agent-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 20px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.agent-bubble-wrapper {
  display: flex;
  gap: 16px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.agent-bubble-wrapper.user-wrapper {
  flex-direction: row-reverse;
}

.agent-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nexus-avatar {
  background-color: transparent;
  color: #fff;
  border: 1px solid #444;
}

.user-avatar-img {
  background-color: #007aff;
  color: #fff;
  font-weight: bold;
}

.agent-bubble {
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.6;
  max-width: 85%;
}

.agent-bubble.system {
  background: transparent;
  padding: 0;
}

.agent-bubble.user {
  background: #2d2d2d;
  color: #ececec;
}

.agent-bubble.nexus {
  background: transparent;
  color: #ececec;
  padding: 0;
}

/* Markdown in assistant replies (open-webui agent layout) */
.agent-bubble-markdown {
  white-space: normal;
  word-break: break-word;
}

.agent-markdown {
  color: inherit;
}

.agent-markdown > :first-child { margin-top: 0; }
.agent-markdown > :last-child { margin-bottom: 0; }

.agent-markdown p,
.agent-markdown ul,
.agent-markdown ol,
.agent-markdown blockquote,
.agent-markdown pre,
.agent-markdown .agent-md-table-wrap {
  margin: 0 0 0.75rem;
}

.agent-markdown h1,
.agent-markdown h2,
.agent-markdown h3 {
  margin: 0 0 0.5rem;
  line-height: 1.3;
  font-weight: 700;
  color: #fff;
}

.agent-markdown h1 { font-size: 1.15rem; }
.agent-markdown h2 { font-size: 1.05rem; }
.agent-markdown h3 { font-size: 0.98rem; }

.agent-markdown ul,
.agent-markdown ol {
  padding-left: 1.35rem;
  list-style-position: outside;
}

.agent-markdown ul { list-style-type: disc; }
.agent-markdown ol { list-style-type: decimal; }

.agent-markdown li + li { margin-top: 0.25rem; }

.agent-markdown blockquote {
  padding-left: 0.85rem;
  border-left: 3px solid rgba(0, 212, 255, 0.4);
  color: #a0a0a0;
}

.agent-markdown code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid #3d3d3d;
}

.agent-markdown pre,
.agent-markdown pre.code-block {
  position: relative;
  overflow-x: auto;
  margin: 0 0 0.75rem;
  padding: 2rem 0.9rem 0.75rem;
  border-radius: 10px;
  background: #111827;
  border: 1px solid rgba(0, 212, 255, 0.35);
  color: #e2e8f0;
  font-family: 'Fira Code', 'Consolas', ui-monospace, monospace;
  font-size: 0.85rem;
  line-height: 1.55;
  white-space: pre;
}

.agent-markdown pre code {
  display: block;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  white-space: pre;
}

/* Syntax colors for highlighted agent code fences */
.agent-markdown pre .comment,
.agent-markdown pre code .comment { color: #94a3b8; }
.agent-markdown pre .keyword,
.agent-markdown pre code .keyword { color: #c4b5fd; font-weight: 600; }
.agent-markdown pre .string,
.agent-markdown pre code .string { color: #6ee7b7; }
.agent-markdown pre .function,
.agent-markdown pre code .function { color: #7dd3fc; font-weight: 600; }

.agent-markdown a {
  color: #7dd3fc;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.agent-markdown hr {
  border: none;
  border-top: 1px solid #3d3d3d;
  margin: 0.75rem 0;
}

.agent-md-table-wrap {
  overflow-x: auto;
}

.agent-md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em;
}

.agent-md-table th,
.agent-md-table td {
  border: 1px solid #3d3d3d;
  padding: 0.4rem 0.65rem;
  text-align: left;
}

.agent-md-table th {
  background: rgba(255, 255, 255, 0.06);
  font-weight: 600;
}

.agent-md-table tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

/* Quick Prompts */
.quick-prompts-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.quick-prompts-row .btn {
  background: #2d2d2d;
  border: 1px solid #444;
  color: #ccc;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.85rem;
}

.quick-prompts-row .btn:hover { background: #3d3d3d; color: #fff; border-color: #555; }

/* Input bar — in document flow (not absolute) so mobile safe-area / dvh work */
.agent-input-container {
  position: relative;
  flex-shrink: 0;
  width: 100%;
  padding: 8px 16px max(12px, env(safe-area-inset-bottom, 0px)) 16px;
  background: linear-gradient(0deg, #171717 70%, rgba(23, 23, 23, 0.92) 100%);
  z-index: 20;
  box-sizing: border-box;
}

.agent-input-form {
  max-width: 800px;
  margin: 0 auto;
  position: relative;
}

.agent-input-box {
  background: #2d2d2d;
  border-radius: 24px;
  display: flex;
  align-items: flex-end;
  padding: 10px 16px;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  border: 1px solid #3d3d3d;
}

.agent-input-box textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: #ececec;
  font-size: 1rem;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 200px;
  padding: 6px 0;
  line-height: 1.5;
}

.agent-input-box textarea::placeholder { color: #888; }

.action-btn, .send-btn {
  background: transparent;
  border: none;
  color: #aaa;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  pointer-events: auto;
}

/* Keep the file input out of layout but available for programmatic click */
#agent-image-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.action-btn:hover { color: #fff; background: #3d3d3d; }
.send-btn { background: #ececec; color: #171717; transition: all 0.2s; }
.send-btn:not(:disabled):hover { background: #fff; box-shadow: 0 0 10px rgba(255, 255, 255, 0.4); transform: scale(1.05); }
.send-btn:disabled { background: #444; color: #222; cursor: default; opacity: 0.5; }

.agent-footer-text {
  text-align: center;
  font-size: 0.75rem;
  color: #666;
  margin-top: 12px;
}

/* Audio Recording UI
   Note: display:flex must not override [hidden] (browser default is display:none). */
#audio-recording-ui {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #ff4757;
  font-weight: 500;
  padding: 0 10px;
}

#audio-recording-ui[hidden] {
  display: none !important;
}

.recording-pulse {
  width: 10px;
  height: 10px;
  background-color: #ff4757;
  border-radius: 50%;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(255, 71, 87, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(255, 71, 87, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(255, 71, 87, 0); }
}

.stop-btn {
  color: #ff4757 !important;
}
.stop-btn:hover {
  background: #ff4757 !important;
  color: #fff !important;
}

/* Attachments — hidden until an image or audio is attached */
#agent-image-preview,
.attachments-preview {
  display: none;
  gap: 12px;
  padding: 12px;
  background: #2d2d2d;
  border-radius: 16px;
  margin-bottom: 8px;
  width: fit-content;
  border: 1px solid #3d3d3d;
}

#agent-image-preview:not([hidden]),
.attachments-preview:not([hidden]) {
  display: flex;
}

#agent-image-preview[hidden],
.attachments-preview[hidden] {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  min-height: 0 !important;
}

.attachment-item {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 8px;
  background: #111;
  background-size: cover;
  background-position: center;
}

.attachment-item.audio-attachment {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #10b981;
}

.attachment-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #ff4757;
  color: #fff;
  border: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 768px) {
  .agent-sidebar { display: none; }

  .open-webui-theme .app-layout {
    /* Re-assert mobile height after browser UI settles */
    height: calc(100dvh - 72px);
    max-height: calc(100dvh - 72px);
    margin-top: 72px;
  }

  .agent-messages {
    padding: 16px 12px 12px 12px;
  }

  .agent-input-container {
    /* Extra bottom inset: home indicator + browser gesture bar */
    padding: 8px 12px max(20px, calc(12px + env(safe-area-inset-bottom, 0px))) 12px;
  }

  .agent-input-box {
    padding: 8px 12px;
    border-radius: 20px;
  }

  .agent-input-box textarea {
    font-size: 16px; /* avoid iOS zoom on focus */
  }

  .agent-top-bar {
    padding: 8px 12px;
  }
}

@media (min-width: 769px) {
  .sidebar-toggle { display: none; }
}

/* Keyboard open: visualViewport can shrink — keep layout within visible area */
@supports (height: 100svh) {
  body.open-webui-theme {
    height: 100svh;
  }
  .open-webui-theme .app-layout {
    height: calc(100svh - 72px);
    max-height: calc(100svh - 72px);
  }
}

@supports (height: 100dvh) {
  body.open-webui-theme {
    height: 100dvh;
  }
  .open-webui-theme .app-layout {
    height: calc(100dvh - 72px);
    max-height: calc(100dvh - 72px);
  }
}
