/* The board assistant's panel (js/agent-panel.js): a side panel at the board's right edge, in the title block's
   voice. Mono labels over Archivo values, hairline rules between rows, one steel button. Tokens only (app.css). */

/* "Asistan" in the board's bar, pressed while its panel is open */
.wb-tools .ag-toggle[aria-expanded="true"] { background: var(--accent-wash); border-color: var(--accent); color: var(--accent); }

.ag-panel {
  position: absolute; top: 64px; right: 12px; bottom: 12px; z-index: 7; display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(360px, calc(100% - 24px));
  border: 1px solid var(--line-strong); border-radius: var(--r-2); background: var(--surface); box-shadow: var(--shadow-pop);
  color: var(--ink); cursor: auto; user-select: text;
}
/* the board's own bar and zoom make room for the panel instead of going under it */
.has-agent .wb-tools { left: calc((100% - 372px) / 2); }
.has-agent .wb-zoom { right: 384px; }
.has-agent .wb-empty { left: calc((100% - 372px) / 2); width: min(560px, calc(100% - 404px)); }

.ag-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 6px 6px 16px; border-bottom: 1px solid var(--line); }
.ag-title { margin: 0 auto 0 0; color: var(--ink-muted); font: 500 11px/1.3 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; }

/* the conversation: each message a row, its speaker a mono label over the text */
.ag-log { display: grid; align-content: start; gap: 0; margin: 0; padding: 0; overflow-y: auto; overscroll-behavior: contain; list-style: none; }
.ag-msg { display: grid; gap: 4px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.ag-who { color: var(--ink-muted); font: 500 11px/1.3 var(--font-mono); letter-spacing: .08em; text-transform: uppercase; }
.ag-msg.is-assistant .ag-who { color: var(--accent); }
.ag-text { margin: 0; font: 400 13px/1.5 var(--font-ui); white-space: pre-wrap; overflow-wrap: anywhere; }
.ag-rich { white-space: normal; }
.ag-rich > * { margin: 0; }
.ag-rich > * + * { margin-top: 6px; }
.ag-rich ul, .ag-rich ol { padding-left: 18px; }
.ag-rich li + li { margin-top: 2px; }
.ag-rich b { font-weight: 600; }
.ag-thumb { grid-column: 2 / -1; display: block; width: 96px; height: 96px; margin-top: 6px; object-fit: cover; border: 1px solid var(--line); border-radius: var(--r-1, 4px); background: var(--surface); }
.ag-msg.is-user { background: var(--wash); }
.ag-msg.is-refuse .ag-text, .ag-msg.is-empty .ag-text, .ag-msg.is-wait .ag-text, .ag-msg.is-system .ag-text { color: var(--ink-muted); }
.ag-msg.is-empty, .ag-msg.is-system { border-bottom: 0; }

/* the plan card: a title block of its steps, the total along its foot */
.ag-plan { margin-top: 6px; border: 1px solid var(--line-strong); border-radius: var(--r-1); background: var(--page); }
.ag-steps { margin: 0; padding: 0; list-style: none; }
.ag-step {
  display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; column-gap: 8px; row-gap: 2px; align-items: baseline;
  padding: 8px 10px; border-bottom: 1px solid var(--line);
}
.ag-no { grid-area: 1 / 1 / 3 / 2; color: var(--ink-muted); font: 500 11px/1.3 var(--font-mono); font-variant-numeric: tabular-nums; }
.ag-tool { grid-area: 1 / 2; color: var(--ink-muted); font: 500 11px/1.3 var(--font-mono); letter-spacing: .06em; text-transform: uppercase; }
.ag-credits { grid-area: 1 / 3; color: var(--ink-muted); font: 500 11px/1.3 var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
.ag-label { grid-area: 2 / 2; font: 400 13px/1.4 var(--font-ui); overflow-wrap: anywhere; }
.ag-status { grid-area: 2 / 3; color: var(--ink-muted); font: 500 11px/1.3 var(--font-mono); text-align: right; }
.ag-status[data-state="running"] { color: var(--ink); }
.ag-status[data-state="done"] { color: var(--ok); }
.ag-status[data-state="failed"], .ag-status[data-state="stopped"], .ag-status[data-state="skipped"] { color: var(--amber); }
.ag-plan-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; }
.ag-total { margin: 0; font: 500 11px/1.3 var(--font-mono); font-variant-numeric: tabular-nums; }
.ag-total.is-free { color: var(--ink-muted); font: 400 12px/1.3 var(--font-ui); }
.ag-actions { display: flex; gap: 6px; }
.ag-actions:empty { display: none; }
.ag-end { margin: 0; padding: 0 10px 10px; color: var(--ink-muted); font: 400 12px/1.5 var(--font-ui); }

/* writing to the assistant */
.ag-form { display: grid; gap: 7px; padding: 12px 16px 14px; border-top: 1px solid var(--line); }
.ag-input { min-height: 64px; max-height: 180px; resize: none; caret-color: var(--accent); font: 400 13px/1.5 var(--font-ui); }
.ag-input:focus { border-color: var(--accent); outline: 0; box-shadow: 0 0 0 3px var(--accent-wash); }
.ag-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ag-hint { margin: 0; min-width: 0; color: var(--ink-muted); font: 400 12px/1.4 var(--font-ui); }
.ag-hint.is-warn { color: var(--amber); }
.ag-foot .btn { flex: none; }

/* a phone: the panel is a sheet along the bottom, over the board */
@media (max-width: 620px) {
  .ag-panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: min(72%, 560px); }
  .has-agent .wb-tools, .has-agent .wb-empty { left: 50%; }
  .has-agent .wb-empty { width: min(560px, calc(100% - 32px)); }
  .ag-foot .btn, .ag-actions .btn, .ag-close { min-height: 44px; }
  .ag-close { width: 44px; }
}

@media (prefers-reduced-motion: no-preference) {
  .ag-panel { animation: ag-rise var(--dur-ui) var(--ease-out); }
  @keyframes ag-rise { from { opacity: 0; translate: 0 4px; } }
}

.ag-step.is-danger .ag-tool, .ag-step.is-danger .ag-label { color: var(--danger); }
.ag-danger { display: flex; gap: 8px; align-items: flex-start; margin: 0; padding: 8px 10px; border-top: 1px solid var(--line); color: var(--danger); font: 500 12px/1.4 var(--font-ui); cursor: pointer; }
.ag-danger input { margin-top: 2px; accent-color: var(--danger); }

.ag-tray { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 6px; padding: 0; list-style: none; }
.ag-chip { position: relative; width: 56px; height: 56px; border: 1px solid var(--line); border-radius: var(--r-1, 4px); overflow: hidden; background: var(--surface); }
.ag-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ag-chip-x { position: absolute; top: 2px; right: 2px; display: grid; place-items: center; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 50%; background: rgb(0 0 0 / 0.6); color: #fff; cursor: pointer; }
.ag-chip-x .i { width: 10px; height: 10px; }
.ag-attach { margin-right: auto; }
.ag-photos { display: flex; gap: 4px; flex-wrap: wrap; }
.ag-photos img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--r-1, 4px); border: 1px solid var(--line); }
.ag-panel.is-drop { outline: 2px dashed var(--accent, var(--ink)); outline-offset: -6px; }

/* the assistant at work: the step it is on, the steps it took, the time it has taken */
.ag-live { display: flex; align-items: center; gap: 8px; min-height: 20px; }
.ag-pulse { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--accent, var(--ink)); }
.ag-now { font: 500 13px/1.4 var(--font-ui); color: var(--ink); }
.ag-clock { margin-left: auto; font: 400 11px/1 var(--font-mono, var(--font-ui)); color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.ag-trail { display: grid; gap: 2px; margin: 4px 0 0 16px; padding: 0; list-style: none; }
.ag-done { display: flex; align-items: center; gap: 6px; font: 400 12px/1.4 var(--font-ui); color: var(--ink-muted); }
.ag-done .i { width: 12px; height: 12px; color: var(--ok, var(--ink-muted)); }
.ag-step[data-state="running"] { background: color-mix(in srgb, var(--accent, var(--ink)) 6%, transparent); }
@media (prefers-reduced-motion: no-preference) {
  .ag-pulse { animation: ag-pulse 1.2s var(--ease-out, ease-out) infinite; }
  @keyframes ag-pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent, var(--ink)) 45%, transparent); } 100% { box-shadow: 0 0 0 8px transparent; } }
  .ag-now {
    background: linear-gradient(90deg, var(--ink) 0%, var(--ink) 40%, var(--ink-muted) 50%, var(--ink) 60%, var(--ink) 100%) 0 0 / 250% 100%;
    -webkit-background-clip: text; background-clip: text; color: transparent;
    animation: ag-shimmer 1.8s linear infinite;
  }
  @keyframes ag-shimmer { from { background-position: 100% 0; } to { background-position: -150% 0; } }
  .ag-now.is-new { animation: ag-shimmer 1.8s linear infinite, ag-in 220ms var(--ease-out, ease-out); }
  @keyframes ag-in { from { opacity: 0; translate: 0 3px; } }
  .ag-done { animation: ag-in 200ms var(--ease-out, ease-out); }
  .ag-step[data-state="running"] .ag-status { animation: ag-blink 1.2s ease-in-out infinite; }
  @keyframes ag-blink { 50% { opacity: 0.45; } }
}

/* the conversation switcher: the shown conversation's name; its list drops over the log */
.ag-head { position: relative; padding-left: 8px; }
.ag-switch {
  display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1 1 auto; height: 30px; margin-right: auto; padding: 0 8px;
  border: 0; border-radius: var(--r-1, 4px); background: transparent; color: var(--ink); font: 500 13px/1 var(--font-ui); text-align: left; cursor: pointer;
}
.ag-switch:hover:not(:disabled), .ag-switch[aria-expanded="true"] { background: var(--accent-wash); }
.ag-switch:disabled { cursor: default; opacity: .6; }
.ag-switch-name { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ag-switch .i { flex: none; width: 12px; height: 12px; color: var(--ink-muted); transition: rotate var(--dur-ui, 160ms) var(--ease-out, ease-out); }
.ag-switch[aria-expanded="true"] .i { rotate: 180deg; }

.ag-thread-list {
  position: absolute; top: calc(100% + 1px); left: 0; right: 0; z-index: 2; display: grid; gap: 2px; max-height: min(420px, 60vh); overflow-y: auto;
  padding: 6px; border-bottom: 1px solid var(--line-strong); background: var(--surface); box-shadow: var(--shadow-pop); overscroll-behavior: contain;
}
.ag-thread-list[hidden] { display: none; }
.ag-thread-new {
  display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px; border: 0; border-radius: var(--r-1, 4px);
  background: transparent; color: var(--accent); font: 500 13px/1 var(--font-ui); text-align: left; cursor: pointer;
}
.ag-thread-new:hover, .ag-thread-new:focus-visible { background: var(--accent-wash); }
.ag-thread-new .i { width: 14px; height: 14px; }
.ag-thread-items { display: grid; gap: 2px; margin: 4px 0 0; padding: 4px 0 0; border-top: 1px solid var(--line); list-style: none; }
.ag-thread { position: relative; display: flex; align-items: center; border-radius: var(--r-1, 4px); }
.ag-thread:hover, .ag-thread:focus-within, .ag-thread.is-current { background: var(--accent-wash); }
.ag-thread.is-current::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 2px; border-radius: 2px; background: var(--accent); }
.ag-thread-open {
  display: grid; gap: 3px; flex: 1 1 auto; min-width: 0; padding: 8px 10px; border: 0; background: transparent; color: var(--ink); text-align: left; cursor: pointer;
}
.ag-thread-title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font: 400 13px/1.3 var(--font-ui); }
.ag-thread.is-current .ag-thread-title { font-weight: 500; }
.ag-thread-meta { color: var(--ink-muted); font: 400 11px/1.3 var(--font-mono); font-variant-numeric: tabular-nums; }
/* the delete shows on the row a pointer or the keyboard is on (always on touch, which has no hover) */
.ag-thread-drop { flex: none; margin-right: 4px; color: var(--ink-muted); opacity: 0; transition: opacity var(--dur-ui, 160ms) var(--ease-out, ease-out); }
.ag-thread:hover .ag-thread-drop, .ag-thread:focus-within .ag-thread-drop, .ag-thread-drop:focus-visible { opacity: 1; }
.ag-thread-drop:hover { color: var(--danger, #c0392b); }
@media (hover: none) { .ag-thread-drop { opacity: 1; } }
.ag-thread-sure { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; width: 100%; padding: 8px 10px; }
.ag-thread-ask { flex: 1 1 100%; color: var(--ink); font: 400 12px/1.4 var(--font-ui); }
.ag-thread-empty { margin: 4px 10px 6px; color: var(--ink-muted); font: 400 12px/1.4 var(--font-ui); }

.ag-choices { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.ag-choice { max-width: 100%; white-space: normal; text-align: left; font-weight: 400; }
