:root {
  --navy: #1f2a44; --ink: #1d2433; --muted: #6b7385; --line: #e3e6ec; --bg: #f4f5f8; --card: #fff;
  --accent: #0f766e; --accent-soft: #e0f2f0;
  --ok: #15803d; --ok-bg: #e6f4ea; --warn: #b45309; --warn-bg: #fff4de; --error: #b91c1c; --error-bg: #fde7e7;
  --run: #1d4ed8; --run-bg: #e3ebfd;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 15px; margin: 0 0 12px; } .mt { margin-top: 24px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; } .r { text-align: right; }
main { max-width: 1440px; margin: 0 auto; padding: 20px 24px 40px; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; }

header.top { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 28px; padding: 10px 24px; }
header.top a { color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand small { font-weight: 400; opacity: .65; margin-left: 4px; }
.logo { background: var(--accent); border-radius: 6px; padding: 3px 7px; font-size: 12px; letter-spacing: .5px; }
header nav { display: flex; gap: 18px; } header nav a { opacity: .85; } header nav a:hover { opacity: 1; }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 13px; }
.pill.readonly { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.25); border-radius: 99px; padding: 3px 10px; font-size: 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check, label.seg { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
label.seg { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
input { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); }
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 7px 12px; cursor: pointer; color: var(--ink); }
.btn:hover { border-color: #c5cad4; } .btn.small { padding: 3px 8px; font-size: 12px; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; } .btn.big { padding: 11px 18px; font-size: 15px; margin-top: 10px; }
.alert { padding: 8px 12px; border-radius: 7px; } .alert.warn { background: var(--warn-bg); color: var(--warn); } .alert.error { background: var(--error-bg); color: var(--error); }

.badge { display: inline-block; border-radius: 99px; padding: 2px 9px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.error { background: var(--error-bg); color: var(--error); } .badge.na { background: #eef0f4; color: var(--muted); }
.badge.run { background: var(--run-bg); color: var(--run); } .badge.big { font-size: 14px; padding: 6px 14px; }
.tag { display: inline-block; background: #eef0f4; color: var(--muted); border-radius: 5px; padding: 0 6px; font-size: 11px; margin-left: 6px; }
.tag.ok { background: var(--ok-bg); color: var(--ok); } .tag.error { background: var(--error-bg); color: var(--error); }
.c-ok { color: var(--ok); } .c-warn { color: var(--warn); } .c-error { color: var(--error); }

.login { display: grid; place-items: center; min-height: 70vh; }
.login form { width: 360px; display: flex; flex-direction: column; gap: 14px; }

.hero { margin-bottom: 18px; }
.flow-mini { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.flow-mini span { background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 4px 12px; }
.flow-mini i { color: var(--muted); font-style: normal; }
.filter { width: 100%; margin-bottom: 8px; }
.tree { max-height: 460px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.tnode label { flex-direction: row; align-items: center; gap: 8px; padding: 6px; color: var(--ink); cursor: pointer; border-bottom: 1px solid #f0f1f4; }
.tnode label:hover { background: #f8f9fb; } .tnode .fname { flex: 1; } .tnode .count { color: var(--muted); font-size: 12px; }
.chosen { margin: 14px 0 0; }

table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); padding: 6px 8px; }
table.list td { border-bottom: 1px solid #f0f1f4; padding: 7px 8px; vertical-align: top; }
tr.click { cursor: pointer; } tr.click:hover td { background: #f8f9fb; }

.runhead { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 18px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* pipeline */
.pipeline { display: flex; align-items: stretch; gap: 0; margin-bottom: 18px; overflow-x: auto; }
.stage { flex: 1; min-width: 128px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px; text-align: center; transition: all .3s; }
.stage .sicon { font-size: 20px; } .stage .sval { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stage .stitle { font-size: 12px; font-weight: 600; } .stage .ssub { font-size: 11px; color: var(--muted); }
.stage.done { border-color: #b8dcc4; background: linear-gradient(#fff, #f3faf5); }
.stage.active { border-color: var(--run); box-shadow: 0 0 0 3px var(--run-bg); animation: pulse 1.4s infinite; }
.stage.idle { opacity: .6; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(29,78,216,.08); } }
.arrow { width: 26px; display: flex; align-items: center; justify-content: center; flex: none; }
.arrow span { width: 100%; height: 2px; background: repeating-linear-gradient(90deg, #aab1c0 0 6px, transparent 6px 10px); background-size: 20px 2px; animation: flow 1s linear infinite; position: relative; }
.arrow span::after { content: ""; position: absolute; right: -2px; top: -4px; border: 5px solid transparent; border-left-color: #aab1c0; }
@keyframes flow { to { background-position: 20px 0; } }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab { font: inherit; background: none; border: none; padding: 8px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

.email { margin-bottom: 14px; }
.ehead { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.eicon { font-size: 16px; }
.kids { margin-left: 14px; padding-left: 14px; border-left: 2px solid var(--line); margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.node { background: #fafbfc; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.node.error { border-color: #f3c2c2; background: #fff8f8; } .node.ignored { opacity: .6; }
.nhead { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .nhead .badge { margin-left: auto; }
.pages { display: grid; grid-auto-flow: row dense; gap: 6px 8px; margin-top: 10px; overflow-x: auto; padding-bottom: 4px; }
.thumb { grid-row: 1; position: relative; border: 2px solid var(--line); border-radius: 6px; overflow: hidden; background: #fff; height: 190px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.thumb.hasqr { border-color: #7cc49a; }
.thumb .pno { position: absolute; top: 3px; left: 3px; background: rgba(31,42,68,.8); color: #fff; font-size: 10px; border-radius: 4px; padding: 0 5px; }
.thumb .qrflag { position: absolute; bottom: 3px; right: 3px; background: var(--ok); color: #fff; font-size: 10px; border-radius: 4px; padding: 0 5px; }
.thumb .qrflag.none { background: #9aa2b1; }
.ibar { display: block; border-radius: 5px; padding: 3px 7px; font-size: 11px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 4px solid; }
.ibar.ok { background: var(--ok-bg); color: var(--ok); } .ibar.warn { background: var(--warn-bg); color: var(--warn); } .ibar.error { background: var(--error-bg); color: var(--error); }
.ibar.info { background: #eef0f4; color: var(--muted); }
.badge.info { background: #eef0f4; color: var(--muted); }
.checks li.info .dot { background: #9aa2b1; }
.summary.info { border-top: 4px solid #9aa2b1; }
.ibar:hover { filter: brightness(.96); }
.boundary { margin-top: 6px; color: var(--muted); }
.log { background: #0f172a; color: #cbd5e1; border-radius: 10px; padding: 12px; font: 12px/1.6 ui-monospace, Menlo, monospace; max-height: 520px; overflow: auto; }
.ev span { color: #64748b; } .ev.warn { color: #fcd34d; } .ev.error { color: #fca5a5; }

/* fatura */
.crumbs { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; font-size: 13px; }
.crumbs > span:not(.spacer):not(.muted) { background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs .spacer { flex: 1; }
.invoice { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.viewer { position: sticky; top: 12px; max-height: calc(100vh - 24px); display: flex; flex-direction: column; padding: 12px; }
.vhead { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; } .vhead .btn { margin-left: auto; }
.vpages { overflow: auto; display: flex; flex-direction: column; gap: 12px; background: #e9ebf0; padding: 12px; border-radius: 8px; }
.vpages figure { margin: 0; } .vpages img { width: 100%; display: block; box-shadow: 0 1px 4px rgba(0,0,0,.15); border: 3px solid transparent; }
.vpages figure.mine img { border-color: var(--accent); } .vpages figure.other { opacity: .45; }
.vpages figcaption { font-size: 12px; color: var(--muted); padding: 4px 2px; }
.details { display: flex; flex-direction: column; gap: 14px; }
.summary.ok { border-top: 4px solid var(--ok); } .summary.warn { border-top: 4px solid var(--warn); } .summary.error { border-top: 4px solid var(--error); }
.sumtop { display: flex; gap: 14px; align-items: center; } .sumtop h1 { font-size: 19px; }
.total { margin-left: auto; text-align: right; font-size: 24px; font-weight: 700; }
.total small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 12px; margin: 14px 0 0; } .kv dt { color: var(--muted); } .kv dd { margin: 0; }
.checks { list-style: none; padding: 0; margin: 0; }
.checks li { display: grid; grid-template-columns: 14px 220px 1fr; gap: 8px; padding: 7px 0; border-bottom: 1px solid #f0f1f4; align-items: baseline; }
.checks .dot { width: 10px; height: 10px; border-radius: 50%; background: #c3c8d2; }
.checks li.ok .dot { background: var(--ok); } .checks li.warn .dot { background: #f59e0b; } .checks li.error .dot { background: var(--error); }
.checks li.error span:last-child { color: var(--error); } .checks li.warn span:last-child { color: var(--warn); }
table.cmp, table.qrf { width: 100%; border-collapse: collapse; }
table.cmp th { text-align: left; font-size: 12px; color: var(--muted); padding: 6px; border-bottom: 1px solid var(--line); }
table.cmp td, table.qrf td { padding: 6px; border-bottom: 1px solid #f0f1f4; }
table.cmp tr.ok td:last-child { color: var(--ok); font-weight: 700; }
table.cmp tr.error td { background: var(--error-bg); } table.cmp tr.error td:last-child { color: var(--error); font-weight: 700; }
table.qrf td.k { font-family: ui-monospace, Menlo, monospace; color: var(--accent); width: 34px; } table.qrf td.v { font-family: ui-monospace, Menlo, monospace; }
code.raw { display: block; word-break: break-all; background: #f4f5f8; padding: 8px; border-radius: 6px; font-size: 11px; margin-top: 6px; }

.progress { margin-bottom: 14px; } .progress .bar { height: 8px; background: #eef0f4; border-radius: 99px; overflow: hidden; }
.progress .bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.ptext { margin-top: 6px; }
input.nif { width: 8.5em; font-family: ui-monospace, Menlo, monospace; padding: 4px 6px; }

@media (max-width: 1000px) { .grid2, .invoice { grid-template-columns: 1fr; } .viewer { position: static; max-height: none; } }

.groups { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; align-items: flex-start; }
.gcard { font: inherit; text-align: left; background: #fff; border: 1px solid var(--line); border-left: 4px solid #9aa2b1; border-radius: 8px; padding: 8px 16px; min-width: 150px; color: var(--ink); }
button.gcard { cursor: pointer; } button.gcard:hover { background: #f8f9fb; }
.gcard b { display: block; font-size: 22px; } .gcard span { font-size: 12px; color: var(--muted); }
.gcard.auto { border-left-color: var(--ok); } .gcard.manual { border-left-color: #f59e0b; } .gcard.error { border-left-color: var(--error); }
.badge.g-auto { background: var(--ok-bg); color: var(--ok); } .badge.g-manual { background: var(--warn-bg); color: var(--warn); } .badge.g-outros { background: #eef0f4; color: var(--muted); }
.greasons { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 16px; } .greasons summary { cursor: pointer; } .greasons td { padding: 2px 8px 2px 0; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.closure { margin: 6px 0 2px; } .closure.ok { color: var(--ok); } .closure.warn { color: var(--warn); }

.simulation { margin: 14px 0; padding: 14px 18px; }
.simulation[hidden] { display: none; }
.simhead { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.simhead h2 { margin: 0; }
.simulation summary { cursor: pointer; font-weight: 600; margin: 8px 0; }
.simscroll { max-height: 320px; overflow: auto; }
.simulation code.wrap { overflow-wrap: anywhere; }
