:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f7f8;
  --surface-3: #ececf1;
  --ink: #0d0d0d;
  --ink-2: #2c2c33;
  --muted: #6e6e80;
  --muted-2: #8e8ea0;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.14);
  --sidebar: #f9f9f9;
  --sidebar-hover: rgba(0, 0, 0, 0.06);
  --sidebar-active: rgba(0, 0, 0, 0.08);
  --sidebar-line: rgba(0, 0, 0, 0.07);
  --accent: #0a3a4a;
  --accent-2: #f37021;
  --danger: #c13b3b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 24px 64px rgba(15, 23, 42, 0.18);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}

@supports (height: 100dvh) {
  .app-shell,
  .chat-main,
  .login-gate {
    height: 100dvh;
    min-height: 100dvh;
  }
}

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
select,
textarea,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: transparent;
  border: 0;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

/* Login */
.login-gate {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: hidden;
}

.login-video-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.login-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.52);
  z-index: 1;
}

.login-card {
  position: relative;
  z-index: 2;
  width: min(400px, calc(100% - 48px));
  padding: 40px 36px 36px;
  background: rgba(255, 255, 255, 0.97);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.32);
  text-align: center;
}

.login-mark-card {
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: contain;
  margin: 0 auto 20px;
}

.login-title {
  margin: 0 0 28px;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.login-dot {
  color: var(--accent-2);
}

.login-actions {
  display: grid;
  gap: 10px;
}

.login-ms-btn {
  width: 100%;
  height: 46px;
  border-radius: 999px;
  padding: 0 24px;
  font-weight: 600;
  font-size: 0.95rem;
  color: #fff;
  background: var(--accent-2);
  transition: filter 0.15s ease, transform 0.05s ease;
}

.login-ms-btn:hover {
  filter: brightness(1.08);
}

.login-ms-btn:active {
  transform: scale(0.98);
}

.primary-action {
  height: 44px;
  border-radius: 999px;
  padding: 0 22px;
  font-weight: 600;
  color: #fff;
  background: var(--ink);
  transition: transform 0.05s ease, background 0.15s ease;
}

.primary-action:hover {
  background: #1d1d1d;
}

.primary-action:active {
  transform: translateY(1px);
}

.ghost-action {
  height: 42px;
  border-radius: 999px;
  padding: 0 22px;
  font-weight: 600;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--line-strong);
}

.ghost-action:hover {
  background: var(--surface-2);
}

/* App shell */
.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  transition: grid-template-columns 0.2s ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.app-shell.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
  pointer-events: none;
  border-right-color: transparent;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-line);
  overflow: hidden;
  transition: transform 0.2s ease, border-right-color 0.2s ease;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 8px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  padding: 6px 6px;
  border-radius: var(--radius-sm);
}

.brand:hover {
  background: var(--sidebar-hover);
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  object-fit: cover;
}

.brand-name {
  font-weight: 600;
  letter-spacing: -0.01em;
}

.icon-only-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--muted);
  display: inline-grid;
  place-items: center;
}

.icon-only-btn:hover {
  background: var(--sidebar-hover);
  color: var(--ink);
}

.icon-only-btn.light:hover {
  background: var(--surface-2);
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 12px 6px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  font-weight: 500;
  text-align: left;
  box-shadow: var(--shadow-sm);
}

.new-chat-btn:hover {
  background: var(--surface-2);
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 12px 8px;
  padding: 0 10px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
}

.sidebar-search input {
  border: 0;
  background: transparent;
  outline: none;
  flex: 1;
  font-size: 0.9rem;
  color: var(--ink);
}

.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 8px 12px;
}

.sidebar-section {
  margin-top: 8px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 4px;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.mini-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  color: var(--muted);
  display: inline-grid;
  place-items: center;
}

.mini-btn:hover {
  background: var(--sidebar-hover);
  color: var(--ink);
}

.project-list,
.chat-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.project-row {
  display: flex;
  flex-direction: column;
}

.project-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink-2);
  font-weight: 500;
  font-size: 0.92rem;
  position: relative;
}

.project-header:hover {
  background: var(--sidebar-hover);
}

.project-header .chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  transition: transform 0.15s ease;
  color: var(--muted);
}

.project-row.open .project-header .chevron {
  transform: rotate(90deg);
}

.project-header .project-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-header .row-menu {
  opacity: 0;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  color: var(--muted);
  display: inline-grid;
  place-items: center;
}

.project-header:hover .row-menu,
.row-item:hover .row-menu,
.row-item.is-active .row-menu {
  opacity: 1;
}

.project-children {
  display: none;
  flex-direction: column;
  gap: 2px;
  margin-left: 18px;
  padding: 2px 0 4px;
  border-left: 1px solid var(--line);
}

.project-row.open .project-children {
  display: flex;
}

.row-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.92rem;
  color: var(--ink-2);
  position: relative;
}

.row-item:hover {
  background: var(--sidebar-hover);
}

.row-item.is-active {
  background: var(--sidebar-active);
}

.row-item .chat-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-item .row-menu {
  opacity: 0;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  color: var(--muted);
  display: inline-grid;
  place-items: center;
}

.empty-row {
  padding: 8px 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.sidebar-foot {
  position: relative;
  padding: 8px;
  border-top: 1px solid var(--sidebar-line);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border-radius: var(--radius-md);
  text-align: left;
}

.user-chip:hover {
  background: var(--sidebar-hover);
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.avatar-user {
  background: linear-gradient(135deg, var(--accent), #154d61);
}

.avatar-assistant {
  background: linear-gradient(135deg, #f8f8f8, #e7e7e7);
  color: transparent;
  background-image: url("./img/logo-mark.jpg");
  background-size: cover;
  background-position: center;
}

.user-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-meta strong {
  font-size: 0.92rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-meta small {
  color: var(--muted);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 8px;
  right: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 30;
}

.user-menu button {
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.user-menu button:hover {
  background: var(--surface-2);
}

/* Main */
.chat-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  height: 100vh;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

#sidebarOpen {
  display: none;
}

.app-shell.sidebar-collapsed #sidebarOpen {
  display: inline-grid;
}

.topbar-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-title h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

.project-chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-2);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Chip que mostra a versao do agente especialista no topbar */
.agent-version-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.agent-picker {
  position: relative;
}

.agent-select {
  appearance: none;
  height: 36px;
  padding: 0 32px 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%236e6e80' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.agent-select:hover {
  background-color: var(--surface-2);
}

/* Thread */
.thread-wrap {
  position: relative;
  overflow-y: auto;
  padding: 16px 16px 24px;
}

.thread-wrap.dragging {
  outline: 3px dashed var(--accent-2);
  outline-offset: -10px;
  background: rgba(243, 112, 33, 0.04);
}

.empty-state {
  max-width: 720px;
  margin: 12vh auto 0;
  text-align: center;
  padding: 0 16px;
}

.empty-mark {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  margin: 0 auto 18px;
  display: block;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.04);
}

.empty-state h1 {
  margin: 0 0 10px;
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.empty-state p {
  color: var(--muted);
  margin: 0 0 28px;
  line-height: 1.55;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-width: 600px;
  margin: 0 auto;
}

.suggestion {
  text-align: left;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.suggestion:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.suggestion strong {
  font-size: 0.92rem;
  font-weight: 600;
}

.suggestion span {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

/* "Powered by OpenAI" abaixo das sugestoes da tela inicial */
.empty-powered-by {
  margin: 18px auto 0;
  text-align: center;
  font-size: 0.74rem;
  color: var(--muted-2);
  letter-spacing: 0.02em;
}

.message-thread {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: min(760px, 100%);
  margin: 0 auto;
  padding-top: 20px;
}

.message-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 14px;
  align-items: flex-start;
}

.message-row .avatar {
  width: 30px;
  height: 30px;
  margin-top: 2px;
}

.message-row.user .avatar-role {
  background: linear-gradient(135deg, var(--accent), #154d61);
  color: #fff;
}

.message-row.assistant .avatar-role {
  background-image: url("./img/logo-mark.jpg");
  background-size: cover;
  background-position: center;
  background-color: #fff;
  color: transparent;
  border: 1px solid var(--line);
}

.avatar-role {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.message-body {
  min-width: 0;
}

.message-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.message-head .role-name {
  color: var(--ink);
}

.message-content {
  line-height: 1.65;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.message-row.user .message-content {
  white-space: pre-wrap;
}

.message-content > *:first-child {
  margin-top: 0;
}

.message-content > *:last-child {
  margin-bottom: 0;
}

.message-content p {
  margin: 0 0 12px;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
  font-weight: 700;
  line-height: 1.3;
  margin: 18px 0 8px;
  color: var(--ink);
}

.message-content h1 { font-size: 1.5rem; }
.message-content h2 { font-size: 1.3rem; }
.message-content h3 { font-size: 1.15rem; }
.message-content h4 { font-size: 1.02rem; }
.message-content h5,
.message-content h6 { font-size: 0.95rem; color: var(--ink-2); }

.message-content ul,
.message-content ol {
  margin: 0 0 12px;
  padding-left: 1.4rem;
}

.message-content li {
  margin: 2px 0;
}

.message-content li > p {
  margin: 0 0 6px;
}

.message-content ul ul,
.message-content ol ol,
.message-content ul ol,
.message-content ol ul {
  margin: 4px 0;
}

.message-content blockquote {
  margin: 0 0 12px;
  padding: 6px 14px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  color: var(--ink-2);
  border-radius: 4px;
}

.message-content blockquote > *:last-child {
  margin-bottom: 0;
}

.message-content a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-content a:hover {
  color: var(--accent-2);
}

.message-content hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 16px 0;
}

.message-content code {
  font-family: "JetBrains Mono", "Fira Code", "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--ink);
}

.message-content pre {
  margin: 0 0 12px;
  padding: 12px 14px;
  background: #0f1115;
  color: #e6e6ec;
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.55;
}

.message-content pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.message-content table {
  border-collapse: collapse;
  margin: 0 0 14px;
  width: 100%;
  display: block;
  overflow-x: auto;
  font-size: 0.92rem;
}

.message-content thead {
  background: var(--surface-2);
}

.message-content th,
.message-content td {
  border: 1px solid var(--line-strong);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}

.message-content th {
  font-weight: 600;
  color: var(--ink);
}

.message-content tr:nth-child(even) td {
  background: var(--surface-2);
}

.message-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

.message-content .katex {
  font-size: 1.02em;
}

.message-content .katex-display {
  margin: 12px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.message-files {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
}

/* Imagens geradas pela tool image_generation do modelo base.
   Quadro com 30% menos que o tamanho original (512 -> 358, 640 -> 448),
   suficiente para visualizar sem dominar a leitura da conversa. */
.message-images {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 358px);
}

.message-image {
  max-width: 100%;
  max-height: 448px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  object-fit: contain;
  background: var(--surface-2);
}

/* Placeholder animado durante geracao de imagem (shimmer + spinner).
   Substituido pela <img> real assim que o evento SSE "image" chega. */
.message-image-placeholder {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  background: linear-gradient(
    110deg,
    var(--surface-2) 20%,
    var(--surface-3) 50%,
    var(--surface-2) 80%
  );
  background-size: 200% 100%;
  animation: messageImageShimmer 2.8s ease-in-out infinite;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.message-image-placeholder-spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid rgba(127, 127, 127, 0.22);
  border-top-color: var(--accent-2);
  animation: messageImageSpin 1.6s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}

@keyframes messageImageShimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

@keyframes messageImageSpin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .message-image-placeholder {
    animation: none;
  }
  .message-image-placeholder-spinner {
    animation-duration: 3s;
  }
}

.message-actions {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.message-row:hover .message-actions {
  opacity: 1;
}

.message-action {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 6px;
}

.message-action:hover {
  background: var(--surface-2);
  color: var(--ink);
}

/* Composer */
.composer-shell {
  padding: 0 16px 18px;
  background: var(--bg);
}

.attachment-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: min(760px, 100%);
  margin: 0 auto 8px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.82rem;
  color: var(--ink-2);
}

.attachment-chip small {
  color: var(--muted);
}

.attachment-chip .chip-remove {
  color: var(--muted);
  width: 16px;
  height: 16px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
}

.attachment-chip .chip-remove:hover {
  background: var(--surface-3);
  color: var(--ink);
}

.composer {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: end;
  gap: 6px;
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 8px 8px 8px 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Agentes especialistas: somente input textual. Esconde o botao de anexo
   e deixa o textarea ocupar a primeira coluna. */
.composer.composer--no-attach {
  grid-template-columns: minmax(0, 1fr) auto;
}

.composer.composer--no-attach .composer-icon {
  display: none;
}

.composer:focus-within {
  border-color: var(--line-strong);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.composer-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--muted);
  display: inline-grid;
  place-items: center;
}

.composer-icon:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.composer textarea {
  width: 100%;
  max-height: 200px;
  border: 0;
  padding: 8px 6px;
  outline: 0;
  resize: none;
  background: transparent;
  line-height: 1.5;
  font-size: 0.96rem;
}

.composer-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  display: inline-grid;
  place-items: center;
  transition: transform 0.05s ease, background 0.15s ease;
}

.composer-send:hover {
  background: #1d1d1d;
}

.composer-send:active {
  transform: translateY(1px);
}

.composer-send:disabled {
  background: var(--surface-3);
  color: var(--muted);
}

.composer-cancel {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  display: inline-grid;
  place-items: center;
}

.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(760px, 100%);
  margin: 8px auto 0;
  font-size: 0.78rem;
  color: var(--muted);
}

/* Disclaimer permanente abaixo do composer: IAs cometem erros */
.composer-disclaimer {
  width: min(760px, 100%);
  margin: 6px auto 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted-2);
  line-height: 1.4;
}

.text-button {
  font-size: 0.82rem;
  color: var(--ink-2);
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 6px;
}

.text-button:hover {
  background: var(--surface-2);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
  animation: fade 0.12s ease;
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-card {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-lg);
}

.modal-card h3 {
  margin: 0 0 6px;
  font-size: 1.1rem;
}

.modal-description {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.9rem;
}

.modal-card input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  outline: none;
  font-size: 0.95rem;
}

.modal-card input:focus {
  border-color: var(--ink);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* Context menu */
.ctx-menu {
  position: fixed;
  z-index: 60;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ctx-menu button,
.ctx-menu .ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.88rem;
  text-align: left;
  color: var(--ink-2);
}

.ctx-menu button:hover,
.ctx-menu .ctx-item:hover {
  background: var(--surface-2);
}

.ctx-menu .ctx-item.danger,
.ctx-menu button.danger {
  color: var(--danger);
}

.ctx-menu .ctx-divider {
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}

.ctx-submenu-label {
  padding: 6px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 70;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.18s ease;
}

@keyframes toastIn {
  from {
    transform: translateX(-50%) translateY(8px);
    opacity: 0;
  }
}

/* Notificacao de stream concluido fora da view atual */
.stream-notification {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px 12px 18px;
  max-width: 360px;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.88rem;
  z-index: 75;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  animation: streamNotifIn 0.22s ease;
}

.stream-notification:hover {
  background: var(--card-hover, var(--card));
  border-color: var(--ink);
}

.stream-notification-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.stream-notification-body strong {
  font-size: 0.9rem;
}

.stream-notification-body span {
  color: var(--muted);
  font-size: 0.8rem;
}

.stream-notification-close {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.stream-notification-close:hover {
  background: var(--bg-subtle, rgba(0, 0, 0, 0.06));
  color: var(--ink);
}

@keyframes streamNotifIn {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
}

.stream-status {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60%;
}

/* Streaming indicator on assistant message */
.message-row.streaming:not(.is-thinking) .message-content::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 16px;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--ink);
  animation: blink 1s steps(2) infinite;
}

@keyframes blink {
  to {
    opacity: 0;
  }
}

/* Thinking placeholder */
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.thinking-dots {
  display: inline-flex;
  align-items: flex-end;
  gap: 5px;
  height: 14px;
}

.thinking-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-2);
  opacity: 0.45;
  animation: bounce 1.2s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.15s;
  background: var(--accent);
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  0%,
  70%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  35% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

.thinking-label {
  position: relative;
  font-style: italic;
  background: linear-gradient(90deg, var(--muted) 0%, var(--ink) 50%, var(--muted) 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 2.4s linear infinite;
}

.thinking-label::after {
  content: "...";
  display: inline-block;
  margin-left: 2px;
  background: inherit;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* Scrollbar */
.sidebar-scroll::-webkit-scrollbar,
.thread-wrap::-webkit-scrollbar {
  width: 8px;
}

.sidebar-scroll::-webkit-scrollbar-thumb,
.thread-wrap::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 999px;
}

.sidebar-scroll::-webkit-scrollbar-thumb:hover,
.thread-wrap::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.22);
}

/* Responsive */
/* Backdrop atras da sidebar quando aberta em mobile. Clique fecha. */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  z-index: 35;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  display: none;
}

@media (max-width: 860px) {
  /* Layout: sidebar vira overlay, conteudo principal usa toda a largura */
  .app-shell {
    grid-template-columns: 0 minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    z-index: 40;
    transform: translateX(-100%);
    box-shadow: var(--shadow-md);
  }

  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
    pointer-events: auto;
  }

  /* Backdrop visivel quando sidebar aberta */
  .sidebar-backdrop {
    display: block;
  }

  .app-shell.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  #sidebarOpen {
    display: inline-grid;
  }

  /* Sugestoes em coluna unica */
  .suggestion-grid {
    grid-template-columns: 1fr;
  }

  /* Empty state mais compacto */
  .empty-state {
    margin-top: 6vh;
  }

  .empty-state h1 {
    font-size: 1.6rem;
  }

  .empty-state p {
    font-size: 0.95rem;
  }

  .empty-mark {
    width: 60px;
    height: 60px;
    margin-bottom: 14px;
  }

  /* Topbar mais compacto */
  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .topbar-title h2 {
    font-size: 0.95rem;
  }

  .agent-select {
    height: 34px;
    font-size: 0.85rem;
    padding: 0 28px 0 10px;
  }

  /* Composer respeitando safe area + touch targets maiores */
  .composer-shell {
    padding: 0 12px max(14px, env(safe-area-inset-bottom));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .composer {
    padding: 6px 6px 6px 4px;
    gap: 4px;
  }

  /* font-size 16px evita zoom automatico do iOS Safari ao focar */
  .composer textarea {
    font-size: 16px;
    padding: 8px 4px;
  }

  .composer-icon,
  .composer-send,
  .composer-cancel {
    width: 42px;
    height: 42px;
  }

  .composer-foot {
    font-size: 0.76rem;
  }

  /* Sidebar foot respeita home indicator do iPhone */
  .sidebar-foot {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  /* Touch targets nas listas (chats, projetos, agentes) */
  .row-item,
  .project-header {
    padding: 10px 8px;
  }

  .agent-tile {
    padding: 11px 10px;
  }

  .icon-only-btn {
    width: 38px;
    height: 38px;
  }

  /* Thread com padding mais enxuto pra ganhar largura util */
  .thread-wrap {
    padding: 14px 14px 18px;
  }

  .message-thread {
    gap: 18px;
    padding-top: 14px;
  }

  /* Acoes de mensagem sempre visiveis em mobile (sem hover) */
  .message-actions {
    opacity: 1;
  }

  /* Notificacao de stream ocupa quase a largura toda */
  .stream-notification {
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    max-width: none;
  }

  /* Toast respeita safe area inferior */
  .toast {
    bottom: max(20px, calc(env(safe-area-inset-bottom) + 12px));
  }

  /* Modais menos apertados em telas pequenas */
  .modal-backdrop {
    padding: 12px;
  }

  .modal-card {
    padding: 18px;
  }
}

@media (max-width: 480px) {
  /* Phones: micro-ajustes finais */
  .empty-state h1 {
    font-size: 1.4rem;
  }

  .topbar-actions {
    gap: 4px;
  }

  .agent-select {
    max-width: 60vw;
  }

  .composer-icon,
  .composer-send,
  .composer-cancel {
    width: 40px;
    height: 40px;
  }

  .stream-status {
    max-width: 64%;
  }
}

.sidebar-section.is-collapsible .section-head {
  cursor: pointer;
  user-select: none;
}

.sidebar-section.is-collapsible .section-head:hover {
  color: var(--ink);
}

.section-chevron {
  flex-shrink: 0;
  color: var(--muted);
  transition: transform 0.18s ease;
}

.sidebar-section.is-collapsible.is-expanded .section-chevron {
  transform: rotate(90deg);
}

.sidebar-section.is-collapsible:not(.is-expanded) .section-body {
  display: none;
}

.agent-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 4px;
}

.agent-tile {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: inherit;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.agent-tile:hover {
  background: rgba(127, 127, 127, 0.08);
}

.agent-tile.is-active {
  background: rgba(127, 127, 127, 0.12);
  border-color: var(--line);
}

.agent-tile.is-unavailable {
  opacity: 0.65;
}

.agent-tile-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.agent-tile-icon svg {
  width: 100%;
  height: 100%;
}

.agent-tile-name {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  color: var(--ink);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-tile.is-active .agent-tile-icon {
  color: var(--accent);
}

.agent-tile-badge {
  flex-shrink: 0;
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(127, 127, 127, 0.12);
  border-radius: 999px;
  padding: 2px 8px;
}

.apps-list {
  padding: 0 10px;
}

.apps-placeholder {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 8px 4px;
  font-style: italic;
}

.wait-progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  max-width: 360px;
}

.wait-progress-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(127, 127, 127, 0.18);
  overflow: hidden;
}

.wait-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  border-radius: inherit;
  transition: width 0.2s linear;
}

.wait-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
