/*
 * Firmeza backoffice: "anil e pemba".
 * The cool white of pemba and the deep blue of anil; dark mode is the gira at night.
 * One memorable thing: the navigation is a guia, sections strung as beads on a thread,
 * and statuses are small beads too. Everything else stays quiet. Type: Atkinson
 * Hyperlegible Next (made for low-vision readers; many who run a casa are elders).
 */

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("../fonts/atkinson-hyperlegible-next-latin-wght.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --pemba: #f5f6f8;      /* page */
  --cal: #ffffff;        /* surfaces */
  --carvao: #1d2130;     /* text */
  --cinza: #5d6375;      /* secondary text */
  --linha: #dadde6;      /* rules and borders */
  --linha-forte: #b9bfcf;
  --anil: #233a7a;       /* accent */
  --anil-ink: #ffffff;
  --anil-wash: #e8ecf7;  /* hover and selection */
  --vela: #9a6412;       /* attention */
  --vela-wash: #fbf1de;
  --dende: #a3302a;      /* danger, overdue */
  --folha: #2e6a4c;      /* paid, fine */

  /* Names the screens already use. */
  --accent: var(--anil);
  --accent-ink: var(--anil-ink);
  --ink: var(--carvao);
  --muted: var(--cinza);
  --paper: var(--pemba);
  --card: var(--cal);
  --line: var(--linha);
  --hover: var(--anil-wash);
  --danger: var(--dende);
  --ok: var(--folha);
  --warn-bg: var(--vela-wash);
  --warn-ink: var(--vela);

  --r-dialog: 12px;
  --r-card: 8px;
  --r-control: 6px;
  --radius: var(--r-card);

  /* Type scale: 13 / 14 / 16 / 19 / 23 / 30 on a 16px base. */
  --t-xs: .8125rem;
  --t-sm: .875rem;
  --t-md: 1rem;
  --t-lg: 1.1875rem;
  --t-xl: 1.4375rem;
  --t-2xl: 1.875rem;

  color-scheme: light dark;
}

/* Dark: when the system asks for it (theme "auto"), or when chosen in the header. Keep both blocks the same. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --pemba: #141826;
    --cal: #1b2031;
    --carvao: #e6e8ef;
    --cinza: #a3a9ba;
    --linha: #2c3247;
    --linha-forte: #3d4560;
    --anil: #a9b6f0;
    --anil-ink: #141826;
    --anil-wash: #232a42;
    --vela: #f2d49a;
    --vela-wash: #3a2e17;
    --dende: #f0a39d;
    --folha: #8ccba9;
  }
}
:root[data-theme="dark"] {
  --pemba: #141826;
  --cal: #1b2031;
  --carvao: #e6e8ef;
  --cinza: #a3a9ba;
  --linha: #2c3247;
  --linha-forte: #3d4560;
  --anil: #a9b6f0;
  --anil-ink: #141826;
  --anil-wash: #232a42;
  --vela: #f2d49a;
  --vela-wash: #3a2e17;
  --dende: #f0a39d;
  --folha: #8ccba9;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Atkinson Hyperlegible Next", system-ui, "Segoe UI", sans-serif;
  font-size: var(--t-md);
  line-height: 1.55;
  color: var(--carvao);
  background: var(--pemba);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--anil); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 10; background: var(--cal); padding: 6px 10px; border-radius: var(--r-control); }

:focus-visible { outline: 3px solid var(--anil); outline-offset: 2px; }

/* --- Shell --- */

.header { background: var(--cal); border-bottom: 1px solid var(--linha); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 24px; flex-wrap: wrap; }
.brand { font-weight: 750; font-size: var(--t-lg); letter-spacing: -.01em; text-decoration: none; color: var(--carvao); }
.header-tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: var(--t-sm); }
.header-tools select { width: auto; padding: 5px 8px; }
.who { color: var(--cinza); }
a.who { text-decoration: none; }
a.who:hover { text-decoration: underline; }

.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 58px); }
.signed-out .layout { grid-template-columns: 1fr; }
.signed-out .nav { display: none; }

/* The guia. Links after a group heading hang on a thread (::after) through their bead (::before). */
.nav { padding: 20px 14px 32px; display: flex; flex-direction: column; border-right: 1px solid var(--linha); }
.nav a {
  position: relative; display: block; padding: 7px 10px; border-radius: var(--r-control);
  color: var(--carvao); text-decoration: none; font-size: .9375rem;
}
.nav a:hover { background: var(--anil-wash); }
.nav a.active { font-weight: 700; color: var(--anil); }
.nav-group { margin: 22px 10px 6px; font-size: var(--t-sm); font-weight: 700; color: var(--carvao); line-height: 1.3; }
.nav-group ~ a { padding-left: 34px; }
.nav-group ~ a::after {
  content: ""; position: absolute; left: 17px; top: 0; bottom: 0; width: 1px; background: var(--linha-forte);
}
.nav-group ~ a::before {
  content: ""; position: absolute; z-index: 1; left: 13px; top: 50%; width: 9px; height: 9px; margin-top: -4.5px;
  border-radius: 50%; background: var(--pemba); border: 1.5px solid var(--linha-forte);
}
.nav-group ~ a:hover::before { border-color: var(--anil); }
.nav-group ~ a.active::before {
  left: 11.5px; width: 12px; height: 12px; margin-top: -6px; background: var(--anil); border-color: var(--anil);
  box-shadow: 0 0 0 3px var(--pemba);
}
/* The thread starts at the first bead and ends at the last one. */
.nav-group + a::after { top: 50%; }
.nav a:has(+ .nav-group)::after, .nav a:last-child::after { bottom: 50%; }
.nav-group + a:has(+ .nav-group)::after, .nav-group + a:last-child::after { display: none; }

.main { padding: 32px 32px 64px; max-width: 1160px; width: 100%; min-width: 0; outline: none; }
.screen.narrow { max-width: 420px; margin: 56px auto; }
.auth-links { margin: 18px 0 0; text-align: center; }
.narrow-card { max-width: 560px; }
.auth-links button.link { padding: 4px 2px; }

@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 2px; border-right: 0; border-bottom: 1px solid var(--linha); padding: 8px 10px; }
  .nav-group { width: 100%; margin: 8px 6px 2px; }
  .nav-group ~ a { padding-left: 24px; }
  .nav-group ~ a::after { display: none; }
  .nav-group ~ a::before { left: 8px; }
  .nav-group ~ a.active::before { left: 6.5px; }
  .header-inner { padding: 10px 16px; }
  .main { padding: 20px 16px 48px; }
}

/* --- Content --- */

h1 { font-size: var(--t-2xl); line-height: 1.15; font-weight: 700; letter-spacing: -.015em; margin: 0 0 20px; }
h2 { font-size: var(--t-lg); line-height: 1.3; font-weight: 700; margin: 32px 0 12px; }
h3 { font-size: var(--t-md); font-weight: 700; margin: 20px 0 4px; }
p { max-width: 72ch; }
.muted, .hint { color: var(--cinza); }
small.hint { font-size: var(--t-xs); }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 0 0 20px; }
.toolbar h1, .toolbar h2 { margin: 0 6px 0 0; }
.toolbar .spacer { flex: 1; }
.toolbar input[type=search], .toolbar select { width: auto; min-width: 220px; }
.toolbar input[type=month] { width: auto; }
.toolbar > a { padding: 6px 10px; border-radius: var(--r-control); text-decoration: none; font-size: var(--t-sm); }
.toolbar > a:hover { background: var(--anil-wash); }
.toolbar > a.active { background: var(--anil); color: var(--anil-ink); }

.card { background: var(--cal); border: 1px solid var(--linha); border-radius: var(--r-card); padding: 22px 24px; margin: 0 0 20px; }
.card > h2:first-child, .card > .toolbar:first-child h2, form.card > h2.full:first-child { margin-top: 0; }
.pre { white-space: pre-line; }

/* Platform overview figures. */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0; margin: 0 0 28px; border-top: 1px solid var(--linha); }
.tile { padding: 14px 16px 14px 0; color: var(--cinza); font-size: var(--t-sm); }
.tile strong { display: block; font-size: var(--t-xl); font-weight: 700; color: var(--carvao); font-variant-numeric: tabular-nums; }

/* Mensalidades: the month as a sentence and a thread filling up. */
.summary { margin: 0 0 24px; }
.summary-line { margin: 0 0 10px; font-size: var(--t-lg); }
.summary-line strong { font-size: var(--t-xl); font-variant-numeric: tabular-nums; }
.progress { height: 6px; border-radius: 3px; background: var(--anil-wash); max-width: 560px; overflow: hidden; }
.progress span { display: block; height: 100%; width: var(--share, 0%); background: var(--anil); border-radius: 3px; }
.summary-counts { display: flex; gap: 18px; flex-wrap: wrap; margin: 12px 0 0; }

.alert { padding: 12px 16px; border-radius: var(--r-card); background: var(--cal); border: 1px solid var(--linha); margin: 0 0 20px; }
.alert.error { border-color: var(--dende); color: var(--dende); }
.alert.warn { background: var(--vela-wash); color: var(--vela); border-color: transparent; }

/* Beads: a dot and a word. Statuses, cargos and markers. */
.badge {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: var(--t-sm); font-weight: 600; color: var(--cinza); line-height: 1.4;
}
.badge::before {
  content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%;
  background: var(--cal); border: 1.5px solid currentColor;
}
.badge.ok { color: var(--folha); }
.badge.ok::before { background: currentColor; }
.badge.danger { color: var(--dende); }
.badge.danger::before { background: currentColor; }
.badge.warn { color: var(--vela); }
.badge.warn::before { background: currentColor; }
.toolbar .badge + .badge { margin-left: 10px; }

.payment { font-size: var(--t-sm); min-width: 15em; }
td:has(.payment) { white-space: normal; }
.payment button.link { font-size: var(--t-sm); }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
dl.facts dt { color: var(--cinza); }
dl.facts dd { margin: 0; white-space: pre-wrap; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--swatch, var(--anil)); margin-right: 8px; vertical-align: middle; }

/* --- Tables --- */

.table-wrap { overflow-x: auto; background: var(--cal); border: 1px solid var(--linha); border-radius: var(--r-card); }
.card .table-wrap { border-radius: var(--r-control); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--linha); vertical-align: top; }
th { font-weight: 600; font-size: var(--t-xs); color: var(--cinza); background: var(--cal); padding-top: 10px; padding-bottom: 8px; border-bottom-color: var(--linha-forte); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--anil-wash) 55%, transparent); }
td a { font-weight: 600; }
/* Short values stay on one line; the table scrolls inside its frame instead of squeezing them. */
td { white-space: nowrap; }
td select { width: auto; min-width: 9em; min-height: 32px; padding: 4px 8px; font-size: var(--t-sm); }
td.actions, th.actions { text-align: right; white-space: nowrap; }
td.actions button { margin-left: 6px; min-height: 32px; padding: 4px 11px; font-size: var(--t-sm); }
td:has(.badge + .badge) { white-space: normal; min-width: 8em; }
td:has(.badge + .badge) .badge { margin: 0 10px 2px 0; }
.code { font-family: ui-monospace, Consolas, monospace; letter-spacing: .08em; font-size: 1.05rem; }

.pager { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 12px; font-size: var(--t-sm); }

/* --- Forms --- */

form.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px 20px; }
form.grid .full { grid-column: 1 / -1; }
form.grid h3.full { margin: 12px 0 -4px; padding-top: 16px; border-top: 1px solid var(--linha); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field[hidden] { display: none; }
.field.check { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.field.check .hint { flex-basis: 100%; padding-left: 28px; }
label { font-weight: 600; font-size: var(--t-sm); }
.field.check label { font-weight: 400; font-size: var(--t-md); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--anil); margin: 0; }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=url], input[type=number],
input[type=date], input[type=time], input[type=tel], input[type=month], select, textarea {
  font: inherit; color: inherit; background: var(--cal); border: 1px solid var(--linha-forte); border-radius: var(--r-control);
  padding: 8px 11px; width: 100%; min-height: 40px;
}
input::placeholder, textarea::placeholder { color: var(--cinza); opacity: .8; }
input:hover, select:hover, textarea:hover { border-color: var(--cinza); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--anil-wash); outline-offset: 0; border-color: var(--anil); }
textarea { resize: vertical; }
.actions-row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.inline { display: flex; gap: 8px; }
.inline input { width: 6em; }

button {
  font: inherit; font-size: .9375rem; font-weight: 600; cursor: pointer; border-radius: var(--r-control);
  padding: 7px 15px; min-height: 38px; border: 1px solid var(--linha-forte); background: var(--cal); color: var(--carvao);
}
button:hover:not(:disabled) { background: var(--anil-wash); border-color: var(--anil); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--anil); color: var(--anil-ink); border-color: var(--anil); }
button.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--anil) 88%, var(--carvao)); }
button.danger { color: var(--dende); border-color: currentColor; background: transparent; }
button.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--dende) 10%, transparent); border-color: var(--dende); }
button.link { border: 0; background: none; color: var(--anil); padding: 4px 6px; min-height: 0; font-weight: 600; }
button.link:hover:not(:disabled) { background: none; text-decoration: underline; }
button.link.danger { color: var(--dende); }
button.icon { padding: 4px 9px; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch input { position: absolute; opacity: 0; }
.swatch span { display: block; width: 28px; height: 28px; border-radius: 50%; background: var(--swatch); border: 3px solid transparent; cursor: pointer; }
.swatch span.default { background: var(--anil); }
.swatch input:checked + span { border-color: var(--carvao); }
.swatch input:focus-visible + span { outline: 3px solid var(--anil); outline-offset: 2px; }

/* Ordem dos trabalhos: a real sequence, so it's numbered. */
.steps { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.steps li { display: grid; grid-template-columns: 28px 1fr 1fr 200px auto; gap: 10px; align-items: start; background: var(--cal); border: 1px solid var(--linha); border-radius: var(--r-card); padding: 12px; }
.steps li.compact { grid-template-columns: 28px 1fr auto; }
.steps .num { font-weight: 700; padding-top: 8px; text-align: center; color: var(--anil); font-variant-numeric: tabular-nums; }
@media (max-width: 760px) { .steps li { grid-template-columns: 28px 1fr; } }

/* --- Dialogs and toast --- */

.dialog { border: 1px solid var(--linha); border-radius: var(--r-dialog); background: var(--cal); color: var(--carvao); padding: 24px 26px; max-width: 480px; width: calc(100% - 32px); }
.dialog.wide { max-width: 720px; }
.dialog::backdrop { background: rgb(20 24 38 / .5); }
.dialog h2 { margin-top: 0; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.dialog[open] { animation: rise .16s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(16px); opacity: 0; transition: .18s;
  background: var(--carvao); color: var(--pemba); padding: 10px 16px; border-radius: var(--r-card); pointer-events: none;
  max-width: calc(100% - 32px); font-weight: 600;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.error { background: var(--dende); color: var(--cal); }

@media (prefers-reduced-motion: reduce) {
  .dialog[open] { animation: none; }
  .toast { transition: none; }
}

/* Test page */
.tests li.pass::before { content: "✓ "; color: var(--folha); }
.tests li.fail::before { content: "✗ "; color: var(--dende); }

/* --- Site section --- */
.toolbar.tabs { gap: 4px; border-bottom: 1px solid var(--linha); padding-bottom: 8px; }
.actions-row.start { justify-content: flex-start; }
.code.small { font-size: var(--t-sm); letter-spacing: 0; overflow-wrap: anywhere; white-space: normal; }
.thumb { width: 72px; height: 72px; border-radius: var(--r-control); object-fit: cover; background: var(--anil-wash); display: inline-block; flex: none; }
.thumb.empty { border: 1.5px dashed var(--linha-forte); background: transparent; }
.cover-preview { width: 100%; max-height: 280px; object-fit: cover; border-radius: var(--r-control); display: block; }
.button-like {
  display: inline-flex; align-items: center; min-height: 38px; padding: 7px 15px; border-radius: var(--r-control);
  border: 1px solid var(--anil); background: var(--anil); color: var(--anil-ink); font-weight: 600; cursor: pointer; position: relative;
}
.button-like:focus-within { outline: 3px solid var(--anil); outline-offset: 2px; }
.button-like input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.photo-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.photo-card { background: var(--cal); border: 1px solid var(--linha); border-radius: var(--r-card); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.photo-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: var(--r-control); }
.photo-card .field.check label { font-size: var(--t-sm); }
.photo-actions { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.photo-pick { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); max-height: 360px; overflow: auto; margin-bottom: 8px; }
.photo-pick .pick { padding: 0; border: 2px solid transparent; border-radius: var(--r-control); overflow: hidden; min-height: 0; background: none; }
.photo-pick .pick:hover, .photo-pick .pick:focus-visible { border-color: var(--anil); }
.photo-pick img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.list-editor { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.list-editor li { display: flex; gap: 8px; align-items: center; }
.inline { align-items: center; flex-wrap: wrap; }

/* Aparência: swatches and a small live preview of the site */
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 8px; }
.languages { display: grid; gap: 8px; margin-bottom: 16px; }
.palette-item { position: relative; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-control); border: 1.5px solid var(--linha); cursor: pointer; font-weight: 600; font-size: var(--t-sm); }
.palette-item input { position: absolute; opacity: 0; }
.palette-item:has(input:checked) { border-color: var(--anil); background: var(--anil-wash); }
.palette-item:has(input:focus-visible) { outline: 3px solid var(--anil); outline-offset: 2px; }
.palette-dot { width: 22px; height: 22px; border-radius: 50%; background: var(--dot); flex: none; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .15); }
.site-preview { border: 1px solid var(--linha); border-radius: var(--r-card); overflow: hidden; max-width: 560px; }
.pv-page { background: var(--pv-bg); color: var(--pv-ink); font-size: .875rem; }
.pv-bar { background: var(--pv-main); color: var(--pv-on); display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; flex-wrap: wrap; white-space: pre; }
.pv-body { padding: 16px 14px 18px; }
.pv-label { color: var(--pv-muted); font-weight: 600; }
.pv-date { font-size: 1.6rem; font-weight: 750; letter-spacing: -.02em; margin-bottom: 10px; }
.pv-guia { border-left: 2px solid color-mix(in srgb, var(--pv-main) 45%, transparent); margin: 0 0 14px 6px; padding-left: 14px; display: flex; flex-direction: column; gap: 6px; }
.pv-item { position: relative; font-weight: 600; }
.pv-bead { position: absolute; left: -21px; top: .35em; width: 12px; height: 12px; border-radius: 50%; background: var(--pv-main); box-shadow: 0 0 0 3px var(--pv-bg); }
.pv-actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.pv-button { background: var(--pv-main); color: var(--pv-on); padding: 8px 14px; border-radius: 8px; font-weight: 700; }
.pv-link { color: var(--pv-main); text-decoration: underline; text-underline-offset: .2em; font-weight: 600; }

/* Minha conta: two-step verification */
.setup-steps { padding-left: 20px; display: grid; gap: 14px; margin: 0 0 16px; }
.setup-steps .muted { margin: 4px 0; }
.qr { width: 196px; margin: 10px 0; padding: 8px; background: #fff; border: 1px solid var(--linha); border-radius: var(--r-control); }
.qr svg { display: block; width: 100%; height: auto; }
.secret { display: inline-block; font-size: var(--t-md); letter-spacing: 0.05em; word-break: break-all; }
.code-input { max-width: 260px; font-variant-numeric: tabular-nums; letter-spacing: 0.1em; }
.recovery-codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.recovery-codes code { font-size: var(--t-md); }
.choice { display: block; margin: 0.75rem 0; }
