/* Shell autenticado — estrutura compartilhada por PF e PJ. */
.app {
  --shell-sidebar-width: 250px;
  --shell-gutter: clamp(var(--space-6), 3.2vw, var(--space-12));
  --shell-grid-gap: var(--space-4);
  min-height: 100svh;
  background: var(--color-background);
  color: var(--color-text-primary);
  font-family: var(--font-family-body);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-body);
}

.app > main {
  min-height: 100svh;
  margin-left: var(--shell-sidebar-width);
  background-color: var(--color-background);
  background-image:
    radial-gradient(circle at 96% 4%, rgba(15, 118, 110, .045), transparent 22%),
    radial-gradient(circle at 9% 94%, rgba(221, 244, 237, .26), transparent 20%);
  background-attachment: fixed;
}

/* Sidebar */
.app .sidebar {
  position: fixed;
  z-index: 15;
  inset: 0 auto 0 0;
  display: flex;
  width: var(--shell-sidebar-width);
  min-width: 0;
  padding: var(--space-6) var(--space-4) var(--space-4);
  border: 0;
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: var(--shadow-xs);
}

.app .sidebar::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: linear-gradient(90deg, var(--color-primary), transparent 76%);
  opacity: .9;
}

.app .sidebar > .logo {
  width: max-content;
  margin: 0 0 var(--space-6);
  padding: 0 var(--space-3);
  color: var(--color-text-primary);
  font-size: 27px;
}

.app .sidebar-tip {
  width: 100%;
  min-height: 0;
  margin: 0 0 var(--space-4);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-subtle);
  color: var(--color-text-primary);
  box-shadow: none;
}

.app .sidebar-tip > span {
  float: left;
  width: 28px;
  height: 28px;
  margin: 0 var(--space-2) var(--space-1) 0;
  background: var(--color-warning-surface);
  color: var(--color-warm-accent);
}

.app .sidebar-tip b {
  margin: 0;
  font: var(--font-weight-bold) var(--font-size-xs)/1.35 var(--font-family-heading);
}

.app .sidebar-tip p {
  display: -webkit-box;
  margin: var(--space-1) 0 0;
  overflow: hidden;
  color: var(--color-text-secondary);
  font-size: 11px;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.app .sidebar-tip small {
  display: block;
  clear: both;
  margin-top: var(--space-2);
  color: var(--color-primary);
  font-size: 11px;
  font-weight: var(--font-weight-bold);
}

.app .sidebar nav {
  display: grid;
  min-height: 0;
  gap: 2px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.app .sidebar nav button {
  position: relative;
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: var(--space-3);
  padding: 9px var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: var(--font-weight-medium);
  line-height: 1.25;
  text-align: left;
}

.app .sidebar nav button::before {
  content: "";
  position: absolute;
  left: 0;
  width: 3px;
  height: 18px;
  border-radius: 0 var(--radius-full) var(--radius-full) 0;
  background: var(--color-primary);
  opacity: 0;
  transform: scaleY(.55);
  transition: opacity var(--motion-duration-base) var(--motion-ease-standard),
    transform var(--motion-duration-base) var(--motion-ease-standard);
}

.app .sidebar nav button > span {
  display: grid;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  place-items: center;
  border-radius: var(--radius-xs);
  color: inherit;
  font-size: 17px;
}

.app .sidebar nav button:is(:hover, .active) {
  background: var(--color-soft-mint);
  color: var(--color-primary);
}

.app .sidebar nav button.active {
  font-weight: var(--font-weight-bold);
}

.app .sidebar nav button.active::before {
  opacity: 1;
  transform: scaleY(1);
}

.app .profile-mini {
  min-height: 54px;
  margin: var(--space-3) 0 0;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text-primary);
  gap: var(--space-2);
}

.app .profile-mini > span:first-child {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  background: var(--color-mint);
  color: var(--color-primary);
}

.app .profile-mini b {
  font-size: var(--font-size-xs);
  line-height: 1.3;
}

.app .profile-mini small {
  color: var(--color-text-secondary);
  font-size: 11px;
  line-height: 1.3;
}

/* Header e ações globais */
.app .topbar {
  position: sticky;
  z-index: 12;
  top: 0;
  display: flex;
  min-height: 82px;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-3) var(--shell-gutter);
  border: 0;
  border-bottom: 1px solid var(--color-border);
  background: rgba(255, 255, 255, .92);
  box-shadow: var(--shadow-xs);
  backdrop-filter: blur(16px);
}

.app.personal-mode .topbar,
.app.business-mode .topbar {
  border-top: 2px solid var(--color-primary);
}

.app .top-identity {
  display: grid;
  min-width: 0;
  align-content: center;
  margin-right: auto;
}

.app .topbar p {
  margin: 0 0 2px;
  color: var(--color-text-secondary);
  font-size: 11px;
  font-weight: var(--font-weight-semibold);
  line-height: 1.35;
  letter-spacing: .055em;
  text-transform: uppercase;
}

.app .topbar h2 {
  margin: 0;
  color: var(--color-text-primary);
  font: var(--font-weight-bold) 17px/1.35 var(--font-family-heading);
  letter-spacing: -.025em;
}

.app .company-identity {
  max-width: min(100%, 480px);
  margin-top: var(--space-1);
  padding: 4px var(--space-2) 4px 4px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-subtle);
  color: var(--color-primary);
}

.app .company-identity-logo {
  width: 28px;
  height: 28px;
  flex-basis: 28px;
  border-radius: var(--radius-xs);
  font-size: 11px;
}

.app .company-identity b,
.app .company-identity i {
  font-size: 11px;
}

.app .top-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: var(--space-2);
}

.app .icon-btn {
  display: grid;
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  box-shadow: var(--shadow-xs);
}

.app .icon-btn:is(:hover, :focus-visible) {
  border-color: var(--color-border-strong);
  background: var(--color-soft-mint);
  color: var(--color-primary);
  transform: translateY(-1px);
}

/* O switch permanece o mesmo controle; apenas o indicador é redesenhado. */
.app .profile-switcher {
  position: relative;
  display: grid;
  width: 220px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-1);
  padding: var(--space-1);
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-subtle);
  box-shadow: inset 0 1px 2px rgba(16, 60, 54, .035);
}

.app .profile-switcher::before {
  content: "";
  position: absolute;
  z-index: 0;
  top: var(--space-1);
  left: var(--space-1);
  width: calc((100% - var(--space-3)) / 2);
  height: calc(100% - var(--space-2));
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  transform: translateX(0);
  transition: transform var(--motion-duration-slow) var(--motion-ease-emphasized),
    background-color var(--motion-duration-base) var(--motion-ease-standard);
}

.app.business-mode .profile-switcher::before {
  transform: translateX(calc(100% + var(--space-1)));
}

.app .profile-switcher button,
.app.business-mode .profile-switcher button.active {
  position: relative;
  z-index: 1;
  min-height: 36px;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-secondary);
  box-shadow: none;
  font: var(--font-weight-bold) var(--font-size-xs)/1.2 var(--font-family-heading);
}

.app .profile-switcher button.active,
.app.business-mode .profile-switcher button.active {
  color: var(--color-primary);
}

.app .profile-switcher button.unavailable {
  opacity: .72;
}

.app.business-mode .profile-switcher [data-switch-profile="pj"].active::after {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 5px;
  border-radius: 50%;
  background: var(--color-warm-accent);
  vertical-align: 2px;
}

/* Página, gutters e controles de período */
.app .page {
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: var(--space-7, 1.75rem) var(--shell-gutter) var(--space-12);
}

.app .page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-6);
}

.app .page-title h1,
.app #page-bills .page-title h1 {
  margin: 0;
  color: var(--color-text-primary);
  font: var(--font-weight-extrabold) 28px/var(--line-height-tight) var(--font-family-heading);
  letter-spacing: -.045em;
}

.app .page-title p,
.app #page-bills .page-title p {
  max-width: 680px;
  margin: var(--space-1) 0 0;
  color: var(--color-text-secondary);
  font-size: 13px;
  line-height: var(--line-height-body);
}

.app :is(.month-picker, .report-period) {
  position: relative;
  display: grid;
  min-width: 208px;
  gap: 2px;
  padding: 7px 36px 7px var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-xs);
}

.app :is(.month-picker, .report-period) > span {
  color: var(--color-text-secondary);
  font-size: 10px;
  font-weight: var(--font-weight-bold);
  line-height: 1.3;
  letter-spacing: .065em;
  text-transform: uppercase;
}

.app :is(.month-picker, .report-period)::after {
  content: "⌄";
  position: absolute;
  top: 50%;
  right: var(--space-3);
  color: var(--color-primary);
  font-size: 16px;
  transform: translateY(-50%);
  pointer-events: none;
}

.app :is(.month-picker, .report-period) .select {
  width: 100%;
  min-height: 20px;
  appearance: none;
  padding: 0;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  color: var(--color-text-primary);
  box-shadow: none;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  text-transform: capitalize;
}

.app :is(.month-picker, .report-period):focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-focus);
}

.app .btn {
  border-radius: var(--radius-md);
}

.app .btn.primary {
  box-shadow: var(--shadow-sm);
}

.app .btn.primary:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* Grid e cards base */
.app .stats-grid {
  gap: var(--shell-grid-gap);
}

.app .dashboard-grid,
.app .savings-grid,
.app .payable-report-grid,
.app .cashflow-grid {
  gap: var(--shell-grid-gap);
}

.app .dashboard-grid {
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, .9fr);
  margin-top: var(--shell-grid-gap);
}

.app .business-dashboard .dashboard-grid {
  grid-template-columns: 1fr;
}

.app .business-dashboard .recent-panel {
  grid-column: 1;
}

.app :is(.stat-card, .panel) {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-xs);
}

.app .panel {
  padding: var(--space-5);
}

.app .stat-card {
  min-height: 118px;
  padding: var(--space-5);
}

.app .stat-head,
.app .stat-card > span,
.app .payables-stats .stat-card > span,
.app .payable-report-stats .stat-card > span {
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  line-height: 1.35;
}

.app .stat-card strong,
.app .payables-stats .stat-card strong,
.app .payable-report-stats .stat-card strong {
  margin: var(--space-3) 0 var(--space-1);
  color: var(--color-text-primary);
  font: var(--font-weight-extrabold) clamp(21px, 1.8vw, 26px)/var(--line-height-tight) var(--font-family-heading);
  letter-spacing: -.035em;
}

.app .stat-card small,
.app .payables-stats .stat-card small,
.app .payable-report-stats .stat-card small {
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  line-height: 1.4;
}

.app .stat-card.balance {
  border-color: transparent;
  background: linear-gradient(140deg, var(--color-primary), var(--color-deep-green));
  box-shadow: var(--shadow-sm);
}

.app .stat-card.balance :is(strong, .stat-head, small) {
  color: var(--color-text-inverse);
}

.app .panel-title {
  align-items: flex-start;
  gap: var(--space-4);
}

.app .panel-title h3,
.app .settings-form h3,
.app .report-chart h3 {
  margin: 0;
  color: var(--color-text-primary);
  font: var(--font-weight-bold) var(--font-size-md)/var(--line-height-heading) var(--font-family-heading);
  letter-spacing: -.02em;
}

.app .panel-title p {
  margin: 3px 0 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  line-height: 1.45;
}

/* Empty states compartilhados, inclusive a primeira ação do dashboard. */
.app .empty,
.app .alerts-empty {
  display: grid;
  min-height: 112px;
  margin: var(--space-3) 0 0;
  place-items: center;
  padding: var(--space-5);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface-subtle);
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  line-height: var(--line-height-body);
  text-align: center;
}

.app .dashboard-first-action {
  min-height: 300px;
  padding: var(--space-10) var(--space-6);
  border-color: var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: radial-gradient(circle at 50% 15%, var(--color-soft-mint), var(--color-surface) 68%);
  box-shadow: var(--shadow-xs);
}

.app.business-mode .dashboard-first-action {
  border-color: var(--color-border-strong);
  background: radial-gradient(circle at 50% 15%, var(--color-soft-mint), var(--color-surface) 68%);
}

.app .dashboard-first-action > span,
.app.business-mode .dashboard-first-action > span {
  width: 54px;
  height: 54px;
  border-radius: var(--radius-md);
  background: var(--color-mint);
  color: var(--color-primary);
  font-size: 25px;
}

.app .dashboard-first-action small,
.app.business-mode .dashboard-first-action small {
  margin-top: var(--space-4);
  color: var(--color-primary);
}

.app .dashboard-first-action h2 {
  margin: var(--space-2) 0 var(--space-1);
  font-size: 24px;
}

.app .dashboard-first-action p {
  margin-bottom: var(--space-5);
}

/* Dark mode mantém a mesma anatomia do shell. */
.theme-dark .app > main {
  background-image:
    radial-gradient(circle at 96% 4%, rgba(42, 169, 156, .055), transparent 22%),
    radial-gradient(circle at 9% 94%, rgba(23, 60, 54, .24), transparent 20%);
}

.theme-dark .app .topbar {
  background: rgba(8, 29, 26, .92);
}

.theme-dark .app :is(.sidebar, .profile-mini, .icon-btn, .profile-switcher, .month-picker, .report-period, .stat-card, .panel) {
  border-color: var(--color-border);
}

.theme-dark .app :is(.sidebar, .profile-mini, .icon-btn, .month-picker, .report-period, .stat-card, .panel) {
  background-color: var(--color-surface);
}

.theme-dark .app .profile-switcher {
  background: var(--color-surface-subtle);
}

.theme-dark .app .profile-switcher::before {
  background: var(--color-surface-raised);
}

.theme-dark .app .sidebar nav button:is(:hover, .active),
.theme-dark .app .icon-btn:is(:hover, :focus-visible) {
  background: var(--color-mint);
}

@media (max-width: 1180px) {
  .app {
    --shell-gutter: var(--space-6);
  }

  .app .dashboard-grid {
    grid-template-columns: minmax(0, 1.45fr) minmax(260px, .85fr);
  }
}

@media (max-width: 1024px) {
  .app {
    --shell-gutter: var(--space-5);
  }

  .app > main,
  .app.clara-open > main {
    margin-left: 0;
    padding-bottom: 76px;
  }

  .app .sidebar {
    inset: auto 0 0;
    z-index: 15;
    display: block;
    width: 100%;
    height: auto;
    padding: 6px var(--space-3) max(6px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--color-border);
    border-right: 0;
    box-shadow: 0 -8px 28px rgba(8, 29, 26, .08);
    transform: none;
  }

  .app .sidebar::before,
  .app .sidebar > .logo,
  .app .sidebar-tip,
  .app .profile-mini {
    display: none;
  }

  .app .sidebar nav {
    display: flex;
    gap: var(--space-1);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .app .sidebar nav::-webkit-scrollbar {
    display: none;
  }

  .app .sidebar nav button {
    min-width: 74px;
    min-height: 56px;
    flex: 0 0 auto;
    flex-direction: column;
    justify-content: center;
    gap: 1px;
    padding: 5px var(--space-2);
    font-size: 11px;
    white-space: nowrap;
  }

  .app .sidebar nav button::before {
    inset: auto auto 0;
    width: 18px;
    height: 3px;
    border-radius: var(--radius-full) var(--radius-full) 0 0;
    transform: scaleX(.55);
  }

  .app .sidebar nav button.active::before {
    transform: scaleX(1);
  }

  .app .sidebar nav button > span {
    width: 20px;
    height: 20px;
    flex-basis: 20px;
    font-size: 16px;
  }

  .app .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .app .recent-panel {
    grid-column: auto;
  }
}

@media (max-width: 760px) {
  .app {
    --shell-gutter: var(--space-4);
    --shell-grid-gap: var(--space-3);
  }

  .app .topbar {
    min-height: 76px;
    gap: var(--space-3);
    padding: var(--space-3) var(--shell-gutter);
  }

  .app .top-actions {
    gap: 6px;
  }

  .app .profile-switcher {
    position: relative;
    left: auto;
    bottom: auto;
    width: 190px;
    transform: none;
    box-shadow: inset 0 1px 2px rgba(16, 60, 54, .035);
  }

  .app .profile-switcher button,
  .app.business-mode .profile-switcher button.active {
    padding-inline: var(--space-2);
  }

  .app #theme-toggle {
    display: grid;
  }

  .app .page {
    padding-top: var(--space-6);
    padding-bottom: var(--space-10);
  }

  .app .page-title {
    align-items: flex-start;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
  }

  .app .page-title h1,
  .app #page-bills .page-title h1 {
    font-size: 25px;
  }

  .app .stat-card {
    min-height: 108px;
    padding: var(--space-4);
  }

  .app .panel {
    padding: var(--space-4);
  }

  .app .dashboard-first-action {
    min-height: 270px;
    padding: var(--space-8) var(--space-5);
  }
}

@media (max-width: 620px) {
  .app .topbar {
    min-height: 0;
    align-items: stretch;
    flex-direction: column;
    padding-block: var(--space-3);
  }

  .app .top-actions {
    width: 100%;
  }

  .app .profile-switcher-wrap {
    min-width: 0;
    flex: 1 1 auto;
    margin-right: 0;
  }

  .app .profile-switcher {
    width: 100%;
  }

  .app .page-title {
    flex-direction: column;
  }

  .app :is(.month-picker, .report-period) {
    width: 100%;
    min-width: 0;
    margin-top: 0;
  }
}

@media (max-width: 470px) {
  .app .stats-grid,
  .app .business-dashboard > .stats-grid,
  .app .business-stats,
  .app .report-stats,
  .app .payables-stats,
  .app .payable-report-stats {
    grid-template-columns: 1fr;
  }

  .app .topbar p {
    font-size: 10px;
  }

  .app .topbar h2 {
    font-size: var(--font-size-md);
  }

  .app .icon-btn {
    width: 38px;
    min-width: 38px;
    height: 38px;
  }
}
