/* ==========================================================================
   PLASWILL ASSISTENTE — ENTERPRISE COPILOT STYLESHEET
   Design System Corporativo Plaswill • Nextcloud Assistant & Indicators Copilot
   Tokens Oficiais: PLAS-API-001 (Branding & Identidade Visual)
   ========================================================================== */

:root {
  /* Plaswill Official Palette */
  --plaswill-yellow: #FFDE00;
  --plaswill-yellow-hover: #E6C800;
  --plaswill-yellow-subtle: #FFFDE6;
  --plaswill-yellow-border: #F0D400;
  --plaswill-graphite: #171A1E;
  --plaswill-blue-corporate: #09506A;
  --plaswill-blue-hover: #073D52;
  --plaswill-dark-bg: #080C14;

  /* Surfaces & Borders */
  --plaswill-surface-white: #FFFFFF;
  --plaswill-surface-alt: #F8FAFC;
  --plaswill-surface-muted: #F1F5F9;
  --plaswill-border: #E2E8F0;
  --plaswill-border-subtle: #EDF2F7;

  /* Text & Contrast (WCAG 2.2 AA/AAA) */
  --plaswill-text-main: #171A1E;
  --plaswill-text-muted: #64748B;
  --plaswill-text-subtle: #94A3B8;

  /* Elevations */
  --shadow-fab: 0 8px 24px -4px rgba(23, 26, 30, 0.22), 0 2px 6px -1px rgba(23, 26, 30, 0.08);
  --shadow-fab-hover: 0 12px 30px -4px rgba(23, 26, 30, 0.28), 0 4px 10px -2px rgba(23, 26, 30, 0.12);
  --shadow-panel: 0 20px 50px -12px rgba(23, 26, 30, 0.20), 0 0 0 1px rgba(226, 232, 240, 0.9);
}

/* ==========================================================================
   1. FLOATING ACTION BUTTON (FAB) — 56×56 PX
   ========================================================================== */
body.is-framed .ia-fab-container,
.is-framed #ia-fab-container,
html.is-framed .ia-fab-container {
  display: none !important;
}

.ia-fab-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10040;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ia-fab-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: var(--plaswill-yellow);
  border: 1px solid var(--plaswill-yellow-border);
  color: var(--plaswill-graphite);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-fab);
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
  user-select: none;
  padding: 0;
}

.ia-fab-btn:hover {
  background-color: var(--plaswill-yellow-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-fab-hover);
}

.ia-fab-btn:active {
  transform: scale(0.94);
}

.ia-fab-btn:focus-visible {
  ring: 4px;
  box-shadow: 0 0 0 4px rgba(9, 80, 106, 0.35), var(--shadow-fab);
}

.ia-fab-btn.is-open {
  background-color: var(--plaswill-graphite);
  color: #FFFFFF;
  border-color: #2D3748;
}

/* Floating Tooltip */
.ia-fab-tooltip {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  background-color: var(--plaswill-graphite);
  color: #FFFFFF;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: all 0.18s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ia-fab-tooltip kbd {
  background: rgba(255, 255, 255, 0.15);
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 0.65rem;
  color: var(--plaswill-yellow);
}

.ia-fab-container:hover .ia-fab-tooltip {
  opacity: 1;
  transform: translateY(0);
}

/* ==========================================================================
   2. DESKTOP FLOATING PANEL (460px — 5 REGIONS)
   ========================================================================== */
.ia-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 20, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 10050;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease-in-out;
}

/* In Desktop, the backdrop is unobtrusive so the user keeps visibility */
@media (min-width: 1024px) {
  .ia-drawer-backdrop {
    display: none; /* Non-blocking in desktop so background dashboards remain fully interactive */
  }
}

.ia-drawer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 460px;
  max-width: calc(100vw - 32px);
  height: 88vh;
  max-height: 780px;
  background-color: var(--plaswill-surface-white);
  border: 1px solid var(--plaswill-border);
  border-radius: 16px;
  z-index: 10060;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-panel);
  opacity: 0;
  transform: translateY(20px) scale(0.97);
  pointer-events: none;
  transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--plaswill-text-main);
}

.ia-drawer.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Expanded View Mode (Maximized for Large Tables & Charts) */
.ia-drawer.is-expanded {
  width: 760px;
}

/* ==========================================================================
   3. REGIÃO 1: CABEÇALHO INSTITUCIONAL (64px)
   ========================================================================== */
.ia-header {
  height: 64px;
  padding: 0 16px;
  background-color: var(--plaswill-surface-white);
  border-bottom: 1px solid var(--plaswill-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.ia-header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ia-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background-color: var(--plaswill-yellow);
  border: 1px solid var(--plaswill-yellow-border);
  color: var(--plaswill-graphite);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.ia-title-box {
  display: flex;
  flex-direction: column;
}

.ia-main-title {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--plaswill-graphite);
  letter-spacing: -0.015em;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.2;
}

.ia-live-pill {
  font-size: 0.62rem;
  font-weight: 700;
  color: #047857;
  background-color: #ECFDF5;
  border: 1px solid #A7F3D0;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ia-sub-title {
  font-size: 0.72rem;
  color: var(--plaswill-text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.ia-sub-title .dot-active {
  width: 6px;
  height: 6px;
  background-color: #10B981;
  border-radius: 50%;
  display: inline-block;
}

.ia-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ia-btn-icon {
  background: transparent;
  border: none;
  color: var(--plaswill-text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
}

.ia-btn-icon:hover {
  background-color: var(--plaswill-surface-muted);
  color: var(--plaswill-text-main);
}

.ia-btn-icon.btn-close:hover {
  background-color: #FEE2E2;
  color: #DC2626;
}

/* ==========================================================================
   4. REGIÃO 2: NAVEGAÇÃO ENTRE FUNCIONALIDADES (Nextcloud Real Tabs)
   ========================================================================== */
.ia-nav-tabs {
  background-color: var(--plaswill-surface-alt);
  border-bottom: 1px solid var(--plaswill-border);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  overflow-x: auto;
}

.ia-nav-tabs-list {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ia-tab-item {
  padding: 5px 10px;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--plaswill-text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: all 0.18s ease;
}

.ia-tab-item:hover {
  color: var(--plaswill-text-main);
  background-color: #E2E8F0;
}

.ia-tab-item.active {
  color: var(--plaswill-text-main);
  background-color: var(--plaswill-surface-white);
  border-color: var(--plaswill-border);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.ia-tab-badge {
  background-color: #E2E8F0;
  color: var(--plaswill-text-main);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 10px;
}

/* ==========================================================================
   5. REGIÃO 3: CONTEXTO DA CONVERSA & "LEMBRE-SE DISSO"
   ========================================================================== */
.ia-context-bar {
  padding: 8px 16px;
  background-color: var(--plaswill-surface-white);
  border-bottom: 1px solid var(--plaswill-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.76rem;
  flex-shrink: 0;
}

.ia-context-title {
  font-weight: 600;
  color: var(--plaswill-text-main);
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}

.ia-context-title .title-indicator {
  width: 7px;
  height: 7px;
  background-color: var(--plaswill-yellow);
  border-radius: 50%;
  border: 1px solid var(--plaswill-yellow-border);
  flex-shrink: 0;
}

.ia-context-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.ia-memory-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--plaswill-text-muted);
  cursor: pointer;
  background: var(--plaswill-surface-alt);
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--plaswill-border);
  user-select: none;
}

.ia-memory-toggle input[type="checkbox"] {
  accent-color: var(--plaswill-yellow-hover);
  cursor: pointer;
}

.ia-btn-new-chat {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--plaswill-text-main);
  background-color: var(--plaswill-surface-white);
  border: 1px solid var(--plaswill-border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ia-btn-new-chat:hover {
  background-color: var(--plaswill-surface-muted);
}

/* ==========================================================================
   6. REGIÃO 4: HISTÓRICO DE MENSAGENS COM ROLAGEM INDEPENDENTE
   ========================================================================== */
.ia-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  background-color: #FAFAFA;
}

.ia-body::-webkit-scrollbar {
  width: 6px;
}
.ia-body::-webkit-scrollbar-track {
  background: transparent;
}
.ia-body::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 999px;
}
.ia-body::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

/* Welcome Card */
.ia-welcome-card {
  background-color: var(--plaswill-surface-white);
  border: 1px solid var(--plaswill-border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.ia-welcome-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ia-welcome-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background-color: var(--plaswill-yellow-subtle);
  border: 1px solid rgba(255, 222, 0, 0.4);
  color: #B45309;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ia-welcome-title {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--plaswill-graphite);
}

.ia-welcome-desc {
  font-size: 0.8rem;
  color: var(--plaswill-text-muted);
  line-height: 1.5;
}

.ia-chips-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--plaswill-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 6px;
}

.ia-chips-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ia-suggestion-chip {
  background-color: var(--plaswill-surface-alt);
  border: 1px solid var(--plaswill-border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.78rem;
  color: var(--plaswill-text-main);
  text-align: left;
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ia-suggestion-chip:hover {
  background-color: var(--plaswill-yellow-subtle);
  border-color: var(--plaswill-yellow);
  transform: translateX(2px);
}

.ia-suggestion-chip::after {
  content: "→";
  color: var(--plaswill-text-muted);
  transition: transform 0.18s ease;
}

.ia-suggestion-chip:hover::after {
  color: var(--plaswill-graphite);
  transform: translateX(3px);
}

/* Messages Structure */
.ia-msg-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 100%;
}

.ia-msg-row.user {
  align-items: flex-end;
}

.ia-msg-row.assistant {
  align-items: flex-start;
}

.ia-msg-author {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--plaswill-text-muted);
  padding: 0 4px;
}

/* User Bubble — Soft Institutional Yellow */
.ia-bubble.user {
  background-color: var(--plaswill-yellow);
  color: var(--plaswill-graphite);
  font-size: 0.86rem;
  line-height: 1.5;
  padding: 10px 14px;
  border-radius: 16px 16px 3px 16px;
  max-width: 85%;
  border: 1px solid var(--plaswill-yellow-border);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

/* Assistant Bubble — Clean White Card with Subtle Border */
.ia-bubble.assistant {
  background-color: var(--plaswill-surface-white);
  border: 1px solid var(--plaswill-border);
  color: var(--plaswill-text-main);
  font-size: 0.86rem;
  line-height: 1.55;
  padding: 14px 16px;
  border-radius: 16px 16px 16px 3px;
  max-width: 96%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* Markdown formatting inside Assistant bubble */
.ia-bubble.assistant h1,
.ia-bubble.assistant h2,
.ia-bubble.assistant h3,
.ia-bubble.assistant h4 {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  color: var(--plaswill-graphite);
  margin: 12px 0 6px 0;
  font-size: 0.92rem;
  font-weight: 700;
}

.ia-bubble.assistant p {
  margin: 6px 0;
}

.ia-bubble.assistant ul,
.ia-bubble.assistant ol {
  margin: 6px 0 8px 18px;
  padding: 0;
}

.ia-bubble.assistant li {
  margin-bottom: 4px;
}

.ia-bubble.assistant strong {
  color: var(--plaswill-graphite);
  font-weight: 600;
}

/* Tables inside Assistant bubble */
.ia-bubble.assistant table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 0.78rem;
  background-color: var(--plaswill-surface-white);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--plaswill-border);
}

.ia-bubble.assistant th,
.ia-bubble.assistant td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--plaswill-border);
}

.ia-bubble.assistant th {
  background-color: var(--plaswill-surface-alt);
  color: var(--plaswill-graphite);
  font-weight: 600;
}

.ia-bubble.assistant tr:last-child td {
  border-bottom: none;
}

/* Chart Container inside Bubble */
.ia-chart-container {
  width: 100%;
  height: 220px;
  margin: 12px 0 8px 0;
  background-color: var(--plaswill-surface-alt);
  border: 1px solid var(--plaswill-border);
  border-radius: 8px;
  overflow: hidden;
}

/* Action Link to Full Dashboard */
.ia-dashboard-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  background-color: var(--plaswill-surface-alt);
  border: 1px solid var(--plaswill-border);
  color: var(--plaswill-blue-corporate);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  text-decoration: none;
}

.ia-dashboard-link-btn:hover {
  background-color: #E0F2FE;
  border-color: #BAE6FD;
}

/* Telemetry Pills */
.ia-tools-telemetry {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--plaswill-border-subtle);
  font-size: 0.68rem;
  color: var(--plaswill-text-muted);
}

.ia-tools-telemetry span.tool-tag {
  background-color: var(--plaswill-surface-alt);
  border: 1px solid var(--plaswill-border);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--plaswill-graphite);
  font-family: monospace;
}

/* Typing / Loading Indicator */
.ia-typing-bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: var(--plaswill-surface-white);
  border: 1px solid var(--plaswill-border);
  padding: 8px 14px;
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.ia-typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ia-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--plaswill-yellow-hover);
  animation: ia-dot-bounce 1.4s infinite ease-in-out both;
}

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

@keyframes ia-dot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

.ia-typing-label {
  font-size: 0.75rem;
  color: var(--plaswill-text-muted);
}

/* ==========================================================================
   7. REGIÃO 5: CAMPO DE INTERAÇÃO FIXO (Composer Compacto + Disclaimer)
   ========================================================================== */
.ia-footer {
  padding: 12px 16px;
  background-color: var(--plaswill-surface-white);
  border-top: 1px solid var(--plaswill-border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ia-composer-box {
  background-color: var(--plaswill-surface-alt);
  border: 1px solid var(--plaswill-border);
  border-radius: 12px;
  padding: 4px 6px 4px 10px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  transition: all 0.18s ease;
}

.ia-composer-box:focus-within {
  background-color: var(--plaswill-surface-white);
  border-color: var(--plaswill-yellow-border);
  box-shadow: 0 0 0 3px rgba(255, 222, 0, 0.25);
}

.ia-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--plaswill-text-main);
  resize: none;
  padding: 6px 0;
  min-height: 20px;
  max-height: 110px;
  line-height: 1.4;
}

.ia-textarea::placeholder {
  color: var(--plaswill-text-subtle);
}

.ia-composer-attach-btn {
  background: transparent;
  border: none;
  color: var(--plaswill-text-muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.ia-composer-attach-btn:hover {
  background-color: #E2E8F0;
  color: var(--plaswill-text-main);
}

.ia-send-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background-color: var(--plaswill-yellow);
  border: 1px solid var(--plaswill-yellow-border);
  color: var(--plaswill-graphite);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
  flex-shrink: 0;
}

.ia-send-btn:hover {
  background-color: var(--plaswill-yellow-hover);
}

.ia-send-btn:active {
  transform: scale(0.95);
}

.ia-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.ia-legal-disclaimer {
  font-size: 0.68rem;
  color: var(--plaswill-text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}

/* ==========================================================================
   8. RESPONSIVIDADE & EXPERIÊNCIA MOBILE (< 768px)
   ========================================================================== */
@media (max-width: 768px) {
  .ia-drawer-backdrop {
    display: block; /* Backdrop active in mobile bottom sheet */
  }

  .ia-drawer {
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }

  .ia-fab-container {
    bottom: 16px;
    right: 16px;
  }

  .ia-header {
    height: 56px;
    padding-top: env(safe-area-inset-top, 0);
  }

  .ia-footer {
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  }
}
