/* HAI panel · chat (Cursor-style) + extras on top of the template */

/* two-line row (title + sub) */
.row-t .sub { display: block; font-size: 13px; color: var(--label-2); margin-top: 1px;
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* selection / copy allowed for message + tool text (template kills it globally) */
.msg, .msg *, .tool-body, .tool-body * {
  user-select: text; -webkit-user-select: text; -webkit-touch-callout: default; }

/* CSS chevron — no UTF-8 glyph icons */
.chev { font-size: 0; width: 9px; height: 9px; flex: 0 0 auto;
        border-right: 2px solid var(--label-3); border-top: 2px solid var(--label-3);
        transform: rotate(45deg); border-radius: 1px; }

/* ---- static fade vignette, fixed to the chat frame (decor only) ---- */
.chatview { position: relative; }
.chatview::before, .chatview::after {
  content: ""; position: absolute; left: 0; right: 0; pointer-events: none; z-index: 4; }
.chatview::before { top: 0; height: calc(var(--safe-top) + 40px);
  background: linear-gradient(to bottom, var(--bg) 32%, transparent); }
.chatview::after { bottom: 0; height: 64px;
  background: linear-gradient(to top, var(--bg) 34%, transparent); }
/* when composer/footer is shown, lift the bottom fade above it */
.chatview:has(.footer:not(.hidden))::after,
.chatview:has(.composer:not(.hidden))::after { bottom: 62px; }

/* ---- AI-chat log: alternating plain text, no bubbles ---- */
.ailog { display: flex; flex-direction: column; gap: 14px;
         padding: 14px var(--pad) 10px; }
.msg { max-width: 88%; font-size: 16px; line-height: 1.5; overflow-wrap: break-word;
       word-break: break-word; }
/* user = bubble on the right */
.msg.user { align-self: flex-end; text-align: left; color: #fff;
            background: var(--accent); padding: 9px 13px; border-radius: 18px;
            border-bottom-right-radius: 6px; }
.msg.hai  { align-self: flex-start; text-align: left; color: var(--label); }
.msg.user .who { display: none; }
.msg .who { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
            color: var(--label-3); margin-bottom: 4px; }

/* Telegram-style spoiler */
.spoiler { background: var(--label-3); color: transparent; border-radius: 4px;
           padding: 0 3px; cursor: pointer; transition: color .2s, background .2s; }
.spoiler.open { background: color-mix(in srgb, var(--label-3) 22%, transparent);
                color: inherit; }

/* markdown inside messages */
.msg p { margin: 0 0 10px; } .msg p:last-child { margin-bottom: 0; }
.msg br { content: ""; display: block; margin: 2px 0; }
.msg pre { background: var(--section-bg); border-radius: 12px; padding: 10px 12px;
           overflow-x: auto; font-size: 13px; line-height: 1.4; text-align: left; }
.msg code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
.msg :not(pre) > code { background: var(--section-bg); border-radius: 5px; padding: 1px 5px; }
.msg blockquote { margin: 6px 0; padding: 2px 0 2px 10px;
                  border-left: 3px solid var(--accent); color: var(--label-2); }
.msg ul, .msg ol { margin: 4px 0; padding-left: 22px; text-align: left; }
.msg h1, .msg h2, .msg h3 { font-size: 1.05em; margin: 10px 0 4px; }
.msg a { color: var(--accent); text-decoration: none; }
.msg img.pe { width: 20px; height: 20px; vertical-align: -4px; }
.msg .pe-lot { display: inline-block; width: 20px; height: 20px; vertical-align: -4px; }

/* word-by-word fade-in for fresh streamed text */
.w { opacity: 0; animation: wfade 0.45s ease forwards; }
@keyframes wfade { to { opacity: 1; } }

/* every message/tool slides+fades in on mount */
.ailog > * { animation: msgIn 0.4s var(--ease-ios, ease) both; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
/* list rows stagger-fade when a screen loads */
.list .row.nav { animation: rowIn 0.32s ease both; }
@keyframes rowIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

/* ---- tool calls: frameless icon + name, expandable ---- */
.tool { align-self: flex-start; max-width: 100%; }
.tool-h { display: flex; align-items: center; gap: 8px; padding: 2px 0; cursor: pointer; }
.tool-h img { width: 17px; height: 17px; opacity: 0.72;
              filter: brightness(0) invert(1); }
.tool-h .tname { font-size: 14px; color: var(--label-2); }
.tool-h .thint { font-size: 12.5px; color: var(--label-3); max-width: 46vw;
                 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool.run .tname { background: linear-gradient(90deg, #6e6e73 25%, #fff 50%, #6e6e73 75%);
                   background-size: 200% 100%; -webkit-background-clip: text;
                   background-clip: text; color: transparent;
                   animation: shimmer 1.5s linear infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: 0% 0; } }
/* animated expand: grid-rows 0fr -> 1fr */
.tool-body { display: grid; grid-template-rows: 0fr; opacity: 0;
             transition: grid-template-rows .34s var(--ease-ios, ease), opacity .28s ease,
                         margin-top .34s var(--ease-ios, ease); margin-top: 0; }
.tool.open .tool-body { grid-template-rows: 1fr; opacity: 1; margin-top: 6px; }
.tool-body > .tb-wrap { overflow: hidden; min-height: 0; }
.tool-h .tname, .tool-h img { transition: opacity .2s ease; }
.tool.open .tool-h .tname { color: var(--label); }
.tool-body pre { background: var(--section-bg); border-radius: 12px; padding: 9px 11px;
                 font-size: 12px; line-height: 1.4; overflow-x: auto; max-height: 40vh;
                 overflow-y: auto; white-space: pre-wrap; word-break: break-word; }
.tool-body .tb-h { font-size: 11px; color: var(--label-3); text-transform: uppercase;
                   letter-spacing: 0.06em; margin: 6px 0 3px; }

/* ---- chat topbar: status dot + gear ---- */
.chat-topbar { position: absolute; z-index: 6; left: var(--pad); right: var(--pad);
               top: calc(var(--safe-top) - 4px); display: flex; align-items: center;
               justify-content: space-between; pointer-events: none; }
.chat-topbar > * { pointer-events: auto; }
.statusdot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
             color: var(--label-3); background: color-mix(in srgb, var(--bg) 70%, transparent);
             padding: 3px 9px 3px 7px; border-radius: 20px; backdrop-filter: blur(8px); }
.statusdot i { width: 7px; height: 7px; border-radius: 50%; background: var(--label-3); }
.statusdot.on i { background: #34c759; box-shadow: 0 0 6px #34c759; animation: pulse 1.6s ease-in-out infinite; }
.statusdot.on em { color: #34c759; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
.gear { width: 34px; height: 34px; border: none; border-radius: 50%; display: grid;
        place-items: center; color: var(--label-2);
        background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(8px); }
.gear:active { transform: scale(0.92); }

/* ---- append queue (collapsed list above composer) ---- */
.queue { flex: 0 0 auto; margin: 0 var(--pad) 4px; display: flex; flex-direction: column; gap: 4px;
         animation: msgIn .3s ease both; }
.queue .qh { font-size: 11px; color: var(--label-3); text-transform: uppercase;
             letter-spacing: .06em; padding: 2px 2px 0; }
.queue .qrow { display: flex; align-items: center; gap: 8px; background: var(--section-bg);
               border-radius: 12px; padding: 8px 10px; font-size: 14px; color: var(--label-2); }
.queue .qrow span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue .qx { flex: 0 0 auto; width: 22px; height: 22px; border: none; border-radius: 50%;
             background: color-mix(in srgb, var(--destructive, #ff453a) 20%, transparent);
             color: var(--destructive, #ff453a); display: grid; place-items: center; font-size: 15px; }

/* ---- stop button in composer ---- */
.stopbtn { flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%; border: none;
           display: grid; place-items: center;
           background: color-mix(in srgb, var(--destructive, #ff453a) 22%, transparent);
           color: var(--destructive, #ff453a); }
.stopbtn:active { transform: scale(0.92); }

/* ---- composer ---- */
.composer { flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px;
            padding: 8px var(--pad) calc(10px + var(--safe-bot)); }
.composer textarea { flex: 1 1 auto; background: var(--section-bg); border: none; outline: none;
                     border-radius: 20px; padding: 10px 14px; color: var(--label);
                     font: 16px/1.3 inherit; resize: none; max-height: 120px; }
.composer textarea::placeholder { color: var(--label-3); }
.composer .send { flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%; border: none;
                  display: grid; place-items: center;
                  background: var(--accent); color: #fff; }
.composer .send:active { transform: scale(0.94); filter: brightness(0.9); }

/* ---- footer with two buttons ---- */
.footer.duo { display: flex; gap: 10px; }
.footer.duo .btn { flex: 1; }
.btn.ghost { background: var(--section-bg); color: var(--label); }
