/* Peças reutilizadas pelas telas (js/components/ gera o HTML de cada uma) */

.icon { display: inline-block; flex-shrink: 0; vertical-align: middle; }

/* ---------- Botões ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.btn:focus-visible, .icon-btn:focus-visible, .link-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.7); }

.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-success { background: var(--ok); color: #fff; }
.btn-success:hover:not(:disabled) { filter: brightness(1.08); }
.btn-danger { background: var(--surface); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn-danger:hover:not(:disabled) { background: var(--bad-soft); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: var(--shadow); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.btn.is-admin { background: var(--brand-soft); color: var(--brand); border-color: transparent; box-shadow: none; }

:root[data-theme="dark"] .btn-success { color: #06210f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-success { color: #06210f; } }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-2);
    cursor: pointer;
}

.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

.trace-btn {
    width: 28px;
    height: 28px;
    border-color: transparent;
    background: transparent;
    color: var(--text-3);
    vertical-align: middle;
}

.trace-btn:hover { background: var(--brand-soft); color: var(--brand); }

.link-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--brand);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.link-btn:hover { background: var(--brand-soft); }

.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Status no topo ---------- */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-2);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.status-pill:hover { background: var(--surface-hover); color: var(--text); }

.connection-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--neutral); }
.connection-dot.connected { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.connection-dot.disconnected { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.connection-dot.alerting { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }

/* ---------- Popover de admin ---------- */
.popover {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 100;
    width: 310px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}

.popover[hidden] { display: none; }
.popover h3 { font-size: 15px; }
.popover p { color: var(--text-2); font-size: 13px; }
.popover-actions { display: flex; gap: 8px; }
.popover-actions .btn { flex: 1; }

@media (max-width: 600px) {
    .popover { position: fixed; top: 70px; left: 16px; right: 16px; width: auto; }
}

/* ---------- Formulários ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: 13px; color: var(--text-2); }

.input, .field input, .field select, .select-field select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus, .field input:focus, .field select:focus, .select-field select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}

.input-mono { font-family: var(--mono); }

.select-field { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; font-weight: 600; }
.select-field select { width: auto; padding: 6px 10px; font-weight: 500; }

/* ---------- Painel (cartão com título) ---------- */
.panel {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.panel-head {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.panel-head h2 { display: flex; align-items: center; gap: 9px; font-size: 15px; font-weight: 700; }
.panel-head h2 .icon { color: var(--accent); }
.panel-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.panel-body { padding: 18px; }
.panel-body.flush { padding: 0; }
.panel-body > .table-wrap { margin: -18px; }
.panel-body.flush > .table-wrap { margin: 0; }

/* ---------- Barra de ferramentas e dica ---------- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 10px 14px;
    flex-wrap: wrap;
    color: var(--text-2);
    font-size: 13px;
}

.toolbar .spacer { flex: 1; }
.toolbar-status { color: var(--text-3); }

.trace-form { display: flex; gap: 10px; flex-wrap: wrap; }
.trace-form .input { flex: 1; min-width: 220px; }

/* ---------- Cartões de indicador ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }

.stat {
    position: relative;
    min-width: 0;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.stat::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 3px; background: transparent; }
.stat-ok::before { background: var(--ok); }
.stat-fail::before { background: var(--bad); }

.stat-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stat-label { color: var(--text-2); font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }

.stat-icon {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    border-radius: 8px;
    color: var(--tone, var(--accent, var(--brand)));
    background: var(--tone-soft, var(--accent-soft, var(--brand-soft)));
}

.stat-value { margin: 8px 0 2px; font-size: 20px; font-weight: 700; line-height: 1.25; overflow-wrap: break-word; }
.stat-fail .stat-value { color: var(--bad); }
.stat-detail { color: var(--text-3); font-size: 12.5px; overflow-wrap: anywhere; }

.tone-ok { --tone: var(--ok); --tone-soft: var(--ok-soft); }
.tone-warn { --tone: var(--warn); --tone-soft: var(--warn-soft); }
.tone-bad { --tone: var(--bad); --tone-soft: var(--bad-soft); }
.tone-info { --tone: var(--info); --tone-soft: var(--info-soft); }
.tone-brand { --tone: var(--brand); --tone-soft: var(--brand-soft); }
.tone-store { --tone: var(--store); --tone-soft: var(--store-soft); }

/* ---------- Selos de status ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    background: var(--neutral-soft);
    color: var(--neutral-text);
}

.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-soft); color: var(--ok-text); }
.badge-warn { background: var(--warn-soft); color: var(--warn-text); }
.badge-bad { background: var(--bad-soft); color: var(--bad-text); }
.badge-info { background: var(--info-soft); color: var(--info-text); }
.badge-pulse::before { animation: pulse 1s infinite alternate; }

@keyframes pulse { from { opacity: 0.35; } to { opacity: 1; } }

/* ---------- Tabelas ---------- */
.table-wrap { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

.data-table th, .data-table td {
    padding: 10px 14px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}

.data-table tr:last-child td { border-bottom: 0; }

.data-table th {
    position: sticky;
    top: 0;
    background: var(--surface-2);
    color: var(--text-3);
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    white-space: nowrap;
}

.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tr.row-alert td { background: color-mix(in srgb, var(--bad-soft) 55%, transparent); }
.data-table tr.row-expandable { cursor: pointer; }
.data-table tr.row-expandable:hover td { background: var(--surface-hover); }
.data-table tr.level-error td:first-child { box-shadow: inset 3px 0 var(--bad); }
.data-table tr.level-warn td:first-child { box-shadow: inset 3px 0 var(--warn); }
.data-table tr.level-info td:first-child { box-shadow: inset 3px 0 var(--info); }
.data-table tr.row-detail td { background: var(--surface-2); }
.data-table .row-label { color: var(--text-2); font-weight: 600; }

.muted { color: var(--text-3); font-size: 12.5px; overflow-wrap: anywhere; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.rate-bad { color: var(--bad); font-weight: 600; }
.clickable { color: var(--brand); cursor: pointer; }
.clickable:hover { text-decoration: underline; }
.actions-cell { white-space: nowrap; display: flex; gap: 6px; }

.code {
    margin: 0;
    padding: 14px;
    border-radius: var(--radius-sm);
    background: var(--code-bg);
    color: var(--code-text);
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* ---------- Estado vazio / carregando / erro ---------- */
.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 28px 16px;
    color: var(--text-3);
    text-align: center;
}

.empty .icon { color: var(--border-strong); }
.empty-bad { color: var(--bad-text); }
.empty-bad .icon { color: var(--bad); }
.empty-ok .icon { color: var(--ok); }

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ---------- Aviso flutuante ---------- */
.toast {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: min(420px, calc(100vw - 36px));
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--info);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: slide-in 0.25s ease;
}

.toast[hidden] { display: none; }
.toast .icon { margin-top: 1px; color: var(--info); }
.toast-success { border-left-color: var(--ok); }
.toast-success .icon { color: var(--ok); }
.toast-error { border-left-color: var(--bad); }
.toast-error .icon { color: var(--bad); }

@keyframes slide-in {
    from { transform: translateX(24px); opacity: 0; }
    to { transform: none; opacity: 1; }
}

/* ---------- Produtos ---------- */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.product-grid.compact { grid-template-columns: minmax(0, 1fr); gap: 8px; }

.product-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.product-grid.compact .product-card { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 14px; background: var(--surface-2); }
/* Coluna estreita: selo e Remover descem de linha em vez de espremer o nome */
.product-grid.compact .product-top { flex: 1 1 160px; }
.product-grid.compact .product-meta { margin-left: auto; flex-shrink: 0; }

.product-top { display: flex; align-items: center; gap: 12px; min-width: 0; }

.product-thumb {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border-radius: 10px;
    color: var(--store);
    background: var(--store-soft);
}

/* min-width: 0 deixa o break-word quebrar uma palavra longa em vez de estourar o card */
.product-name { font-weight: 700; font-size: 14.5px; overflow-wrap: break-word; min-width: 0; }
.product-price { color: var(--text-2); font-variant-numeric: tabular-nums; }
.product-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.product-card .btn { margin-top: auto; }

/* ---------- Estoque ---------- */
.stock-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px 16px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.stock-row:last-child { border-bottom: 0; }
.stock-name { font-weight: 700; }
.stock-qty { text-align: right; }
.stock-qty strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.stock-qty span { display: block; color: var(--text-3); font-size: 12px; }
.stock-bar { grid-column: 1 / -1; display: flex; height: 6px; border-radius: 999px; background: var(--neutral-soft); overflow: hidden; }
.stock-bar i { display: block; height: 100%; border-radius: inherit; background: var(--store); }
.stock-bar i.reserved { background: var(--warn); }

/* ---------- Saga (compra) ---------- */
.saga-list { display: flex; flex-direction: column; gap: 10px; max-height: 70vh; overflow-y: auto; }

.saga-card {
    padding: 11px 14px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
}

.saga-card.selectable { cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.saga-card.selectable:hover { background: var(--surface-hover); }
.saga-card.selectable:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.saga-card.selected { border-color: var(--brand); background: var(--brand-soft); }

.saga-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.saga-header h3 { font-size: 14px; font-weight: 600; }
.saga-meta { display: flex; align-items: center; gap: 8px; margin: 2px 0 9px; color: var(--text-3); font-size: 12px; }
/* O id da saga é longo: corta com reticências (inteiro no título) */
.saga-meta .mono { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.saga-actions { display: flex; gap: 2px; margin-left: auto; }
.row-actions { width: 1%; text-align: right; white-space: nowrap; }
.saga-error { margin-top: 8px; color: var(--bad-text); font-size: 12.5px; }

/* Progresso da saga: um segmento por passo */
.segs { display: flex; align-items: center; gap: 3px; }
.seg { flex: 1; max-width: 56px; height: 5px; border-radius: 999px; background: var(--neutral-soft); }
.seg.COMPLETED { background: var(--ok); }
.seg.FAILED { background: var(--bad); }
.seg.COMPENSATED { background: var(--warn); }
.seg.SKIPPED { background: var(--neutral-soft); box-shadow: inset 0 0 0 1px var(--warn); }
.seg.COMPENSATION_FAILED { background: var(--bad); box-shadow: 0 0 0 1px var(--bad-soft); }
.seg.RUNNING { background: var(--info); animation: pulse 1s infinite alternate; }
.segs-sep { display: inline-flex; margin: 0 3px 0 6px; color: var(--warn-text); }

/* ---------- Modal (diagrama da saga) ---------- */
.modal {
    width: min(1180px, calc(100vw - 32px));
    margin: auto;
    max-height: calc(100vh - 32px);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-lg);
}
.modal::backdrop { background: rgba(10, 12, 20, 0.55); }
.modal[open] { animation: modal-in 0.15s ease-out; }

.modal-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.modal-title h2 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 16px; }
.modal-sub { overflow: hidden; color: var(--text-3); font-family: var(--mono); font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.modal-head [data-close] { margin-left: auto; }
.modal-body { min-height: 120px; }
.modal-body > .empty { padding: 24px; }

@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

/* ---------- Diagrama da saga (modal do fluxo) ----------
 * No estilo da visão geral do console da Lambda: cartões de serviço ligados
 * por conectores. Os conectores (.fx-link) ficam no vão à esquerda do
 * elemento; em tela estreita viram verticais, acima dele.
 */
.fx { --gap: 26px; --vgap: 22px; container-type: inline-size; display: flex; flex-direction: column; }

.fx-canvas {
    display: grid;
    grid-template-columns: 140px minmax(0, 1fr) 140px;
    align-items: center;
    column-gap: var(--gap);
    padding: 22px;
    border-bottom: 1px solid var(--border);
    background-color: var(--surface-2);
    background-image: radial-gradient(var(--border) 1px, transparent 1px);
    background-size: 16px 16px;
}

/* Sem resumo embaixo: o canvas fecha o painel */
.fx-canvas:last-child { border-bottom: 0; border-radius: 0 0 var(--radius) var(--radius); }

.fx-node, .fx-cell { position: relative; min-width: 0; }

/* Cartão de serviço */
.fx-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-content: start;
    gap: 8px;
    height: 100%;
    padding: 10px 11px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    transition: border-color 0.25s, box-shadow 0.25s, opacity 0.25s;
}

.fx-tile {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: var(--neutral);
    color: #fff;
}
.tile-lambda { background: var(--svc-lambda); }
.tile-api { background: var(--svc-api); }
.tile-sfn { background: var(--svc-sfn); width: 24px; height: 24px; border-radius: 5px; }
.tile-result-done { background: var(--ok); }
.tile-result-running { background: var(--info); }
.tile-result-compensated { background: var(--warn); }
.tile-result-failed, .tile-result-compensation-failed { background: var(--bad); }

.fx-text { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
/* Lambdas: ícone e serviço em cima, nome embaixo (cabe nas cinco colunas) */
.fx-service { align-self: center; justify-self: end; color: var(--text-3); font-size: 9.5px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; }
.fx-service + .fx-text { grid-column: 1 / -1; }
.fx-name { color: var(--text); font-size: 13px; font-weight: 700; line-height: 1.25; }
.fx-sub { overflow: hidden; color: var(--text-3); font-family: var(--mono); font-size: 10.5px; white-space: nowrap; text-overflow: ellipsis; }

.fx-state {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 4px;
    padding-top: 7px;
    border-top: 1px solid var(--border);
    color: var(--text-3);
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
}

.fx-card.is-running { border-color: var(--info); animation: fx-pulse 1.2s ease-out infinite; }
.fx-card.is-running .fx-state { color: var(--info-text); font-weight: 600; }
.fx-card.is-done .fx-state { color: var(--ok-text); }
.fx-card.is-failed { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.fx-card.is-failed .fx-state { color: var(--bad-text); font-weight: 600; }
.fx-card.is-compensated .fx-state { color: var(--warn-text); }
.fx-card.is-compensation-failed { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.fx-card.is-compensation-failed .fx-state { color: var(--bad-text); font-weight: 600; }
.fx-card.is-skipped { opacity: 0.45; box-shadow: none; }
.fx-card.is-skipped .fx-tile, .fx-card.is-pending .fx-tile { filter: grayscale(0.6); }
.fx-card.is-pending { border-style: dashed; box-shadow: none; }

@keyframes fx-pulse {
    0% { box-shadow: 0 0 0 0 var(--info-soft); }
    100% { box-shadow: 0 0 0 8px transparent; }
}

/* State machine: moldura com as duas faixas */
.fx-frame {
    padding: 12px 14px 16px;
    border: 1px dashed var(--svc-sfn);
    border-radius: 10px;
    background: var(--surface);
}

.fx-frame-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.fx-frame-head .fx-sub { font-family: var(--font); font-size: 12px; }

.fx-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); column-gap: var(--gap); }
.fx-drops { position: relative; height: 34px; }
.fx-back { transition: opacity 0.25s; }
.fx-back:not(.is-active) { opacity: 0.7; }

.fx-lane-label {
    position: absolute;
    left: 0;
    top: 50%;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transform: translateY(-50%);
    color: var(--text-3);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
.is-compensating .fx-lane-label { color: var(--warn-text); }

/* Conectores */
.fx-link {
    position: absolute;
    top: 50%;
    right: 100%;
    width: var(--gap);
    border-top: 2px solid var(--border-strong);
    transform: translateY(-1px);
    pointer-events: none;
}
.fx-link.on { border-top-color: var(--text-2); }
.fx-link.dashed { border-top-style: dashed; }
.fx-link.dashed.on { border-top-color: var(--warn); }

.fx-link::after {
    content: '';
    position: absolute;
    top: -6px;
    border: 5px solid transparent;
}
.fx-link.to-right::after { right: -2px; border-left: 7px solid var(--border-strong); border-right: 0; }
.fx-link.to-left::after { left: -2px; border-right: 7px solid var(--border-strong); border-left: 0; }
.fx-link.no-head::after { display: none; }
.fx-link.to-right.on::after { border-left-color: var(--text-2); }
.fx-link.to-left.on::after { border-right-color: var(--warn); }

.fx-drop { position: absolute; top: 0; bottom: 0; left: 50%; border-left: 2px dashed var(--warn); transform: translateX(-1px); }
.fx-drop::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: -6px;
    border: 5px solid transparent;
    border-top: 7px solid var(--warn);
    border-bottom: 0;
}
.fx-drop.no-head::after { display: none; }

/* Caminho da falha (depois do Pagamento) até o Reembolso */
.fx-elbow, .fx-pass { position: absolute; inset: 0; pointer-events: none; }
.fx-pass::before, .fx-elbow::after { content: ''; position: absolute; top: 50%; left: 0; border-top: 2px dashed var(--warn); transform: translateY(-1px); }
.fx-pass::before { right: 0; }
.fx-elbow::after { right: 50%; }
.fx-elbow::before { content: ''; position: absolute; top: 0; bottom: 50%; left: 50%; border-left: 2px dashed var(--warn); transform: translateX(-1px); }

/* Resumo do que aconteceu */
.fx-summary { display: flex; align-items: center; gap: 8px; margin: 0; padding: 12px 18px; color: var(--text-2); font-size: 13.5px; }
.fx-summary::before { content: ''; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--neutral); }
.fx-summary.tone-info::before { background: var(--info); }
.fx-summary.tone-ok::before { background: var(--ok); }
.fx-summary.tone-warn::before { background: var(--warn); }
.fx-summary.tone-bad::before { background: var(--bad); }

/* Espaço estreito: uma coluna, de cima para baixo */
@container (max-width: 1020px) {
    .fx-canvas { grid-template-columns: minmax(0, 1fr); row-gap: var(--vgap); padding: 16px; }
    .fx-trigger, .fx-result { max-width: 320px; }
    .fx-row { grid-template-columns: minmax(0, 1fr); row-gap: var(--vgap); }
    .fx-back { display: flex; flex-direction: column-reverse; gap: var(--vgap); }
    .fx-drops { height: 30px; }
    .fx-drops .fx-cell, .fx-path, .fx-empty { display: none; }
    /* Cartão numa linha só: ícone, nome, estado */
    .fx-card { grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; }
    .fx-service { display: none; }
    .fx-service + .fx-text { grid-column: auto; }
    .fx-state { grid-column: auto; padding-top: 0; border-top: 0; }

    .fx-link {
        top: auto;
        right: auto;
        bottom: 100%;
        left: 26px;
        width: 0;
        height: var(--vgap);
        border-top: 0;
        border-left: 2px solid var(--border-strong);
        transform: none;
    }
    .fx-link.on { border-left-color: var(--text-2); }
    .fx-link.dashed { border-left-style: dashed; }
    .fx-link.dashed.on { border-left-color: var(--warn); }
    /* Compensação sobe ao contrário (column-reverse): o conector vai embaixo */
    .fx-back .fx-link { top: 100%; bottom: auto; }
    .fx-link.to-right::after, .fx-link.to-left::after {
        top: auto;
        right: auto;
        bottom: -2px;
        left: -6px;
        border: 5px solid transparent;
        border-top: 7px solid var(--border-strong);
        border-bottom: 0;
    }
    .fx-link.to-right.on::after { border-top-color: var(--text-2); }
    .fx-link.to-left.on::after { border-top-color: var(--warn); }
}

/* ---------- Gráfico de barras empilhadas (aba Métricas) ---------- */
.chart svg { display: block; width: 100%; height: 150px; border-radius: var(--radius-sm); background: var(--surface-2); }
.chart-notes { margin: 10px 0 0; font-size: 12px; }
.chart-ref { stroke: var(--text-3); stroke-width: 1.5; stroke-dasharray: 6 4; }
.chart-axis { display: flex; justify-content: space-between; margin-top: 6px; color: var(--text-3); font-size: 12px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; color: var(--text-2); font-size: 13px; }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 3px; vertical-align: -1px; }
.legend strong { color: var(--text); }

/* ---------- Linha do tempo (aba Desempenho) ---------- */
.timeline { position: relative; height: 22px; min-width: 260px; border-radius: 6px; background: var(--neutral-soft); overflow: hidden; }
.timeline .bar { position: absolute; top: 4px; bottom: 4px; min-width: 3px; border-radius: 4px; background: var(--ok); }
.timeline .bar.compensation, .legend .compensation { background: var(--warn); }
.timeline .bar.failed, .legend .failed { background: var(--bad); }
.timeline .bar.running, .legend .running { background: var(--neutral); }
.timeline .bar.skipped, .legend .skipped { background: var(--neutral-soft); }
.legend .ok { background: var(--ok); }

/* ---------- Caos (injeção de falhas) ---------- */
.chaos-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    max-width: 1440px;
    margin: 16px 32px 0;
    padding: 10px 14px;
    border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
    border-radius: var(--radius-sm);
    background: var(--warn-soft);
    color: var(--warn-text);
    font-size: 13px;
}

.chaos-banner[hidden] { display: none; }
.chaos-banner strong { color: inherit; }
.chaos-banner .link-btn { margin-left: auto; }

.chaos-presets { display: flex; flex-direction: column; gap: 12px; }

.chaos-preset {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.chaos-preset:last-child { padding-bottom: 0; border-bottom: none; }
.chaos-preset p { margin-top: 4px; }
.chaos-preset .btn { flex-shrink: 0; }

@media (max-width: 600px) {
    .chaos-banner { margin: 12px 16px 0; }
}

/* Aba Diagramas: os SVGs são claros, então ficam num quadro branco nos dois temas */
.diagram-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.diagram-tabs .btn[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; box-shadow: none; }
a.btn { text-decoration: none; }
.diagram-summary { margin: 0 0 12px; color: var(--text-2); font-size: 13px; }
.diagram-frame { background: #ffffff; border: 1px solid var(--border); border-radius: 10px; overflow: auto; max-height: 80vh; }
.diagram-frame img { display: block; width: 100%; height: auto; }
.diagram-frame.is-actual img { width: auto; max-width: none; }
