/* ============================================================
   Portfolio chat widget
   Uses only the site's existing design tokens (--panel, --line,
   --blue, --text, --muted, --accent-ink, --chip-bg, --radius)
   so it inherits both the dark and light themes automatically.
   Layered at z-index 150: above page content, below the project
   modal (200) and the toast (300).
   ============================================================ */

/* ---------- launcher bubble ---------- */
.chat-fab{
  position:fixed;z-index:150;
  right:calc(24px + env(safe-area-inset-right));
  bottom:calc(24px + env(safe-area-inset-bottom));
  width:56px;height:56px;border-radius:50%;padding:0;cursor:pointer;
  display:flex;align-items:center;justify-content:center;
  background:var(--blue);color:var(--accent-ink);border:none;
  box-shadow:0 12px 32px rgba(0,0,0,.4);
  touch-action:manipulation;
  transition:transform .15s ease,filter .15s ease,opacity .15s ease;
}
.chat-fab:hover{transform:translateY(-2px);filter:brightness(1.06)}
.chat-fab svg{width:24px;height:24px;display:block}
.chat-fab .chat-fab-close{display:none}
.chat-fab[aria-expanded="true"] .chat-fab-open{display:none}
.chat-fab[aria-expanded="true"] .chat-fab-close{display:block}

/* unread/attention pip */
.chat-fab-pip{
  position:absolute;top:2px;right:2px;width:12px;height:12px;border-radius:50%;
  background:var(--green);border:2px solid var(--bg);
}
.chat-fab-pip[hidden]{display:none}

/* ---------- panel ---------- */
.chat-panel{
  position:fixed;z-index:150;
  right:calc(24px + env(safe-area-inset-right));
  bottom:calc(92px + env(safe-area-inset-bottom));
  width:380px;max-width:calc(100vw - 32px);
  height:min(560px,calc(100vh - 140px));
  height:min(560px,calc(100dvh - 140px));
  display:flex;flex-direction:column;overflow:hidden;
  background:var(--panel);border:1px solid var(--line);border-radius:16px;
  box-shadow:0 30px 80px rgba(0,0,0,.5);
  animation:chatIn .2s ease;
}
.chat-panel[hidden]{display:none}
@keyframes chatIn{from{opacity:0;transform:translateY(12px) scale(.98)}to{opacity:1;transform:none}}

/* ---------- header ---------- */
.chat-head{
  display:flex;align-items:center;gap:10px;padding:14px 16px;
  background:var(--panel-2);border-bottom:1px solid var(--line);flex-shrink:0;
}
.chat-head-dot{
  width:9px;height:9px;border-radius:50%;background:var(--green);
  box-shadow:0 0 8px var(--green);flex-shrink:0;
}
.chat-head-txt{min-width:0}
.chat-head h2{
  font-family:'Chakra Petch',sans-serif;font-weight:700;font-size:.95rem;
  margin:0;line-height:1.2;color:var(--text);
}
.chat-head p{
  font-family:'JetBrains Mono',monospace;font-size:.66rem;color:var(--muted);
  margin:2px 0 0;line-height:1.2;
}
.chat-x{
  margin-left:auto;flex-shrink:0;width:28px;height:28px;border-radius:8px;cursor:pointer;
  display:flex;align-items:center;justify-content:center;touch-action:manipulation;
  background:transparent;border:1px solid var(--line);color:var(--muted);
  font-size:1.1rem;line-height:1;transition:color .15s ease,border-color .15s ease;
}
.chat-x:hover{color:var(--blue);border-color:var(--blue)}

/* ---------- message log ---------- */
.chat-log{
  flex:1;overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch;
  padding:16px;display:flex;flex-direction:column;gap:12px;
  font-size:.88rem;line-height:1.6;
}
.chat-msg{max-width:86%;padding:10px 13px;border-radius:12px;white-space:pre-wrap;overflow-wrap:anywhere}
.chat-msg.bot{
  align-self:flex-start;background:var(--panel-2);color:var(--text);
  border:1px solid var(--line);border-bottom-left-radius:4px;
}
.chat-msg.me{
  align-self:flex-end;background:var(--chip-bg);color:var(--text);
  border:1px solid var(--line);border-bottom-right-radius:4px;
}
.chat-msg.err{
  align-self:stretch;max-width:100%;background:transparent;color:var(--amber);
  border:1px dashed var(--line);font-size:.82rem;
}
.chat-msg a{color:var(--blue);text-decoration:underline;overflow-wrap:anywhere}

/* typing indicator */
.chat-typing{align-self:flex-start;display:flex;gap:4px;padding:12px 13px}
.chat-typing span{
  width:6px;height:6px;border-radius:50%;background:var(--muted);
  animation:chatBlink 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2){animation-delay:.18s}
.chat-typing span:nth-child(3){animation-delay:.36s}
@keyframes chatBlink{0%,80%,100%{opacity:.25;transform:translateY(0)}40%{opacity:1;transform:translateY(-3px)}}

/* ---------- suggested prompts ---------- */
.chat-sugg{
  display:flex;gap:6px;flex-wrap:wrap;padding:0 16px 12px;flex-shrink:0;
}
.chat-sugg[hidden]{display:none}
.chat-sugg button{
  font-family:'JetBrains Mono',monospace;font-size:.68rem;cursor:pointer;touch-action:manipulation;
  background:transparent;color:var(--muted);
  border:1px solid var(--line);border-radius:999px;padding:5px 10px;min-height:30px;
  transition:color .15s ease,border-color .15s ease;
}
.chat-sugg button:hover{color:var(--text);border-color:var(--blue)}

/* ---------- composer ---------- */
.chat-form{
  display:flex;align-items:center;gap:8px;padding:10px 12px;flex-shrink:0;
  background:var(--panel-2);border-top:1px solid var(--line);
}
.chat-form input{
  flex:1;min-width:0;background:transparent;border:none;outline:none;
  color:var(--text);font-family:'Manrope',system-ui,sans-serif;font-size:.88rem;padding:8px 4px;
}
.chat-form input::placeholder{color:var(--muted)}
.chat-form input:focus-visible{outline:none}
.chat-send{
  flex-shrink:0;width:34px;height:34px;border-radius:9px;cursor:pointer;touch-action:manipulation;
  display:flex;align-items:center;justify-content:center;
  background:var(--blue);color:var(--accent-ink);border:none;
  transition:filter .15s ease,opacity .15s ease;
}
.chat-send:hover:not(:disabled){filter:brightness(1.08)}
.chat-send:disabled{opacity:.4;cursor:not-allowed}
.chat-send svg{width:16px;height:16px;display:block}

.chat-foot{
  font-family:'JetBrains Mono',monospace;font-size:.6rem;color:var(--muted);
  text-align:center;padding:0 12px 9px;background:var(--panel-2);flex-shrink:0;
}

/* ---------- focus visibility ---------- */
.chat-fab:focus-visible,.chat-x:focus-visible,.chat-send:focus-visible,
.chat-sugg button:focus-visible,.chat-form input:focus-visible{
  outline:2px solid var(--blue);outline-offset:2px;
}

/* ---------- mobile: full-height bottom sheet, not a floating box ---------- */
@media(max-width:640px){
  .chat-panel{
    right:0;left:0;bottom:0;width:auto;max-width:none;
    height:88vh;height:88dvh;
    border-radius:16px 16px 0 0;
    padding-bottom:env(safe-area-inset-bottom);
  }
  .chat-fab{
    right:calc(16px + env(safe-area-inset-right));
    bottom:calc(16px + env(safe-area-inset-bottom));
  }

  /* Comfortable tap targets (44px is the accepted minimum) and no iOS
     auto-zoom-on-focus, which triggers on any input under 16px. */
  .chat-x{width:40px;height:40px;font-size:1.3rem}
  .chat-send{width:44px;height:44px}
  .chat-send svg{width:18px;height:18px}
  .chat-form input{font-size:16px;padding:10px 4px}
  .chat-form{padding:10px 12px calc(10px + env(safe-area-inset-bottom))}
  .chat-sugg button{min-height:36px;padding:7px 12px;font-size:.72rem}
  .chat-head{padding:16px}
  .chat-head h2{font-size:1rem}
  .chat-msg{max-width:90%;font-size:.92rem}
}

/* Very short viewports (landscape phones, split-screen): don't let an
   88vh sheet clip below the fold — cap it against real space instead. */
@media(max-width:640px) and (max-height:480px){
  .chat-panel{height:min(88vh,calc(100dvh - 8px))}
}

/* ---------- reduced motion ---------- */
@media(prefers-reduced-motion:reduce){
  .chat-panel{animation:none}
  .chat-fab:hover{transform:none}
  .chat-typing span{animation:none;opacity:.6}
}
