/* AI shell panel (technician only; the customer never sees any of this). */
:root { --ai-w: 420px; --warn: #b26a00; }
@media (prefers-color-scheme: dark) { :root { --warn: #f0a640; } }

.ai-panel { width: var(--ai-w); flex: 0 0 var(--ai-w); display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid var(--border); min-height: 0; }
.ai-panel[hidden] { display: none; }
.ai-head { padding: 14px 16px 10px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--border); }
.ai-title { display: flex; align-items: center; gap: 10px; }
.ai-title h3 { margin: 0; font-size: 15px; letter-spacing: -.01em; }
.ai-title .spacer { flex: 1; }
.ai-close { background: transparent; color: var(--muted); padding: 4px 8px; font-size: 18px; line-height: 1; }
.ai-close:hover { background: var(--surface-2); }
.ai-status { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ai-status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); display: inline-block; }
.ai-status .dot.on { background: var(--ok); }
.ai-status .dot.off { background: var(--err); }
.ai-tabs { display: flex; background: var(--surface); border-radius: 999px; padding: 3px; gap: 2px; }
.ai-tabs button { flex: 1; padding: 6px 10px; font-size: 13px; background: transparent; color: var(--muted); }
.ai-tabs button:hover { background: var(--surface-2); }
.ai-tabs button.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.ai-feed { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.ai-feed > * { flex-shrink: 0; }
.ai-empty { color: var(--muted); font-size: 13.5px; text-align: center; margin: auto 12px; line-height: 1.55; }
.ai-empty b { color: var(--text); font-weight: 600; }
.ai-empty .chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 12px; }
.ai-empty .chips button { font-size: 12.5px; font-weight: 500; padding: 6px 11px; background: var(--surface); color: var(--text); }
.ai-empty .chips button:hover { background: var(--surface-2); }

.ai-msg { display: flex; gap: 9px; align-items: flex-start; font-size: 14px; }
.ai-msg .who { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700;
  background: var(--surface-2); color: var(--text); overflow: hidden; }
.ai-msg .who img { width: 100%; height: 100%; object-fit: cover; }
.ai-msg.ai .who { background: var(--accent); color: var(--on-accent); }
.ai-msg .body { white-space: pre-wrap; word-wrap: break-word; padding-top: 3px; min-width: 0; }
.ai-msg.you .body { color: var(--text); font-weight: 500; }
.ai-msg.err .body { color: var(--err); }
.ai-thinking { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; padding-left: 35px; }
.ai-thinking::before { content: ""; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--border);
  border-top-color: var(--accent); animation: ai-spin .8s linear infinite; }
@keyframes ai-spin { to { transform: rotate(360deg); } }

.ai-cmd { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden; margin-left: 35px; }
.ai-shellfeed .ai-cmd { margin-left: 0; }
.ai-cmd.pending { border-color: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 15%, transparent); }
.ai-cmd.blocked, .ai-cmd.denied { opacity: .8; }
.ai-cmd .top { display: flex; align-items: center; gap: 8px; padding: 8px 10px 0; font-size: 12px; color: var(--muted); }
.ai-cmd .top .spacer { flex: 1; }
.ai-badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.ai-badge.read { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.ai-badge.change { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.ai-badge.blocked, .ai-badge.fail { background: color-mix(in srgb, var(--err) 15%, transparent); color: var(--err); }
.ai-badge.run::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; margin-right: 5px;
  vertical-align: 1px; animation: ai-pulse 1s ease-in-out infinite; }
@keyframes ai-pulse { 50% { opacity: .3; } }
.ai-cmd code { display: block; font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; padding: 6px 10px 8px;
  white-space: pre-wrap; word-break: break-all; color: var(--text); }
.ai-cmd code::before { content: "> "; color: var(--accent); }
.ai-cmd .why { font-size: 12.5px; color: var(--muted); padding: 0 10px 8px; }
.ai-cmd .ask { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--border); background: var(--bg); }
.ai-cmd .ask .q { flex: 1; font-size: 12.5px; color: var(--warn); font-weight: 600; }
.ai-cmd .ask button { padding: 6px 14px; font-size: 13px; }
.ai-cmd pre { margin: 0; max-height: 220px; overflow: auto; padding: 8px 10px; border-top: 1px solid var(--border); background: var(--bg);
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.ai-cmd pre[hidden] { display: none; }
.ai-cmd pre .stderr { color: var(--err); }
.ai-cmd .foot { display: flex; gap: 10px; align-items: center; padding: 6px 10px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.ai-cmd .foot button { background: transparent; color: var(--accent); padding: 0; font-size: 12px; font-weight: 600; }
.ai-cmd .foot .spacer { flex: 1; }

.ai-compose { padding: 12px 16px 16px; border-top: 1px solid var(--border); }
.ai-compose form { display: flex; gap: 8px; align-items: flex-end; background: var(--surface); border-radius: 16px; padding: 6px 6px 6px 12px;
  border: 1px solid transparent; transition: border-color .15s; }
.ai-compose form:focus-within { border-color: var(--accent); }
.ai-compose textarea { flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 14px;
  padding: 6px 0; max-height: 140px; min-height: 22px; }
.ai-compose.shell textarea { font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.ai-compose button { padding: 7px 14px; font-size: 13px; }
.ai-hint { font-size: 11.5px; color: var(--muted); margin-top: 7px; padding-left: 4px; }

#aiToggle.on { background: var(--accent); color: var(--on-accent); }
@media (max-width: 900px) {
  :root { --ai-w: 100%; }
  #session.ai-open .stage, #session.ai-open #chat { display: none; }
}
