/* New interface: application shell and the few components the shell
   needs (brand, buttons, notices, state banner). Port of the approved mockup
   (mockup-nova-interface/styles.css, GUIA_DO_MOCKUP.md §6) with the same class
   names. Loaded on every page of the customer app and of /sys, after tokens.css
   and ui_primitives.css (buttons, fields, notices, dialog).

   Page components live in ui_components.css, which every page also loads. */

* { box-sizing: border-box; }
html { scroll-padding-top: 88px; }
body {
  margin: 0; min-width: 320px; min-height: 100vh;
  background: var(--canvas); color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased;
}
svg.icon { flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; top: -60px; left: 12px; z-index: 100; padding: 10px 16px;
  border: 2px solid var(--accent); border-radius: 10px; background: var(--surface);
  color: var(--accent-strong); font-size: 14px; font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: 12px; outline: none; }
main[tabindex="-1"]:focus { outline: none; }

/* Brand */
.brand {
  display: inline-flex; align-items: center; gap: 12px; color: var(--ink);
  font-size: 20px; font-weight: 700; letter-spacing: -0.325px; text-decoration: none;
}
a.brand:hover { color: var(--ink); text-decoration: none; }
.brand-mark {
  position: relative; width: 31px; height: 31px; display: grid; place-items: center;
  overflow: hidden; border-radius: 10px; background: var(--nav); color: var(--ink-inverse); font-size: 16px; letter-spacing: -1px;
}
.brand-mark::after {
  content: ""; position: absolute; right: -8px; bottom: -8px; width: 21px; height: 21px;
  border-radius: 50%; background: var(--brand-highlight);
}
.brand-area { padding-left: 12px; border-left: 1px solid var(--line-strong); color: var(--muted); font-size: 14px; font-weight: 500; letter-spacing: 0; }

/* Focus always visible: 2px in the bridge colour. */
.side-link:focus-visible, .skip-link:focus-visible,
.brand:focus-visible, .lang-option:focus-visible, .sidebar-links a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.app-sidebar .side-link:focus-visible, .app-sidebar .lang-option:focus-visible, .sidebar-links a:focus-visible { outline-color: var(--brand-highlight); }

/* Shell */
.app-shell {
  min-height: 100vh; display: grid; grid-template-rows: 68px 1fr;
  grid-template-columns: 244px minmax(0, 1fr);
  grid-template-areas: "app-topbar app-topbar" "app-sidebar app-main";
}
.app-topbar {
  grid-area: app-topbar; position: sticky; top: 0; z-index: 30; display: flex;
  align-items: center; justify-content: space-between; gap: 16px; padding: 0 28px;
  border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 96%, transparent); backdrop-filter: blur(12px);
}
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.topbar-actions form { margin: 0; }
.app-user { display: flex; align-items: center; gap: 12px; color: var(--muted-strong); font-size: 14px; font-weight: 500; }
.avatar {
  width: 36px; height: 36px; display: grid; place-items: center; flex: none; border: 1px solid var(--line-strong);
  border-radius: 50%; background: var(--neutral-soft); color: var(--muted-strong); font-size: 13px; font-weight: 700;
}
.app-sidebar {
  grid-area: app-sidebar; position: sticky; top: 68px; height: calc(100vh - 68px);
  display: flex; flex-direction: column; overflow-y: auto; padding: 24px 16px 20px; background: var(--nav); color: var(--ink-inverse);
}
.app-sidebar nav { margin: 0; }
.nav-group + .nav-group { margin-top: 20px; }
.nav-label { padding: 0 12px 8px; color: var(--nav-muted); font-size: 12px; font-weight: 600; }
.side-nav { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.side-link {
  width: 100%; min-height: 40px; display: flex; align-items: center; gap: 12px; padding: 0 12px;
  border-radius: 10px; color: var(--nav-muted); font-size: 14px; font-weight: 500; text-decoration: none; transition: background-color .18s ease, color .18s ease, box-shadow .18s ease;
}
.side-link:hover { background: color-mix(in srgb, var(--ink-inverse) 5%, transparent); color: var(--ink-inverse); text-decoration: none; }
.side-link.active { background: var(--nav-active); color: var(--ink-inverse); box-shadow: inset 3px 0 var(--brand-highlight); }
.side-link svg { width: 18px; height: 18px; flex: none; }
.sidebar-toggle {
  display: none; margin-bottom: 16px; border: 0; background: transparent; font-family: var(--font-sans); text-align: left; cursor: pointer;
}
.side-tooltip {
  position: fixed; z-index: 40; max-width: 240px; padding: 6px 10px; border-radius: 6px; background: var(--ink); color: var(--ink-inverse);
  font-size: 13px; font-weight: 500; line-height: 1.3; white-space: nowrap; pointer-events: none; transform: translateY(-50%);
}
.side-tooltip[hidden] { display: none; }
.sidebar-foot { display: grid; gap: 12px; margin-top: auto; padding: 16px 12px 3px; border-top: 1px solid color-mix(in srgb, var(--ink-inverse) 8%, transparent); }
.sidebar-admin { display: grid; gap: 2px; font-size: 13px; }
.sidebar-admin strong { color: var(--ink-inverse); font-weight: 600; overflow-wrap: anywhere; }
.sidebar-admin span { color: var(--nav-muted); font-size: 12px; }
.sidebar-links { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 0; padding: 0; list-style: none; font-size: 12px; }
.sidebar-links a { display: inline-flex; align-items: center; min-height: 24px; color: var(--nav-muted); text-decoration: none; }
.sidebar-links a:hover { color: var(--ink-inverse); text-decoration: underline; }
.lang-form { margin: 0; }
.lang-options { display: flex; gap: 2px; width: fit-content; padding: 3px; border-radius: 10px; background: color-mix(in srgb, var(--ink-inverse) 6%, transparent); }
.lang-option {
  min-width: 40px; min-height: 28px; padding: 0 8px; border: 0; border-radius: 6px; background: transparent;
  color: var(--nav-muted); font-family: var(--font-sans); font-size: 12px; font-weight: 600; cursor: pointer;
}
.lang-option:hover { color: var(--ink-inverse); }
.lang-option[aria-pressed="true"] { background: var(--nav-active); color: var(--ink-inverse); }
.app-main { grid-area: app-main; min-width: 0; padding: 32px clamp(24px, 4vw, 52px) 48px; }
.app-content { width: min(var(--content-max), 100%); margin-inline: auto; }
.app-content--wide { width: min(var(--content-max-wide), 100%); }
.mobile-menu { display: none; }

/* State banner (connection down, support mode) */
.state-banner {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; margin-bottom: 20px;
  padding: 14px 20px; border: 1px solid var(--danger-line); border-left-width: 4px; border-radius: 14px; background: var(--danger-soft);
}
.state-banner > svg { width: 20px; height: 20px; color: var(--danger); stroke-width: 1.9; }
.state-banner p { margin: 0; font-size: 14px; line-height: 1.45; }
.state-banner form { margin: 0; }
.state-banner.is-warning { border-color: var(--amber-line); background: var(--amber-soft); }
.state-banner.is-warning > svg { color: var(--amber); }
.state-banner.is-info { border-color: var(--blue-line); background: var(--blue-soft); }
.state-banner.is-info > svg { color: var(--blue); }
.state-banner.is-off { border-color: var(--line-strong); background: var(--surface-soft); }
.state-banner.is-off > svg { color: var(--muted-strong); }

/* Public pages (login, sign-up, account e-mails): no menu */
.auth-page { display: flex; min-height: 100vh; flex-direction: column; }
/* Always over --canvas: these mixes give the approved colours on that background. */
.public-topbar { border-bottom: 1px solid color-mix(in srgb, var(--line-strong) 31%, transparent); background: color-mix(in srgb, var(--surface-subtle) 47%, transparent); }
.public-nav { width: min(1160px, calc(100% - 40px)); min-height: 74px; display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-inline: auto; }
.public-nav .lang-options { background: var(--surface-soft); box-shadow: inset 0 0 0 1px var(--line-soft); }
.public-nav .lang-option { color: var(--muted); }
.public-nav .lang-option:hover { color: var(--ink); }
.public-nav .lang-option[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.auth-main { flex: 1; display: grid; place-items: center; padding: 40px 16px; }
.auth-main > div { width: min(1120px, 100%); }
.public-footer { padding: 20px 16px 28px; }
.public-footer .sidebar-links { justify-content: center; }
.public-footer .sidebar-links a { color: var(--muted); }
.public-footer .sidebar-links a:hover { color: var(--ink); }
.public-footer .sidebar-links a:focus-visible { outline-color: var(--accent); }

/* Chat page inside the shell: the conversation takes the whole main area. */
.chat-layout .app-shell { height: 100vh; height: 100dvh; min-height: 0; }
.chat-layout .app-main { display: flex; flex-direction: column; min-height: 0; padding: 0; overflow: hidden; }
.chat-layout .app-main > .notice, .chat-layout .app-main > .state-banner { margin: 12px 16px 0; }
.chat-layout .chat-page { flex: 1; min-height: 0; }

/* Exact complement of the 980px rail below, which needs no toggle. */
@media not all and (max-width: 980px) {
  .sidebar-toggle { display: flex; }
  .sidebar-collapsed .app-shell { grid-template-columns: 76px minmax(0, 1fr); }
  .sidebar-collapsed .app-sidebar { padding-inline: 12px; }
  .sidebar-collapsed .nav-label, .sidebar-collapsed .side-link span, .sidebar-collapsed .sidebar-foot { display: none; }
  .sidebar-collapsed .side-link { justify-content: center; padding: 0; }
  .sidebar-collapsed .side-link.active { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink-inverse) 7%, transparent); }
  .sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }
}
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 76px minmax(0, 1fr); }
  .app-sidebar { padding-inline: 12px; }
  .nav-label, .side-link span, .sidebar-foot { display: none; }
  .side-link { justify-content: center; padding: 0; }
  .side-link.active { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink-inverse) 7%, transparent); }
}
@media (max-width: 760px) {
  .app-shell { display: block; padding-top: 64px; }
  .app-topbar { position: fixed; top: 0; width: 100%; height: 62px; padding: 0 16px; }
  .brand-area, .logout-label, .app-user-name { display: none; }
  .mobile-menu { display: grid; }
  .app-sidebar {
    position: fixed; top: 62px; left: 0; z-index: 28; width: min(270px, 84vw); height: calc(100vh - 62px);
    padding: 20px 16px; visibility: hidden; transform: translateX(-105%); pointer-events: none;
    transition: transform .22s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .22s; box-shadow: 20px 0 45px color-mix(in srgb, var(--ink) 18%, transparent);
  }
  .app-sidebar.open { visibility: visible; transform: translateX(0); pointer-events: auto; transition-delay: 0s; }
  .nav-label, .side-link span { display: block; }
  .sidebar-foot { display: grid; }
  .side-link { justify-content: flex-start; padding: 0 12px; }
  .app-main { padding: 24px 16px 40px; }
  .state-banner { grid-template-columns: auto 1fr; }
  .state-banner .button, .state-banner form { grid-column: 2; justify-self: start; }
  .chat-layout .app-shell { height: auto; }
  .chat-layout .app-main { height: calc(100vh - 64px); height: calc(100dvh - 64px); padding: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
