/* AI assistant — admin settings tab (Phase A). Uses the app's theme variables so it follows light/dark mode. */

.ai-admin-subtitle {
  margin: 18px 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ui-text-primary, #1d1d1f);
}

.ai-admin-muted {
  margin: 4px 0;
  font-size: 12px;
  font-weight: 400;
  color: var(--ui-text-secondary, #6e6e73);
}

.ai-admin-model {
  margin: 8px 0;
  font-size: 12px;
  color: var(--ui-text-primary, #1d1d1f);
}

.ai-admin-notice {
  margin: 8px 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(217, 119, 6, 0.35);
  background: rgba(217, 119, 6, 0.1);
  color: var(--ui-text-primary, #1d1d1f);
  font-size: 12px;
}

.ai-admin-roles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.ai-admin-role {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ui-text-primary, #1d1d1f);
  cursor: pointer;
}

.ai-admin-limit-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-admin-limit-row input {
  width: 180px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--ui-panel-muted-border, rgba(0, 0, 0, 0.15));
  background: transparent;
  color: var(--ui-text-primary, #1d1d1f);
  font: inherit;
}

.ai-admin-limit-row input:focus-visible {
  outline: 2px solid var(--ui-focus-ring-color, #2563eb);
  outline-offset: 1px;
}

.ai-admin-error {
  min-height: 1em;
  margin: 4px 0;
  font-size: 12px;
  color: #dc2626;
}

.ai-admin-actions {
  display: flex;
  justify-content: flex-end;
  margin: 8px 0 4px;
}

.ai-admin-actions .admin-btn-primary {
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
}

.ai-admin-actions .admin-btn-primary:disabled {
  opacity: 0.6;
  cursor: progress;
}

.ai-admin-usage {
  margin-top: 12px;
  padding-top: 4px;
  border-top: 1px solid var(--ui-panel-muted-border, rgba(0, 0, 0, 0.1));
}

.ai-admin-usage-line {
  font-size: 12px;
  color: var(--ui-text-primary, #1d1d1f);
}

.ai-admin-badge {
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(220, 38, 38, 0.12);
  color: #dc2626;
  font-size: 11px;
  font-weight: 600;
}

.ai-admin-progress {
  height: 6px;
  margin: 6px 0;
  border-radius: 999px;
  background: var(--ui-panel-muted-surface, rgba(0, 0, 0, 0.06));
  overflow: hidden;
}

.ai-admin-progress-fill {
  height: 100%;
  background: var(--ui-accent, #2563eb);
}

.ai-admin-progress-fill.is-full {
  background: #dc2626;
}

.ai-admin-table {
  width: 100%;
  margin-top: 8px;
  border-collapse: collapse;
  font-size: 12px;
  color: var(--ui-text-primary, #1d1d1f);
}

.ai-admin-table th,
.ai-admin-table td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--ui-panel-muted-border, rgba(0, 0, 0, 0.08));
  text-align: left;
}

.ai-admin-table th {
  font-weight: 600;
  color: var(--ui-text-secondary, #6e6e73);
}

.ai-admin-num {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
}

.ai-admin-empty {
  font-size: 12px;
  color: var(--ui-text-secondary, #6e6e73);
}

/* ---------------------------------------------------------------------------
   Floating chat (Phase D). Above the page and viewer, below modals (13000+) and toasts (15000).
   --------------------------------------------------------------------------- */

.ai-chat {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 12000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  font-family: var(--font-ui, inherit);
}

.ai-chat-fab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 999px;
  /* "Chrome" style, like the viewer's floating panels and toolbar (css/index.css tokens): glass surface, thin border,
     soft shadow, accent-coloured icon. Follows the light/dark theme through the tokens. */
  border: var(--ui-chrome-border, 1px solid rgba(0, 0, 0, 0.08));
  background: var(--ui-chrome-surface, rgba(255, 255, 255, 0.85));
  backdrop-filter: var(--ui-backdrop-filter, none);
  -webkit-backdrop-filter: var(--ui-backdrop-filter, none);
  box-shadow: var(--ui-chrome-shadow, 0 6px 16px rgba(0, 0, 0, 0.12));
  color: var(--ui-accent, #2563eb);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.15s ease;
}

.ai-chat-fab:hover {
  /* Accent tint over the glass surface (the tint alone would be see-through over the 3D). */
  background:
    linear-gradient(var(--ui-accent-soft-bg, rgba(37, 99, 235, 0.15)), var(--ui-accent-soft-bg, rgba(37, 99, 235, 0.15))),
    var(--ui-chrome-surface, rgba(255, 255, 255, 0.85));
}

.ai-chat-fab:active {
  transform: scale(0.96);
}

.ai-chat.is-open .ai-chat-fab {
  /* Accent tint over the glass surface (the tint alone would be see-through over the 3D). */
  background:
    linear-gradient(var(--ui-accent-soft-bg, rgba(37, 99, 235, 0.15)), var(--ui-accent-soft-bg, rgba(37, 99, 235, 0.15))),
    var(--ui-chrome-surface, rgba(255, 255, 255, 0.85));
}

.ai-chat-fab-icon {
  display: inline-flex;
  font-size: 22px;
  line-height: 1;
}

.ai-chat-fab-icon svg {
  width: 24px;
  height: 24px;
  stroke-width: 2;
}

.ai-chat-fab:focus-visible,
.ai-chat-icon-btn:focus-visible,
.ai-chat-send:focus-visible,
.ai-chat-chip:focus-visible {
  outline: 2px solid var(--ui-focus-ring-color, #2563eb);
  outline-offset: 2px;
}

.ai-chat.is-open .ai-chat-fab {
  order: 2;
}

.ai-chat-panel {
  order: 1;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 120px));
  border: var(--ui-chrome-border, 1px solid rgba(0, 0, 0, 0.08));
  border-radius: var(--ui-chrome-radius, 12px);
  background: var(--ui-chrome-surface, #fff);
  backdrop-filter: var(--ui-backdrop-filter, none);
  box-shadow: var(--ui-chrome-shadow, 0 6px 16px rgba(0, 0, 0, 0.12));
  color: var(--ui-text-primary, #1d1d1f);
  overflow: hidden;
}

.ai-chat-panel[hidden] {
  display: none;
}

.ai-chat-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--ui-panel-muted-border, rgba(0, 0, 0, 0.08));
}

.ai-chat-title-wrap {
  flex: 1;
  min-width: 0;
}

.ai-chat-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.ai-chat-subtitle {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--ui-text-secondary, #5b6470);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-chat-icon-btn {
  padding: 4px 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ui-text-secondary, #5b6470);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.ai-chat-icon-btn:hover {
  background: var(--ui-panel-muted-surface, rgba(0, 0, 0, 0.05));
  color: var(--ui-text-primary, #1d1d1f);
}

.ai-chat-close {
  font-size: 18px;
  line-height: 1;
}

.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-chat-msg {
  max-width: 88%;
  padding: 8px 11px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.ai-chat-msg p {
  margin: 0 0 6px;
}

.ai-chat-msg p:last-child {
  margin-bottom: 0;
}

.ai-chat-msg ul {
  margin: 0 0 6px;
  padding-left: 18px;
}

.ai-chat-msg--user {
  align-self: flex-end;
  background: var(--ui-accent, #2563eb);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-chat-msg--assistant,
.ai-chat-msg--pending,
.ai-chat-msg--hint {
  align-self: flex-start;
  background: var(--ui-panel-muted-surface, rgba(0, 0, 0, 0.04));
  border: 1px solid var(--ui-panel-muted-border, rgba(0, 0, 0, 0.06));
  border-bottom-left-radius: 4px;
}

.ai-chat-msg--hint {
  color: var(--ui-text-secondary, #5b6470);
}

.ai-chat-msg--pending {
  color: var(--ui-text-secondary, #5b6470);
  font-style: italic;
  animation: ai-chat-pulse 1.4s ease-in-out infinite;
}

.ai-chat-msg--error {
  align-self: flex-start;
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.25);
  color: var(--ui-text-primary, #1d1d1f);
}

@keyframes ai-chat-pulse {
  50% {
    opacity: 0.55;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-chat-msg--pending {
    animation: none;
  }
}

.ai-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.ai-chat-chip {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(37, 99, 235, 0.3);
  background: var(--ui-accent-soft-bg, rgba(37, 99, 235, 0.12));
  color: var(--ui-accent, #2563eb);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.ai-chat-chip:disabled {
  opacity: 0.6;
  cursor: progress;
}

.ai-chat-viewer-status {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--ui-text-secondary, #5b6470);
}

.ai-chat-viewer-status:empty {
  display: none;
}

.ai-chat-notice {
  margin: 0;
  padding: 8px 12px;
  border-top: 1px solid var(--ui-panel-muted-border, rgba(0, 0, 0, 0.08));
  background: rgba(217, 119, 6, 0.1);
  font-size: 12px;
}

.ai-chat-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--ui-panel-muted-border, rgba(0, 0, 0, 0.08));
}

.ai-chat-input {
  flex: 1;
  resize: none;
  padding: 7px 9px;
  border-radius: 10px;
  border: 1px solid var(--ui-panel-muted-border, rgba(0, 0, 0, 0.15));
  background: transparent;
  color: var(--ui-text-primary, #1d1d1f);
  font: inherit;
  font-size: 13px;
}

.ai-chat-input:focus-visible {
  outline: 2px solid var(--ui-focus-ring-color, #2563eb);
  outline-offset: 0;
}

.ai-chat-send {
  align-self: flex-end;
  padding: 8px 14px;
  border: none;
  border-radius: 10px;
  background: var(--ui-accent, #2563eb);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.ai-chat-send:disabled,
.ai-chat-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 600px) {
  .ai-chat {
    right: 16px;
    bottom: 16px;
  }

  .ai-chat-panel {
    width: calc(100vw - 32px);
    height: calc(100vh - 100px);
  }
}

/* Grounding: where the numbers come from, and a warning when some couldn't be verified. */
.ai-chat-sources {
  margin: 8px 0 0;
  padding-top: 6px;
  border-top: 1px solid var(--ui-panel-muted-border, rgba(0, 0, 0, 0.08));
  font-size: 11px;
  line-height: 1.4;
  color: var(--ui-text-secondary, #5b6470);
}

.ai-chat-sources-title {
  font-weight: 600;
}

.ai-chat-warning {
  margin: 0 0 8px !important;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid rgba(217, 119, 6, 0.4);
  background: rgba(217, 119, 6, 0.12);
  font-size: 12px;
}

/* Tabs: "Conversa" / "Ajuda" (plans/ai-assistant-help-tab.plan.md) */
.ai-chat-tabs {
  display: flex;
  gap: 4px;
  padding: 6px 12px 0;
  border-bottom: 1px solid var(--ui-panel-muted-border, rgba(0, 0, 0, 0.08));
}

.ai-chat-tab {
  padding: 6px 10px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--ui-text-secondary, #5b6470);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.ai-chat-tab:hover {
  color: var(--ui-text-primary, #1d1d1f);
}

.ai-chat-tab.is-active {
  color: var(--ui-accent, #2563eb);
  border-bottom-color: var(--ui-accent, #2563eb);
}

.ai-chat-tab:focus-visible {
  outline: 2px solid var(--ui-focus-ring-color, #2563eb);
  outline-offset: -2px;
}

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

.ai-chat-pane[hidden] {
  display: none;
}

.ai-chat-help {
  overflow-y: auto;
  padding: 4px 14px 14px;
  font-size: 12.5px;
  line-height: 1.5;
}

.ai-chat-help-title {
  margin: 14px 0 4px;
  font-size: 13px;
  font-weight: 600;
}

.ai-chat-help-group {
  margin: 10px 0 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ui-text-secondary, #5b6470);
}

.ai-chat-help .ai-chat-chips {
  margin-top: 4px;
}

.ai-chat-help-muted {
  margin: 0;
  color: var(--ui-text-secondary, #5b6470);
}

.ai-chat-help ul {
  margin: 4px 0 0;
  padding-left: 18px;
}

.ai-chat-help li + li {
  margin-top: 4px;
}

.ai-chat-help-counter {
  margin: 4px 0 0;
}

/* Answer formatting: headings, numbered lists, tables (answer-format.js) */
.ai-chat-msg ol {
  margin: 0 0 6px;
  padding-left: 20px;
}

.ai-chat-msg li + li {
  margin-top: 2px;
}

.ai-chat-msg .ai-chat-heading {
  margin: 8px 0 4px;
}

.ai-chat-msg code {
  padding: 0 4px;
  border-radius: 4px;
  background: var(--ui-panel-muted-surface, rgba(0, 0, 0, 0.06));
  font-size: 12px;
}

/* Wide tables scroll sideways inside the message instead of stretching the panel. */
.ai-chat-table-wrap {
  max-width: 100%;
  margin: 4px 0 8px;
  overflow-x: auto;
}

.ai-chat-table {
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.35;
}

.ai-chat-table th,
.ai-chat-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--ui-panel-muted-border, rgba(0, 0, 0, 0.1));
  text-align: left;
  vertical-align: top;
}

.ai-chat-table th {
  font-weight: 600;
  white-space: nowrap;
}

.ai-chat-table .ai-chat-num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.ai-chat-table tbody tr:last-child td {
  border-bottom: none;
}

/* Bigger chat window (header button "⤢"), remembered per browser. Never larger than the screen. */
.ai-chat.is-expanded .ai-chat-panel {
  width: min(900px, calc(100vw - 48px));
  height: min(85vh, calc(100vh - 120px));
}

.ai-chat.is-expanded .ai-chat-msg {
  max-width: 92%;
}

.ai-chat-expand {
  font-size: 15px;
  line-height: 1;
}

/* "Sobre a seleção" tag above the question box (plans/ai-assistant-selection.plan.md, step 1c) */
.ai-chat-selection {
  padding: 6px 12px 0;
}

.ai-chat-selection[hidden] {
  display: none;
}

.ai-chat-selection-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--ui-panel-muted-border, rgba(0, 0, 0, 0.15));
  background: transparent;
  color: var(--ui-text-secondary, #5b6470);
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

.ai-chat-selection-toggle::before {
  content: '';
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
}

.ai-chat-selection.is-on .ai-chat-selection-toggle {
  border-color: var(--ui-accent, #2563eb);
  background: var(--ui-accent-soft-bg, rgba(37, 99, 235, 0.15));
  color: var(--ui-accent, #2563eb);
  font-weight: 600;
}

.ai-chat-selection.is-on .ai-chat-selection-toggle::before {
  background: currentColor;
}

.ai-chat-selection.is-warning .ai-chat-selection-toggle {
  border-color: rgba(217, 119, 6, 0.4);
  background: rgba(217, 119, 6, 0.1);
  color: var(--color-warning, #b26a00);
  cursor: default;
}

.ai-chat-selection.is-warning .ai-chat-selection-toggle::before {
  display: none;
}

.ai-chat-selection-toggle:focus-visible {
  outline: 2px solid var(--ui-focus-ring-color, #2563eb);
  outline-offset: 2px;
}

/* "Mostrar no 3D" next to the status when the open plan can't show the elements (plans/ai-assistant-plans-2d.plan.md, 2b) */
.ai-chat-chip-inline {
  margin-left: 4px;
  vertical-align: baseline;
}
