/* Contas em Dia — app de telemóvel. Uma coluna, barra de separadores em baixo. */
:root {
  --bg: #f3f6f4; --surface: #ffffff; --fg: #17262b; --muted: #5e7177; --line: #d6dedb;
  --accent: #0f6f73; --accent-fg: #ffffff; --accent-soft: #dcefee;
  --good: #1f7a4d; --bad: #b4433a; --warn: #8a5f00;
  --good-soft: #dff0e6; --bad-soft: #f7e3e0; --warn-soft: #f6ecd2;
  --display: 'Outfit', system-ui, sans-serif;
  --body: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e191c; --surface: #162327; --fg: #e7eef0; --muted: #96a8ae; --line: #283a3f;
    --accent: #4fb9bc; --accent-fg: #06191b; --accent-soft: #163538;
    --good: #5fcf93; --bad: #f08c82; --warn: #e4b94c;
    --good-soft: #163527; --bad-soft: #3a1f1d; --warn-soft: #3a3016;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg); font-family: var(--body); font-size: 16px; line-height: 1.45;
  padding-top: env(safe-area-inset-top, 0px);
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { font-family: var(--display); margin: 0; text-wrap: balance; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

main {
  max-width: 640px; margin: 0 auto;
  padding-block: 16px 110px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 16px;
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--display); font-weight: 700; }
.brand i { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); color: var(--accent-fg);
  display: inline-grid; place-items: center; font-style: normal; font-size: .9rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.big { font-family: var(--display); font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.daynav { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px; text-align: center; }
.daynav strong { font-family: var(--display); font-size: 1.1rem; }
.iconbtn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  font-size: 1.3rem; cursor: pointer; }
.iconbtn:disabled { opacity: .35; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: .86rem; color: var(--muted); font-weight: 500; }
label.field > span.lbl { display: flex; justify-content: space-between; gap: 8px; }
input[type=text], input[type=email], input[type=date], input[type=time], input[inputmode], select, textarea {
  width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  padding: 10px 12px; font-size: 1.05rem; color: var(--fg);
}
input.money { font-family: var(--display); font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }
textarea { min-height: 120px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 380px) { .grid2 { grid-template-columns: 1fr; } }

.btn { min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  padding: 10px 16px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; text-decoration: none; color: var(--fg); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; font-size: .9rem; }

.calc { border-radius: 10px; padding: 10px 12px; background: var(--accent-soft); color: var(--fg); font-size: .95rem; }
.calc.warn { background: var(--warn-soft); }
.calc.bad { background: var(--bad-soft); }

.list { display: flex; flex-direction: column; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--line);
  background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; width: 100%; cursor: pointer; color: var(--fg); }
.item:last-child { border-bottom: 0; }
.item .t { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.item .s { grid-column: 1 / 2; color: var(--muted); font-size: .84rem; min-width: 0; overflow-wrap: anywhere; }
.item .v { grid-row: 1 / 3; grid-column: 2; align-self: center; text-align: right; font-weight: 600; }

.chip { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; min-width: 0; }
.kpi span { display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.kpi b { display: block; font-family: var(--display); font-size: 1.05rem; font-variant-numeric: tabular-nums;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi.good b { color: var(--good); } .kpi.bad b { color: var(--bad); }

.preview { width: 100%; max-height: 52vh; overflow: auto; border-radius: 10px; border: 1px solid var(--line); background: #fff; }
.preview img, .preview canvas { display: block; width: 100%; height: auto; }

.status { font-size: .9rem; display: flex; align-items: center; gap: 8px; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

table.days { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.days th, table.days td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; }
table.days th:first-child, table.days td:first-child { text-align: left; }
table.days th { color: var(--muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }
.tablewrap { overflow-x: auto; }

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
}
nav.tabs button { background: none; border: 0; padding: 10px 2px 12px; font-size: .74rem; font-weight: 600; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; position: relative; }
nav.tabs button .ic { font-size: 1.25rem; line-height: 1; }
nav.tabs button[aria-current="page"] { color: var(--accent); }
nav.tabs .badge { position: absolute; top: 4px; left: calc(50% + 8px); background: var(--bad); color: #fff; border-radius: 999px;
  font-size: .65rem; min-width: 18px; padding: 1px 5px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .92rem; z-index: 30;
  max-width: min(92vw, 520px); box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.center { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .95rem; overflow-wrap: anywhere;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.bar { height: 6px; border-radius: 3px; background: var(--accent-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
