/* ---------------------------------------------------------
   3. Layout shell
   --------------------------------------------------------- */

/* --- Site header --- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  /* Was a literal translucent white + backdrop-blur: broke dark mode (white
     bar behind light text -> unreadable nav). A flat --color-surface bar
     with a hairline bottom border is also what the Registro header contract
     calls for (docs/ui/DESIGN_CONTRACT.md §4). */
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  height: var(--header-h);
}

.site-header__inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--sp-4);
  height: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

/* Brand / logo — serif per docs/ui/DESIGN_CONTRACT.md §4 ("Brand in serif"). */
.site-header__brand {
  font-family: Georgia, "Times New Roman", serif;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-primary);
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  transition: color var(--motion-fast) var(--ease);
}
.site-header__brand:hover { text-decoration: none; color: var(--color-primary-dk); }
.site-header__brand-icon {
  width: 2.125rem;
  height: 2.125rem;
  border-radius: 0.45rem;
  box-shadow: var(--shadow-sm);
}

/* Hamburger (mobile only) */
.nav-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  width: 2.5rem;
  height: 2.5rem;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  flex-shrink: 0;
  color: var(--color-text);
  transition: background var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease);
}
.nav-toggle:hover {
  background: var(--color-primary-lt);
  border-color: var(--color-primary);
}
.nav-toggle:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Hamburger bars */
.nav-toggle__bars {
  width: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}
.nav-toggle__bars span {
  display: block;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  transition: transform var(--motion) var(--ease), opacity var(--motion) var(--ease);
}

/* Animated open state via sibling-checkbox trick */
#nav-state { display: none; }

#nav-state:checked ~ .site-header .nav-toggle__bars span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
#nav-state:checked ~ .site-header .nav-toggle__bars span:nth-child(2) {
  opacity: 0;
}
#nav-state:checked ~ .site-header .nav-toggle__bars span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

/* --- Primary nav --- */
.site-nav {
  /* On mobile: hidden below header, full-width dropdown */
  display: none;
  position: absolute;
  top: var(--header-h);
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  z-index: 99;
  padding: var(--sp-2) 0;
  margin-bottom: var(--sp-3);
}

/* The nav now lives INSIDE .site-header, so it is no longer a direct sibling of
   #nav-state — reach it through the header. */
#nav-state:checked ~ .site-header .site-nav {
  display: block;
}

body.is-nav-open .site-nav {
  display: block;
}

.site-nav__list {
  list-style: none;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--sp-4);
}

.site-nav__list li { border-bottom: 1px solid var(--color-border); }
.site-nav__list li:last-child { border-bottom: none; }

.site-nav__list a {
  display: block;
  padding: var(--sp-3) var(--sp-2);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: color var(--motion-fast) var(--ease), background var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease);
}
.site-nav__list a:hover,
.site-nav__list a[aria-current="page"],
.site-nav__list a[aria-current="location"] {
  color: var(--color-primary);
  background: var(--color-primary-lt);
  border-radius: var(--radius);
  text-decoration: none;
}

/* --- User slot (right side of header) --- */
.site-header__user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
/* User menu (docs/ui/UI_V3_PLAN.md L8): <details> dropdown replacing the old
   raw "email + hairline divider + solid red Esci button" row. Trigger =
   avatar initials + truncated email + caret; panel floats with --shadow-pop
   and holds only the logout form, styled as a menu item with danger TEXT
   (never a solid button). Same zero-JS <details> pattern as .export-menu
   (nav-areas.css); static/app.js (data-user-menu) only adds outside-click
   close. */
.user-menu {
  position: relative;
}
.user-menu__trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 2.5rem;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: background var(--motion-fast) var(--ease);
}
.user-menu__trigger::-webkit-details-marker { display: none; }
.user-menu__trigger:hover,
.user-menu[open] > .user-menu__trigger {
  background: var(--accent-soft);
}
.user-menu__trigger:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}
.user-menu__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent-fill);
  color: var(--on-accent);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.user-menu__email {
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
.user-menu__caret {
  font-size: 0.65rem;
  color: var(--color-text-muted);
}
.user-menu__panel {
  display: none;
  position: absolute;
  z-index: 60;
  top: calc(100% + var(--sp-1));
  right: 0;
  min-width: 11rem;
  padding: var(--sp-1);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop);
}
.user-menu[open] > .user-menu__panel {
  display: block;
}
.user-menu__logout-form {
  display: block;
  margin: 0;
}
.user-menu__item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}
.user-menu__item:hover,
.user-menu__item:focus-visible {
  background: var(--accent-soft);
  color: var(--accent-ink);
  outline: none;
}
.user-menu__item--danger {
  color: var(--color-danger);
}
.user-menu__item--danger:hover,
.user-menu__item--danger:focus-visible {
  background: var(--st-bad-bg);
  color: var(--color-danger);
}

/* Theme toggle (header). A real <form method="post" action="/tema"> so it
   works with no JS (app/tema.py); static/app.js intercepts the submit to
   flip the theme client-side instead. Min 40x40px touch target. */
.theme-toggle-form { display: inline-flex; margin: 0; }
.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: var(--sp-1);
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}
.theme-toggle-btn:hover { background: var(--color-primary-lt); color: var(--color-text); }
.theme-toggle-icon { font-size: 1.15rem; line-height: 1; }

/* Header notifications bell (inline SVG, docs/ui/DESIGN_CONTRACT.md §0.11 —
   no emoji as UI glyphs) + unread count pill. The bell is a relatively-
   positioned anchor so the pill overlaps its corner. */
.header-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  min-height: 2.5rem;
  text-decoration: none;
  line-height: 1;
  padding: var(--sp-1);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  transition: background var(--motion-fast) var(--ease);
}
.header-bell:hover { background: var(--color-primary-lt); }
.header-bell__icon {
  width: 1.125rem;
  height: 1.125rem;
}
/* Compact count pill (docs/ui/UI_V3_PLAN.md L8): mono tabular numerals, a
   solid --color-danger circle rather than the tinted/bordered .badge chip
   (a raw count isn't a status chip). Circular badge-with-content is an
   already-established shape exception (docs/ui/DESIGN_CONTRACT.md §3 "the
   theme's own circles" — same family as .wizard-step__num and the .info
   "?" summary), not a new pill radius. The 2px surface ring keeps it
   legible sitting on top of the bell icon in both themes. */
.header-bell__count {
  position: absolute;
  top: -0.15rem;
  right: -0.3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.05rem;
  height: 1.05rem;
  padding: 0 0.3em;
  border: 2px solid var(--color-surface);
  border-radius: 999px;
  background: var(--color-danger);
  color: var(--on-accent);
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* Notification centre list. */
.notifica-list { list-style: none; margin: 0; padding: 0; }
.notifica {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
  justify-content: space-between;
  padding: var(--sp-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin-bottom: var(--sp-2);
  background: var(--color-surface);
}
/* Unread state = soft fill only (docs/ui/DESIGN_CONTRACT.md §0.4: no accent
   bars — this used to carry a 3px accent border-top on top of the fill). */
.notifica--unread {
  background: var(--color-primary-lt);
}
.notifica__main { min-width: 0; }
.notifica__tipo { font-weight: 600; }
.notifica__msg { margin: var(--sp-1) 0; }
.notifica__when { font-size: var(--text-xs); }
.notifica__actions { flex-shrink: 0; }

/* --- Main content --- */
.site-main {
  flex: 1;
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-4) var(--sp-6);
  position: relative;
}

/* --- Footer --- */
/* Slim chrome (docs/ui/UI_V3_PLAN.md L8): one muted line behind a hairline
   top border. Vertical padding roughly halved (was --sp-4 all around). */
.site-footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: var(--sp-2) var(--sp-4);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.site-footer__report {
  display: inline-flex;
  align-items: center;
  margin-left: var(--sp-3);
  color: var(--accent-ink);
  font-weight: 650;
}
.site-footer__report:focus-visible {
  outline: 2px solid var(--accent-fill);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* Technical-report intake: context is present but deliberately subordinate to
   the description, so users can report a problem quickly on a phone. */
.support-report {
  max-width: 52rem;
}
.support-report__intro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin: 0 0 var(--sp-4);
}
.support-report__intro p { max-width: 58rem; margin: 0; color: var(--color-text-muted); }
.support-report__context {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  margin: var(--sp-3) 0;
  background: var(--color-surface-2);
  border-radius: var(--radius);
  font-size: var(--text-sm);
}
.support-report__context span { overflow-wrap: anywhere; color: var(--color-text-muted); }
.support-report__triage { display: grid; gap: var(--sp-2); min-width: 14rem; }
.support-report__triage label { display: grid; gap: 2px; font-size: var(--text-xs); color: var(--color-text-muted); }
.support-report__triage select, .support-report__triage textarea { width: 100%; min-width: 0; font: inherit; }
.support-report__history { margin-top: var(--sp-2); font-size: var(--text-xs); }
.support-report__history summary { cursor: pointer; color: var(--accent-ink); }
.support-report__history ul { margin: var(--sp-2) 0 0; padding-left: var(--sp-4); color: var(--color-text-muted); }
@media (max-width: 520px) {
  .site-footer { display: flex; justify-content: space-between; gap: var(--sp-3); text-align: left; }
  .site-footer__report { margin-left: 0; flex-shrink: 0; }
  .support-report__intro { align-items: flex-start; }
  .support-report__intro .btn { width: 100%; justify-content: center; }
}

/* ---------------------------------------------------------
   4. Flash / toast region
   --------------------------------------------------------- */
.flash-region {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-4) 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.flash {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: var(--text-sm);
}
.flash--info,
.flash-info    { background: var(--accent-soft); border-color: var(--accent-fill); color: var(--accent-ink); }
.flash--success,
.flash-success { background: var(--st-ok-bg);    border-color: var(--st-ok-border);   color: var(--st-ok); }
.flash--warning,
.flash-warning { background: var(--st-warn-bg);  border-color: var(--st-warn-border); color: var(--st-warn); }
.flash--error,
.flash-error   { background: var(--st-bad-bg);   border-color: var(--st-bad-border);  color: var(--st-bad); }

/* ---------------------------------------------------------
   5. Page header (title + action buttons)
   --------------------------------------------------------- */
.page-header {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--sp-3);
  /* One step tighter (was sp-6/sp-4): the header ate enough vertical space
     to push short pages into scrolling — user density feedback 05/07/2026. */
  margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--color-border);
}

/* Groups the h1 + optional context line as one flex-grow column, so
   .page-header stays a simple 2-item row (heading | actions) — docs/ui/
   UI_V3_PLAN.md L3/page_header(context=). */
.page-header__heading {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  flex: 1 1 auto;
  min-width: 0;
}

.page-header__title {
  /* Display role (docs/ui/DESIGN_CONTRACT.md §3): serif weight 600. The
     accent dash that used to sit above this title was removed per §0.4 (no
     accent bars, ever) — identity now comes from the serif face alone. */
  font-family: Georgia, "Times New Roman", serif;
  font-size: var(--text-2xl);
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.25;
}

/* Optional muted line under the h1: counts / company scope (§6-bis). Never
   a second title — small, secondary ink, no icon. */
.page-header__context {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.page-header__actions {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  align-items: center;
  /* shrink:1 so a long action row (e.g. the 12-button portafoglio header)
     is bounded by the viewport and wraps instead of overflowing on mobile. */
  flex-shrink: 1;
}
