*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11";
}
img, svg { display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 500; margin: 0; letter-spacing: -0.01em; line-height: 1.2; }
p, dl, dd { margin: 0; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }
[hidden] { display: none !important; }
.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; }
:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; border-radius: 4px; }

/* Tipografia utilitária */
.eyebrow {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--ink);
}
.num { font-variant-numeric: tabular-nums; }
.display-num {
  font-family: var(--font-display);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  word-spacing: -0.05em;
}
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.accent { color: var(--orange); }
.link { color: var(--navy); font-weight: 500; font-size: 14px; transition: opacity var(--t); }
.link:hover { opacity: 0.75; }

/* Superfícies */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.pad { padding: 24px; }

/* Botões: um primário, um secundário, nada de cores por ação */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 20px;
  border-radius: var(--r); border: 1px solid transparent;
  font-weight: 500; font-size: 14px; white-space: nowrap; cursor: pointer;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease), color var(--t) var(--ease);
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-700); }
.btn-secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-secondary:hover { border-color: var(--line-strong); }
.btn-ghost { background: none; color: var(--ink-2); }
.btn-ghost:hover { color: var(--ink); }
.btn-block { width: 100%; }
.btn-sm { height: 36px; padding: 0 14px; font-size: 13px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.icon-btn {
  position: relative; display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%; color: var(--ink);
  transition: background var(--t);
}
.icon-btn:hover { background: var(--bg); }
.count {
  position: absolute; top: 4px; right: 3px;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--orange); color: #fff;
  font-size: 12px; font-weight: 600; line-height: 16px; text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Formulários */
.field { display: grid; gap: 6px; min-width: 0; }
.field input, .phone input { min-width: 0; width: 100%; }
.field > label, .field > legend { font-size: 13px; font-weight: 500; color: var(--ink); margin-bottom: 0; }
.hint { font-size: 13px; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%; height: 44px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface);
  transition: border-color var(--t), box-shadow var(--t);
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px var(--tint); }
.textarea { height: auto; min-height: 76px; padding: 10px 12px; resize: vertical; }
.select {
  appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236A6B7A' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.error-text { font-size: 13px; color: var(--bad); }

/* Estados: só texto pequeno e ponto */
.status {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  height: 24px; padding: 0 10px; border-radius: 12px;
  border: 1px solid var(--line); background: #fff;
  font-size: 13px; font-weight: 600;
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status--confirmado { color: var(--ok); }
.status--pendente { color: var(--pending); }
.status--rejeitado { color: var(--bad); }

/* Barra de progresso da obra */
.progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.progress__fill { height: 100%; background: var(--orange); border-radius: 2px; transform-origin: left; animation: grow 900ms var(--ease) both; }
@keyframes grow { from { transform: scaleX(0); } }

/* Avatar: círculo com borda fina, eco do monograma */
.avatar {
  display: inline-grid; place-items: center; flex: none;
  border-radius: 50%; border: 1px solid var(--line);
  background: var(--tint); color: var(--navy);
  font-family: var(--font-display); font-weight: 500; letter-spacing: 0.02em;
}

.avatar--photo { overflow: hidden; background: var(--line); }
.avatar--photo img { width: 100%; height: 100%; object-fit: cover; }

/* Conversa (membro e tesouraria) */
.chat { display: flex; flex-direction: column; gap: 6px; }
.chat__day { align-self: center; margin: 14px 0 6px; padding: 4px 12px; border-radius: 12px; background: #F2F2F5; font-size: 13px; color: var(--ink-2); }
.msg { max-width: 78%; display: flex; flex-direction: column; }
.msg p { padding: 10px 14px; border-radius: 18px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg time { font-size: 13px; color: var(--ink-2); margin: 4px 6px 0; }
.msg.is-me { align-self: flex-end; align-items: flex-end; }
.msg.is-me p { background: var(--navy); color: #fff; border-bottom-right-radius: 6px; }
.msg.is-them { align-self: flex-start; }
.msg.is-them p { background: #F2F2F5; color: var(--ink); border-bottom-left-radius: 6px; }
.msg__who { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 0 6px 4px; }
.composer { display: flex; align-items: flex-end; gap: 10px; }
.composer textarea {
  flex: 1; min-height: 46px; max-height: 140px; resize: none; padding: 12px 16px; border-radius: 23px;
  border: 1px solid var(--line); background: #FAFAFB; font-size: 14px; outline: none; line-height: 1.4;
  transition: border-color var(--t), background var(--t);
}
.composer textarea:focus { border-color: var(--navy); background: #fff; }
.composer button {
  flex: none; display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%;
  background: var(--navy); color: #fff; transition: background var(--t), opacity var(--t);
}
.composer button:hover { background: var(--navy-700); }
.composer button[disabled] { opacity: 0.4; cursor: not-allowed; }

/* Instalar no telemóvel */
.install { display: grid; gap: 18px; }
.install__app { display: flex; align-items: center; gap: 14px; }
.install__app img { border-radius: 14px; box-shadow: 0 0 0 1px var(--line); }
.install__name { font-size: 16px; font-weight: 700; }
.install__tabs { margin: 0; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.steps__item { display: flex; gap: 14px; align-items: flex-start; font-size: 14px; line-height: 1.5; }
.steps__n { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--tint); color: var(--navy); font-size: 13px; font-weight: 700; }
.kbd { display: inline-grid; place-items: center; vertical-align: middle; width: 26px; height: 26px; margin: 0 2px; border-radius: 7px; border: 1px solid var(--line); background: #FAFAFB; color: var(--navy); }
.install__url { font-size: 13px; color: var(--ink-2); padding: 14px 16px; border-radius: 12px; background: #FAFAFB; border: 1px dashed var(--line-strong); }
.install__url strong { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }

/* Tabelas limpas */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  font-size: 13px; font-weight: 500; color: var(--ink-2); text-align: left;
  padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .r { text-align: right; }
.table .num, .table .r { font-variant-numeric: tabular-nums; }
.table tbody tr.click { cursor: pointer; transition: background var(--t); }
.table tbody tr.click:hover { background: #FAFAF9; }
.cell-person { display: flex; align-items: center; gap: 12px; }
.cell-sub { font-size: 13px; color: var(--ink-2); }

/* Gráfico de barras */
.chart { display: flex; align-items: stretch; gap: 0; position: relative; }
.chart__axis { flex: none; display: flex; flex-direction: column; justify-content: space-between; padding: 0 10px 22px 0; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; text-align: right; min-width: 52px; }
.chart__axis span { line-height: 1; }
.chart__axis span:first-child { transform: translateY(-50%); }
.chart__axis span:last-child { transform: translateY(50%); }
.chart--axis .chart__track { position: relative; border-bottom: 1px solid var(--line-strong); }
.chart--axis .chart__track::before, .chart--axis .chart__track::after { content: ""; position: absolute; left: 0; right: 0; border-top: 1px dashed var(--line); }
.chart--axis .chart__track::before { top: 0; }
.chart--axis .chart__track::after { top: 50%; }
.chart__bar { position: relative; z-index: 1; }
.chart__col:hover .chart__bar { background: #9DA2C6; }
.chart__col.is-current:hover .chart__bar { background: var(--navy-700); }
.chart__col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.chart__val { font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.chart__track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.chart__bar {
  width: min(56%, 30px); min-height: 2px;
  background: #C9CCE0; border-radius: 1px 1px 0 0;
  transform-origin: bottom; animation: rise 700ms var(--ease) both;
}
.chart__col:nth-child(even) .chart__bar { animation-delay: 40ms; }
.chart__col.is-current .chart__bar { background: var(--navy); }
.chart__col.is-current .chart__val { color: var(--ink); font-weight: 500; }
.chart__label { font-size: 13px; color: var(--ink-2); }
.chart__col.is-current .chart__label { color: var(--ink); font-weight: 500; }
@keyframes rise { from { transform: scaleY(0); } }

/* Diálogos */
dialog.sheet {
  border: 0; padding: 0; border-radius: var(--r-lg);
  width: calc(100% - 32px); max-width: 520px; max-height: calc(100dvh - 48px);
  box-shadow: var(--shadow-pop); color: var(--ink);
}
dialog.sheet[open] { animation: pop 180ms var(--ease); }
dialog.sheet::backdrop { background: rgba(20, 21, 43, 0.32); }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }
.sheet__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 16px 24px; border-bottom: 1px solid var(--line); }
.sheet__head h2 { font-size: 16px; }
.sheet__body { padding: 24px; }
.sheet__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 24px; border-top: 1px solid var(--line); }

/* Recibo — o elemento-assinatura */
.receipt { padding: 26px 24px 22px; }
.receipt__head { display: flex; align-items: center; gap: 12px; padding-bottom: 18px; border-bottom: 2px solid var(--navy); }
.receipt__mark { width: 34px; height: auto; flex: none; }
.receipt__org { flex: 1; min-width: 0; }
.receipt__org p:first-child { font-size: 14px; font-weight: 700; color: var(--navy); }
.receipt__org p:last-child { font-size: 13px; color: var(--ink-2); margin-top: 1px; }
.receipt__no { text-align: right; }
.receipt__no span { display: block; font-size: 13px; color: var(--ink-2); }
.receipt__no strong { font-size: 14px; font-weight: 600; letter-spacing: 0.02em; }
.receipt__amount { display: flex; align-items: center; gap: 10px; margin-top: 22px; padding: 14px 16px; border: 1px solid var(--line-strong); border-radius: var(--r); }
.receipt__cur { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.receipt__amount .display-num { flex: 1; font-size: 30px; line-height: 1; font-weight: 600; color: var(--navy); }
.receipt__words { margin-top: 16px; font-size: 14px; line-height: 1.6; color: var(--ink); }
.receipt__words strong { font-weight: 600; }
.receipt__rows { margin-top: 18px; border-top: 1px solid var(--line); }
.receipt__row { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.receipt__row:last-child { border-bottom: 0; }
.receipt__row dt { color: var(--ink-2); flex: none; }
.receipt__row dd { text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.receipt__note { margin-top: 20px; padding: 14px 16px; background: var(--tint); border-radius: var(--r); font-size: 13px; color: var(--ink); }
.receipt__proof { margin-top: 20px; }
.receipt__proof img { max-width: 100%; border: 1px solid var(--line); border-radius: var(--r); }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: 96px; z-index: 50;
  transform: translate(-50%, 8px); opacity: 0; pointer-events: none;
  background: var(--navy-700); color: #fff; font-size: 14px;
  padding: 10px 16px; border-radius: var(--r);
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}
#toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.is-admin #toast { bottom: 32px; }

.empty { padding: 32px 24px; text-align: center; color: var(--ink-2); font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media print {
  body { background: #fff; }
  .hero, .m-nav, .receipt-actions, .back, .a-side, .a-top { display: none !important; }
  .receipt-wrap { margin: 0; border: 0; }
  .m-main { padding: 0 !important; }
  .card { border: 0; box-shadow: none; }
}

/* Régua da obra: escala da meta com marcas de 5% e o ponto atual */
.ruler { margin-top: 30px; }
.ruler__track { position: relative; height: 10px; background: var(--tint); }
.ruler__fill { position: absolute; inset: 0 auto 0 0; background: var(--navy); transform-origin: left; animation: grow 900ms var(--ease) both; }
.ruler__mark { position: absolute; top: -26px; bottom: -6px; width: 0; border-left: 2px solid var(--orange); }
.ruler__mark b { position: absolute; top: 0; left: 6px; font-size: 13px; font-weight: 700; color: var(--orange); white-space: nowrap; font-variant-numeric: tabular-nums; }
.ruler__mark.is-end b { left: auto; right: 6px; }
.ruler__ticks { position: relative; height: 8px; border-left: 1px solid var(--line-strong); }
.ruler__ticks i { position: absolute; top: 0; width: 1px; height: 4px; background: var(--line-strong); }
.ruler__ticks i.is-major { height: 8px; background: var(--ink-2); }
.ruler__scale { position: relative; height: 16px; margin-top: 4px; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.ruler__scale span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.ruler__scale span:first-child { transform: none; }
.ruler__scale span:last-child { transform: translateX(-100%); }
@media (max-width: 520px) {
  .receipt { padding: 22px 18px 18px; }
  .receipt__org p:first-child { font-size: 13px; white-space: nowrap; }
  .receipt__mark { width: 28px; }
  .receipt__amount { flex-wrap: wrap; row-gap: 8px; padding: 12px 14px; }
  .receipt__amount .display-num { font-size: 26px; }
}

/* Botão a preparar um ficheiro: girador, largura estável e sem cliques repetidos */
.btn.is-busy, .btn.is-done { pointer-events: none; }
.btn.is-busy { opacity: 0.92; }
.btn-spin { width: 16px; height: 16px; flex: none; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn-spin { animation-duration: 1600ms; } }
