/* ==========================================================================
   MJay Frontend — Variáveis e Design Tokens (Spec 012)
   ========================================================================== */

:root {
  /* Tipografia */
  --font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition-speed: 0.2s;

  /* Cores Base (Dark Mode por Padrão) */
  --bg-primary: #0D0D10;
  --bg-sidebar: #111113;
  --bg-surface: #1A1A1E;
  --bg-surface-hover: #232327;
  --border-subtle: #2A2A2E;
  --text-primary: #F5F5F7;
  --text-secondary: #9A9AA2;
  --accent-primary: #10B981;       /* Verde Esmeralda */
  --accent-secondary: #3B82F6;     /* Azul */
  --accent-warning: #F59E0B;       /* Âmbar */
  --success: #22C55E;              /* Verde Online */

  /* Scrollbar Tokens */
  --scrollbar-thumb: rgba(255, 255, 255, 0.16);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.28);
  --scrollbar-track: transparent;

  /* Dimensões */
  --sidebar-width: 280px;
  --sidebar-collapsed-width: 68px;
  --topbar-height: 64px;
  --chat-max-width: 768px;
}

[data-theme="light"] {
  --bg-primary: #FFFFFF;
  --bg-sidebar: #F7F7F8;
  --bg-surface: #F0F0F2;
  --bg-surface-hover: #E5E5E8;
  --border-subtle: #E2E2E5;
  --text-primary: #18181B;
  --text-secondary: #6B6B73;
  --accent-primary: #059669;
  --accent-secondary: #2563EB;
  --accent-warning: #D97706;

  /* Scrollbar Tokens */
  --scrollbar-thumb: rgba(0, 0, 0, 0.18);
  --scrollbar-thumb-hover: rgba(0, 0, 0, 0.32);
  --scrollbar-track: transparent;
}

/* ==========================================================================
   Custom Scrollbars (Design Moderno & Dark Mode)
   ========================================================================== */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: 9999px;
  transition: background-color var(--transition-speed) ease;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-thumb-hover);
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Layout Principal
   ========================================================================== */

.app-layout {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  position: relative;
}

/* ==========================================================================
   Sidebar (Desktop & Drawer)
   ========================================================================== */

.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  height: 100%;
  flex-shrink: 0;
  transition: width var(--transition-speed) ease, transform var(--transition-speed) ease;
  z-index: 50;
}

.sidebar-header {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: #FFFFFF;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

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

.user-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-context {
  font-size: 12px;
  color: var(--text-secondary);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition-speed), color var(--transition-speed);
}

.btn-icon:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
}

.btn-mic.listening {
  color: #ef4444 !important;
  background-color: rgba(239, 68, 68, 0.15) !important;
  animation: pulse-mic 1.5s infinite;
}

@keyframes pulse-mic {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
  }
}

.new-chat-wrapper {
  padding: 12px 16px;
}

.btn-new-chat {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition-speed) ease;
}

.btn-new-chat:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--accent-primary);
}

.sidebar-history-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.history-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 8px 4px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  position: relative;
  transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
  user-select: none;
}

.history-item:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
}

.history-item.active {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 500;
  border-left: 3px solid var(--accent-primary);
}

.history-item-icon {
  flex-shrink: 0;
  opacity: 0.7;
}

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

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
}

.user-select-dropdown {
  width: 100%;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}

/* Sidebar Recolhida (Desktop) */
.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .user-info,
.sidebar.collapsed .btn-label,
.sidebar.collapsed .history-section-title,
.sidebar.collapsed .history-item-text,
.sidebar.collapsed .user-selector-container {
  display: none;
}

.sidebar.collapsed .btn-new-chat {
  justify-content: center;
  padding: 10px;
}

.sidebar.collapsed .collapse-btn svg {
  transform: rotate(180deg);
}

/* ==========================================================================
   Topbar
   ========================================================================== */

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  overflow: hidden;
  background-color: var(--bg-primary);
}

.topbar {
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  background-color: var(--bg-primary);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.mobile-menu-btn {
  display: none;
}

.agent-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.agent-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.model-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--accent-primary);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 12px;
  cursor: default;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: all var(--transition-speed);
}

.theme-toggle:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--accent-primary);
}

[data-theme="dark"] .sun-icon { display: block; }
[data-theme="dark"] .moon-icon { display: none; }
[data-theme="light"] .sun-icon { display: none; }
[data-theme="light"] .moon-icon { display: block; }

/* ==========================================================================
   Área de Chat (Viewport)
   ========================================================================== */

.chat-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  scroll-behavior: smooth;
}

.welcome-section {
  max-width: var(--chat-max-width);
  width: 100%;
  margin: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.welcome-section.hidden {
  display: none;
}

.avatar-container {
  margin-bottom: 16px;
}

.large-avatar {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  padding: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.2);
}

.avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.avatar-text {
  background-color: var(--bg-surface);
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 700;
  color: var(--text-primary);
}

.online-indicator {
  position: absolute;
  width: 18px;
  height: 18px;
  background-color: var(--success);
  border: 3px solid var(--bg-primary);
  border-radius: 50%;
  bottom: 4px;
  right: 4px;
}

.official-badge {
  display: inline-block;
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-primary);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
}

.welcome-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  font-style: italic;
  max-width: 520px;
  margin-bottom: 32px;
}

/* Quick Cards */
.quick-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  width: 100%;
  text-align: left;
}

.suggestion-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 16px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: all var(--transition-speed) ease;
  position: relative;
}

.suggestion-card:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--accent-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-icon-green { background: rgba(16, 185, 129, 0.15); color: var(--accent-primary); }
.card-icon-blue { background: rgba(59, 130, 246, 0.15); color: var(--accent-secondary); }
.card-icon-amber { background: rgba(245, 158, 11, 0.15); color: var(--accent-warning); }

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.card-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.card-arrow {
  display: none;
}

/* ==========================================================================
   Lista de Mensagens
   ========================================================================== */

.messages-list {
  max-width: var(--chat-max-width);
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.message-row {
  display: flex;
  gap: 12px;
  width: 100%;
}

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

.message-row.user .message-bubble {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
  border-radius: 16px 16px 4px 16px;
  padding: 12px 16px;
  max-width: 85%;
  word-break: break-word;
  font-size: 15px;
  line-height: 1.5;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  border: 1px solid var(--border-subtle);
}

[data-theme="light"] .message-row.user .message-bubble {
  background-color: #E2E8F0;
  color: #0F172A;
}

.message-row.assistant {
  justify-content: flex-start;
  align-items: flex-start;
}

.mini-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  padding: 1.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  overflow: hidden;
}

.mini-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.mini-avatar-fallback {
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 700;
}

.assistant-message-content {
  flex: 1;
  max-width: 90%;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  position: relative;
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.sender-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.message-body {
  word-break: break-word;
}

/* Spec 023 §5.1 — cursor do streaming enquanto o texto ainda está chegando. */
.message-row.streaming .streaming-body:empty::after {
  content: '▍';
  animation: piscarCursor 1s steps(1) infinite;
  color: var(--text-secondary);
}

@keyframes piscarCursor {
  50% { opacity: 0; }
}

.message-body p {
  margin-bottom: 10px;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.message-body pre {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 10px 0;
}

.message-body code {
  font-family: Consolas, Monaco, monospace;
  font-size: 13px;
}

.message-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 13px;
}

.message-body th, .message-body td {
  border: 1px solid var(--border-subtle);
  padding: 8px 10px;
  text-align: left;
}

.message-body th {
  background-color: var(--bg-surface);
}

.copy-btn {
  opacity: 0;
  position: absolute;
  top: 0;
  right: 0;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: opacity var(--transition-speed);
}

.assistant-message-content:hover .copy-btn {
  opacity: 1;
}

/* Indicador digitando */
.typing-indicator {
  display: flex;
  gap: 12px;
  align-items: center;
  max-width: var(--chat-max-width);
  width: 100%;
  margin-top: 10px;
}

.typing-indicator.hidden {
  display: none;
}

.typing-bubble {
  background-color: var(--bg-surface);
  padding: 10px 16px;
  border-radius: 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--border-subtle);
  max-width: 100%;
}

.dots {
  display: flex;
  gap: 3px;
  align-items: center;
  flex-shrink: 0;
}

.typing-status-text {
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.dot {
  width: 7px;
  height: 7px;
  background-color: var(--text-secondary);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

.scroll-bottom-btn {
  position: absolute;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 10;
}

.scroll-bottom-btn.hidden {
  display: none;
}

/* ==========================================================================
   Input Bar (Rodapé)
   ========================================================================== */

.input-section {
  padding: 12px 24px 16px;
  background-color: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  flex-shrink: 0;
}

.input-container {
  max-width: var(--chat-max-width);
  width: 100%;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 8px 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  transition: border-color var(--transition-speed);
}

.input-container:focus-within {
  border-color: var(--accent-primary);
}

.chat-textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  padding: 6px 4px;
  max-height: 160px;
  overflow-y: auto;
}

.chat-textarea::placeholder {
  color: var(--text-secondary);
}

.input-actions-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: none;
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity var(--transition-speed), transform var(--transition-speed);
}

.btn-send:hover:not(:disabled) {
  transform: scale(1.05);
}

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.input-container.disabled {
  opacity: 0.6;
  background-color: var(--bg-primary);
  border-color: var(--border-subtle);
  cursor: not-allowed;
}

.chat-textarea:disabled {
  cursor: not-allowed;
  color: var(--text-secondary);
}

.historical-banner {
  max-width: var(--chat-max-width);
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.25);
  color: var(--accent-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 8px;
  margin-top: 8px;
  text-align: center;
}

.historical-banner.hidden {
  display: none;
}

.disclaimer-text {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 8px;
}

/* ==========================================================================
   Componente Toast
   ========================================================================== */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background-color: var(--bg-surface-hover);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  z-index: 100;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
}

/* ==========================================================================
   Responsividade (Breakpoints da Spec 012)
   ========================================================================== */

/* Tablet (768px – 1023px) */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 45;
  }

  .sidebar-overlay.active {
    display: block;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .collapse-btn {
    display: none;
  }
}

/* Mobile (< 768px) */
@media (max-width: 767px) {
  .topbar {
    padding: 0 16px;
  }

  .model-badge {
    display: none;
  }

  .theme-label {
    display: none;
  }

  .welcome-title {
    font-size: 20px;
  }

  .welcome-subtitle {
    font-size: 13px;
    margin-bottom: 20px;
  }

  .large-avatar {
    width: 76px;
    height: 76px;
  }

  .avatar-text {
    font-size: 26px;
  }

  .avatar-container {
    margin-bottom: 10px;
  }

  .official-badge {
    margin-bottom: 8px;
  }

  .quick-cards-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .suggestion-card {
    flex-direction: row;
    align-items: center;
    padding: 10px 12px;
    gap: 10px;
  }

  .card-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
  }

  .card-content {
    flex: 1;
  }

  .card-title {
    font-size: 13px;
    margin-bottom: 2px;
  }

  .card-desc {
    font-size: 11px;
  }

  .card-arrow {
    display: block;
    color: var(--text-secondary);
    font-size: 18px;
  }

  .chat-viewport {
    padding: 16px 12px 20px;
  }

  .input-section {
    padding: 6px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  }

  .input-container {
    padding: 6px 10px;
    border-radius: 14px;
  }

  .chat-textarea {
    font-size: 14px;
    padding: 4px 2px;
  }

  .disclaimer-text {
    font-size: 10px;
    margin-top: 4px;
  }

  .message-row.user .message-bubble {
    max-width: 90%;
  }

  .assistant-message-content {
    max-width: 95%;
  }
}

/* ==========================================================================
   Controle de Visões (Login vs Chat)
   ========================================================================== */

#loginView {
  display: none;
}

#chatView {
  display: none;
}

body.auth-pendente {
  height: 100vh;
  height: 100dvh;
  overflow-y: auto !important;
}

body.auth-pendente #loginView {
  display: flex;
}

body.auth-pendente #chatView {
  display: none !important;
}

body.auth-ok #loginView {
  display: none !important;
}

body.auth-ok #chatView {
  display: flex;
}

/* ==========================================================================
   Visão de Login Corporativo (Spec 013)
   ========================================================================== */

.login-view {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--bg-primary);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: relative;
}

/* Topbar do Login */
.login-topbar {
  height: var(--topbar-height);
  width: 100%;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  background-color: var(--bg-primary);
  flex-shrink: 0;
  z-index: 10;
}

.login-topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mj-logo-box {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.25);
  flex-shrink: 0;
}

.mj-logo-text {
  font-size: 14px;
  font-weight: 800;
  color: #FFFFFF;
  letter-spacing: -0.5px;
}

.workspace-branding {
  display: flex;
  flex-direction: column;
}

.workspace-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.workspace-sub {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-primary);
  letter-spacing: 0.5px;
  line-height: 1.2;
}

.login-topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.agent-status-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 6px 14px;
  border-radius: 9999px;
  cursor: default;
}

.status-dot-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--success);
  position: relative;
  flex-shrink: 0;
}

.status-dot-pulse::after {
  content: '';
  position: absolute;
  top: -3px;
  left: -3px;
  right: -3px;
  bottom: -3px;
  border-radius: 50%;
  border: 1.5px solid var(--success);
  animation: pulse-ring 2s cubic-bezier(0.455, 0.03, 0.515, 0.955) infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(0.8); opacity: 0.8; }
  50% { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(0.8); opacity: 0; }
}

.agent-status-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.agent-version {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
}

.agent-state {
  font-size: 10px;
  color: var(--text-secondary);
}

/* Área Central de Login */
.login-main {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 16px 28px;
  width: 100%;
  box-sizing: border-box;
}

.login-card {
  width: 100%;
  max-width: 440px;
  margin: auto;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  position: relative;
  overflow: hidden;
  transition: all var(--transition-speed) ease;
}

[data-theme="light"] .login-card {
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.07);
}

.login-card-stripe {
  height: 4px;
  width: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
}

.login-card-content {
  padding: 32px 28px 24px;
  display: flex;
  flex-direction: column;
}

.login-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 18px;
}

.login-avatar-wrapper {
  margin-bottom: 12px;
}

.login-avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  padding: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.2);
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: -0.3px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Alerta de erro */
.login-error-alert {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: rgba(239, 68, 68, 0.12);
  border: 1px solid #EF4444;
  color: #EF4444;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 18px;
  animation: shake 0.3s ease;
}

.login-error-alert.hidden {
  display: none !important;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* Formulário */
.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  height: 48px;
  padding: 0 14px;
  transition: all var(--transition-speed) ease;
}

.input-with-icon:focus-within {
  border-color: var(--accent-secondary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.input-with-icon.input-error {
  border-color: #EF4444 !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2) !important;
}

.field-icon {
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  margin-right: 10px;
  flex-shrink: 0;
}

.login-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  height: 100%;
}

.login-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

.toggle-password-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color var(--transition-speed) ease;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.toggle-password-btn:hover {
  color: var(--text-primary);
}

.eye-open-icon,
.eye-closed-icon {
  display: block;
  flex-shrink: 0;
}

.eye-open-icon.hidden,
.eye-closed-icon.hidden {
  display: none !important;
}

/* Custom Checkbox */
.form-check-group {
  display: flex;
  align-items: center;
  margin: 2px 0 4px;
}

.custom-checkbox-container {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-size: 14px;
  color: var(--text-secondary);
  transition: color var(--transition-speed) ease;
}

.custom-checkbox-container:hover {
  color: var(--text-primary);
}

.custom-checkbox-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.custom-checkbox-mark {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-speed) ease;
  color: #FFFFFF;
}

.custom-checkbox-input:checked ~ .custom-checkbox-mark {
  background-color: var(--accent-secondary);
  border-color: var(--accent-secondary);
}

.custom-checkbox-mark svg {
  opacity: 0;
  transform: scale(0.6);
  transition: all var(--transition-speed) ease;
}

.custom-checkbox-input:checked ~ .custom-checkbox-mark svg {
  opacity: 1;
  transform: scale(1);
}

.custom-checkbox-input:focus-visible ~ .custom-checkbox-mark {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.35);
}

.checkbox-label-text {
  font-size: 14px;
}

/* Botão Entrar */
.btn-login {
  width: 100%;
  height: 48px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  color: #FFFFFF;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 4px;
  transition: all var(--transition-speed) ease;
  position: relative;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.25);
}

.btn-login:hover:not(:disabled) {
  transform: scale(1.01);
  filter: brightness(1.08);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.35);
}

.btn-login:active:not(:disabled) {
  transform: scale(0.99);
}

.btn-login:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-login-text.hidden,
.btn-login-arrow.hidden {
  display: none !important;
}

.login-spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #FFFFFF;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.login-spinner.hidden {
  display: none !important;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Rodapé do Card */
.login-card-footer {
  margin-top: 24px;
}

.security-divider {
  display: flex;
  align-items: center;
  gap: 12px;
}

.divider-line {
  flex: 1;
  height: 1px;
  background-color: var(--border-subtle);
}

.security-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 12px;
}

.security-badge svg {
  color: var(--accent-primary);
  flex-shrink: 0;
}

.security-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.security-title {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
}

.security-subtitle {
  font-size: 10px;
  color: var(--text-secondary);
  opacity: 0.7;
}

/* Botão Sair da Sidebar */
.btn-logout {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-speed) ease;
}

.btn-logout:hover {
  background-color: rgba(239, 68, 68, 0.1);
  border-color: #EF4444;
  color: #EF4444;
}

.sidebar.collapsed .btn-logout {
  padding: 8px;
}

.sidebar.collapsed .btn-logout .logout-text {
  display: none;
}

/* Breakpoints do Login */
@media (max-width: 767px) {
  .login-topbar {
    padding: 0 14px;
    height: 56px;
  }

  .workspace-sub {
    display: none;
  }

  .agent-status-pill .agent-version {
    display: none;
  }

  .login-main {
    padding: 14px 12px calc(20px + env(safe-area-inset-bottom, 0px));
  }

  .login-card {
    border-radius: 16px;
    max-width: 100%;
  }

  .login-card-content {
    padding: 22px 16px 18px;
  }

  .login-avatar {
    width: 64px;
    height: 64px;
  }

  .login-header {
    margin-bottom: 14px;
  }

  .login-title {
    font-size: 20px;
    margin-bottom: 4px;
  }

  .login-subtitle {
    font-size: 13px;
  }

  .login-form {
    gap: 13px;
  }

  .login-input {
    font-size: 14px;
  }

  .btn-login {
    height: 46px;
    font-size: 14px;
  }

  .login-card-footer {
    margin-top: 18px;
  }
}

@media (max-width: 379px) {
  .login-main {
    padding: 8px 8px calc(14px + env(safe-area-inset-bottom, 0px));
  }

  .login-card-content {
    padding: 16px 12px 14px;
  }

  .login-avatar {
    width: 56px;
    height: 56px;
  }

  .login-title {
    font-size: 18px;
  }

  .login-subtitle {
    font-size: 12px;
  }

  .input-with-icon {
    height: 44px;
  }
}

@media (max-height: 720px) {
  .login-main {
    padding: 10px 12px 20px;
  }

  .login-card-content {
    padding: 20px 20px 18px;
  }

  .login-avatar {
    width: 60px;
    height: 60px;
  }

  .login-header {
    margin-bottom: 12px;
  }

  .login-title {
    font-size: 19px;
  }

  .login-form {
    gap: 12px;
  }

  .login-card-footer {
    margin-top: 14px;
  }
}

/* ==========================================================================
   Card de Confirmação com Checklist (Multi-itens / Multi-tarefas)
   ========================================================================== */

.confirmation-card {
  margin-top: 14px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: opacity var(--transition-speed) ease;
}

.confirmation-card.disabled {
  opacity: 0.6;
  pointer-events: none;
}

.confirmation-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.confirmation-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.confirmation-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  background-color: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  cursor: pointer;
  transition: background-color var(--transition-speed) ease, border-color var(--transition-speed) ease;
  user-select: none;
}

[data-theme="light"] .confirmation-item {
  background-color: rgba(0, 0, 0, 0.02);
}

.confirmation-item:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--accent-primary);
}

.confirmation-checkbox {
  margin-top: 2px;
  accent-color: var(--accent-primary);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.confirmation-item-label {
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-primary);
  word-break: break-word;
}

.confirmation-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}

.btn-confirm-yes,
.btn-confirm-no {
  flex: 1;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: transform 0.1s ease, filter var(--transition-speed) ease, opacity var(--transition-speed) ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
}

.btn-confirm-yes {
  background: linear-gradient(135deg, var(--accent-primary), #059669);
  color: #FFFFFF;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.btn-confirm-yes:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-confirm-no {
  background: var(--bg-surface-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.btn-confirm-no:hover:not(:disabled) {
  background-color: rgba(239, 68, 68, 0.15);
  color: #EF4444;
  border-color: rgba(239, 68, 68, 0.3);
  transform: translateY(-1px);
}

.btn-confirm-yes:disabled,
.btn-confirm-no:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}



/* Spec 024 — anexos das ferramentas do MCP */
.anexos-ia { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.anexo-ia { border: 1px solid rgba(127, 127, 127, .25); border-radius: 12px; padding: 8px 10px; font-size: 13px; }
.anexo-titulo { font-weight: 600; margin-bottom: 4px; }
.anexo-tabela { overflow: auto; max-height: 320px; }
.anexo-tabela table { border-collapse: collapse; width: 100%; }
.anexo-tabela th, .anexo-tabela td { text-align: left; padding: 3px 6px; border-bottom: 1px solid rgba(127, 127, 127, .2); white-space: nowrap; }
.anexo-card { display: inline-flex; flex-direction: column; margin: 0 12px 4px 0; }
.anexo-card b { font-size: 18px; }
