/* ============================================================================
   App shell: sidebar + topbar + content
   ========================================================================== */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; transition: grid-template-columns var(--t-base) var(--ease); }
.app.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

/* ---------------------------------------------------------------- Sidebar */
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: var(--sp-3) var(--sp-3) var(--sp-3); overflow: hidden; z-index: 40;
}
.sidebar__brand { display: flex; align-items: center; gap: 10px; padding: 6px 6px 12px; min-height: 52px; }
.sidebar__logo { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; background: var(--accent); color: var(--accent-contrast); font-weight: 800; font-size: 14px; letter-spacing: -0.02em; overflow: hidden; }
.sidebar__logo img { width: 100%; height: 100%; object-fit: cover; }
.sidebar__brand-text { min-width: 0; line-height: 1.2; }
.sidebar__brand-name { font-weight: 700; font-size: 13.5px; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar__brand-sub { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ws-switch { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface-raised); text-align: left; transition: background var(--t-fast), border-color var(--t-fast); }
.ws-switch:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.ws-switch .ws-switch__caret { margin-left: auto; color: var(--text-muted); font-size: 14px; }
.ws-switch__name { font-weight: 600; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-switch__vertical { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar__nav { flex: 1; overflow-y: auto; overflow-x: hidden; margin-top: var(--sp-3); padding-right: 2px; }
.nav-group { margin-bottom: var(--sp-4); }
.nav-group__title { font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); padding: 4px 10px 6px; white-space: nowrap; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--r-md); color: var(--text-secondary);
  font-size: 13px; font-weight: 500; position: relative; white-space: nowrap; transition: background var(--t-fast), color var(--t-fast);
}
.nav-item i { font-size: 18px; flex-shrink: 0; width: 20px; text-align: center; }
.nav-item:hover { background: var(--surface-hover); color: var(--text-primary); }
.nav-item.is-active { background: var(--accent-soft); color: var(--text-primary); font-weight: 600; }
.nav-item.is-active::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--accent); }
.nav-item.is-active i { color: var(--accent); }
.nav-item__badge { margin-left: auto; font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--surface-hover); color: var(--text-secondary); }
.nav-item.is-active .nav-item__badge { background: rgba(var(--accent-rgb), 0.25); color: var(--text-primary); }

.sidebar__footer { border-top: 1px solid var(--border); padding-top: var(--sp-3); margin-top: var(--sp-2); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: var(--r-md); width: 100%; text-align: left; transition: background var(--t-fast); }
.user-chip:hover { background: var(--surface-hover); }
.user-chip__name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip__role { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

.sidebar__collapse { position: absolute; right: -12px; top: 22px; width: 24px; height: 24px; border-radius: 50%; background: var(--surface-raised); border: 1px solid var(--border-strong); color: var(--text-secondary); display: grid; place-items: center; font-size: 12px; z-index: 41; transition: transform var(--t-base) var(--ease); }
.sidebar__collapse:hover { color: var(--text-primary); }
.is-collapsed .sidebar__collapse { transform: rotate(180deg); }

/* Collapsed */
.is-collapsed .sidebar { padding-left: 10px; padding-right: 10px; }
.is-collapsed .sidebar__brand-text, .is-collapsed .ws-switch__text, .is-collapsed .ws-switch__caret, .is-collapsed .sidebar .nav-group__title,
.is-collapsed .sidebar .nav-item span, .is-collapsed .sidebar .nav-item__badge, .is-collapsed .user-chip__text { display: none; }
.is-collapsed .ws-switch { justify-content: center; padding: 6px; }
.is-collapsed .sidebar .nav-item { justify-content: center; padding: 9px; }
.is-collapsed .sidebar .nav-item.is-active::before { left: -10px; }
.is-collapsed .sidebar__brand { justify-content: center; padding-left: 0; padding-right: 0; }
.is-collapsed .user-chip { justify-content: center; }

/* ---------------------------------------------------------------- Topbar */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h); display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--content-pad); background: rgba(var(--bg-rgb), 0.78); backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--border);
}
.topbar__menu { display: none; }
.nav-scrim { display: none; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-muted); min-width: 0; }
.crumbs a:hover { color: var(--text-primary); }
.crumbs .sep { opacity: 0.5; }
.crumbs .current { color: var(--text-primary); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__search { margin-left: auto; display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px 0 12px; min-width: 240px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); font-size: 13px; cursor: text; transition: border-color var(--t-fast), background var(--t-fast); }
.topbar__search:hover { border-color: var(--border-strong); background: var(--surface-raised); }
.topbar__search i { font-size: 16px; }
.topbar__search .kbd { margin-left: auto; display: inline-flex; gap: 3px; }
.topbar__actions { display: flex; align-items: center; gap: 4px; }

/* ---------------------------------------------------------------- Content */
.content { padding: var(--sp-5) var(--content-pad) var(--sp-10); flex: 1; }
.content--narrow { max-width: 1100px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-5); flex-wrap: wrap; }
.page-head__title { font-size: var(--fs-title); font-weight: 700; letter-spacing: -0.02em; }
.page-head__eyebrow { font-size: var(--fs-micro); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px; }
.page-head__sub { color: var(--text-secondary); font-size: 13px; margin-top: 4px; max-width: 720px; }
.page-head__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-head--hero .page-head__title { font-size: var(--fs-display); letter-spacing: -0.03em; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.section-head__title { font-size: 14px; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.section-head__title .count { font-weight: 600; color: var(--text-muted); font-size: 12px; }
.section-head__sub { font-size: 12px; color: var(--text-muted); }

/* Settings shell */
.settings { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: var(--sp-8); align-items: start; }
.settings__nav { position: sticky; top: calc(var(--topbar-h) + 20px); }
.settings__nav .nav-item { padding: 7px 10px; }
.settings__body { max-width: 880px; }
@media (max-width: 1024px) { .settings { grid-template-columns: 1fr; gap: var(--sp-4); } .settings__nav { position: static; display: flex; gap: 4px; overflow-x: auto; padding-bottom: 6px; } .settings__nav .nav-group { margin: 0; display: flex; gap: 4px; } .settings__nav .nav-group__title { display: none; } }

/* Raio-X split */
.xray { display: grid; grid-template-columns: minmax(0, 65fr) minmax(300px, 35fr); gap: var(--sp-6); align-items: start; }
.xray__side { position: sticky; top: calc(var(--topbar-h) + 20px); }
@media (max-width: 1100px) { .xray { grid-template-columns: 1fr; } .xray__side { position: static; } }

/* ---------------------------------------------------------------- Mobile */
@media (max-width: 1024px) {
  .app, .app.is-collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; width: min(300px, 86vw); transform: translateX(-104%); transition: transform var(--t-slow) var(--ease); box-shadow: var(--shadow-lg); }
  .app.is-nav-open .sidebar { transform: none; }
  .is-collapsed .sidebar__brand-text, .is-collapsed .ws-switch__text, .is-collapsed .ws-switch__caret, .is-collapsed .sidebar .nav-group__title, .is-collapsed .sidebar .nav-item span, .is-collapsed .sidebar .nav-item__badge, .is-collapsed .user-chip__text { display: initial; }
  .is-collapsed .sidebar .nav-item { justify-content: flex-start; padding: 7px 10px; }
  .is-collapsed .sidebar__brand-full { display: flex; } .is-collapsed .sidebar__brand-mini { display: none; }
  .sidebar__collapse { display: none; }
  .topbar__menu { display: grid; }
  .topbar__search { min-width: 0; flex: 1; }
  .topbar__search .kbd, .topbar__search .placeholder { display: none; }
  .nav-scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 39; opacity: 0; pointer-events: none; transition: opacity var(--t-base); }
  .app.is-nav-open .nav-scrim { opacity: 1; pointer-events: auto; }
}

/* ---------------------------------------------------------------- Brand (logo horizontal / símbolo) */
.sidebar__brand { text-decoration: none; color: inherit; }
.sidebar__brand-full { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sidebar__brand-mini { display: none; }
.is-collapsed .sidebar__brand-full { display: none; }
.is-collapsed .sidebar__brand-mini { display: block; }
.brand-logo { display: inline-flex; align-items: center; height: var(--logo-h, 28px); max-width: 100%; }
.brand-logo img { height: var(--logo-h, 28px); width: auto; max-width: 200px; object-fit: contain; display: block; }
.brand-logo .brand-logo__dark { display: none; }
html[data-theme="dark"] .brand-logo .brand-logo__light { display: none; }
html[data-theme="dark"] .brand-logo .brand-logo__dark { display: block; }
.powered-by { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 6px 4px; font-size: 10.5px; color: var(--text-muted); text-decoration: none; white-space: nowrap; }
.powered-by:hover { color: var(--text-secondary); }
.powered-by .sidebar__logo { width: 18px; height: 18px; border-radius: 5px; font-size: 10px; }
.powered-by .sidebar__brand-text { line-height: 1; }
.powered-by .sidebar__brand-name { font-size: 11px; }
.powered-by .sidebar__brand-sub { display: none; }
.is-collapsed .powered-by span:first-child, .is-collapsed .powered-by .sidebar__brand-text { display: none; }

/* ---------------------------------------------------------------- Menu: botão no topo, grupos recolhíveis, scroll fino à esquerda, ativo centralizado */
.sidebar__collapse { display: none !important; }
.topbar__menu { display: grid; }
.topbar__menu i { transition: transform var(--t-base) var(--ease); }
.sidebar__nav { direction: rtl; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; padding-right: 0; padding-left: 6px; margin-left: -6px; }
.sidebar__nav > * { direction: ltr; }
.sidebar__nav::-webkit-scrollbar { width: 4px; } .sidebar__nav::-webkit-scrollbar-track { background: transparent; } .sidebar__nav::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; } .sidebar__nav:hover::-webkit-scrollbar-thumb { background: var(--text-muted); }
button.nav-group__title { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer; border-radius: var(--r-sm); transition: color var(--t-fast), background var(--t-fast); }
button.nav-group__title:hover { color: var(--text-secondary); background: var(--surface-hover); }
button.nav-group__title i { font-size: 12px; opacity: .55; transition: transform var(--t-base) var(--ease), opacity var(--t-fast); }
button.nav-group__title:hover i { opacity: 1; }
.nav-group.is-closed button.nav-group__title i { transform: rotate(-90deg); }
.nav-group__items { display: grid; overflow: hidden; transition: grid-template-rows var(--t-base) var(--ease), opacity var(--t-base); grid-template-rows: 1fr; opacity: 1; }
.nav-group__items > div { min-height: 0; }
.nav-group.is-closed .nav-group__items { grid-template-rows: 0fr; opacity: 0; }
.is-collapsed .sidebar .nav-group.is-closed .nav-group__items { grid-template-rows: 1fr; opacity: 1; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.avatar { overflow: hidden; }

/* ---------------------------------------------------------------- Topo compacto no celular: só menu, título, busca e notificações. Tema e guia ficam no menu do usuário (sidebar). */
.menu__theme { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 10px; font-size: 13px; color: var(--text-primary); }
.menu__theme > span { display: flex; align-items: center; gap: 10px; } .menu__theme > span i { font-size: 16px; color: var(--text-secondary); }
@media (max-width: 720px) {
  .topbar { gap: var(--sp-2); padding-inline: 10px; }
  .crumbs { flex: 1; min-width: 0; } .crumbs a, .crumbs .sep { display: none; } .crumbs .current { font-size: 14px; }
  .topbar__search { flex: 0 0 auto; width: 34px; padding: 0; justify-content: center; margin-left: 0; }
  .topbar__actions .theme-switch, .topbar__actions #guide-btn { display: none; }
  .topbar__actions .badge { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #notif-menu { position: fixed; left: 10px; right: 10px; top: calc(var(--topbar-h) + 6px); min-width: 0 !important; max-height: min(70dvh, 480px) !important; }
}
@media (max-width: 400px) { .topbar__actions .badge { display: none; } }

/* ---------------------------------------------------------------- Configurações no celular: barra de seções rolável (pílulas), cabeçalhos que quebram linha */
@media (max-width: 1024px) {
  .settings__nav { margin-inline: calc(var(--content-pad) * -1); padding-inline: var(--content-pad); scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; }
  .settings__nav::-webkit-scrollbar { display: none; }
  .settings__nav .nav-item { flex: 0 0 auto; white-space: nowrap; scroll-snap-align: start; border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; }
  .settings__nav .nav-item.is-active { border-color: transparent; }
  .settings__body { max-width: none; }
}
@media (max-width: 720px) {
  .section-head { flex-wrap: wrap; } .section-head > .t-micro, .section-head > span { flex-basis: 100%; }
  .page-head__actions { width: 100%; } .page-head__actions .btn { flex: 1 1 auto; justify-content: center; }
  .int-card__desc { min-height: 0; }
  .settings .card--pad { padding: 14px; }
}
