/* ============================================================
   AVNI — portfolio chat widget
   Reuses the "Ledger" design tokens from style.css (must load first).
   ============================================================ */

.avni-launcher {
  position: fixed;
  right: 24px;
  top: 92px;
  z-index: 999;
  width: 60px;
  height: 60px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.avni-launcher:hover {
  border-color: var(--teal);
  transform: translateY(-1px);
}

.avni-launcher.is-hidden {
  display: none;
}

.avni-launcher .avni-avatar {
  width: 40px;
  height: 40px;
}

.avni-panel {
  position: fixed;
  right: 24px;
  top: calc(160px + var(--avni-vv-top, 0px));
  z-index: 999;
  width: min(360px, calc(100vw - 48px));
  height: min(480px, calc(var(--avni-vh, 100vh) - 140px));
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.avni-panel.is-open {
  display: flex;
}

.avni-panel-header {
  padding: 16px 44px 16px 18px;
  border-bottom: 1px solid var(--line);
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
}

.avni-panel-header .avni-avatar {
  width: 36px;
  height: 36px;
  flex: none;
}

.avni-panel-header .avni-header-text {
  min-width: 0;
}

.avni-panel-header .avni-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
  margin: 0 0 4px;
}

.avni-panel-header h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 19px;
  margin: 0;
  color: var(--paper);
}

.avni-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px;
}

.avni-close:hover {
  color: var(--paper);
}

.avni-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.avni-messages::-webkit-scrollbar {
  width: 6px;
}

.avni-messages::-webkit-scrollbar-track {
  background: transparent;
}

.avni-messages::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 3px;
}

.avni-messages::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

.avni-msg {
  font-size: 14px;
  line-height: 1.5;
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 6px;
}

.avni-msg.user {
  align-self: flex-end;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  color: var(--paper);
}

.avni-msg.assistant {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--paper-dim);
}

.avni-msg.assistant.pending {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.avni-msg.assistant.pending .avni-avatar {
  width: 22px;
  height: 22px;
  flex: none;
  animation: avni-pulse 0.9s ease-in-out infinite;
}

@keyframes avni-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

@media (prefers-reduced-motion: reduce) {
  .avni-msg.assistant.pending .avni-avatar { animation: none; }
}

.avni-caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--teal);
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: avni-blink 0.9s step-end infinite;
}

@keyframes avni-blink {
  50% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .avni-caret { animation: none; }
}

.avni-msg.error {
  align-self: flex-start;
  color: var(--brass);
  border-color: var(--line);
  font-family: var(--font-mono);
  font-size: 12px;
}

.avni-input-wrap {
  flex: none;
  border-top: 1px solid var(--line);
}

.avni-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 12px 4px;
}

.avni-char-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  padding: 0 14px 10px;
}

.avni-char-count.is-near-limit {
  color: var(--brass);
}

.avni-input-row input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 10px 12px;
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 14px;
}

.avni-input-row input:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 1px;
}

.avni-input-row button {
  background: var(--teal);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  padding: 0 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.avni-input-row button:disabled {
  opacity: 0.5;
  cursor: default;
}

@media (max-width: 480px) {
  /* Full-screen docked sheet, not a floating card — header at top, messages
     fill the middle, input pinned directly above the keyboard. Bottom tracks
     --avni-kb-inset (the derived keyboard height) so the input never ends up
     underneath it; falls back to the home-indicator safe area when closed.
     Top adds --avni-vv-top (visualViewport.offsetTop) on top of the safe
     area — iOS Safari shifts the *visual* viewport down to scroll a focused
     input above the keyboard without ever scrolling the document, so a
     fixed `top` anchored only to the safe area drifts out of alignment with
     what's actually visible, exposing the real page through the gap.
     Bottom subtracts that same --avni-vv-top back out of --avni-kb-inset —
     kb-inset is the *total* shrinkage of the visible window from its
     baseline, but part of that shrinkage is the exact same downward shift
     already spent on `top`. Counting it in both reserves that space twice,
     leaving the panel's bottom edge short of the keyboard by vv-top's worth
     of exposed page underneath, for as long as the keyboard stays open. */
  .avni-panel {
    left: 0;
    right: 0;
    top: calc(env(safe-area-inset-top, 0px) + var(--avni-vv-top, 0px));
    bottom: max(calc(var(--avni-kb-inset, 0px) - var(--avni-vv-top, 0px)), 0px, env(safe-area-inset-bottom, 0px));
    width: auto;
    height: auto;
    border-radius: 0;
  }
  .avni-launcher { right: 12px; top: 92px; }
}

.avni-contact-card {
  margin-top: 10px;
  border-top: 1px solid var(--line-strong);
  padding-top: 10px;
}

.avni-contact-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 6px 0;
}

.avni-contact-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  flex: none;
}

.avni-contact-value {
  color: var(--paper);
  border-bottom: 1px solid var(--teal);
  padding-bottom: 1px;
  font-size: 13px;
  align-self: flex-start;
  overflow-wrap: anywhere;
}

.avni-contact-value:hover {
  opacity: 0.8;
}

.avni-nudge {
  position: fixed;
  right: 24px;
  top: 160px;
  z-index: 998;
  width: min(260px, calc(100vw - 48px));
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.avni-nudge.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.avni-nudge::before {
  content: "";
  position: absolute;
  top: -7px;
  right: 22px;
  width: 12px;
  height: 12px;
  background: var(--bg-raised);
  border-left: 1px solid var(--line-strong);
  border-top: 1px solid var(--line-strong);
  transform: rotate(45deg);
}

.avni-nudge p {
  margin: 0;
  color: var(--paper-dim);
  font-size: 13px;
  line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) {
  .avni-nudge { transition: none; }
}

@media (max-width: 480px) {
  .avni-nudge { right: 12px; top: 160px; }
}
