* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  /* Stop the whole page from rubber-banding when you drag the tree. Scrolling
     happens inside #app, not the document. */
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; overflow: hidden; }

/* Header ------------------------------------------------------------------- */
.site-header {
  display: flex;
  align-items: center;
  gap: 10px 22px;
  padding: 12px 22px;
  background: var(--green);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.5);
  flex-wrap: wrap;
}
.site-header .logo-link { display: inline-flex; align-items: center; line-height: 0; flex-shrink: 0; }
.site-header .logo {
  height: 36px;
  width: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18), 0 0 0 4px rgba(255, 255, 255, 0.05);
}
.site-header h1 {
  font-family: var(--font-display);
  font-size: 19px;
  margin: 0;
  margin-right: 6px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.logout-btn {
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 7px 15px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13.5px;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.logout-btn:hover { background: rgba(255, 255, 255, 0.1); color: #fff; border-color: rgba(255, 255, 255, 0.35); }

.site-header nav { display: flex; gap: 2px; background: rgba(255, 255, 255, 0.06); padding: 3px; border-radius: var(--radius-sm); }
.site-header nav a {
  color: rgba(255, 255, 255, 0.72);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 7px;
  font-weight: 600;
  font-size: 14px;
  transition: background .15s ease, color .15s ease;
}
.site-header nav a:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.site-header nav a.active { background: #fff; color: var(--green); }

.search-wrap { margin-left: auto; position: relative; }
#search {
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  width: 230px;
  max-width: 50vw;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  transition: background .15s ease, border-color .15s ease;
}
#search::placeholder { color: rgba(255, 255, 255, 0.5); }
#search:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.4);
}

/* Main + panels ------------------------------------------------------------ */
#app { flex: 1; padding: 40px 32px 64px; overflow: auto; }

/* Content tabs flow seamlessly on the page — no outer card. Structure comes
   from full-width hairline rules and the small sub-cards, not a big frame. */
.panel {
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
  padding: 0;
  max-width: 1060px;
  margin: 0 auto;
}
/* Page title — refined display serif for editorial character. */
.panel h2 {
  color: var(--ink);
  margin: 0;
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -0.8px;
  line-height: 1.05;
}
/* Section heading: a small uppercase label with a hairline rule that fades out. */
.panel h3 {
  color: var(--muted);
  margin: 36px 0 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 16px;
}
.panel h3::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, var(--line), transparent);
}
.muted { color: var(--muted); }
.muted-tag {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-left: 6px;
}
.panel p { line-height: 1.6; }

/* Small uppercase label above a heading — same eyebrow throughout the app. */
.eyebrow {
  margin: 0 0 14px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  position: relative;
  padding-left: 28px;
}
.eyebrow::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 20px;
  height: 1px;
  background: var(--ink);
  opacity: 0.4;
}
.lead { font-size: 17px; color: var(--muted); max-width: 60ch; margin-top: 14px; line-height: 1.55; }

/* Stats as clean borderless figures, separated from the content by a rule. */
.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 48px;
  margin: 28px 0 26px;        /* breathing room between the rule and whatever follows */
  padding-bottom: 26px;
  border-bottom: 1px solid var(--line);
}
.stat-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 0;
  min-width: 0;
  background: none;
  border: none;
  box-shadow: none;
}
.stat-num {
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 600;
  letter-spacing: -0.8px;
  line-height: 1;
  color: var(--ink);
}
.stat-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 4px;
}
.stat { font-size: 16px; }

.actions { margin: 26px 0 4px; display: flex; flex-wrap: wrap; gap: 10px; }

/* Bulk-download buttons on Home. Same ghost-button look as the rest, but
   spaced away from the stats above and the "Raízes" heading below. */
.home-bulk-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 6px 0 0; }
.home-bulk-actions button:disabled { opacity: 0.6; cursor: default; }

/* Title row that pairs an h2 with a small actions slot (e.g. the filter gear
   on Unlinked). Wraps cleanly on narrow screens. */
.page-title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-title-row h2 { margin: 0; }
.page-actions { display: flex; align-items: center; gap: 8px; }
/* When the filter gear sits on the page (not a toolbar), give it the same hairline button look. */
.page-actions .viewer-filter-wrap > button {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  padding: 6px 12px;
  font-size: 16px;
}
.page-actions .viewer-filter-wrap > button:hover { background: var(--bg); border-color: var(--muted); }

/* Buttons ------------------------------------------------------------------ */
button {
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid transparent;
  background: var(--btn-bg);
  color: var(--btn-fg);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s ease, transform .05s ease, box-shadow .15s ease;
}
button:hover { background: var(--btn-bg-hover); }
button:active { transform: translateY(1px); }

.btn-ghost {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line-strong);
}
.btn-ghost:hover { background: var(--bg); border-color: var(--muted); }

:where(a, button, summary, input, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

a { color: var(--ink); text-decoration-color: var(--line-strong); text-underline-offset: 2px; }
.panel p a { color: var(--ink); font-weight: 600; }
.panel p a:hover { color: var(--accent); }

/* Link lists (roots / godsons) as a tidy card grid. */
.root-list, .godson-list {
  list-style: none;
  padding: 0;
  margin: 0 0 4px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(252px, 1fr));
  gap: 10px;
}
.root-list li, .godson-list li { margin: 0; }
.root-list a, .godson-list a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--ink);
  font-weight: 600;
  transition: border-color .15s ease, box-shadow .15s ease, transform .1s ease;
}
.root-list a:hover, .godson-list a:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.root-list a .muted, .godson-list a .muted {
  font-weight: 600;
  font-size: 12px;
  margin-left: auto;
  min-width: 24px;
  text-align: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--sunken);
  border: 1px solid var(--line);
  color: var(--muted);
}

/* Member profile page — a proper profile: generated geometric banner up top,
   the avatar straddling the banner and the data area, then the details below.
   The whole thing sits in a card that fills the panel width. */
.profile-page {
  background: var(--paper);
  /* Bleed to the edges of #app (cancel its 40/32/64 padding) so the profile
     IS the page, not a floating card. No border/radius/shadow chrome. */
  margin: -40px -32px -64px;
  max-width: none;
  min-height: calc(100% + 104px);      /* 40 top + 64 bottom padding */
  padding: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  /* Block flow (banner → identity → body). The tree embed is positioned
     absolutely on top of this, popped out over the right side. */
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.profile-banner {
  position: relative;
  height: 240px;
  background: var(--banner-base, var(--sunken));
  overflow: hidden;
}
.profile-banner svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
/* EAISEL logo peeking out from the centre of the banner — the top portion
   sits inside the banner and the rest is clipped by overflow:hidden. Kept
   translucent so it feels like a watermark rather than a stamp. */
.profile-banner::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 380px;
  height: 380px;
  transform: translate(-50%, 42%);
  background: url("../assets/eaisel-logo.png") center / contain no-repeat;
  opacity: 0.4;
  pointer-events: none;
  z-index: 1;
}

/* Identity strip: avatar overlaps the banner; name + role sit beside it, with
   the action buttons pushed to the right. Wraps cleanly on narrow screens. */
.profile-identity {
  display: flex;
  align-items: flex-start;           /* name & role sit high, next to the avatar's top */
  gap: 24px;
  padding: 8px 32px 22px;
  margin-top: -60px;                 /* avatar overlaps the banner; name clears it */
  flex-wrap: wrap;
}
.profile-avatar-slot { flex-shrink: 0; }
.profile-headline {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  padding-top: 68px;                 /* centre name & role vertically on the avatar */
  gap: 6px;
}
/* Role sits on one line with the Notas button after it. */
.profile-role-line {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.profile-role-line .profile-role { margin: 0; }
/* Smooth sans, heavy weight (no jittery serif). Room for descenders/accents
   (ç, g, j) instead of clipping; long names wrap rather than get cut. */
.profile-headline h2 {
  margin: 0;
  font-family: var(--font);
  font-weight: 800;
  letter-spacing: -0.4px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
/* Role sits under the name — a little smaller, muted, no eyebrow dash. */
.profile-role {
  margin: 6px 0 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--muted);
  font-family: var(--font);
}
/* Data area: sits on a light-gray backdrop to separate it from the identity
   strip above. Sections are inline label rows on that backdrop, echoing the
   reference profile-page layout — cleaner than opaque cards. */
.profile-body {
  padding: 20px 32px 32px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}
.profile-section {
  margin: 0;
  padding: 14px 20px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 20px;
}
.profile-section h3 {
  margin: 0;
  flex: 0 0 130px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.profile-section > *:not(h3) { flex: 1; min-width: 0; }
/* Fields section (custom columns) keeps its own stacked grid. */
.profile-section .profile-info { margin: 0; }
/* No full-width rules stretching across the page. */
.profile-body h3::after { display: none; }


/* Field info: label + value rows, editorial spacing, per-field hairlines that
   stop at the row's own width (not stretching across the page). Auto-fills
   into two columns on wide screens. */
.profile-info {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0 32px;
  margin: 6px 0 4px;
}
.pfield {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.pfield-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.pfield-value {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

/* Notas button — a straight rectangle, sits inline right after the role. */
.profile-notes-btn {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 0;
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  transition: background .15s ease, border-color .15s ease;
}
.profile-notes-btn:hover { background: var(--sunken); border-color: var(--muted); }

/* Tree embed: read-only mini-map centred on the current member. Square, with
   a clear "click me" affordance; a subtle "Abrir na árvore" caption on hover. */
/* Tree embed — a compact card popped out over the top-right of the profile,
   floating above the banner/identity with a strong shadow. Fixed (short)
   height; does not stretch the page. */
.profile-tree-embed {
  position: absolute;
  top: 120px;
  right: 32px;
  width: min(560px, 42%);
  height: 300px;
  z-index: 5;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
  transition: box-shadow .15s ease, transform .1s ease, border-color .15s ease;
}
.profile-tree-embed:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.profile-tree-embed svg {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;                    /* block all interactions inside */
}
.profile-tree-embed svg * { pointer-events: none; }
/* Highlight the current member in the mini-map so you can spot them. */
.profile-tree-embed .node.is-current rect:first-of-type {
  stroke: var(--ink) !important;
  stroke-width: 5 !important;
  filter: drop-shadow(0 0 8px rgba(0, 0, 0, 0.25));
}
/* Overlay caption that appears on hover — reads as "Open in tree". */
.profile-tree-embed::after {
  content: "Abrir na árvore ↗";
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 5px 10px;
  background: rgba(20, 23, 28, 0.82);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity .15s ease;
  pointer-events: none;
}
.profile-tree-embed:hover::after { opacity: 1; }

.profile-avatar {
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: var(--paper);
  border: 6px solid var(--paper);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.profile-avatar::before {
  content: attr(data-initials);
  /* Smooth sans, heavy weight — matches the profile name/role fonts. */
  font-family: var(--font);
  font-size: 64px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: -0.02em;
}
.profile-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* Editable avatar (gated app only): click to upload a new picture. The overlay
   text appears on hover so the affordance is discoverable without being noisy. */
.profile-avatar.is-editable { cursor: pointer; }
.profile-avatar.is-editable::after {
  content: "Trocar foto";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 23, 28, 0.55);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity .15s ease;
  z-index: 2;
}
.profile-avatar.is-editable:hover::after,
.profile-avatar.is-editable:focus-within::after { opacity: 1; }

/* Notebook dialog: roomy textarea modal for jotting member-specific notes. */
.notebook-dialog {
  width: min(960px, 96vw);
  max-width: 960px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  /* Horizontal centering is overridden by JS when we know where .profile-main
     sits — the dialog is aligned to the data column, not the whole viewport. */
}
.notebook-dialog::backdrop {
  background: rgba(20, 23, 28, 0.5);
}
.notebook-form { display: flex; flex-direction: column; gap: 0; }
.notebook-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.notebook-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.notebook-close {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 4px 8px;
  font-size: 16px;
  cursor: pointer;
}
.notebook-close:hover { color: var(--ink); background: var(--sunken); }
.notebook-text {
  font: inherit;
  font-size: 15px;
  line-height: 1.55;
  width: 100%;
  height: min(60vh, 460px);
  min-height: 220px;
  padding: 18px 20px;
  border: none;
  background: transparent;
  color: var(--ink);
  resize: vertical;
}
.notebook-text:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent-weak); }
.notebook-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
}
.notebook-status { font-size: 12.5px; min-height: 1em; }
.notebook-save { padding: 7px 16px; font-size: 13.5px; }

/* Member card modal — a shareable landscape "trading card": geometric banner
   (with the full EAISEL logo) as background, the member's photo covering the
   right edge top-to-bottom, name/role + configured attributes on the left. */
.member-card-dialog {
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  overflow: visible;
  max-width: none;
  width: max-content;
}
/* Only lay out the flex column while the dialog is OPEN — otherwise this
   display would override the UA `dialog:not([open]) { display:none }` and the
   card would never hide when closed. */
.member-card-dialog[open] {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
}
.member-card-dialog::backdrop { background: rgba(20, 23, 28, 0.6); backdrop-filter: blur(3px); }

.member-card {
  position: relative;
  width: min(600px, 92vw);
  aspect-ratio: 5 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--mcard-base, var(--sunken));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  color: var(--mcard-fg, #fff);
}
.member-card { position: relative; z-index: 1; }

/* Render frame: holds the exported card SVG at 1:1 so the preview matches the
   copied/downloaded PNG. The SVG's own rounded corners (rx=14) define the
   shape; the drop-shadow follows that shape. */
.mcard-render {
  position: relative;
  z-index: 1;
  width: min(600px, 92vw);
  aspect-ratio: 5 / 3;
  filter: drop-shadow(0 24px 60px rgba(0, 0, 0, 0.45));
}
.mcard-svg-holder { position: absolute; inset: 0; }
.mcard-svg-holder svg { display: block; width: 100%; height: 100%; }

/* Download / copy buttons under the card — one on each side (bottom-left and
   bottom-right), lifted above the card's drop shadow. */
.mcard-actions {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.mcard-side-btn {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.mcard-side-btn:hover { background: var(--bg); border-color: var(--muted); }
.mcard-side-btn:disabled { opacity: 0.6; cursor: default; }

/* Background layers: geometric SVG fills; the full logo sits centred on top,
   translucent (a watermark, not a stamp). */
.mcard-bg { position: absolute; inset: 0; }
.mcard-bg svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.mcard-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("../assets/eaisel-logo.png") center / 66% no-repeat;
  opacity: 0.28;
}

/* Photo panel: a diagonally-cut slab on the right edge. The photo fills it
   (cover); an accent "slash" sits just behind and peeks along the diagonal so
   the cut reads as a deliberate sports-card edge, not a straight seam. */
.mcard-photo-wrap {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 50%;
  z-index: 2;
}
/* Accent slash — a thin white band, cut a touch wider so a diagonal line
   shows to the left of the photo. */
.mcard-slash {
  position: absolute;
  inset: 0;
  background: #fff;
  clip-path: polygon(25% 0%, 100% 0%, 100% 100%, 5% 100%);
}
.mcard-photo {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--mcard-base, var(--sunken));
  /* Cut just inside the slash so only a thin white band shows along the edge. */
  clip-path: polygon(27% 0%, 100% 0%, 100% 100%, 7% 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Initials shown when no photo loads (img hidden). */
.mcard-photo::after {
  content: attr(data-initials);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: 18%;               /* nudge off the diagonal cut */
  /* Smooth sans, heavy weight — matches the name/role fonts on the card. */
  font-family: var(--font);
  font-size: 68px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.55);
  z-index: 0;
}
.mcard-photo-main {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  /* Portrait sources fill the width entirely — object-position can't shift
     them horizontally. A transform on the element itself always works: pull
     the image rightward within its panel so the subject clears the diagonal
     cut on the left. The .mcard-photo clip-path hides the empty area exposed
     on the left. */
  transform: translateX(7%);
}

/* Content: name/role and attributes, left side, over a readability scrim. */
.mcard-content {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 3;
  padding: 22px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.mcard-head { display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
.mcard-name {
  margin: 0;
  /* Smooth sans (same family as the tree), heavy weight — no jittery serif. */
  font-family: var(--font);
  font-size: 30px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.2px;
  overflow-wrap: anywhere;
  color: var(--mcard-fg);
}
/* Role — below the name, left-aligned, a touch greyer. No divider line. */
.mcard-role {
  margin: 5px 0 0;
  padding: 0;
  text-align: left;
  font-family: var(--font);
  font-size: 20px;
  font-weight: 800;
  /* Trailing letter-spacing shifts the block's optical centre but pads the
     right edge — a negative text-indent cancels the leading half so it lines
     up flush under the name. */
  letter-spacing: 0.16em;
  text-indent: 0.1em;
  text-transform: uppercase;
  color: var(--mcard-fg);
  opacity: 0.62;
}
/* Attributes pinned to the bottom of the card; each field is one row with a
   single full-width separator above it. */
.mcard-attrs {
  margin-top: auto;
  display: flex;
  flex-direction: column;
}
.mcard-field {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid color-mix(in srgb, var(--mcard-fg) 22%, transparent);
}
.mcard-field:first-child { border-top: none; }
.mcard-field-label {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mcard-fg);
  opacity: 0.82;
  white-space: nowrap;
}
.mcard-field-value {
  flex: 1;
  min-width: 0;
  font-size: 14.5px;
  font-weight: 800;
  line-height: 1.2;
  color: var(--mcard-fg);
  text-align: right;
  overflow-wrap: anywhere;
}
/* Flat translucent overlay spanning the WHOLE card, sitting above the banner
   but BEHIND the slash/photo (z-index 1 vs the photo's 2) — so it lifts the
   text legibility without touching the picture. Adjust with --mcard-scrim:
     0   = no overlay (banner fully visible, text hard to read)
     1   = solid panel (banner fully hidden)
   A light banner gets a white overlay (dark text on top); a dark banner gets
   a dark overlay (light text on top). */
/* --mcard-scrim: 0 = no white/dark layer (full base + shapes visible),
   1 = solid panel (base fully hidden). Lower it to let the branch colour
   or the geometric shapes read more strongly. */
.member-card { --mcard-scrim: 0.25; }
.mcard-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.member-card[data-fg="dark"] .mcard-overlay {
  background: rgba(255, 255, 255, var(--mcard-scrim));
}
.member-card[data-fg="light"] .mcard-overlay {
  background: rgba(12, 14, 18, var(--mcard-scrim));
}

.mcard-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
}
.mcard-close:hover { background: rgba(0, 0, 0, 0.6); }

/* No-photo mode: drop the photo panel and the logo watermark. The content
   switches to the .mcard-np layout below. */
.member-card.mcard-no-photo .mcard-photo-wrap { display: none; }
.member-card.mcard-no-photo .mcard-bg::after { display: none; }

/* No-photo layout: a role "tag" (red accent bar + label) and two decorative
   badges across the top, a big centred name filling the middle, and the
   attributes as a two-column grid pinned to the bottom. Kept in sync with
   buildNoPhotoForeground() in views.js so the popup matches the exported PNG. */
.mcard-content.mcard-np {
  width: 100%;
  padding: 20px 30px;
  gap: 0;
}
/* Header: role on the left, badges on the right. */
.mcard-np-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 30px;
}
.mcard-badges { display: flex; gap: 8px; }
.mcard-badge-svg { display: inline-flex; width: 30px; height: 30px; }
.mcard-badge-svg svg { display: block; width: 100%; height: 100%; }
.mcard-np-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 0 20px;              /* pulled up toward the header */
}
.mcard-np .mcard-name {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: 0;
  text-align: center;
  line-height: 1.0;
}
.mcard-np-main { font-size: 66px; font-weight: 800; }
/* Nickname stays on one line — the fitted font-size (set inline) keeps it
   inside the card rather than wrapping. */
.mcard-np-nick { font-size: 48px; font-weight: 800; white-space: nowrap; }
/* Role in the top-left of the header band. */
.mcard-np-role {
  margin: 0;
  font-family: var(--font);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-align: left;
  color: var(--mcard-fg);
  opacity: 0.7;
}
.mcard-np-grid {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 36px;
}
.mcard-np-grid::before {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 50%;
  width: 1px;
  background: color-mix(in srgb, var(--mcard-fg) 28%, transparent);
}
.mcard-np-grid.mcard-np-grid-single::before { display: none; }
.mcard-np-cell {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--mcard-fg) 28%, transparent);
}

/* Upload-picture modal: a small dialog with a click-or-paste drop zone. The
   same dialog is reused across opens; listeners are bound once and dispatch
   to a module-scoped upload pipeline that's swapped per open. */
.upload-dialog {
  width: min(420px, 92vw);
  padding: 20px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.upload-dialog::backdrop {
  background: rgba(20, 23, 28, 0.5);
}
.upload-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 4px 8px;
  font-size: 16px;
  cursor: pointer;
}
.upload-close:hover { color: var(--ink); background: var(--sunken); }
.upload-title {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.upload-zone {
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--sunken);
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.upload-zone:hover,
.upload-zone:focus-visible,
.upload-zone.is-drag {
  background: var(--bg);
  border-color: var(--accent);
  outline: none;
}
.upload-icon {
  font-family: var(--font-display);
  font-size: 48px;
  font-weight: 300;
  color: var(--muted);
  line-height: 1;
  margin-bottom: 10px;
}
.upload-prompt {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
}
.upload-prompt .muted { font-size: 12.5px; }
.upload-status { margin: 12px 0 0; font-size: 12.5px; min-height: 1em; }
.upload-actions {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}
.upload-reset {
  padding: 8px 14px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  border-radius: var(--radius-sm);
}

/* Bulk-download options dialog (Home → "Descarregar cartões"). Piggybacks on
   .upload-dialog for the outer shell; these rules only cover the mode picker,
   the cols/rows grid, and the action row. */
.cards-opts-dialog .co-opt {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0;
  font-size: 14px;
  cursor: pointer;
}
.cards-opts-dialog .co-opt small { display: block; margin-top: 2px; }
.cards-opts-dialog .co-sep-opts {
  display: flex;
  gap: 14px;
  padding: 4px 0 4px 24px;
  font-size: 13px;
  transition: opacity .15s ease;
}
.cards-opts-dialog .co-sep-opts label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.cards-opts-dialog .co-sep-opts small { margin-left: 4px; }
.cards-opts-dialog .co-sep-opts.is-off {
  opacity: 0.35;
  pointer-events: none;
}
.cards-opts-dialog .co-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 4px 0 4px 24px;
  font-size: 13px;
  transition: opacity .15s ease;
}
.cards-opts-dialog .co-grid label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.cards-opts-dialog .co-grid input[type="number"] {
  width: 62px;
  padding: 5px 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--sunken);
  color: var(--ink);
  font: inherit;
}
.cards-opts-dialog .co-grid.is-off {
  opacity: 0.35;
  pointer-events: none;
}
.cards-opts-dialog .co-wallcards {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 0 4px;
  margin-top: 6px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  cursor: pointer;
}
.cards-opts-dialog .co-wallcards small { display: block; margin-top: 2px; }
.cards-opts-dialog .co-actions {
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.cards-opts-dialog .co-ok {
  padding: 8px 14px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  border-radius: var(--radius-sm);
}


.fields {
  display: block;
  margin: 0 0 8px;
  background: transparent;
  border: none;
  border-radius: 0;
}
.fields dt {
  color: var(--muted);
  margin: 36px 0 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 16px;
}
.fields dt::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, var(--line), transparent);
}
.fields dd { margin: 0; line-height: 1.6; color: var(--muted); }

/* Padrinho / Afilhados — squared chips with a hairline border so they read as
   clickable affordances. Dark fill on hover for an unambiguous active state. */
.relation { margin: 0; line-height: 2.4; }
.profile-section .relation { line-height: 1.8; }
.relation > a {
  display: inline-block;
  padding: 8px 16px;
  margin: 0 6px 6px 0;
  border-radius: var(--radius-sm);
  background: var(--paper);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  font-weight: 600;
  font-size: 14.5px;
  text-decoration: none;
  transition: background .15s ease, color .15s ease, border-color .15s ease, transform .1s ease, box-shadow .15s ease;
}
.relation > a:hover {
  background: var(--paper);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

/* Tree view ---------------------------------------------------------------- */
.tree-panel {
  max-width: none;
  padding: 0;
  overflow: hidden;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  /* Fills #app's content area exactly (#app is flex:1 inside a fixed-height
     body flex column), so the stage adapts to any viewport without leaving a
     few pixels of overflow scroll. */
  height: 100%;
  display: flex;
  flex-direction: column;
}
.tree-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  flex-wrap: wrap;
}
.tree-toolbar button {
  padding: 5px 12px;
  font-size: 16px;
  line-height: 1;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line-strong);
}
.tree-toolbar button:hover { background: var(--bg); border-color: var(--muted); }

/* Member-visibility filter (gear button + checkbox dropdown). */
.viewer-filter-wrap { position: relative; }
.viewer-filter-wrap > button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  line-height: 1;
  padding: 6px 12px;
}
.viewer-filter-wrap > button .vf-icon { font-size: 15px; }
.viewer-filter-wrap > button .vf-text { font-weight: 600; }
.viewer-filter-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  min-width: 220px;
  z-index: 20;
}
.viewer-filter-menu h4 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.viewer-filter-menu label {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 0;
  font-weight: 500;
  cursor: pointer;
  color: var(--ink);
}
.viewer-filter-menu label:hover { color: var(--muted); }

.legend {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-left: auto;
}
.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-weight: 600;
  color: var(--ink);
  font-size: 12.5px;
}
.legend-chip .swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.legend-chip-branch { background: var(--paper); }
.legend-chip-branch .swatch + .swatch { margin-left: -4px; }

.tree-stage {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;          /* lets the flex child shrink below intrinsic size */
  overflow: hidden;
  cursor: grab;
  touch-action: none;   /* let JS handle drag/pinch instead of the browser */
  background:
    radial-gradient(circle, var(--line) 1px, transparent 1px) 0 0 / var(--grid-size, 26px) var(--grid-size, 26px);
}
/* Faint EAISEL logo watermark, fixed in the centre of the viewport behind the
   tree (does not pan/zoom; ignored by the pointer). Size/opacity come from
   config (CONFIG.treeView) via the --wm-* custom properties set in JS. */
.tree-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("../assets/eaisel-logo.png") center / var(--wm-size, min(78vh, 70vw)) no-repeat;
  opacity: var(--wm-opacity, 0.05);
  pointer-events: none;
  z-index: 0;
}
.tree-stage.grabbing { cursor: grabbing; }
.tree-stage svg { position: relative; z-index: 1; width: 100%; height: 100%; display: block; }

/* Optional photo background for the public /tree viewer (Settings › Appearance
   › Background & watermark). The photo lives on ::after so its opacity is
   independent of the rest; the dot grid is suppressed underneath. */
.tree-stage.has-bg { background: var(--paper); }
.tree-stage.has-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--shared-bg-image, none) center / cover no-repeat;
  opacity: var(--shared-bg-opacity, 1);
  pointer-events: none;
  z-index: 0;
}
/* Hide the EAISEL stamp watermark when the user has switched it off. */
.tree-stage.no-watermark::before { display: none; }

.node { cursor: pointer; }
.node:hover rect:first-of-type { filter: brightness(1.06); }
.node:focus { outline: none; }
.node:focus rect:first-of-type { stroke: #000; stroke-width: 3; stroke-dasharray: 5 3; }

.node-toggle { cursor: pointer; }
.node-toggle:hover circle { filter: brightness(0.94); }
.node-toggle:focus { outline: none; }
.node-toggle:focus circle { stroke-width: 3; }

/* Fullscreen --------------------------------------------------------------- */
.tree-panel:fullscreen { background: var(--paper); }
.tree-panel:fullscreen .tree-stage { height: calc(100vh - 52px); }

/* Shared (read-only) view: chromeless, tree fills the window ---------------- */
body.shared .site-header,
body.shared .site-footer { display: none; }
body.shared #app { padding: 0; }
/* Flex column so the stage fills the space left under the toolbar; dvh (with a
   vh fallback) keeps the bottom from hiding behind the mobile URL bar. margin:0
   cancels the main-app's negative side margin so nothing clips off-screen. */
body.shared .tree-panel {
  max-width: none;
  border: none;
  box-shadow: none;
  border-radius: 0;
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body.shared .tree-stage { flex: 1; height: auto; min-height: 0; }
/* Keep the chromeless toolbar clear of the status bar / notch and the stage
   clear of the home indicator on phones with safe-area insets. */
body.shared .tree-toolbar {
  padding-top: max(8px, env(safe-area-inset-top));
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
}
body.shared .tree-stage { padding-bottom: env(safe-area-inset-bottom); }
body.shared .node { cursor: default; }
body.shared .node:hover rect:first-of-type { filter: none; }

/* Definições (settings form) ----------------------------------------------- */

.cfg-group {
  margin: 10px 0 18px;
}

.cfg-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 0;
}

.cfg-row > label {
  min-width: 160px;
  font-weight: 600;
}

/* -------------------------------------------------------------------------- */
/* Branch sheet colour rows (FIXED)                                           */
/* -------------------------------------------------------------------------- */

.cfg-row-sheet {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.cfg-row-sheet > label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-weight: 500;
}

.cfg-row-sheet > label input[type="checkbox"] {
  flex: 0 0 auto;
}

.cfg-row-sheet > label {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.cfg-row-sheet input[type="color"] {
  justify-self: end;
  flex: 0 0 auto;
}

input[type="color"] {
  width: 46px;
  height: 30px;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--paper);
  cursor: pointer;
}

input[type="color"]:disabled {
  opacity: .4;
  cursor: not-allowed;
}

input[type="text"].cfg-branch-name,
input[type="text"].cfg-branch-root,
.cfg-wide {
  font: inherit;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
}

.cfg-section input[type="text"]:focus,
.cfg-section input[type="number"]:focus,
.cfg-wide:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

.cfg-branch-root {
  flex: 1;
  max-width: 360px;
}

.cfg-wide {
  width: 100%;
  max-width: 480px;
}

/* Foldable settings sections */

.cfg-section {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  padding: 0 20px;
}

.cfg-section:first-of-type {
  margin-top: 10px;
}

.cfg-section > summary {
  cursor: pointer;
  list-style: none;
  padding: 16px 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.cfg-section > summary::-webkit-details-marker {
  display: none;
}

.cfg-section > summary::before {
  content: "▸";
  font-size: 11px;
  color: var(--muted);
  transition: transform .15s ease;
}

.cfg-section[open] > summary::before {
  transform: rotate(90deg);
}

.cfg-section[open] > summary {
  border-bottom: 1px solid var(--line);
}

.cfg-section > summary:hover {
  color: var(--muted);
}

.cfg-section-body {
  padding: 16px 0 18px;
}

/* Appearance */

.cfg-tv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 4px 28px;
}

.cfg-tv-grid .cfg-row {
  align-items: flex-start;
  padding: 6px 0;
}

.cfg-label {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.cfg-label > label {
  min-width: 0;
  font-weight: 600;
}

.cfg-desc {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 400;
  line-height: 1.3;
}

.cfg-tv-grid input {
  margin-top: 2px;
}

input[type="number"],
input[type="text"].cfg-tv-text {
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
}

input[type="number"] {
  width: 92px;
}

input[type="text"].cfg-tv-text {
  width: 150px;
}

.cfg-branch {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--sunken);
}

.cfg-branch-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.cfg-branch-name {
  flex: 1;
  font-weight: 700;
}

.cfg-branch-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  margin-top: 8px;
}

.cfg-row-sheet {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.cfg-row-sheet > label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-weight: 500;
}

.cfg-row-sheet input[type="color"] {
  margin-left: 2px;
  flex-shrink: 0;
}

/* Dark mode ----------------------------------------------------------------- */
/* Most colours adapt automatically via the tokens; only the active nav pill
   needs a touch more contrast against the (now darker) header. */
html.dark .site-header nav a.active { background: #e7e9ee; color: #14171c; }

/* Footer ------------------------------------------------------------------- */
.site-footer {
  padding: 10px 22px;
  font-size: 13px;
  color: var(--muted);
  background: var(--paper);
  border-top: 1px solid var(--line);
}
#status.error { color: #d93f3f; }

/* Profile pages — per-sheet member-page templates -------------------------- */
.cfg-profile {
  border: none;
  background: transparent;
  padding: 0;
  margin-bottom: 26px;
}
.cfg-profile:last-child { margin-bottom: 0; }
.cfg-profile-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0 0 14px;
}
.cfg-profile-head h4 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.cfg-profile-head::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, var(--line), transparent);
  order: 1;
}
.cfg-profile-count {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  order: 2;
}
.cfg-profile-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px 44px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin: 0 0 10px;
}
.cfg-profile-row { display: contents; }
.cfg-profile-row > * { border-top: 1px solid var(--line); }
.cfg-profile-row:first-child > * { border-top: none; }
.cfg-profile-row input {
  font: inherit;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 12px 16px;
  color: var(--ink);
  min-width: 0;
}
.cfg-profile-row input:focus {
  outline: none;
  background: var(--accent-weak, var(--sunken));
  box-shadow: none;
}
.cfg-profile-row .cfg-profile-label {
  background: var(--sunken);
  font-weight: 600;
  color: var(--ink);
  border-right: 1px solid var(--line);
}
.cfg-profile-row .cfg-profile-col {
  text-align: center;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-right: 1px solid var(--line);
  padding-left: 8px;
  padding-right: 8px;
}
.cfg-profile-row .cfg-del {
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--muted);
  padding: 0;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.cfg-profile-row .cfg-del:hover {
  background: var(--sunken);
  color: var(--ink);
}
.cfg-profile-empty {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 13px;
  padding: 16px;
  text-align: center;
  color: var(--muted);
}
.cfg-profile-add {
  font-size: 13px;
  padding: 7px 14px;
}

.cfg-lead { max-width: none; }

/* Secondary nav — a separate pill for the Practice tab so it visually sits
   apart from the main Home / Tree / Unlinked / Settings group. Same pill
   styling as the primary nav; just a margin to detach it. */
.site-header nav.nav-secondary { margin-left: 6px; }

/* Practice ----------------------------------------------------------------
   Padrinho-guessing drills. The stage centres a member card above a
   rectangular (rounded-corner) input with a custom dropdown; feedback flashes
   green/red under the form without shifting layout. */
.practice-panel .practice-score {
  display: flex;
  gap: 26px;
  color: var(--ink);
  font-family: var(--font);
}
/* Let the description flow to the panel edge so the two sentences fit on
   one line at desktop widths (the default .lead cap at 60ch would wrap it). */
.practice-panel .lead { max-width: none; }
.practice-score-item {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}
.practice-score-num {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1;
}
.practice-score-label {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Pulled a bit further down from the description so the game breathes. */
.practice-stage {
  margin: 64px auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  text-align: center;
}
.practice-member {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}
.practice-avatar {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: var(--paper);
  border: 6px solid var(--paper);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.practice-avatar::before {
  content: attr(data-initials);
  font-family: var(--font);
  font-size: 54px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: -0.02em;
}
.practice-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.practice-panel .practice-name {
  margin: 0;
  display: block;
  font-family: var(--font);            /* sans-serif reads better for names */
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--ink);
  text-transform: none;
}
.practice-panel .practice-name::after { display: none; }   /* kill the h3 hairline rule */

.practice-form {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 560px;
  align-items: stretch;
}
/* Wrap around the input so the custom dropdown can be positioned relative
   to just the input, not the whole form (which also contains the button). */
.practice-input-shell {
  position: relative;
  flex: 1;
  display: flex;
}
.practice-input {
  flex: 1;
  padding: 14px 20px;
  font-family: var(--font);
  font-size: 17px;
  font-weight: 500;
  border: 1px solid var(--line-strong);
  border-radius: 12px;                    /* rectangular with soft corners */
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.practice-input::placeholder { color: var(--muted); font-weight: 400; }
.practice-input:focus {
  outline: none;
  border-color: var(--muted);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}
.practice-input:disabled { background: var(--sunken); color: var(--muted); }
.practice-submit {
  padding: 14px 26px;
  border-radius: 12px;                    /* match the input */
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
}
.practice-form.is-correct .practice-input {
  border-color: #1e9b5a;
  background: rgba(30, 155, 90, 0.08);
}
.practice-form.is-wrong .practice-input {
  border-color: #c9312a;
  background: rgba(201, 49, 42, 0.08);
}

/* Custom autocomplete dropdown ---------------------------------------------
   Browser autofill on this input is off — we build our own so the suggestions
   match the game's data (member names + SEM PADRINHO) and don't collide with
   the browser's password/history suggestions. */
.practice-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  margin: 0;
  /* Extra bottom padding so the last option has some breathing room from
     the dropdown's rounded edge. */
  padding: 6px 6px 10px;
  list-style: none;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 20;
  overflow-y: auto;
  text-align: left;
}
.practice-dropdown[hidden] { display: none; }
.practice-option {
  padding: 9px 14px;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: background .1s ease;
}
.practice-option:hover,
.practice-option.is-selected {
  background: var(--sunken);
}

.practice-feedback {
  min-height: 30px;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.practice-feedback.is-correct { color: #1e9b5a; }
.practice-feedback.is-wrong { color: #c9312a; }
.practice-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 800;
}
.practice-feedback.is-correct .practice-icon { background: rgba(30, 155, 90, 0.15); }
.practice-feedback.is-wrong .practice-icon { background: rgba(201, 49, 42, 0.15); }
.practice-feedback strong { font-weight: 800; }

/* Mobile / small screens --------------------------------------------------- */
@media (max-width: 640px) {
  /* Header: compact 3-row layout. The logo identifies the app, so we drop the
     long title text on mobile to save vertical space (it was costing ~50px
     for nothing). Row 1 is the logo, centred, with logout absolutely anchored
     to the right; rows 2 and 3 are nav and search, both full-width. */
  .site-header {
    position: relative;
    gap: 8px;
    padding: 10px 12px;
    row-gap: 10px;
  }
  .site-header h1 { display: none; }
  .site-header .logo-link { order: 0; flex: 1 1 100%; justify-content: center; }
  .site-header .logo { height: 38px; width: 38px; }
  .site-header nav { order: 2; flex: 1 1 100%; }
  .site-header nav a { padding: 7px 12px; font-size: 13.5px; flex: 1; text-align: center; }
  .search-wrap { order: 3; flex: 1 1 100%; margin-left: 0; }
  #search { width: 100%; max-width: none; padding: 9px 14px; font-size: 15px; }
  .logout-btn {
    order: 1;
    position: absolute;
    top: 10px;
    right: 12px;
    padding: 6px 12px;
    font-size: 12.5px;
  }

  #app { padding: 16px 14px 28px; }

  /* Compact figure row + section rules on a narrow viewport. */
  .panel h2 { font-size: 24px; letter-spacing: -0.3px; }
  .panel h3 { margin-top: 22px; }

  /* Profile page: bleed to the mobile #app padding (16/14/28); the embed drops
     out of its popped-out position and stacks below the data, full width. */
  .profile-page { margin: -16px -14px -28px; min-height: calc(100% + 44px); }
  .profile-banner { height: 160px; }
  .profile-banner::after { width: 260px; height: 260px; transform: translate(-50%, 45%); }
  .profile-identity { padding: 0 16px 18px; margin-top: -44px; gap: 16px; }
  .profile-body { padding: 20px 16px 24px; gap: 12px; }
  .profile-section {
    padding: 14px 16px;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .profile-section h3 { flex: 0 0 auto; }
  .profile-tree-embed {
    position: static;
    width: auto;
    height: 300px;
    margin: 0 16px 24px;
  }
  .profile-headline { padding-top: 40px; }
  .profile-avatar { width: 150px; height: 150px; }
  .profile-avatar::before { font-size: 54px; }
  .profile-role { font-size: 16px; }
  .profile-notes-btn { padding: 5px 10px; font-size: 12px; }
  .stats { gap: 12px 28px; padding-bottom: 20px; margin-top: 20px; }
  .stat-num { font-size: 26px; }
  .root-list, .godson-list { grid-template-columns: 1fr; gap: 8px; }

  /* Tree fills the rest of the viewport beneath the header — using flex so the
     stage adapts to whatever vertical room is left, regardless of header /
     toolbar height. Hardcoding a vh subtraction was leaving the bottom rows
     off-screen. */
  .tree-panel {
    margin: 0 -14px;
    border-radius: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .tree-stage { flex: 1; height: auto; min-height: 0; }
  /* One compact, swipeable toolbar row instead of three wrapped rows — keeps
     the tree as tall as possible. The filter ("Membros") is pulled to the front
     so it's the first thing you see and tap. */
  .tree-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    padding: 8px 10px;
  }
  .tree-toolbar::-webkit-scrollbar { display: none; }
  .tree-toolbar > * { flex: 0 0 auto; }
  .tree-toolbar button { padding: 8px 11px; font-size: 15px; min-height: 40px; }
  .tree-toolbar .muted { display: none; }
  .tree-toolbar .viewer-filter-wrap { order: -1; }   /* filter first */
  .tree-toolbar .viewer-filter-wrap > button {
    background: var(--btn-bg);
    color: var(--btn-fg);
    border-color: transparent;
    min-height: 40px;
    padding: 8px 14px;
  }
  .legend { width: auto; margin: 0; flex-wrap: nowrap; }
  .legend-chip { flex: 0 0 auto; }

  /* Filter dropdown: anchor to the right of the viewport so it can't spill
     off-screen, and grow the touch targets so checkboxes are tappable. */
  .viewer-filter-wrap > button { padding: 9px 13px; font-size: 18px; min-width: 44px; min-height: 36px; }
  .viewer-filter-menu {
    position: fixed;
    top: auto;
    bottom: 16px;
    right: 16px;
    left: 16px;
    max-height: 60dvh;
    overflow: auto;
    padding: 16px 18px;
    min-width: 0;
  }
  .viewer-filter-menu label { padding: 10px 0; font-size: 15px; }

  /* Settings: tighter section padding, wrapped action buttons, full-width
     number inputs so the value isn't squeezed. */
  .cfg-section { padding: 0 14px; }
  .cfg-section-body { padding: 12px 0 16px; }
  .cfg-tv-grid { grid-template-columns: 1fr; gap: 2px 0; }
  .cfg-row { flex-wrap: wrap; gap: 8px 12px; }
  .cfg-tv-grid .cfg-row { padding: 10px 0; border-top: 1px solid var(--line); }
  .cfg-tv-grid .cfg-row:first-of-type { border-top: none; }
  .cfg-tv-grid input[type="number"],
  .cfg-tv-grid input[type="text"].cfg-tv-text { width: 100%; max-width: none; }
  .cfg-row > label { min-width: 0; }
  .cfg-actions { flex-wrap: wrap; }
  .cfg-actions button { flex: 1 1 calc(50% - 5px); }
  .cfg-wide { max-width: none; }
  .cfg-branch-root { max-width: none; }

  /* Title row on Unlinked: stack the title and the filter gear cleanly. */
  .page-title-row { align-items: center; }

  /* Practice: shrink the avatar, wrap the input row, and let the submit
     button span its own line so both fit comfortably on a phone. Also drop
     the secondary nav pill flush against the primary one. */
  .site-header nav.nav-secondary { margin-left: 0; }
  .practice-stage { gap: 24px; margin-top: 36px; }
  .practice-avatar { width: 128px; height: 128px; border-width: 5px; }
  .practice-avatar::before { font-size: 40px; }
  .practice-panel .practice-name { font-size: 24px; }
  .practice-form { flex-wrap: wrap; }
  .practice-input-shell { width: 100%; }
  .practice-input { width: 100%; padding: 12px 18px; font-size: 16px; }
  .practice-submit { width: 100%; padding: 12px 22px; }
  .practice-panel .practice-score { gap: 18px; }
  .practice-score-num { font-size: 24px; }
}

