/* The AI helper: a button fixed to the bottom right corner of every module that
   has a helper, and a panel sliding in from the right. Teal sets the helper
   apart from figures computed by the dashboard itself. */
.ai-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 22px 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--board-current);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(20, 60, 58, .28);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}
.ai-launcher:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(20, 60, 58, .34); }
.ai-launcher:focus-visible { outline: 3px solid rgba(255, 61, 0, .45); outline-offset: 3px; }
.ai-launcher[hidden], body.ai-drawer-open .ai-launcher { display: none; }

.ai-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  width: min(440px, 100vw);
  border-left: 1px solid var(--board-rule-strong);
  background: #fff;
  box-shadow: -12px 0 32px rgba(40, 30, 10, .14);
  animation: ai-slide-in .2s ease-out;
}
.ai-drawer[hidden] { display: none; }
@keyframes ai-slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.ai-drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--board-rule); border-top: 4px solid var(--board-current); }
.ai-drawer-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.ai-drawer-head p { margin: 6px 0 0; color: var(--board-muted); font-size: 11.5px; line-height: 1.45; }
.ai-drawer-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ai-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 16px 20px 18px; }
.ai-panel[hidden] { display: none; }

.ai-title { display: flex; align-items: center; gap: 8px; }
.ai-badge { display: inline-grid; place-items: center; min-width: 24px; height: 18px; padding: 0 5px; border-radius: 4px; background: var(--board-current); color: #fff; font-size: 10px; font-weight: 800; letter-spacing: 0.04em; }
.ai-log { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; margin-bottom: 12px; }
.ai-intro { margin: 0; color: var(--board-muted); font-size: 12.5px; line-height: 1.5; }
.ai-message { font-size: 13px; line-height: 1.55; color: var(--board-ink); }
.ai-message p { margin: 0 0 6px; }
.ai-message p:last-child { margin-bottom: 0; }
.ai-message ul { margin: 0 0 6px; padding-left: 18px; }
.ai-message li { margin-bottom: 3px; }
.ai-message.user { align-self: flex-end; max-width: 85%; padding: 8px 12px; border-radius: 12px 12px 2px 12px; background: #f1f2ec; }
.ai-message.assistant { padding-left: 10px; border-left: 2px solid var(--board-current); }
.ai-message.error { color: var(--board-bad); font-weight: 600; }
.ai-suggestions { display: grid; gap: 6px; margin-bottom: 12px; }
.ai-suggestions[hidden] { display: none; }
.ai-form { display: grid; gap: 8px; }
.ai-input { width: 100%; min-height: 64px; padding: 10px 12px; border: 1px solid var(--board-rule-strong); border-radius: 10px; background: #fff; color: var(--board-ink); font: inherit; font-size: 13px; resize: vertical; }
.ai-input:focus-visible { outline: 2px solid var(--board-current); outline-offset: 1px; }
.ai-form-actions { display: flex; gap: 8px; }
.ai-form-actions [hidden] { display: none; }
.ai-status { min-height: 1em; margin: 6px 0 0; color: var(--board-muted); font-size: 11px; }

/* A list of corrections drafted by the helper, waiting to be saved. */
.ai-draft { display: grid; gap: 8px; padding: 12px 14px; border: 1px dashed var(--board-current); border-radius: 10px; background: #f6fbfa; font-size: 13px; }
.ai-draft ol, .result-corrections ol { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.ai-draft-what { display: block; font-weight: 600; }
.ai-draft-detail { display: block; color: var(--board-muted); font-size: 12px; }
.ai-draft-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.result-corrections { display: grid; gap: 12px; }
.result-corrections article { padding: 10px 12px; border: 1px solid var(--board-rule); border-radius: 8px; font-size: 13px; }
.result-corrections header { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; margin-bottom: 8px; }
.result-corrections header span { color: var(--board-muted); font-size: 11.5px; }
.result-corrections a { color: var(--board-ink); font-size: 11.5px; font-weight: 700; }

/* On a wide screen the panel moves the page aside instead of covering it. */
@media (min-width: 1180px) { body.ai-drawer-open .app { margin-right: min(440px, 100vw); } }
/* Room at the bottom of the page so the button never covers the last row. */
body:has(.ai-launcher:not([hidden])) .main { padding-bottom: 96px; }
@media (max-width: 700px) {
  .ai-launcher { right: 16px; bottom: 16px; min-height: 48px; padding: 0 18px 0 14px; }
}
@media (prefers-reduced-motion: reduce) { .ai-drawer { animation: none; } .ai-launcher { transition: none; } }
