/* F.O.C.O: grafo de tasks, modal, markdown, cluster e assistente. Carregado depois do arquivo anterior em index.html (a ordem da cascata importa). */

/* ------------------------------------------------------------------ grafo de tasks */

.task-graph-wrap {
  display: flex;
  flex-direction: column;
}

.task-graph-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--divider);
}

.task-graph-toolbar__title {
  font-family: var(--font-display);
  font-size: var(--fs-16);
  font-weight: 700;
  color: var(--text);
}

.task-graph-toolbar__link {
  margin-left: var(--sp-2);
  font-size: var(--fs-13);
}

.task-graph-run-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 var(--sp-2);
  border: 1px solid var(--neutral-border);
  border-radius: var(--radius-sm);
  background: var(--neutral-bg);
  color: var(--neutral);
  font-size: var(--fs-12);
  font-weight: 700;
}

.task-graph-run-badge--running {
  background: var(--info-bg);
  border-color: var(--info-border);
  color: var(--info);
}

.task-graph-run-badge--internal_error {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.task-graph-nav {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.task-graph-nav__btn {
  min-width: 32px;
  height: 30px;
  padding: 0 var(--sp-2);
  border: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: var(--fs-13);
  font-weight: 700;
  cursor: pointer;
}

.task-graph-nav__btn:last-child {
  border-right: 0;
}

.task-graph-nav__btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.task-graph-nav__pct {
  min-width: 48px;
  padding: 0 var(--sp-2);
  border-right: 1px solid var(--border);
  font-size: var(--fs-12);
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.task-graph-hint {
  padding: var(--sp-2) var(--sp-5);
  font-size: var(--fs-12);
  color: var(--text-muted);
}

.task-graph-canvas {
  position: relative;
  height: min(52vh, 520px);
  min-height: 280px;
  margin: 0 var(--sp-5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--graph-bg);
  background-image: radial-gradient(circle, var(--graph-dot) 1px, transparent 1px);
  background-size: 16px 16px;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.app--nav-collapsed .task-graph-canvas {
  height: min(70vh, 780px);
}

.task-graph-canvas--panning {
  cursor: grabbing;
}

.task-graph-stage {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.task-graph-svg {
  display: block;
  overflow: visible;
}

.task-graph-edge {
  fill: none;
  stroke: var(--graph-edge);
  stroke-width: 1.5;
}

.task-graph-node {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  height: 100%;
  padding: 8px 10px 8px 12px;
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font-text);
  font-size: 12px;
  line-height: 1.3;
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-1);
}

.task-graph-node:hover {
  border-color: var(--foco-blue);
}

.task-graph-node:focus-visible {
  outline: var(--focus-outline);
  outline-offset: 1px;
}

.task-graph-node--selected {
  border-color: var(--foco-blue);
  box-shadow: 0 0 0 2px var(--foco-blue);
}

.task-graph-node--success {
  border-left-color: var(--success);
}

.task-graph-node--failed {
  border-left-color: var(--danger);
  background: var(--danger-bg);
}

.task-graph-node--running {
  border-left-color: var(--foco-blue);
  background: var(--info-bg);
}

.task-graph-node--skipped {
  border-left-color: var(--text-subtle);
  color: var(--text-muted);
}

.task-graph-node--blocked,
.task-graph-node--pending {
  border-left-color: var(--border-strong);
  color: var(--text-muted);
}

.task-graph-node--condition {
  border-style: dashed;
  border-left-style: solid;
}

.task-graph-node__title {
  font-weight: 700;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-graph-node__status {
  color: var(--text-2);
}

.task-graph-node__cluster {
  font-size: 11px;
  color: var(--text-muted);
}

.task-graph-detail {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin: var(--sp-4) var(--sp-5) var(--sp-5);
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: var(--fs-13);
}

.task-graph-detail__head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.task-graph-detail__head h4 {
  font-family: var(--font-mono);
  font-size: var(--fs-14);
}

.task-graph-detail__pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 var(--sp-2);
  border: 1px solid var(--neutral-border);
  border-radius: var(--radius-sm);
  background: var(--neutral-bg);
  color: var(--neutral);
  font-size: var(--fs-12);
  font-weight: 600;
}

.task-graph-detail__pill--success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success);
}

.task-graph-detail__pill--failed {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.task-graph-detail__pill--running {
  background: var(--info-bg);
  border-color: var(--info-border);
  color: var(--info);
}

.task-graph-detail__msg {
  color: var(--text-2);
}

.task-graph-detail__meta,
.task-graph-detail__diag {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  color: var(--text-2);
}

.task-graph-detail__nb {
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
}

.task-graph-detail__diag li {
  padding-left: var(--sp-3);
  border-left: 3px solid var(--border-strong);
}

.task-graph-detail__diag--ok {
  border-left-color: var(--success) !important;
}

.task-graph-detail__diag--warn {
  border-left-color: #c79a00 !important;
}

.task-graph-detail__diag--err {
  border-left-color: var(--danger) !important;
}

.task-graph-detail__diag--info {
  border-left-color: var(--foco-blue) !important;
}

.task-graph-empty {
  padding: var(--sp-5);
}

/* ------------------------------------------------------------------ modal */

#foco-modal-host {
  display: none;
}

#foco-modal-host.foco-modal-host--open {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
}

.foco-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(9, 9, 11, 0.62);
}

.foco-modal {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 2 * var(--sp-5));
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg, 8px);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  border: 1px solid var(--border-strong);
  border-top: 1px solid var(--border-strong);
}

.foco-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--divider);
}

.foco-modal__title {
  font-size: var(--fs-18);
}

.foco-modal__close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.foco-modal__close:hover {
  background: var(--surface-3);
  color: var(--text);
}

.foco-modal__body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-5);
  overflow-y: auto;
  color: var(--text-2);
}

.foco-modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--divider);
  background: var(--surface-2);
}

.foco-modal__pre {
  margin: 0;
  padding: var(--sp-3);
  max-height: 50vh;
  overflow: auto;
  border-radius: var(--radius);
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: var(--fs-13);
}

.dialog-host {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
}

.foco-modal--sm {
  width: min(440px, 100%);
}

/* ------------------------------------------------------------------ markdown (saída do modelo) */

.md {
  color: var(--text-2);
  line-height: var(--lh-prose);
  overflow-wrap: anywhere;
}

.md > * + * {
  margin-top: var(--sp-3);
}

.md > .md-h + * {
  margin-top: var(--sp-2);
}

.md > * + .md-h {
  margin-top: var(--sp-5);
}

.md-h {
  font-family: var(--font-display);
  color: var(--text);
}

h3.md-h {
  font-size: var(--fs-16);
}

h4.md-h {
  font-size: var(--fs-14);
}

h5.md-h {
  font-size: var(--fs-12);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.md ul,
.md ol {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding-left: var(--sp-5);
}

.md ul {
  list-style: disc;
}

.md ol {
  list-style: decimal;
}

.md li > ul,
.md li > ol {
  margin-top: var(--sp-1);
}

.md li::marker {
  color: var(--text-muted);
}

.md strong {
  color: var(--text);
  font-weight: 700;
}

.md code {
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--text);
}

.md pre.code code {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
}

.md blockquote {
  padding: var(--sp-2) var(--sp-4);
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}

.md hr {
  border: 0;
  border-top: 1px solid var(--divider);
}

.md .table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ------------------------------------------------------------------ cluster estruturado */

.facts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--sp-3);
}

.fact {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  min-width: 0;
}

.fact__label {
  font-size: var(--fs-12);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.fact__value {
  font-weight: 700;
  color: var(--text);
  overflow-wrap: anywhere;
}

.fact__value--muted {
  font-weight: 500;
  color: var(--text-muted);
}

.subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
  margin-bottom: var(--sp-2);
}

.subhead__title {
  font-size: var(--fs-14);
  font-weight: 700;
  color: var(--text);
}

/* ------------------------------------------------------------------ assistente (chat) */

.chat {
  display: flex;
  flex-direction: column;
  max-width: 920px;
  min-height: calc(100vh - var(--header-h) - 220px);
}

.chat__log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  padding-bottom: var(--sp-5);
}

.chat-welcome {
  padding: var(--sp-6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-2);
}

.chat-welcome__title {
  font-size: var(--fs-20);
}

.chat-welcome__text {
  margin-top: var(--sp-2);
  max-width: var(--measure);
  color: var(--text-2);
  line-height: var(--lh-prose);
}

.chat-welcome__sub {
  margin-top: var(--sp-6);
  margin-bottom: var(--sp-4);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--divider);
  font-size: var(--fs-12);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.chat-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text-2);
  font-size: var(--fs-13);
  cursor: pointer;
}

.chip-btn:hover:not(:disabled) {
  border-color: var(--foco-blue);
  color: var(--link);
}

.msg {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: var(--sp-3);
  align-items: start;
}

.msg__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--foco-navy);
  color: #ffffff;
  font-family: var(--font-display);
  font-size: var(--fs-12);
  font-weight: 700;
}

.msg__body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
}

.msg__meta {
  font-size: var(--fs-12);
  font-weight: 700;
  color: var(--text-muted);
}

.msg--user {
  grid-template-columns: minmax(0, 1fr);
  justify-items: end;
}

.msg--user .msg__bubble {
  max-width: 80%;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-lg) var(--radius-lg) 2px var(--radius-lg);
  background: var(--brand-badge-bg);
  border: 1px solid var(--brand-badge-border);
  color: var(--text);
  line-height: var(--lh-prose);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg__card {
  padding: var(--sp-4) var(--sp-5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.msg__card > .kpi-row,
.msg__card > .msg__actions {
  margin-top: var(--sp-5);
}

.thinking {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.thinking > summary {
  display: grid;
  grid-template-columns: 16px auto minmax(0, 1fr) auto 16px;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
  list-style: none;
  font-size: var(--fs-13);
}

.thinking > summary::-webkit-details-marker {
  display: none;
}

.thinking__title {
  font-weight: 700;
  color: var(--text);
}

.thinking__now {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thinking__pct {
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.thinking__chev {
  color: var(--text-muted);
  transition: transform 0.15s ease;
}

.thinking[open] .thinking__chev {
  transform: rotate(180deg);
}

.thinking__ok {
  color: var(--success);
}

.thinking__fail {
  color: var(--danger);
}

.thinking__body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  padding: var(--sp-2) var(--sp-4) var(--sp-4);
  border-top: 1px solid var(--divider);
}

.thinking__body .checklist {
  background: var(--surface);
}

.msg__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.action-card {
  border: 1px solid var(--border);
  border-left: 4px solid var(--foco-blue);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.action-card--danger {
  border-left-color: var(--danger);
}

.action-card--done {
  border-left-color: var(--success);
}

.action-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5) 0;
}

.action-card__eyebrow {
  font-size: var(--fs-12);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.action-card__title {
  margin-top: var(--sp-1);
  font-size: var(--fs-16);
}

.action-card__body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5) var(--sp-4);
  color: var(--text-2);
  line-height: var(--lh-prose);
}

.action-card__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--divider);
  background: var(--surface-2);
}

.action-card__foot .field {
  flex: 1 1 220px;
}

.composer {
  position: sticky;
  bottom: 0;
  z-index: 5;
  padding: var(--sp-3) 0 var(--sp-4);
  background: linear-gradient(to bottom, transparent, var(--bg) 24%);
}

.composer__box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: var(--sp-2);
  padding: var(--sp-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-2);
}

.composer__box:focus-within {
  border-color: var(--foco-blue);
  box-shadow: var(--focus-ring);
}

.composer__input {
  width: 100%;
  min-height: 40px;
  max-height: 200px;
  padding: var(--sp-2) var(--sp-3);
  border: 0;
  background: transparent;
  color: var(--text);
  line-height: var(--lh-base);
  resize: none;
}

.composer__input:focus {
  outline: none;
}

.composer__hint {
  margin-top: var(--sp-2);
  font-size: var(--fs-12);
  color: var(--text-muted);
}
